✨ Implement online check toggle command
This commit is contained in:
		
							parent
							
								
									76ab693760
								
							
						
					
					
						commit
						746734ec90
					
				
							
								
								
									
										62
									
								
								cli/commands/toogleonlinecheck.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								cli/commands/toogleonlinecheck.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,62 @@
 | 
				
			|||||||
 | 
					package commands
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"git.dragon-labs.de/alphyron/group_helper/cli"
 | 
				
			||||||
 | 
						"git.dragon-labs.de/alphyron/group_helper/logic"
 | 
				
			||||||
 | 
						tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type toggleOnlineCheckCommand struct {
 | 
				
			||||||
 | 
						groupHelperService logic.GroupHelperService
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewToggleOnlineCheckCommand(groupHelperService logic.GroupHelperService) cli.Command {
 | 
				
			||||||
 | 
						return &toggleOnlineCheckCommand{
 | 
				
			||||||
 | 
							groupHelperService: groupHelperService,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (i toggleOnlineCheckCommand) GetUsage() string {
 | 
				
			||||||
 | 
						return "/toggleOnlineCheck"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (i toggleOnlineCheckCommand) GetCommand() string {
 | 
				
			||||||
 | 
						return "/toggleOnlineCheck"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (i toggleOnlineCheckCommand) GetDescription() string {
 | 
				
			||||||
 | 
						return "Toggle the setting for a online check when a user join"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (i toggleOnlineCheckCommand) ExecuteCommand(bot *tgbotapi.BotAPI, update *tgbotapi.Update) (bool, error) {
 | 
				
			||||||
 | 
						group, err := i.groupHelperService.GetGroupByID(update.Message.Chat.ID)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return false, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						group.OnlineCheck = !group.OnlineCheck
 | 
				
			||||||
 | 
						group, err = i.groupHelperService.UpdateGroup(group)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return false, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Update the group setting for OnlineCheck to: "+strconv.FormatBool(group.OnlineCheck))
 | 
				
			||||||
 | 
						_, err = bot.Send(msg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return err == nil, err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (i toggleOnlineCheckCommand) AllowChatType(chat *tgbotapi.Chat) bool {
 | 
				
			||||||
 | 
						return chat.IsGroup() || chat.IsSuperGroup()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (i toggleOnlineCheckCommand) AllowMember(member *tgbotapi.ChatMember) bool {
 | 
				
			||||||
 | 
						return member.IsAdministrator() || member.IsCreator()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (i toggleOnlineCheckCommand) AllowEveryMember() bool {
 | 
				
			||||||
 | 
						return false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										1
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								main.go
									
									
									
									
									
								
							@ -81,6 +81,7 @@ func InitialCommandManager(bot *tgbotapi.BotAPI, service logic.GroupHelperServic
 | 
				
			|||||||
	cm.RegisterCommand(commands.NewLeaveMessage(service))
 | 
						cm.RegisterCommand(commands.NewLeaveMessage(service))
 | 
				
			||||||
	cm.RegisterCommand(commands.NewKickMessage(service))
 | 
						cm.RegisterCommand(commands.NewKickMessage(service))
 | 
				
			||||||
	cm.RegisterCommand(commands.NewVerifiedMessage(service))
 | 
						cm.RegisterCommand(commands.NewVerifiedMessage(service))
 | 
				
			||||||
 | 
						cm.RegisterCommand(commands.NewToggleOnlineCheckCommand(service))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return cm
 | 
						return cm
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -9,7 +9,8 @@ type Group struct {
 | 
				
			|||||||
	UserLeaveMessage    string  `gorm:"column:msg_user_leave;type:text"`
 | 
						UserLeaveMessage    string  `gorm:"column:msg_user_leave;type:text"`
 | 
				
			||||||
	UserKickMessage     string  `gorm:"column:msg_user_kick;type:text"`
 | 
						UserKickMessage     string  `gorm:"column:msg_user_kick;type:text"`
 | 
				
			||||||
	ForbidWriting       bool    `gorm:"column:forbid_writing"`
 | 
						ForbidWriting       bool    `gorm:"column:forbid_writing"`
 | 
				
			||||||
	OnlineCheck         int     `gorm:"column:kick_cooldown"`
 | 
						OnlineCheck         bool    `gorm:"column:online_check"`
 | 
				
			||||||
 | 
						KickCooldown        int     `gorm:"column:kick_cooldown"`
 | 
				
			||||||
	Users               []*User `gorm:"many2many:GroupUser;"`
 | 
						Users               []*User `gorm:"many2many:GroupUser;"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -30,7 +31,8 @@ func (group *Group) FillDefaultValues() {
 | 
				
			|||||||
		group.UserVerifiedMessage = "[{{user.firstname}} {{user.lastname}}](tg://user?id={{user.id}}) is now permitted to stay in the chat!"
 | 
							group.UserVerifiedMessage = "[{{user.firstname}} {{user.lastname}}](tg://user?id={{user.id}}) is now permitted to stay in the chat!"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if group.OnlineCheck == 0 {
 | 
						if group.KickCooldown == 0 {
 | 
				
			||||||
		group.OnlineCheck = 5
 | 
							group.KickCooldown = 5
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user