Make Notice() not do string formatting anymore

In various places, we build messages using `Sprintf` before passing them
to `Notice()`.

If we let `Notice()` do string formatting, we run the chance of having
it try to format our already-preformatted text. If our text includes
format references (e.g. `%s`), it would cause a problem (`%s(MISSING)`).

One way to trigger it is to change the bot prefix from `!pm` to `%pm`.
Doing so, `sendHelp()` would create some help message which contains
`%pm` references. `Notice()` would then try to process them as well,
leading to a bunch of `%!p(MISSING)m` in the final text.
This commit is contained in:
Slavi Pantaleev
2022-08-25 10:49:52 +03:00
parent 7e1b7f5c08
commit 1babbb7169
2 changed files with 6 additions and 6 deletions

View File

@@ -61,8 +61,8 @@ func (b *Bot) Error(ctx context.Context, roomID id.RoomID, message string, args
}
// Notice sends a notice message to the matrix room
func (b *Bot) Notice(ctx context.Context, roomID id.RoomID, message string, args ...interface{}) {
content := format.RenderMarkdown(fmt.Sprintf(message, args...), true, true)
func (b *Bot) Notice(ctx context.Context, roomID id.RoomID, message string) {
content := format.RenderMarkdown(message, true, true)
content.MsgType = event.MsgNotice
_, err := b.lp.Send(roomID, &content)
if err != nil {