✨ Implement kick set and get message command
This commit is contained in:
parent
f6316ada97
commit
6135ed75be
@ -33,7 +33,7 @@ func (j joinMessage) ExecuteCommand(api *tgbotapi.BotAPI, update *tgbotapi.Updat
|
|||||||
message := update.Message.Text
|
message := update.Message.Text
|
||||||
parts := strings.Split(message, " ")
|
parts := strings.Split(message, " ")
|
||||||
|
|
||||||
if len(parts) == 0 {
|
if len(parts) == 1 {
|
||||||
_, err := api.Send(tgbotapi.NewMessage(update.Message.Chat.ID, "Wrong usage of this Command:\n"+j.GetUsage()))
|
_, err := api.Send(tgbotapi.NewMessage(update.Message.Chat.ID, "Wrong usage of this Command:\n"+j.GetUsage()))
|
||||||
return err != nil, err
|
return err != nil, err
|
||||||
}
|
}
|
||||||
|
90
cli/commands/kickmessage.go
Normal file
90
cli/commands/kickmessage.go
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
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
|
||||||
|
}
|
@ -33,7 +33,7 @@ func (j leaveMessage) ExecuteCommand(api *tgbotapi.BotAPI, update *tgbotapi.Upda
|
|||||||
message := update.Message.Text
|
message := update.Message.Text
|
||||||
parts := strings.Split(message, " ")
|
parts := strings.Split(message, " ")
|
||||||
|
|
||||||
if len(parts) == 0 {
|
if len(parts) == 1 {
|
||||||
_, err := api.Send(tgbotapi.NewMessage(update.Message.Chat.ID, "Wrong usage of this Command:\n"+j.GetUsage()))
|
_, err := api.Send(tgbotapi.NewMessage(update.Message.Chat.ID, "Wrong usage of this Command:\n"+j.GetUsage()))
|
||||||
return err != nil, err
|
return err != nil, err
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ func (j leaveMessage) ExecuteCommand(api *tgbotapi.BotAPI, update *tgbotapi.Upda
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO Create a replace for placeholder
|
//TODO Create a replace for placeholder
|
||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, group.UserJoinMessage)
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, group.UserLeaveMessage)
|
||||||
msg.ParseMode = "Markdown"
|
msg.ParseMode = "Markdown"
|
||||||
api.Send(tgbotapi.NewMessage(update.Message.Chat.ID, "Example LeaveMessage"))
|
api.Send(tgbotapi.NewMessage(update.Message.Chat.ID, "Example LeaveMessage"))
|
||||||
_, err = api.Send(msg)
|
_, err = api.Send(msg)
|
||||||
|
1
main.go
1
main.go
@ -79,6 +79,7 @@ func InitialCommandManager(bot *tgbotapi.BotAPI, service logic.GroupHelperServic
|
|||||||
cm.RegisterCommand(commands.NewHelpCommand(cm))
|
cm.RegisterCommand(commands.NewHelpCommand(cm))
|
||||||
cm.RegisterCommand(commands.NewJoinMessage(service))
|
cm.RegisterCommand(commands.NewJoinMessage(service))
|
||||||
cm.RegisterCommand(commands.NewLeaveMessage(service))
|
cm.RegisterCommand(commands.NewLeaveMessage(service))
|
||||||
|
cm.RegisterCommand(commands.NewKickMessage(service))
|
||||||
|
|
||||||
return cm
|
return cm
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user