-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.go
More file actions
39 lines (31 loc) · 1.01 KB
/
command.go
File metadata and controls
39 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"strings"
telegram "github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/BecauseOfProg/BecauseOfProg_Bot/commands"
)
var commandsList = map[string]func(bot *telegram.BotAPI, update telegram.Update, args []string) error{
"start": commands.StartCommand,
"categories": commands.CategoriesCommand,
}
func HandleCommand(bot *telegram.BotAPI, update telegram.Update, isCallback bool) error {
var commandName string
var args []string
if isCallback {
parts := strings.Split(strings.TrimPrefix(update.CallbackQuery.Data, "/"), " ")
commandName = parts[0]
args = parts[1:]
} else {
commandName = update.Message.Command()
if update.Message.CommandArguments() != "" {
args = strings.Split(update.Message.CommandArguments(), " ")
}
}
command, exists := commandsList[commandName]
if !exists {
_, err := bot.Send(telegram.NewMessage(update.Message.Chat.ID, "❓ Oups, il semble que cette commande soit inconnue!"))
return err
}
err := command(bot, update, args)
return err
}