✨ Implement forbid writing toggle command
This commit is contained in:
parent
746734ec90
commit
f48595c0f4
62
cli/commands/togglewritingforbid.go
Normal file
62
cli/commands/togglewritingforbid.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 toggleWritingForbidCommand struct {
|
||||||
|
groupHelperService logic.GroupHelperService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewToggleWritingForbidCommand(groupHelperService logic.GroupHelperService) cli.Command {
|
||||||
|
return &toggleWritingForbidCommand{
|
||||||
|
groupHelperService: groupHelperService,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i toggleWritingForbidCommand) GetUsage() string {
|
||||||
|
return "/toggleWritingForbidCommand"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i toggleWritingForbidCommand) GetCommand() string {
|
||||||
|
return "/toggleWritingForbidCommand"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i toggleWritingForbidCommand) GetDescription() string {
|
||||||
|
return "Toggle the setting for forbid writing while not verified"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i toggleWritingForbidCommand) 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.ForbidWriting = !group.ForbidWriting
|
||||||
|
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 toggleWritingForbidCommand) AllowChatType(chat *tgbotapi.Chat) bool {
|
||||||
|
return chat.IsGroup() || chat.IsSuperGroup()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i toggleWritingForbidCommand) AllowMember(member *tgbotapi.ChatMember) bool {
|
||||||
|
return member.IsAdministrator() || member.IsCreator()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i toggleWritingForbidCommand) AllowEveryMember() bool {
|
||||||
|
return false
|
||||||
|
}
|
1
main.go
1
main.go
@ -82,6 +82,7 @@ func InitialCommandManager(bot *tgbotapi.BotAPI, service logic.GroupHelperServic
|
|||||||
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))
|
cm.RegisterCommand(commands.NewToggleOnlineCheckCommand(service))
|
||||||
|
cm.RegisterCommand(commands.NewToggleWritingForbidCommand(service))
|
||||||
|
|
||||||
return cm
|
return cm
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user