Externalized all commands in corresponding package
the build was successful Details

This commit is contained in:
Antoine Bartuccio 2018-07-24 12:21:50 +02:00
parent f7f3308372
commit 7336770332
Signed by: klmp200
GPG Key ID: E7245548C53F904B
5 changed files with 80 additions and 18 deletions

View File

@ -2,7 +2,7 @@
* @Author: Bartuccio Antoine
* @Date: 2018-07-23 15:24:22
* @Last Modified by: klmp200
* @Last Modified time: 2018-07-24 11:58:31
* @Last Modified time: 2018-07-24 12:35:08
*/
package main
@ -17,6 +17,14 @@ import (
)
func main() {
registered_commands := map[string]func(*tb.Message){
tb.OnText: commands.OnText,
"/hello": commands.Hello,
"/sponge": commands.Sponge,
"/git": commands.Git,
"/framapad": commands.Framapad,
}
if err := settings.LoadSettings("settings.json", "settings_custom.json"); err != nil {
log.Fatal(err)
}
@ -35,23 +43,9 @@ func main() {
}
shared.Bot = b
b.Handle("/hello", func(m *tb.Message) {
b.Send(m.Chat, "Bonjour "+m.Sender.Username)
})
b.Handle(tb.OnText, func(m *tb.Message) {
shared.History.AddMessage(m.Chat.ID, m.Text)
})
b.Handle("/sponge", commands.Sponge)
b.Handle("/git", func(m *tb.Message) {
b.Send(m.Chat, "Mon code est accessible librement à l'adresse https://git.klmp200.net/ALFRED/ALFRED. Venez contribuer :)")
})
b.Handle("/framapad", func(m *tb.Message) {
b.Send(m.Chat, "Venez participer à mon développement en posant vos idées ici : https://mensuel.framapad.org/p/ALFRED2LERETOUR.")
})
for key, value := range registered_commands {
b.Handle(key, value)
}
log.Println("Starting bot")
b.Start()

17
commands/framapad.go Normal file
View File

@ -0,0 +1,17 @@
/*
* @Author: Bartuccio Antoine
* @Date: 2018-07-24 12:11:26
* @Last Modified by: klmp200
* @Last Modified time: 2018-07-24 12:12:58
*/
package commands
import (
"../shared"
tb "gopkg.in/tucnak/telebot.v2"
)
func Framapad(m *tb.Message) {
shared.Bot.Send(m.Chat, "Venez participer à mon développement en posant vos idées ici : https://mensuel.framapad.org/p/ALFRED2LERETOUR.")
}

17
commands/git.go Normal file
View File

@ -0,0 +1,17 @@
/*
* @Author: Bartuccio Antoine
* @Date: 2018-07-24 12:07:34
* @Last Modified by: klmp200
* @Last Modified time: 2018-07-24 12:08:49
*/
package commands
import (
"../shared"
tb "gopkg.in/tucnak/telebot.v2"
)
func Git(m *tb.Message) {
shared.Bot.Send(m.Chat, "Mon code source est accessible librement à l'adresse https://git.klmp200.net/ALFRED/ALFRED. Venez contribuer :)")
}

17
commands/hello.go Normal file
View File

@ -0,0 +1,17 @@
/*
* @Author: Bartuccio Antoine
* @Date: 2018-07-24 12:05:45
* @Last Modified by: klmp200
* @Last Modified time: 2018-07-24 12:06:39
*/
package commands
import (
"../shared"
tb "gopkg.in/tucnak/telebot.v2"
)
func Hello(m *tb.Message) {
shared.Bot.Send(m.Chat, "Bonjour "+m.Sender.Username)
}

17
commands/on_text.go Normal file
View File

@ -0,0 +1,17 @@
/*
* @Author: Bartuccio Antoine
* @Date: 2018-07-24 12:09:37
* @Last Modified by: klmp200
* @Last Modified time: 2018-07-24 12:10:26
*/
package commands
import (
"../shared"
tb "gopkg.in/tucnak/telebot.v2"
)
func OnText(m *tb.Message) {
shared.History.AddMessage(m.Chat.ID, m.Text)
}