This repository has been archived by the owner on Jul 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.go
131 lines (109 loc) · 3.04 KB
/
event.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package actions
import (
"github.com/chronophylos/chb3/nominatim"
"github.com/chronophylos/chb3/openweather"
"github.com/chronophylos/chb3/state"
"github.com/gempir/go-twitch-irc/v2"
"github.com/rs/zerolog"
)
var botNames = []string{"nightbot", "fossabot", "streamelements"}
// Permission is a int
type Permission int
// Possible values for Permission.
const (
Everyone Permission = iota
Subscriber
Regular
Moderator
Broadcaster
Owner
)
type Event struct {
Log zerolog.Logger
Twitch *twitch.Client
State *state.Client
Weather *openweather.Client
Location *nominatim.Client
ImgurClientID string
BotName string
Debug bool
Msg *twitch.PrivateMessage
Match []string
Sleeping bool
Perm Permission
Skipped bool
}
// Init sets some internal values like the permission of the sender.
func (e *Event) Init() {
switch {
case e.IsOwner():
e.Perm = Owner
case e.IsBroadcaster():
e.Perm = Broadcaster
case e.IsModerator():
e.Perm = Moderator
case e.IsRegular():
e.Perm = Regular
case e.IsSubscriber():
e.Perm = Subscriber
}
// no need to set e.Perm to Everyone since it is the default.
}
// Say sends message to the current channel.
func (e *Event) Say(message string) {
e.Twitch.Say(e.Msg.Channel, message)
}
// HasPermission compares perm with the permission level of the sender and
// reports wheather the sender has a permission of at least perm.
func (e *Event) HasPermission(perm Permission) bool {
return e.Perm >= perm
}
// IsCoolingDown reports wheather the command is available or if it is cooling
// down.
// This could be because of a user, channel or command cooldown.
// TODO: implement
func (e *Event) IsCoolingDown() bool {
return false
}
// IsRegular reports wheather the sender is a regular.
// TODO: implement
func (e *Event) IsRegular() bool { return false }
// IsSubscriber reports wheather the sender is a subscriber in the current
// channel.
func (e *Event) IsSubscriber() bool {
return e.Msg.Tags["subscriber"] == "1"
}
// IsModerator reports wheather the sender is a moderator in the current
// channel.
func (e *Event) IsModerator() bool {
return e.Msg.Tags["mod"] == "1"
}
// IsBroadcaster reports wheather the sender is the owner of the current
// channel.
func (e *Event) IsBroadcaster() bool {
return e.Msg.User.Name == e.Msg.Channel
}
// IsOwner reports wheather the sender is the bots owner.
func (e *Event) IsOwner() bool {
return e.Msg.User.ID == "54946241"
}
// IsBot reports wheather the message was sent by a bot.
// Currently it compares the name of the sender with a list of know bots.
// TODO: check in other places eg. badges
func (e *Event) IsBot() bool {
for _, name := range botNames {
if e.Msg.User.Name == name {
return true
}
}
return false
}
// IsInBotChannel reports wheather the current channel is owned by the bot.
func (e *Event) IsInBotChannel() bool {
return e.Msg.Channel == e.BotName
}
// Skip skips this command and allows other commands to run.
func (e *Event) Skip() {
e.Skipped = true
}
//go:generate stringer -type=Permission