-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
110 lines (90 loc) · 1.73 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package main
import (
"database/sql"
"fmt"
"net/http"
"net/url"
"os"
"time"
sg "os/signal"
sc "syscall"
dg "github.com/bwmarrin/discordgo"
_ "github.com/lib/pq"
"github.com/pariz/gountries"
)
var (
botID string
db *sql.DB
countries = gountries.New()
b *url.URL
f Client
customFlags = map[string]int{
"flag_eng": 463313404254486529,
}
)
const DATE_LAYOUT = "2006-01-02"
func main() {
b, err := url.Parse("http://api.football-data.org/v2/")
if err != nil {
fmt.Println("Problem parsing the base URL:", err)
return
}
ak := os.Getenv("API_KEY")
if ak == "" {
fmt.Println("API_KEY NOT SET.")
return
}
f = Client{
APIKey: ak,
BaseURL: b,
Client: &http.Client{Timeout: 3 * time.Second},
}
fmt.Println("Hello, world!")
tk := os.Getenv("TOKEN")
if tk == "" {
fmt.Println("TOKEN NOT SET.")
return
}
bot, err := dg.New(fmt.Sprintf("Bot %v", tk))
if err != nil {
fmt.Println("error in bot")
return
}
user, err := bot.User("@me")
if err != nil {
fmt.Println("error in user")
return
}
db, err = getDB()
if err != nil {
fmt.Println("error in getting DB", err)
return
}
defer db.Close()
_, err = db.Exec(`
CREATE TABLE IF NOT EXISTS guilds (
id VARCHAR PRIMARY KEY,
name TEXT,
prefix TEXT
)
`)
if err != nil {
fmt.Println("err in creating table guilds", err)
return
}
botID = user.ID
bot.AddHandler(pingPong)
bot.AddHandler(hi)
bot.AddHandler(bye)
bot.AddHandler(commands)
err = bot.Open()
if err != nil {
fmt.Println("error opening Discord connection,", err)
return
}
defer bot.Close()
fmt.Println("Bot is running")
scn := make(chan os.Signal, 1)
sg.Notify(scn, sc.SIGINT, sc.SIGTERM, os.Interrupt, os.Kill)
<-scn
}