-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_caps.go
56 lines (40 loc) · 1.04 KB
/
filter_caps.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 garvis
import (
"regexp"
"strings"
"golang.org/x/net/context"
"github.com/go-telegram-bot-api/telegram-bot-api"
)
type CapsFilter struct {
bot *tgbotapi.BotAPI
ctx context.Context
done chan bool
}
func (filter CapsFilter) Run(update tgbotapi.Update) error {
m := update.Message.Text
if checkCapsFilter(m) {
filter.Trigger(update)
}
filter.done <- true
return nil
}
func (filter CapsFilter) GetCommands(map[string]Filter) {
}
func (filter CapsFilter) RunCommand(string, CommandArguments) {
}
func (filter CapsFilter) Trigger(update tgbotapi.Update) {
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "SHUT THE FUCK UP MATE")
filter.bot.Send(msg)
}
func checkCapsFilter(m string) bool {
// Strip emojis and symbols
emojiRx := regexp.MustCompile(`[\x{1F600}-\x{1F6FF}|[\x{2600}-\x{26FF}]|[^\pL\s]`)
m = emojiRx.ReplaceAllString(m, ``)
// Exclude laughing
laughingRx := regexp.MustCompile(`((H|X)A)+`)
m = laughingRx.ReplaceAllString(m, ``)
if m == strings.ToUpper(m) && len(m) > 5 {
return true
}
return false
}