forked from johansundell/cocbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremovehopper.go
More file actions
37 lines (35 loc) · 1004 Bytes
/
removehopper.go
File metadata and controls
37 lines (35 loc) · 1004 Bytes
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
package main
import (
"context"
"strings"
)
func init() {
key := commandFunc{"!remove hopper [name]", "Remove hopper warnings", "", categoryAdmin}
lockMap.Lock()
defer lockMap.Unlock()
botFuncs[key] = func(ctx context.Context, command string) (string, error) {
cmd := strings.Replace(key.command, " [name]", "", -1)
if strings.HasPrefix(command, cmd) {
s, msg, err := getSessionsAndMessageFromContext(ctx)
if err != nil {
return "", err
}
if doesMemberHasAdminAccess(s, msg) || isSudde(msg) {
name := strings.TrimSpace(command[len(cmd):])
if len(name) > 0 {
res, err := db.Exec("UPDATE members SET exited = 0 WHERE name = ?", name)
if err != nil {
return "", nil
}
if n, err := res.RowsAffected(); err == nil && n > 0 {
return "Removed hopper warning for " + name, nil
}
return "Could not find member " + name + " or (s)he had no warnings", nil
}
} else {
return securityMessage, nil
}
}
return "", nil
}
}