Compare commits

...

3 Commits

Author SHA1 Message Date
Chris Sexton 21d4b11df9 admin: add reboot command 2020-04-21 16:54:03 -04:00
Chris Sexton d0998d0a63 emojifyme: don't crash when github isn't available
Note: we probably need some command to re-slurp this address or a
command to restart the bot in the event that something went terribly
wrong.
2020-04-21 16:54:03 -04:00
Chris Sexton 0b553da32d bot: respond to commands given by a message suffix 2020-04-21 16:54:03 -04:00
3 changed files with 17 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import (
"math/rand" "math/rand"
"net/http" "net/http"
"reflect" "reflect"
"regexp"
"strings" "strings"
"time" "time"
@ -142,10 +143,16 @@ func (b *bot) Who(channel string) []user.User {
return users return users
} }
var suffixRegex *regexp.Regexp
// IsCmd checks if message is a command and returns its curtailed version // IsCmd checks if message is a command and returns its curtailed version
func IsCmd(c *config.Config, message string) (bool, string) { func IsCmd(c *config.Config, message string) (bool, string) {
cmdcs := c.GetArray("CommandChar", []string{"!"}) cmdcs := c.GetArray("CommandChar", []string{"!"})
botnick := strings.ToLower(c.Get("Nick", "bot")) botnick := strings.ToLower(c.Get("Nick", "bot"))
r := fmt.Sprintf(`(?i)\s*\W*\s*?%s\W*$`, botnick)
if suffixRegex == nil {
suffixRegex = regexp.MustCompile(r)
}
if botnick == "" { if botnick == "" {
log.Fatal(). log.Fatal().
Msgf(`You must run catbase -set nick -val <your bot nick>`) Msgf(`You must run catbase -set nick -val <your bot nick>`)
@ -164,6 +171,9 @@ func IsCmd(c *config.Config, message string) (bool, string) {
if message[0] == ':' || message[0] == ',' { if message[0] == ':' || message[0] == ',' {
message = message[1:] message = message[1:]
} }
} else if suffixRegex.MatchString(message) {
iscmd = true
message = suffixRegex.ReplaceAllString(message, "")
} else { } else {
for _, cmdc := range cmdcs { for _, cmdc := range cmdcs {
if strings.HasPrefix(lowerMessage, cmdc) && len(cmdc) > 0 { if strings.HasPrefix(lowerMessage, cmdc) && len(cmdc) > 0 {

View File

@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"html/template" "html/template"
"net/http" "net/http"
"os"
"strings" "strings"
"time" "time"
@ -66,6 +67,11 @@ func (p *AdminPlugin) message(conn bot.Connector, k bot.Kind, message msg.Messag
return false return false
} }
if strings.ToLower(body) == "reboot" {
log.Info().Msgf("Got reboot command")
os.Exit(0)
}
if strings.ToLower(body) == "shut up" { if strings.ToLower(body) == "shut up" {
dur := time.Duration(p.cfg.GetInt("quietDuration", 5)) * time.Minute dur := time.Duration(p.cfg.GetInt("quietDuration", 5)) * time.Minute
log.Info().Msgf("Going to sleep for %v, %v", dur, time.Now().Add(dur)) log.Info().Msgf("Going to sleep for %v, %v", dur, time.Now().Add(dur))

View File

@ -39,7 +39,7 @@ func New(b bot.Bot) *EmojifyMePlugin {
var emoji []Emoji var emoji []Emoji
err = json.Unmarshal(body, &emoji) err = json.Unmarshal(body, &emoji)
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("Error parsing emoji list") log.Error().Err(err).Msg("Error parsing emoji list")
} }
emojiMap := map[string]string{} emojiMap := map[string]string{}