Skip to content

Commit

Permalink
Support for set ban all users for emojii. This is temporary fix, beca…
Browse files Browse the repository at this point in the history
…use telegram does not send join chat messages.
  • Loading branch information
kak-tus committed Nov 10, 2023
1 parent ba872ea commit 11bd292
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions telegram/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"time"

"github.com/forPelevin/gomoji"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/kak-tus/irma_bot/storage"
)
Expand Down Expand Up @@ -125,6 +126,33 @@ func (hdl *InstanceObj) processMsg(ctx context.Context, msg *tgbotapi.Message) e
return hdl.newMembers(ctx, log, msg)
}

group, err := hdl.model.Queries.GetGroup(ctx, msg.Chat.ID)
if err != nil && err != sql.ErrNoRows {
return err
}

if group.BanEmojiiCount.Valid && group.BanEmojiiCount.Int32 > 0 &&
len(gomoji.CollectAll(msg.Text)) > int(group.BanEmojiiCount.Int32) {
log.Info().Msg("ban for emojii not newbie")

if err := hdl.deleteMessage(msg.Chat.ID, msg.MessageID); err != nil {
return err
}

kick := tgbotapi.KickChatMemberConfig{
ChatMemberConfig: tgbotapi.ChatMemberConfig{
ChatID: msg.Chat.ID,
UserID: msg.From.ID,
},
UntilDate: time.Now().In(time.UTC).AddDate(0, 0, 1).Unix(),
}

_, err = hdl.bot.Request(kick)
if err != nil {
return err
}
}

name := fmt.Sprintf("@%s", hdl.cnf.BotName)

if strings.HasPrefix(msg.Text, name) {
Expand Down

0 comments on commit 11bd292

Please sign in to comment.