2018-07-23 16:59:39 +02:00
|
|
|
/*
|
|
|
|
* @Author: Bartuccio Antoine
|
|
|
|
* @Date: 2018-07-23 15:24:22
|
|
|
|
* @Last Modified by: klmp200
|
2018-07-25 22:52:12 +02:00
|
|
|
* @Last Modified time: 2018-07-25 19:27:21
|
2018-07-23 16:59:39 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-07-24 11:59:36 +02:00
|
|
|
"./commands"
|
2018-07-23 16:59:39 +02:00
|
|
|
"./settings"
|
2018-07-24 02:28:45 +02:00
|
|
|
"./shared"
|
2018-07-23 16:59:39 +02:00
|
|
|
tb "gopkg.in/tucnak/telebot.v2"
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2018-07-24 12:21:50 +02:00
|
|
|
registered_commands := map[string]func(*tb.Message){
|
2018-07-24 15:24:09 +02:00
|
|
|
tb.OnText: commands.OnText,
|
|
|
|
"/hello": commands.Hello,
|
|
|
|
"/sponge": commands.Sponge,
|
|
|
|
"/git": commands.Git,
|
|
|
|
"/framapad": commands.Framapad,
|
|
|
|
"/setgender": commands.SetGender,
|
|
|
|
"/gender": commands.Gender,
|
2018-07-24 21:01:24 +02:00
|
|
|
"/roll": commands.Dice,
|
2018-07-25 22:52:12 +02:00
|
|
|
"/trump": commands.LastTrumpTweet,
|
2018-07-24 12:21:50 +02:00
|
|
|
}
|
|
|
|
|
2018-07-23 19:25:35 +02:00
|
|
|
if err := settings.LoadSettings("settings.json", "settings_custom.json"); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2018-07-23 16:59:39 +02:00
|
|
|
|
2018-07-24 02:28:45 +02:00
|
|
|
log.Println("Initialize history")
|
2018-07-24 12:57:31 +02:00
|
|
|
shared.InitHistory(int(settings.Settings["history size"].(float64)),
|
|
|
|
settings.Settings["history file"].(string))
|
2018-07-24 15:24:09 +02:00
|
|
|
log.Println("Initialize users infos")
|
|
|
|
shared.InitUsers(settings.Settings["users file"].(string))
|
2018-07-24 02:28:45 +02:00
|
|
|
|
2018-07-23 16:59:39 +02:00
|
|
|
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
|
|
|
|
}
|
2018-07-24 11:59:36 +02:00
|
|
|
shared.Bot = b
|
2018-07-23 16:59:39 +02:00
|
|
|
|
2018-07-24 12:21:50 +02:00
|
|
|
for key, value := range registered_commands {
|
|
|
|
b.Handle(key, value)
|
|
|
|
}
|
2018-07-24 03:07:13 +02:00
|
|
|
|
2018-07-23 16:59:39 +02:00
|
|
|
log.Println("Starting bot")
|
|
|
|
b.Start()
|
|
|
|
}
|