forked from git.klmp200.net/ALFRED
73 lines
1.7 KiB
Go
73 lines
1.7 KiB
Go
/*
|
|
* @Author: Bartuccio Antoine
|
|
* @Date: 2018-07-23 15:24:22
|
|
* @Last Modified by: klmp200
|
|
* @Last Modified time: 2018-07-24 03:05:51
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"./plugin_manager"
|
|
"./settings"
|
|
"./shared"
|
|
tb "gopkg.in/tucnak/telebot.v2"
|
|
"log"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
if err := settings.LoadSettings("settings.json", "settings_custom.json"); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
log.Println("Initialize history")
|
|
shared.InitHistory(int(settings.Settings["history size"].(float64)))
|
|
|
|
log.Println("Bot initialisation")
|
|
b, err := tb.NewBot(tb.Settings{
|
|
Token: settings.Settings["token"].(string),
|
|
Poller: &tb.LongPoller{Timeout: 10 * time.Second},
|
|
})
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
return
|
|
}
|
|
|
|
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", func(m *tb.Message) {
|
|
message := ""
|
|
for i, char := range shared.History.LastMessage(m.Chat.ID) {
|
|
if i%2 == 0 {
|
|
message += strings.ToLower(string(char))
|
|
} else {
|
|
message += strings.ToUpper(string(char))
|
|
}
|
|
}
|
|
b.Send(m.Chat, message)
|
|
|
|
})
|
|
|
|
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.")
|
|
})
|
|
|
|
plugin_manager.Init("plugin", b)
|
|
b.Handle(tb.OnText, plugin_manager.HandleMessage)
|
|
plugin_manager.StartPlugins()
|
|
log.Println("Starting bot")
|
|
b.Start()
|
|
}
|