diff --git a/cli/commands/info.go b/cli/commands/info.go index ee247e7..88ea723 100644 --- a/cli/commands/info.go +++ b/cli/commands/info.go @@ -30,7 +30,7 @@ func (i infoCommand) ExecuteCommand(bot *tgbotapi.BotAPI, update *tgbotapi.Updat "General Information to this Bot\n" + "===============================\n" + "Developer: @Alphyron\n" + - "Version: 2.1.0\n" + + "Version: 2.2.2\n" + "Git: [Gitea Repository](https://git.dragon-labs.de/alphyron/group_assistant)\n" + "===============================" diff --git a/cli/commands/togglewritingforbid.go b/cli/commands/togglewritingforbid.go index fcb2cc5..bcd6507 100644 --- a/cli/commands/togglewritingforbid.go +++ b/cli/commands/togglewritingforbid.go @@ -39,7 +39,7 @@ func (i toggleWritingForbidCommand) ExecuteCommand(bot *tgbotapi.BotAPI, update return false, err } - msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Update the group setting for OnlineCheck to: "+strconv.FormatBool(group.OnlineCheck)) + msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Update the group setting for forbid-writing to: "+strconv.FormatBool(group.ForbidWriting)) _, err = bot.Send(msg) return err == nil, err diff --git a/main.go b/main.go index f2049ae..ce80d9c 100644 --- a/main.go +++ b/main.go @@ -85,6 +85,7 @@ func InitialRoutineManager(bot *tgbotapi.BotAPI, commandManager *cli.CommandMana rm.RegisterRoutine(routines.NewDatabaseRoutine(service)) rm.RegisterRoutine(routines.NewJoinCheckerRoutine(userData)) rm.RegisterRoutine(routines.NewVerifierRoutine(service, userData)) + rm.RegisterRoutine(routines.NewJoinWritingCheckerRoutine(userData)) return rm } diff --git a/telegram/routines/joinwritingchecker.go b/telegram/routines/joinwritingchecker.go new file mode 100644 index 0000000..b3c650e --- /dev/null +++ b/telegram/routines/joinwritingchecker.go @@ -0,0 +1,37 @@ +package routines + +import ( + "git.dragon-labs.de/alphyron/group_helper/models" + "git.dragon-labs.de/alphyron/group_helper/obj" + "git.dragon-labs.de/alphyron/group_helper/telegram" + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" +) + +type joinWritingCheckerRoutine struct { + verifyData *obj.VerifyData +} + +func NewJoinWritingCheckerRoutine(verifyData *obj.VerifyData) telegram.Routine { + return joinWritingCheckerRoutine{ + verifyData: verifyData, + } +} + +func (j joinWritingCheckerRoutine) Update(botAPI *tgbotapi.BotAPI, update *tgbotapi.Update, group *models.Group) error { + + if update.Message == nil { // ignore any non-Message Updates + return nil + } + + if update.Message.Chat.IsPrivate() || update.Message.Chat.IsChannel() { + return nil + } + + if j.verifyData.ExistCountdownForUserInGroup(update.Message.From.ID, group.GroupID) { + if group.ForbidWriting { + _, err := botAPI.DeleteMessage(tgbotapi.NewDeleteMessage(group.GroupID, update.Message.MessageID)) + return err + } + } + return nil +}