-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
75 lines (68 loc) · 1.84 KB
/
types.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
package main
import (
"database/sql"
"encoding/json"
"log"
"os"
_ "github.com/lib/pq"
"github.com/thedadams/telegram-bot-api"
)
// CAHBot inherits from tgbotapi.
type CAHBot struct {
*tgbotapi.BotAPI
DBConn *sql.DB
AllQuestionCards []QuestionCard `json:"all_question_cards"`
AllAnswerCards []AnswerCard `json:"all_answer_cards"`
Settings []Setting `json:"settings"`
}
// NewCAHBot creates a new CAHBot.
func NewCAHBot(token string) (*CAHBot, error) {
GenericBot, err := tgbotapi.NewBotAPI(os.Getenv("TOKEN"))
if err != nil {
log.Printf("Error initializing bot: %v", err)
return nil, err
}
// Need to get the card data
var AllQuestionCards []QuestionCard
err = json.Unmarshal(AllQuestions, &AllQuestionCards)
if err != nil {
log.Printf("%v", err)
return nil, err
}
var AllAnswerCards []AnswerCard
err = json.Unmarshal(AllAnswers, &AllAnswerCards)
if err != nil {
log.Printf("%v", err)
return nil, err
}
var Settings []Setting
err = json.Unmarshal(AllSettings, &Settings)
if err != nil {
log.Printf("%v", err)
return nil, err
}
db, err := sql.Open("postgres", os.Getenv("DATABASE_URL"))
if err != nil {
log.Printf("%v", err)
}
return &CAHBot{GenericBot, db, AllQuestionCards, AllAnswerCards, Settings}, err
}
// QuestionCard represents a white card in CAH.
type QuestionCard struct {
ID int `json:"id"`
Text string `json:"text"`
NumAnswers int `json:"numAnswers"`
Expansion string `json:"expansion"`
}
// AnswerCard represents a black card in CAH.
type AnswerCard struct {
ID int `json:"id"`
Text string `json:"text"`
Expansion string `json:"expansion"`
}
// Setting represents a setting in the game that can be changed.
type Setting struct {
Name string `json:"name"`
CData string `json:"cdata"`
Options []Setting `json:"options"` // optional
}