91 lines
2.4 KiB
Go
91 lines
2.4 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"
|
|
"strings"
|
|
)
|
|
|
|
type kickMessage struct {
|
|
groupHelperService logic.GroupHelperService
|
|
}
|
|
|
|
func NewKickMessage(groupHelperService logic.GroupHelperService) cli.Command {
|
|
return &kickMessage{
|
|
groupHelperService: groupHelperService,
|
|
}
|
|
}
|
|
|
|
func (j kickMessage) GetUsage() string {
|
|
return "/kick (set/get) [message]"
|
|
}
|
|
|
|
func (j kickMessage) GetCommand() string {
|
|
return "/kick"
|
|
}
|
|
|
|
func (j kickMessage) GetDescription() string {
|
|
return "Get or set the kick message"
|
|
}
|
|
|
|
func (j kickMessage) ExecuteCommand(api *tgbotapi.BotAPI, update *tgbotapi.Update) (bool, error) {
|
|
message := update.Message.Text
|
|
parts := strings.Split(message, " ")
|
|
|
|
if len(parts) == 1 {
|
|
_, err := api.Send(tgbotapi.NewMessage(update.Message.Chat.ID, "Wrong usage of this Command:\n"+j.GetUsage()))
|
|
return err != nil, err
|
|
}
|
|
|
|
args := strings.Split(message, " ")
|
|
group, err := j.groupHelperService.GetGroupByID(update.Message.Chat.ID)
|
|
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
switch args[1] {
|
|
case "get":
|
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, group.UserJoinMessage)
|
|
api.Send(tgbotapi.NewMessage(update.Message.Chat.ID, "Current KickMessage (decoded)"))
|
|
_, err = api.Send(msg)
|
|
return err != nil, err
|
|
case "set":
|
|
if len(parts) <= 2 {
|
|
_, err := api.Send(tgbotapi.NewMessage(update.Message.Chat.ID, "Wrong usage of this Command:\n"+j.GetUsage()))
|
|
return err != nil, err
|
|
}
|
|
|
|
newJoinMessage := strings.Join(args[2:], " ")
|
|
group.UserJoinMessage = newJoinMessage
|
|
group, err = j.groupHelperService.UpdateGroup(group)
|
|
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
//TODO Create a replace for placeholder
|
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, group.UserKickMessage)
|
|
msg.ParseMode = "Markdown"
|
|
api.Send(tgbotapi.NewMessage(update.Message.Chat.ID, "Example KickMessage"))
|
|
_, err = api.Send(msg)
|
|
return err != nil, err
|
|
default:
|
|
_, err := api.Send(tgbotapi.NewMessage(update.Message.Chat.ID, "Wrong usage of this Command:\n"+j.GetUsage()))
|
|
return err != nil, err
|
|
}
|
|
}
|
|
|
|
func (j kickMessage) AllowChatType(chat *tgbotapi.Chat) bool {
|
|
return chat.IsGroup() || chat.IsSuperGroup()
|
|
}
|
|
|
|
func (j kickMessage) AllowMember(member *tgbotapi.ChatMember) bool {
|
|
return member.IsAdministrator() || member.IsCreator()
|
|
}
|
|
|
|
func (j kickMessage) AllowEveryMember() bool {
|
|
return false
|
|
}
|