mirror of
https://git.klmp200.net/ALFRED/ALFRED.git
synced 2025-01-18 10:36:44 +01:00
Say Hello Alfred :)
This commit is contained in:
parent
173eb2e45b
commit
1c94f8dced
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,3 +14,4 @@
|
||||
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
|
||||
.glide/
|
||||
|
||||
settings_custom.json
|
@ -1,3 +1,5 @@
|
||||
# ALFRED
|
||||
|
||||
ALFRED : Adorable Loyal Friend Reading Erratic Direct messages ALFRED is a Telegram Bot
|
||||
ALFRED : Adorable Loyal Friend Reading Erratic Direct messages ALFRED is a Telegram Bot
|
||||
|
||||
Custom settings mount point inside docker is `/settings_custom.json`.
|
36
alfred.go
Normal file
36
alfred.go
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-23 15:24:22
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-23 16:05:01
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"./settings"
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
settings.LoadSettings("settings.json", "settings_custom.json")
|
||||
|
||||
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.Sender, "Bonjour monsieur")
|
||||
})
|
||||
|
||||
log.Println("Starting bot")
|
||||
b.Start()
|
||||
}
|
3
settings.json
Normal file
3
settings.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"token": "INSERT TOKEN HERE"
|
||||
}
|
44
settings/settings.go
Normal file
44
settings/settings.go
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-23 15:24:30
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-23 16:02:42
|
||||
*/
|
||||
|
||||
package settings
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
)
|
||||
|
||||
var Settings map[string]interface{}
|
||||
|
||||
// Load settings from given file path
|
||||
// Return error in case of bad import
|
||||
func loadJson(path string) error {
|
||||
file, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = json.Unmarshal(file, &Settings)
|
||||
return err
|
||||
}
|
||||
|
||||
// Load settings from given files paths
|
||||
// Default settings are mandatory and program crash if there is an error at importation
|
||||
// Custom settings are skipped if malformed or not found
|
||||
func LoadSettings(settings_default_path, settings_custom_path string) {
|
||||
log.Println("Loading settings")
|
||||
Settings = make(map[string]interface{})
|
||||
if err := loadJson(settings_default_path); err != nil {
|
||||
log.Println("error importing default settings")
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := loadJson(settings_custom_path); err != nil {
|
||||
log.Println("error importing custom settings, skipping")
|
||||
log.Println(err)
|
||||
}
|
||||
log.Println("Settings loaded")
|
||||
}
|
8
settings/settings_test.go
Normal file
8
settings/settings_test.go
Normal file
@ -0,0 +1,8 @@
|
||||
/*
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-23 16:08:28
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-23 16:08:37
|
||||
*/
|
||||
|
||||
package settings
|
Loading…
Reference in New Issue
Block a user