mirror of https://github.com/velour/catbase.git
admin: leave and come back
This commit is contained in:
parent
1166fc732e
commit
cee267dbb8
|
@ -50,6 +50,8 @@ type bot struct {
|
||||||
|
|
||||||
password string
|
password string
|
||||||
passwordCreated time.Time
|
passwordCreated time.Time
|
||||||
|
|
||||||
|
quiet bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type EndPoint struct {
|
type EndPoint struct {
|
||||||
|
@ -259,3 +261,7 @@ func (b *bot) GetPassword() string {
|
||||||
}
|
}
|
||||||
return b.password
|
return b.password
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *bot) SetQuiet(status bool) {
|
||||||
|
b.quiet = status
|
||||||
|
}
|
||||||
|
|
|
@ -54,6 +54,9 @@ func (b *bot) runCallback(conn Connector, plugin Plugin, evt Kind, message msg.M
|
||||||
|
|
||||||
// Send a message to the connection
|
// Send a message to the connection
|
||||||
func (b *bot) Send(conn Connector, kind Kind, args ...interface{}) (string, error) {
|
func (b *bot) Send(conn Connector, kind Kind, args ...interface{}) (string, error) {
|
||||||
|
if b.quiet {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
return conn.Send(kind, args...)
|
return conn.Send(kind, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,7 @@ type Bot interface {
|
||||||
DefaultConnector() Connector
|
DefaultConnector() Connector
|
||||||
GetWebNavigation() []EndPoint
|
GetWebNavigation() []EndPoint
|
||||||
GetPassword() string
|
GetPassword() string
|
||||||
|
SetQuiet(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connector represents a server connection to a chat service
|
// Connector represents a server connection to a chat service
|
||||||
|
|
|
@ -33,6 +33,7 @@ func (mb *MockBot) Who(string) []user.User { return []user.User{} }
|
||||||
func (mb *MockBot) WhoAmI() string { return "tester" }
|
func (mb *MockBot) WhoAmI() string { return "tester" }
|
||||||
func (mb *MockBot) DefaultConnector() Connector { return nil }
|
func (mb *MockBot) DefaultConnector() Connector { return nil }
|
||||||
func (mb *MockBot) GetPassword() string { return "12345" }
|
func (mb *MockBot) GetPassword() string { return "12345" }
|
||||||
|
func (mb *MockBot) SetQuiet(bool) {}
|
||||||
func (mb *MockBot) Send(c Connector, kind Kind, args ...interface{}) (string, error) {
|
func (mb *MockBot) Send(c Connector, kind Kind, args ...interface{}) (string, error) {
|
||||||
switch kind {
|
switch kind {
|
||||||
case Message:
|
case Message:
|
||||||
|
|
|
@ -55,7 +55,7 @@ var forbiddenKeys = map[string]bool{
|
||||||
func (p *AdminPlugin) message(conn bot.Connector, k bot.Kind, message msg.Message, args ...interface{}) bool {
|
func (p *AdminPlugin) message(conn bot.Connector, k bot.Kind, message msg.Message, args ...interface{}) bool {
|
||||||
body := message.Body
|
body := message.Body
|
||||||
|
|
||||||
if p.quiet {
|
if p.quiet && message.Body != "come back" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +67,14 @@ func (p *AdminPlugin) message(conn bot.Connector, k bot.Kind, message msg.Messag
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if p.quiet && message.Body == "come back" {
|
||||||
|
p.quiet = false
|
||||||
|
p.bot.SetQuiet(false)
|
||||||
|
backMsg := p.bot.Config().Get("admin.comeback", "Okay, I'm back.")
|
||||||
|
p.bot.Send(conn, bot.Message, message.Channel, backMsg)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
if strings.ToLower(body) == "reboot" {
|
if strings.ToLower(body) == "reboot" {
|
||||||
p.bot.Send(conn, bot.Message, message.Channel, "brb")
|
p.bot.Send(conn, bot.Message, message.Channel, "brb")
|
||||||
log.Info().Msgf("Got reboot command")
|
log.Info().Msgf("Got reboot command")
|
||||||
|
@ -76,13 +84,18 @@ func (p *AdminPlugin) message(conn bot.Connector, k bot.Kind, message msg.Messag
|
||||||
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))
|
||||||
p.bot.Send(conn, bot.Message, message.Channel, "Okay. I'll be back later.")
|
leaveMsg := p.bot.Config().Get("admin.shutup", "Okay. I'll be back later.")
|
||||||
|
p.bot.Send(conn, bot.Message, message.Channel, leaveMsg)
|
||||||
p.quiet = true
|
p.quiet = true
|
||||||
|
p.bot.SetQuiet(true)
|
||||||
go func() {
|
go func() {
|
||||||
select {
|
select {
|
||||||
case <-time.After(dur):
|
case <-time.After(dur):
|
||||||
p.quiet = false
|
p.quiet = false
|
||||||
|
p.bot.SetQuiet(false)
|
||||||
log.Info().Msg("Waking up from nap.")
|
log.Info().Msg("Waking up from nap.")
|
||||||
|
backMsg := p.bot.Config().Get("admin.backmsg", "I'm back, bitches.")
|
||||||
|
p.bot.Send(conn, bot.Message, message.Channel, backMsg)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in New Issue