/
WisdomCmd.go
70 lines (61 loc) · 1.97 KB
/
WisdomCmd.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
package commands
import (
"context"
"errors"
"fmt"
"github.com/cancelledbit/pizda_bot/app/repository"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"log"
"math"
"os"
"strconv"
"time"
)
type WisdomCmd struct {
dbCmd
AuthorId string
UserName string
}
func (c WisdomCmd) Execute(cmd *tgbotapi.Message) {
count, err := strconv.Atoi(cmd.CommandArguments())
if err != nil || count == 0 {
count = 1
}
maxPhrases, err := strconv.Atoi(os.Getenv("MAX_PHRASES_GEN"))
if err != nil {
maxPhrases = 3
}
count = int(math.Min(float64(count), float64(maxPhrases)))
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
defer cancel()
r := repository.UserWisdomRepository(ctx, c.DB)
phrases, err := r.Get(c.AuthorId, count)
if err != nil {
log.Println(err)
return
}
text := fmt.Sprintf("%s когда-то сказал: \n", c.UserName)
for _, p := range phrases {
text += fmt.Sprintf("%s \n", p.Text)
}
reply := tgbotapi.NewMessage(cmd.Chat.ID, text)
reply.ReplyToMessageID = cmd.MessageID
_, err = c.Bot.Send(reply)
if err != nil {
log.Println(err)
}
}
func GetWisdomUserPattern(userId int64) (string, error) {
config := map[int64]string{
5167519420: "/(\\sпис[яею])|(\\sпоп[аук])|(износ)|(накур)|(дудк)|(\\sвон[яю])|(\\sнож[ек])|(\\sслад)|(\\sхагз)|(\\sдево[нч])|(черк)|(лиза)|(\\sкончи)|(\\sжоп)/iu",
5865654725: "/\\s(ир[аоу])|(секс)|(муж)|(п[еи]зд)|(сос)|(ваг)|(сис)|(пис)|(ху)/iu",
409842850: "/\\s(ебл)|(секс)|(муж)|(нарк)|(мото)|(дудк)|(трава)|(баб)|(гомо)|(геи)/iu",
5655245858: "/\\s(монгол)|(коре)|(казах)|(п[еи]тон)|(сперм)|(секс)|(ганд)|(джанг)|(апи)|(ма[мт])|(ксан)|(клуб)|(бар)|(рейв)/iu",
418587687: "/.{80}/",
}
pattern, ok := config[userId]
if ok {
return pattern, nil
}
return "", errors.New("pattern not found")
}