-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
82 lines (68 loc) · 1.52 KB
/
main.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"fmt"
"log"
"net/http"
"time"
"github.com/Sagleft/uchatbot-engine"
coingecko "github.com/superoo7/go-gecko/v3"
)
const (
configJSONPath = "config.json"
dataProviderConnectTimeout = 5 * time.Second
)
func main() {
app := newSolution()
err := checkErrors(
app.parseConfig,
app.dataProviderConnect,
app.initBot,
)
if err != nil {
log.Fatalln(err)
}
app.printLaunched()
app.runInBackground()
}
func newSolution() *solution {
return &solution{}
}
func (app *solution) printLaunched() {
fmt.Println("bot started")
}
func (app *solution) runInBackground() {
forever := make(chan bool)
// run in background
<-forever
}
func (app *solution) initBot() error {
var err error
app.Engine, err = uchatbot.NewChatBot(uchatbot.ChatBotData{
Client: &app.Config.Utopia,
Chats: app.Config.Chats,
Callbacks: uchatbot.ChatBotCallbacks{
OnContactMessage: app.onContactMessage,
OnChannelMessage: app.onChannelMessage,
OnPrivateChannelMessage: app.onPrivateChannelMessage,
},
UseErrorCallback: true,
ErrorCallback: app.onError,
})
return err
}
func (app *solution) onError(err error) {
log.Println(err)
}
func (app *solution) dataProviderConnect() error {
app.DataProvider = coingecko.NewClient(&http.Client{
Timeout: dataProviderConnectTimeout,
})
return nil
}
func (app *solution) getCryptonPrice() (float32, error) {
data, err := app.DataProvider.SimpleSinglePrice("utopia", "usd")
if err != nil {
return 0, err
}
return data.MarketPrice, nil
}