package commands import ( "git.dragon-labs.de/alphyron/group_helper/cli" "git.dragon-labs.de/alphyron/group_helper/logic" "git.dragon-labs.de/alphyron/group_helper/models" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" "strings" ) type joinMessage struct { groupHelperService logic.GroupHelperService } func NewJoinMessage(groupHelperService logic.GroupHelperService) cli.Command { return &joinMessage{ groupHelperService: groupHelperService, } } func (j joinMessage) GetUsage() string { return "/join (set/get) [message]" } func (j joinMessage) GetCommand() string { return "/join" } func (j joinMessage) GetDescription() string { return "Get or set the join message" } func (j joinMessage) ExecuteCommand(api *tgbotapi.BotAPI, update *tgbotapi.Update, group *models.Group) (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, " ") switch args[1] { case "get": msg := tgbotapi.NewMessage(update.Message.Chat.ID, group.UserJoinMessage) api.Send(tgbotapi.NewMessage(update.Message.Chat.ID, "Current JoinMessage (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.UserJoinMessage) msg.ParseMode = "Markdown" api.Send(tgbotapi.NewMessage(update.Message.Chat.ID, "Example JoinMessage")) _, 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 joinMessage) AllowChatType(chat *tgbotapi.Chat) bool { return chat.IsGroup() || chat.IsSuperGroup() } func (j joinMessage) AllowMember(member *tgbotapi.ChatMember) bool { return member.IsAdministrator() || member.IsCreator() } func (j joinMessage) AllowEveryMember() bool { return false }