package help import ( "testing" "unicode/utf8" "github.com/bwmarrin/discordgo" ) // Discord refuses an embed that is over its limits, and then /help would send // nothing. This catches it when a command is added to the text. func TestHelpFitsDiscordsLimits(t *testing.T) { list := embeds(&discordgo.MessageEmbedAuthor{Name: "Velox Bot"}) if len(list) == 0 { t.Fatal("no help") } seen := 0 for n, e := range list { total := utf8.RuneCountInString(e.Title) + utf8.RuneCountInString(e.Description) if len(e.Fields) > 25 { t.Errorf("embed %d has %d fields, at most 25", n, len(e.Fields)) } for _, f := range e.Fields { seen++ if l := utf8.RuneCountInString(f.Value); l == 0 || l > maxFieldChars { t.Errorf("field %q has %d characters, must be 1 to %d", f.Name, l, maxFieldChars) } if l := utf8.RuneCountInString(f.Name); l == 0 || l > 256 { t.Errorf("field name %q has %d characters, at most 256", f.Name, l) } total += fieldSize(f) } if total > 6000 { t.Errorf("embed %d has %d characters, Discord allows 6000", n, total) } } if seen != len(fields()) { t.Errorf("%d fields shown of %d", seen, len(fields())) } } // The help is meant to be wide and short: inline fields, so Discord puts // three side by side, and it should fit in one message. func TestHelpIsCompactAndInline(t *testing.T) { if n := len(embeds(&discordgo.MessageEmbedAuthor{Name: "Velox Bot"})); n != 1 { t.Errorf("the help should fit in one message, it takes %d", n) } inline := 0 for _, f := range fields() { if f.Inline { inline++ } } if inline < len(fields())-2 { t.Errorf("only %d of %d fields are inline", inline, len(fields())) } }