-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
87 lines (72 loc) · 2.17 KB
/
main.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
package main
import (
"encoding/json"
"fmt"
"time"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
var bot *tgbotapi.BotAPI
func connectBot(token string) (updates tgbotapi.UpdatesChannel, err error) {
bot, err = tgbotapi.NewBotAPI(token)
if err != nil {
return nil, err
}
bot.Debug = true
updateConfig := tgbotapi.NewUpdate(0)
updateConfig.Timeout = 30
updates = bot.GetUpdatesChan(updateConfig)
return updates, err
}
func spamer() {
for {
time.Sleep(time.Duration(time.Millisecond * 1000 * 5))
orders := readConfirmedOrder(time.Millisecond * 1000 * 5)
fmt.Println(len(orders))
for _, order := range orders {
fmt.Println(order)
order.State = WaitRated
updateOrder(&order)
acceptRatingDataJson, _ := json.Marshal(CallbackRatingData{
Type: AcceptRating,
Id: order.Id,
})
rejectRatingDataJson, _ := json.Marshal(CallbackRatingData{
Type: RejectRating,
Id: order.Id,
})
checkExecutedOrderMessage := tgbotapi.NewMessage(order.CustomerId, "Ваш"+" [заказ](https://t.me/krumos/"+fmt.Sprint(order.MessageId)+") уже выполнен?")
RatingButtonConfig := tgbotapi.NewInlineKeyboardMarkup(
tgbotapi.NewInlineKeyboardRow(
tgbotapi.NewInlineKeyboardButtonData("Да", string(acceptRatingDataJson)),
tgbotapi.NewInlineKeyboardButtonData("Нет", string(rejectRatingDataJson)),
))
checkExecutedOrderMessage.ReplyMarkup = RatingButtonConfig
checkExecutedOrderMessage.ParseMode = tgbotapi.ModeMarkdownV2
bot.Send(checkExecutedOrderMessage)
}
}
}
func main() {
getText("texts.yaml")
var config Config
err := config.getConfig()
if err != nil {
panic(err)
}
updates, err := connectBot(config.Token)
if err != nil {
panic(err)
}
connectDB(":5432", "postgres", "password", "postgres")
go spamer()
for update := range updates {
if update.CallbackQuery != nil {
// прилетел апдейт с инлайн кнопок
responseStateMachine(update, &config)
}
if update.Message != nil {
// обычное сообщение
commandsStateMachine(update, &config)
}
}
}