-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug.go
More file actions
63 lines (52 loc) · 1.2 KB
/
debug.go
File metadata and controls
63 lines (52 loc) · 1.2 KB
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
57
58
59
60
61
62
63
package main
import (
"strings"
"sync"
"github.com/AshokShau/gotdbot"
)
var chatDebugState = struct {
mu sync.RWMutex
state map[int64]bool
}{
state: make(map[int64]bool),
}
func isDebugEnabled(chatID int64) bool {
if chatID == 0 {
return true
}
chatDebugState.mu.RLock()
enabled, ok := chatDebugState.state[chatID]
chatDebugState.mu.RUnlock()
if !ok {
return true
}
return enabled
}
func setDebugEnabled(chatID int64, enabled bool) {
if chatID == 0 {
return
}
chatDebugState.mu.Lock()
chatDebugState.state[chatID] = enabled
chatDebugState.mu.Unlock()
}
func debugCommandHandler(c *gotdbot.Client, ctx *gotdbot.Context) error {
m := ctx.EffectiveMessage
chatID := ctx.EffectiveChatId
parts := strings.Fields(m.GetText())
if len(parts) < 2 {
_, _ = m.ReplyText(c, "Usage: /debug on|off", nil)
return gotdbot.EndGroups
}
switch strings.ToLower(parts[1]) {
case "on":
setDebugEnabled(chatID, true)
_, _ = m.ReplyText(c, "Debug logger is now ON for this chat.", nil)
case "off":
setDebugEnabled(chatID, false)
_, _ = m.ReplyText(c, "Debug logger is now OFF for this chat.", nil)
default:
_, _ = m.ReplyText(c, "Usage: /debug on|off", nil)
}
return gotdbot.EndGroups
}