2020-04-26 12:41:50 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.dragon-labs.de/alphyron/group_helper/cli"
|
|
|
|
"git.dragon-labs.de/alphyron/group_helper/logic"
|
2020-05-09 18:54:42 +00:00
|
|
|
"git.dragon-labs.de/alphyron/group_helper/models"
|
2020-04-26 12:41:50 +00:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2020-05-09 18:54:42 +00:00
|
|
|
func (i toggleWritingForbidCommand) ExecuteCommand(bot *tgbotapi.BotAPI, update *tgbotapi.Update, group *models.Group) (bool, error) {
|
2020-04-26 12:41:50 +00:00
|
|
|
|
|
|
|
group.ForbidWriting = !group.ForbidWriting
|
2020-05-09 18:54:42 +00:00
|
|
|
group, err := i.groupHelperService.UpdateGroup(group)
|
2020-04-26 12:41:50 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|