Skip to content

Commit 599428d

Browse files
author
Honpray
committed
Read token from environment variable
1 parent fbe808e commit 599428d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

main.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ var (
2626
)
2727

2828
func init() {
29-
token = "Bot NTgxOTkxNjkwODA2NjI0MjY3.XOsnkQ.CBvABPtPgErY7aEcdDbH8xSaUuE"
29+
token = os.Getenv("DG_TOKEN")
30+
if token == "" {
31+
log.Fatal("No env variable DG_TOKEN found.")
32+
}
3033
logPath = "turing.log"
3134
dbSource = "./test.db"
3235

@@ -53,7 +56,7 @@ func init() {
5356

5457
func dbInit() {
5558
// Create User table
56-
stmt, _ = db.Prepare("CREATE TABLE IF NOT EXISTS user (uid INTEGER PRIMARY KEY, dcid TEXT, uname TEXT, fname TEXT, lname TEXT, createts DATETIME);")
59+
stmt, err = db.Prepare("CREATE TABLE IF NOT EXISTS user (uid INTEGER PRIMARY KEY, dcid TEXT, uname TEXT, fname TEXT, lname TEXT, createts DATETIME);")
5760
if err != nil {
5861
log.Fatal(err)
5962
}
@@ -73,7 +76,7 @@ func dbInit() {
7376
}
7477

7578
// Create relationship table
76-
stmt, _ = db.Prepare("CREATE TABLE IF NOT EXISTS user_problem (upid INTEGER PRIMARY KEY, uid INTEGER, pid INTEGER, ts DATETIME, note TEXT);")
79+
stmt, err = db.Prepare("CREATE TABLE IF NOT EXISTS user_problem (upid INTEGER PRIMARY KEY, uid INTEGER, pid INTEGER, ts DATETIME, note TEXT);")
7780
if err != nil {
7881
log.Fatal(err)
7982
}
@@ -96,7 +99,7 @@ func handleCommand(s *discordgo.Session, m *discordgo.MessageCreate) {
9699
}
97100
log.Printf("test @%v: %v", user.Username, content)
98101
log.Println("test reply:", reply.Content)
99-
} else if matched, err := regexp.MatchString(`^!solved [A-Z]+[0-9]+( -m ".+")?$`, content); matched && err == nil {
102+
} else if matched, err := regexp.MatchString(`^!solved [a-zA-Z]+[0-9]+( -m ".+")?$`, content); matched && err == nil {
100103
slv := strings.SplitN(content, " ", 4)
101104
pname := slv[1]
102105

test.db

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)