diff --git a/channels/leaveduserchecker.go b/channels/leaveduserchecker.go index 6a6cb59..efe545f 100644 --- a/channels/leaveduserchecker.go +++ b/channels/leaveduserchecker.go @@ -80,6 +80,14 @@ func checkGroupUser(group *models.Group, groupHelperService logic.GroupHelperSer } if !(member.User.IsBot || member.User.FirstName == "Telegram") { + if member.User == nil || member.User.FirstName == "" { + member.User = &tgbotapi.User{ + ID: -1, + FirstName: "Unknown", + IsBot: false, + } + } + leaveMessage := group.UserLeaveMessage leaveMessage = message.ReplaceMessage(leaveMessage, member.User) diff --git a/cli/commands/info.go b/cli/commands/info.go index 8b7fc5f..747f566 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.2.6\n" + + "Version: 2.2.7\n" + "Git: [Gitea Repository](https://git.dragon-labs.de/alphyron/group_assistant)\n" + "===============================" diff --git a/telegram/routines/database.go b/telegram/routines/database.go index 7e7d385..9a7865a 100644 --- a/telegram/routines/database.go +++ b/telegram/routines/database.go @@ -5,6 +5,7 @@ import ( "git.dragon-labs.de/alphyron/group_helper/models" "git.dragon-labs.de/alphyron/group_helper/telegram" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" + "log" ) type databaseRoutine struct { @@ -43,29 +44,29 @@ func (d databaseRoutine) Update(botAPI *tgbotapi.BotAPI, update *tgbotapi.Update _, err := d.groupHelperService.UpdateGroup(group) return err } - /* - if update.Message.LeftChatMember != nil { - user, err := d.groupHelperService.GetUserByID(int64(update.Message.LeftChatMember.ID)) - if err != nil { - return err - } + if update.Message.LeftChatMember != nil { + user, err := d.groupHelperService.GetUserByID(int64(update.Message.LeftChatMember.ID)) - go func() { - success, err := d.groupHelperService.UserLeaveGroup(user, group) - log.Println(success) - log.Println(err) - - }() - config := tgbotapi.ChatConfig{ - ChatID: update.Message.Chat.ID, - } - size, _ := botAPI.GetChatMembersCount(config) - group.Size = size - 1 - _, err = d.groupHelperService.UpdateGroup(group) + if err != nil { return err } - */ + + go func() { + success, err := d.groupHelperService.UserLeaveGroup(user, group) + log.Println(success) + log.Println(err) + + }() + config := tgbotapi.ChatConfig{ + ChatID: update.Message.Chat.ID, + } + size, _ := botAPI.GetChatMembersCount(config) + group.Size = size - 1 + _, err = d.groupHelperService.UpdateGroup(group) + return err + } + user, err := d.groupHelperService.GetUserByID(int64(update.Message.From.ID)) if err != nil {