Merge pull request #148 from velour/help

help: fix the help system after I borke it
This commit is contained in:
Chris Sexton 2019-02-12 12:31:02 -05:00 committed by GitHub
commit e7ac991b42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View File

@ -22,7 +22,7 @@ func (b *bot) Receive(kind Kind, msg msg.Message, args ...interface{}) bool {
// msg := b.buildMessage(client, inMsg)
// do need to look up user and fix it
if kind == Message && strings.HasPrefix(msg.Body, "help ") && msg.Command {
if kind == Message && strings.HasPrefix(msg.Body, "help") && msg.Command {
parts := strings.Fields(strings.ToLower(msg.Body))
b.checkHelp(msg.Channel, parts)
goto RET
@ -64,6 +64,7 @@ func (b *bot) checkHelp(channel string, parts []string) {
// just print out a list of help topics
topics := "Help topics: about variables"
for name, _ := range b.plugins {
name = strings.Split(strings.TrimPrefix(name, "*"), ".")[0]
topics = fmt.Sprintf("%s, %s", topics, name)
}
b.Send(Message, channel, topics)
@ -77,14 +78,20 @@ func (b *bot) checkHelp(channel string, parts []string) {
b.listVars(channel, parts)
return
}
plugin, ok := b.plugins[parts[1]]
if ok {
b.runCallback(plugin, Help, msg.Message{Channel: channel}, channel, parts)
for name, plugin := range b.plugins {
if strings.HasPrefix(name, "*"+parts[1]) {
if b.runCallback(plugin, Help, msg.Message{Channel: channel}, channel, parts) {
return
} else {
msg := fmt.Sprintf("I'm sorry, I don't know what %s is!", parts[1])
msg := fmt.Sprintf("I'm sorry, I don't know how to help you with %s.", parts[1])
b.Send(Message, channel, msg)
return
}
}
}
msg := fmt.Sprintf("I'm sorry, I don't know what %s is!", strings.Join(parts, " "))
b.Send(Message, channel, msg)
}
}
func (b *bot) LastMessage(channel string) (msg.Message, error) {

View File

@ -78,6 +78,7 @@ func New(b bot.Bot) *TwitchPlugin {
}
b.Register(p, bot.Message, p.message)
b.Register(p, bot.Help, p.help)
p.registerWeb()
return p
@ -144,6 +145,7 @@ func (p *TwitchPlugin) help(kind bot.Kind, message msg.Message, args ...interfac
msg += fmt.Sprintf("twitch.istpl (default: %s)\n", isStreamingTplFallback)
msg += fmt.Sprintf("twitch.nottpl (default: %s)\n", notStreamingTplFallback)
msg += fmt.Sprintf("twitch.stoppedtpl (default: %s)\n", stoppedStreamingTplFallback)
msg += "You can reset all messages with `!reset twitch`"
msg += "And you can ask who is streaming with `!twitch status`"
p.Bot.Send(bot.Message, message.Channel, msg)
return true