-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
64 lines (52 loc) · 1.59 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
package main
import (
"os"
"os/signal"
"syscall"
"github.com/KforG/discord-price-bot/config"
"github.com/KforG/discord-price-bot/functions"
"github.com/KforG/discord-price-bot/ccs"
"github.com/KforG/discord-price-bot/logging"
"github.com/bwmarrin/discordgo"
)
func main() {
//init logging
logFile, _ := os.OpenFile("debug.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
logging.SetLogFile(logFile)
logging.Infof("Discord bot started up! \n")
//init config
err := config.ReadConfig()
if err != nil {
logging.Errorf("error loading config.json %s\n", err)
panic(err)
}
//Init session
dg, err := discordgo.New(config.BotPrefix + config.Token)
if err != nil {
logging.Errorf("error creating new Discord sesssion, %s\n", err)
}
logging.Infof("Successfully created new discord session \n")
dg.AddHandler(functions.DetermineCommand)
//Open websocket to Discord
err = dg.Open()
if err != nil {
logging.Errorf("error opening websocket connection, %s\n", err)
panic(err)
}
//Display username of bot
me, err := dg.User("@me")
if err != nil {
logging.Warnf("error obtaining account details, %s\n", err)
}
logging.Infof("We've logged in as %s\n", me)
go functions.UpdateChannelStats(dg) //Update channelname price/MC/nethash/diff
go ccs.UpdateCCSChannel(dg) // Update CCS channel - Proposals looking for funding etc.
// Hold up program for Go routines and exit gracefully
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
logging.Infof("Input detected\n")
//Shutdown
dg.Close()
logging.Infof("Closed connection.\n")
}