refine shutup feature
This commit is contained in:
parent
ed2d94f810
commit
e0f0f2d282
7 changed files with 70 additions and 48 deletions
48
bot.go
48
bot.go
|
@ -1,15 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
|
||||||
"log"
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
"watn3y/bloaterbotv3/botIO"
|
"watn3y/bloaterbotv3/botIO"
|
||||||
"watn3y/bloaterbotv3/commonlogic"
|
"watn3y/bloaterbotv3/commands"
|
||||||
"watn3y/bloaterbotv3/config"
|
"watn3y/bloaterbotv3/text"
|
||||||
"watn3y/bloaterbotv3/text/nhentai"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var shutuptime time.Time
|
var shutuptime time.Time
|
||||||
|
@ -23,48 +18,13 @@ func bot() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if update.Message.IsCommand() {
|
if update.Message.IsCommand() {
|
||||||
go commands(update, bot)
|
commands.Commands(update, bot)
|
||||||
} else {
|
} else {
|
||||||
if time.Since(shutuptime).Minutes() >= 60 {
|
if time.Since(shutuptime).Minutes() >= 60 {
|
||||||
go textMatcher(update, bot)
|
text.Matcher(update, bot)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func textMatcher(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|
||||||
|
|
||||||
//nhentai
|
|
||||||
const nhentaiRegex string = "([ \\t\\n\\r]|^)\\d{2,}([ \\t\\n\\r]|$)"
|
|
||||||
isNhentai, err := regexp.MatchString(nhentaiRegex, update.Message.Text)
|
|
||||||
if err != nil {
|
|
||||||
log.Panicf("Failed to compile regex for nhentai", err)
|
|
||||||
}
|
|
||||||
if isNhentai && commonlogic.ContainsInt64(config.BotConfig.Nhentai.EnabledChats, update.Message.Chat.ID) {
|
|
||||||
go nhentai.Nhentai(nhentaiRegex, update, bot)
|
|
||||||
}
|
|
||||||
|
|
||||||
//balonlyl
|
|
||||||
var isBalonlyl bool = false
|
|
||||||
for _, word := range config.BotConfig.Balonlyl.TriggerWords {
|
|
||||||
if strings.Contains(strings.ToLower(update.Message.Text), word) && commonlogic.ContainsInt64(config.BotConfig.Balonlyl.EnabledChats, update.Message.Chat.ID) {
|
|
||||||
isBalonlyl = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if isBalonlyl {
|
|
||||||
go balonlyl(update, bot)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func commands(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|
||||||
if strings.ToLower(update.Message.Command()) == "shutup" || strings.ToLower(update.Message.Command()) == "shut" {
|
|
||||||
shutuptime = time.Now().UTC()
|
|
||||||
|
|
||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Shutting up")
|
|
||||||
botIO.SendMessage(msg, bot)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
4
build.sh
Normal file
4
build.sh
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
###!/usr/bin/env bash
|
||||||
|
|
||||||
|
HASH=$(git log -1 --pretty=%h)
|
||||||
|
docker build -t bloaterbot:latest -t bloaterbot:$HASH .
|
|
@ -1 +0,0 @@
|
||||||
package main
|
|
17
commands/commands.go
Normal file
17
commands/commands.go
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
"watn3y/bloaterbotv3/botIO"
|
||||||
|
"watn3y/bloaterbotv3/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Commands(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
||||||
|
if strings.ToLower(update.Message.Command()) == "shutup" || strings.ToLower(update.Message.Command()) == "shut" {
|
||||||
|
config.BotConfig.Shutup[update.Message.Chat.ID] = time.Now().UTC()
|
||||||
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Shutting up")
|
||||||
|
botIO.SendMessage(msg, bot)
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,7 +12,7 @@ type config struct {
|
||||||
APIToken string
|
APIToken string
|
||||||
DebugMode bool
|
DebugMode bool
|
||||||
PrivilegedUsers []int64
|
PrivilegedUsers []int64
|
||||||
ShutupTime time.Time
|
Shutup map[int64]time.Time
|
||||||
Nhentai struct {
|
Nhentai struct {
|
||||||
EnabledChats []int64
|
EnabledChats []int64
|
||||||
APIEndpoint string
|
APIEndpoint string
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package balonlyl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||||
|
@ -6,7 +6,7 @@ import (
|
||||||
"watn3y/bloaterbotv3/config"
|
"watn3y/bloaterbotv3/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func balonlyl(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
func Balonlyl(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
||||||
|
|
||||||
/*balonlylLines := [4]string{
|
/*balonlylLines := [4]string{
|
||||||
balonlylAT + " they're talking about you",
|
balonlylAT + " they're talking about you",
|
42
text/matcher.go
Normal file
42
text/matcher.go
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
package text
|
||||||
|
|
||||||
|
import (
|
||||||
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||||
|
"log"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
"watn3y/bloaterbotv3/commonlogic"
|
||||||
|
"watn3y/bloaterbotv3/config"
|
||||||
|
"watn3y/bloaterbotv3/text/balonlyl"
|
||||||
|
"watn3y/bloaterbotv3/text/nhentai"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Matcher(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
||||||
|
if time.Since(config.BotConfig.Shutup[update.Message.Chat.ID]) <= time.Minute {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//nhentai
|
||||||
|
const nhentaiRegex string = "([ \\t\\n\\r]|^)\\d{2,}([ \\t\\n\\r]|$)"
|
||||||
|
isNhentai, err := regexp.MatchString(nhentaiRegex, update.Message.Text)
|
||||||
|
if err != nil {
|
||||||
|
log.Panicf("Failed to compile regex for nhentai", err)
|
||||||
|
}
|
||||||
|
if isNhentai && commonlogic.ContainsInt64(config.BotConfig.Nhentai.EnabledChats, update.Message.Chat.ID) {
|
||||||
|
go nhentai.Nhentai(nhentaiRegex, update, bot)
|
||||||
|
}
|
||||||
|
|
||||||
|
//balonlyl
|
||||||
|
var isBalonlyl bool = false
|
||||||
|
for _, word := range config.BotConfig.Balonlyl.TriggerWords {
|
||||||
|
if strings.Contains(strings.ToLower(update.Message.Text), word) && commonlogic.ContainsInt64(config.BotConfig.Balonlyl.EnabledChats, update.Message.Chat.ID) {
|
||||||
|
isBalonlyl = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if isBalonlyl {
|
||||||
|
go balonlyl.Balonlyl(update, bot)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue