func RunCommandBatch(commandLines [][]string, post discourse.S_Post, bot *discourse.DiscourseSite) { log.Info("Processing commands in post", post.Topic_id, post.Post_number, commandLines) var context = CommandContext{ User: CredentialsFromPost(post), Post: post, Bot: bot, replyBuffer: make([]string, 0), } for _, command := range commandLines { log.Debug(command[1], "X", command[2]) if HasCommand(command[1]) { RunCommand(command[1], command[2], &context) } else { log.Warn("No such command", command[1]) } } if context.redis != nil { context.redis.Close() } if len(context.replyBuffer) > 0 { bot.Reply(post.Topic_id, post.Post_number, strings.Join(context.replyBuffer, "\n\n")) } }
func WithRedis(bot *discourse.DiscourseSite, f func(redis.Conn)) { conn := bot.TakeUnsharedRedis() defer conn.Close() f(conn) }