63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
|
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
|
||
|
}
|