2023-01-24 02:24:45 +03:00
|
|
|
package main
|
|
|
|
|
2023-01-24 23:17:30 +03:00
|
|
|
import (
|
|
|
|
"fmt"
|
2023-06-07 21:21:54 +03:00
|
|
|
"log"
|
2023-04-13 11:13:24 +03:00
|
|
|
"math/rand"
|
2023-01-24 23:17:30 +03:00
|
|
|
|
|
|
|
"git.nefrace.ru/nefrace/nechotron"
|
|
|
|
"git.nefrace.ru/nefrace/tongo"
|
|
|
|
)
|
|
|
|
|
2023-06-13 02:22:44 +03:00
|
|
|
// Docs
|
2023-04-13 11:13:24 +03:00
|
|
|
|
2023-06-13 02:22:44 +03:00
|
|
|
func handleMe(u *nechotron.Update, text string) error {
|
|
|
|
u.DeleteMessage()
|
|
|
|
_, err := u.AnswerMarkdown(fmt.Sprintf("_*%s* %s_", nechotron.EscapeMd2(u.From().FirstName), nechotron.EscapeMd2(text)))
|
2023-04-13 11:13:24 +03:00
|
|
|
return err
|
2023-02-13 01:40:20 +03:00
|
|
|
}
|
|
|
|
|
2023-06-13 02:22:44 +03:00
|
|
|
var helpText = `
|
|
|
|
Вот мои команды:
|
|
|
|
%s
|
2023-06-08 01:44:38 +03:00
|
|
|
|
2023-06-13 02:22:44 +03:00
|
|
|
Время сборки бота: %s`
|
|
|
|
|
|
|
|
func handleHelp(u *nechotron.Update, text string) error {
|
|
|
|
commands := nechotron.MakeCommandList("`%s` \\- _%s_\n", commandHelp, commandMe)
|
|
|
|
_, err := u.AnswerMarkdown(fmt.Sprintf(helpText, commands, BuildTime))
|
2023-06-08 01:44:38 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-06-13 02:22:44 +03:00
|
|
|
func handleSay(u *nechotron.Update, text string) error {
|
|
|
|
u.DeleteMessage()
|
|
|
|
_, err := u.AnswerMarkdown(fmt.Sprintf("*_%s_*", nechotron.EscapeMd2(text)))
|
2023-01-24 23:17:30 +03:00
|
|
|
return err
|
2023-04-13 11:13:24 +03:00
|
|
|
}
|
2023-01-24 02:24:45 +03:00
|
|
|
|
2023-04-13 11:13:24 +03:00
|
|
|
func handleOfftop(u *nechotron.Update) error {
|
|
|
|
text := "Держите [ссылку на оффтоп](%s)\\!"
|
|
|
|
offtopLink := "https://t.me/Godot_Engine_Offtop"
|
|
|
|
offtopAnswers, err := tongo.NewStore[TriggerText](db).GetMany(u.Ctx, tongo.E("trigger", "offtop"))
|
|
|
|
if err == nil {
|
|
|
|
if len(offtopAnswers) > 0 {
|
|
|
|
text = offtopAnswers[rand.Intn(len(offtopAnswers)-1)].Text
|
|
|
|
}
|
|
|
|
}
|
|
|
|
offtopUrl, err := tongo.NewStore[Config](db).GetOne(u.Ctx, tongo.E("name", "offtop_url"))
|
|
|
|
if err == nil {
|
|
|
|
offtopLink = offtopUrl.Value.(string)
|
|
|
|
}
|
|
|
|
text = fmt.Sprintf(text, offtopLink)
|
|
|
|
kb := nechotron.NewInlineKeyboard().Row(nechotron.InButtonCallback("Спасибо, не надо", "delete")).Markup()
|
|
|
|
opts := nechotron.NewOptions().
|
|
|
|
MarkdownV2().
|
|
|
|
ReplyTo(u.MessageID()).
|
|
|
|
ReplyMarkup(kb).
|
|
|
|
MessageOptions()
|
|
|
|
u.AnswerText(text, opts)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleDeleteCallback(u *nechotron.Update) error {
|
|
|
|
u.DeleteMessage()
|
|
|
|
return nil
|
2023-01-24 02:24:45 +03:00
|
|
|
}
|
2023-06-13 02:22:44 +03:00
|
|
|
|
|
|
|
func handleUsersImport(u *nechotron.Update) error {
|
|
|
|
f, _ := u.Bot.GetFile(u.Message.Document.FileID)
|
|
|
|
file, _ := u.Bot.DownloadFile(f.Result.FilePath)
|
|
|
|
log.Println(string(file))
|
|
|
|
return nil
|
|
|
|
}
|