-
Notifications
You must be signed in to change notification settings - Fork 0
/
act_admin.go
56 lines (48 loc) · 1.36 KB
/
act_admin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package axb
import (
"os"
"strings"
"github.com/keybase/go-keybase-chat-bot/kbchat"
)
func doShutdown(bot *Bot, msg *kbchat.SubscriptionMessage, args []string) error {
if len(args) != 3 || args[1] != "bot" || args[2] != "now" {
return bot.ReplyTo(msg, "you must `shutdown bot now`")
}
bot.ReplyTo(msg, "Goodbye cruel world!")
os.Exit(0)
return nil
}
func doPrintAdmins(bot *Bot, msg *kbchat.SubscriptionMessage, args []string) error {
var sb strings.Builder
sb.WriteString("Admins are: ")
isFirst := true
for _, v := range bot.admins {
if !isFirst {
sb.WriteString(", ")
}
sb.WriteString(v)
isFirst = false
}
return bot.ReplyTo(msg, sb.String())
}
func doAddAdmin(bot *Bot, msg *kbchat.SubscriptionMessage, args []string) error {
if len(args) != 2 {
return bot.ReplyTo(msg, "syntax 'add_admin <username>'")
}
bot.admins = append(bot.admins, args[1])
return bot.ReplyTo(msg, "Added %s as an admin", args[1])
}
func doRemoveAdmin(bot *Bot, msg *kbchat.SubscriptionMessage, args []string) error {
var newadmins []string
if len(args) != 2 {
return bot.ReplyTo(msg, "syntax 'remove_admin <username>'")
}
for _, v := range bot.admins {
if v == args[1] {
continue
}
newadmins = append(newadmins, v)
}
bot.admins = newadmins
return bot.ReplyTo(msg, "Removed %s as an admin", args[1])
}