🐛 Fix some message bugs and delete message if not verified and group setting set true

This commit is contained in:
Alphyron 2021-03-14 01:14:51 +01:00
parent cf1e03ef0e
commit 474744f928
4 changed files with 40 additions and 2 deletions

View File

@ -30,7 +30,7 @@ func (i infoCommand) ExecuteCommand(bot *tgbotapi.BotAPI, update *tgbotapi.Updat
"General Information to this Bot\n" + "General Information to this Bot\n" +
"===============================\n" + "===============================\n" +
"Developer: @Alphyron\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" + "Git: [Gitea Repository](https://git.dragon-labs.de/alphyron/group_assistant)\n" +
"===============================" "==============================="

View File

@ -39,7 +39,7 @@ func (i toggleWritingForbidCommand) ExecuteCommand(bot *tgbotapi.BotAPI, update
return false, err 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) _, err = bot.Send(msg)
return err == nil, err return err == nil, err

View File

@ -85,6 +85,7 @@ func InitialRoutineManager(bot *tgbotapi.BotAPI, commandManager *cli.CommandMana
rm.RegisterRoutine(routines.NewDatabaseRoutine(service)) rm.RegisterRoutine(routines.NewDatabaseRoutine(service))
rm.RegisterRoutine(routines.NewJoinCheckerRoutine(userData)) rm.RegisterRoutine(routines.NewJoinCheckerRoutine(userData))
rm.RegisterRoutine(routines.NewVerifierRoutine(service, userData)) rm.RegisterRoutine(routines.NewVerifierRoutine(service, userData))
rm.RegisterRoutine(routines.NewJoinWritingCheckerRoutine(userData))
return rm return rm
} }

View File

@ -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
}