Update, new mentions, fixed captcha icons Y-pos
This commit is contained in:
@ -22,7 +22,7 @@ func userJoined(b *bot, update *echotron.Update) error {
|
||||
bytes, err := captcha.ToBytes()
|
||||
if err != nil {
|
||||
log.Printf("Error creating captcha bytes: %v", bytes)
|
||||
b.SendMessage("Не могу создать капчу, @nefrace, проверь логи.", update.Message.From.ID, &echotron.MessageOptions{MessageThreadID: update.Message.ThreadID})
|
||||
b.SendMessage("Не могу создать капчу, @nefrace, проверь логи.", update.Message.From.ID, &echotron.MessageOptions{MessageThreadID: int64(update.Message.ThreadID)})
|
||||
}
|
||||
message := update.Message
|
||||
store := tongo.NewStore[db.User](Client)
|
||||
@ -33,6 +33,7 @@ func userJoined(b *bot, update *echotron.Update) error {
|
||||
FirstName: message.From.FirstName,
|
||||
LastName: message.From.LastName,
|
||||
IsBanned: false,
|
||||
IsJoined: false,
|
||||
ChatId: message.Chat.ID,
|
||||
JoinedMessage: message.ID,
|
||||
CorrectAnswer: int8(captcha.CorrectAnswer),
|
||||
@ -90,8 +91,8 @@ func checkCaptcha(b *bot, update *echotron.Update) error {
|
||||
}
|
||||
if message.ThreadID != int(chat.TopicId) {
|
||||
b.DeleteMessage(message.Chat.ID, message.ID)
|
||||
text := fmt.Sprintf("*[%s](tg://user?id=%d)*, сначала пройди капчу\\!", user.FirstName, user.UserId)
|
||||
res, _ := b.SendMessage(text, message.Chat.ID, &echotron.MessageOptions{ParseMode: echotron.MarkdownV2, MessageThreadID: message.ThreadID})
|
||||
text := fmt.Sprintf("*%s*, сначала пройди капчу\\!", UserMention(sender))
|
||||
res, _ := b.SendMessage(text, message.Chat.ID, &echotron.MessageOptions{ParseMode: echotron.MarkdownV2, MessageThreadID: int64(message.ThreadID)})
|
||||
go waitAndDelete(&b.API, res.Result, 10*time.Second)
|
||||
return nil
|
||||
}
|
||||
@ -105,12 +106,12 @@ func checkCaptcha(b *bot, update *echotron.Update) error {
|
||||
solved = true
|
||||
b.DeleteMessage(message.Chat.ID, message.ID)
|
||||
b.DeleteMessage(message.Chat.ID, user.CaptchaMessage)
|
||||
msg := fmt.Sprintf("*[%s](tg://user?id=%d)* только что успешно прошёл капчу\\!", EscapeText(echotron.MarkdownV2, user.FirstName), user.UserId)
|
||||
msg := fmt.Sprintf("Капча успешно пройдена пользователем *%s*", UserMention(sender))
|
||||
options := echotron.MessageOptions{
|
||||
ParseMode: echotron.MarkdownV2,
|
||||
}
|
||||
if message.Chat.IsForum {
|
||||
options.MessageThreadID = int(b.CaptchaTopic)
|
||||
options.MessageThreadID = b.CaptchaTopic
|
||||
}
|
||||
res, err := b.SendMessage(msg, message.Chat.ID, &options)
|
||||
if err != nil {
|
||||
@ -174,6 +175,6 @@ func setTopic(b *bot, update *echotron.Update) error {
|
||||
return err
|
||||
}
|
||||
b.DeleteMessage(m.Chat.ID, m.ID)
|
||||
b.SendMessage("Данный топик выбран в качестве проверочного для пользователей", m.Chat.ID, &echotron.MessageOptions{MessageThreadID: m.ThreadID})
|
||||
b.SendMessage("Данный топик выбран в качестве проверочного для пользователей", m.Chat.ID, &echotron.MessageOptions{MessageThreadID: int64(m.ThreadID)})
|
||||
return nil
|
||||
}
|
||||
|
@ -2,8 +2,10 @@ package kicker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"kickerbot/db"
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -119,5 +121,31 @@ func EscapeText(parseMode echotron.ParseMode, text string) string {
|
||||
|
||||
func waitAndDelete(b *echotron.API, message *echotron.Message, t time.Duration) {
|
||||
time.Sleep(t)
|
||||
b.DeleteMessage(message.Chat.ID, message.ID)
|
||||
if _, err := b.DeleteMessage(message.Chat.ID, message.ID); err != nil {
|
||||
log.Printf("Can't delay-delete message: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func MentionUser(user *echotron.User) string {
|
||||
return fmt.Sprintf("[%s](tg://user?id=%d)", EscapeText(echotron.MarkdownV2, user.FirstName), user.ID)
|
||||
}
|
||||
|
||||
var chars = []string{"_", "\\*", "\\[", "\\]", "\\(", "\\)", "~", "`", ">", "#", "\\+", "\\-", "=", "|", "{", "}", "\\.", "!"}
|
||||
var r = strings.Join(chars, "")
|
||||
var reg = regexp.MustCompile("[" + r + "]+")
|
||||
|
||||
func EscapeMd2(s string) string {
|
||||
return reg.ReplaceAllString(s, "\\$0")
|
||||
}
|
||||
|
||||
func Mention(name string, id int64) string {
|
||||
return fmt.Sprintf("[%s](tg://user?id=%d)", EscapeMd2(name), id)
|
||||
}
|
||||
|
||||
func UserMention(u *echotron.User) string {
|
||||
return Mention(u.FirstName, u.ID)
|
||||
}
|
||||
|
||||
func UserMentionDB(u *db.User) string {
|
||||
return Mention(u.FirstName, u.UserId)
|
||||
}
|
||||
|
@ -48,15 +48,15 @@ func TaskNotifyUsers(b *echotron.API) {
|
||||
for _, user := range users {
|
||||
if time.Since(user.LastNotification) > 2*time.Minute {
|
||||
user.LastNotification = time.Now()
|
||||
text := fmt.Sprintf("*[%s](tg://user?id=%d)*, напоминаю, что тебе необходимо пройти капчу\\!", EscapeText(echotron.MarkdownV2, user.FirstName), user.UserId)
|
||||
text := fmt.Sprintf("*%s*, напоминаю, что тебе необходимо пройти капчу\\!", UserMentionDB(user))
|
||||
store.ReplaceItem(ctx, *user, false)
|
||||
chat, err := chatStore.GetOne(ctx, tongo.E("chat_id", user.ChatId))
|
||||
topic := 0
|
||||
var topic int64 = 0
|
||||
if err != nil {
|
||||
log.Printf("Can't get chat from user: %s", err)
|
||||
return
|
||||
} else {
|
||||
topic = int(chat.TopicId)
|
||||
topic = chat.TopicId
|
||||
}
|
||||
res, err := b.SendMessage(text, user.ChatId, &echotron.MessageOptions{MessageThreadID: topic, ParseMode: echotron.MarkdownV2})
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user