forked from Clinet/clinet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
121 lines (114 loc) · 4.38 KB
/
config.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
111
112
113
114
115
116
117
118
119
120
121
package main
import (
"errors"
"regexp"
"github.com/JoshuaDoes/duckduckgolang"
"github.com/JoshuaDoes/go-soundcloud"
"github.com/JoshuaDoes/go-wolfram"
"github.com/bwmarrin/discordgo"
"github.com/google/go-github/github"
"github.com/koffeinsource/go-imgur"
"github.com/nishanths/go-xkcd"
"google.golang.org/api/youtube/v3"
)
//Bot data structs
type BotClients struct {
DuckDuckGo *duckduckgo.Client
GitHub *github.Client
Imgur imgur.Client
SoundCloud *soundcloud.Client
Wolfram *wolfram.Client
XKCD *xkcd.Client
YouTube *youtube.Service
}
type BotData struct {
BotClients BotClients
BotKeys BotKeys `json:"botKeys"`
BotName string `json:"botName"`
BotOwnerID string `json:"botOwnerID"`
BotOptions BotOptions `json:"botOptions"`
BotToken string `json:"botToken"`
CommandPrefix string `json:"cmdPrefix"`
CustomResponses []CustomResponseQuery `json:"customResponses"`
CustomStatuses []CustomStatus `json:"customStatuses"`
DebugMode bool `json:"debugMode"`
//RecoverCrashes bool `json:"recoverCrashes"`
//SendOwnerStackTraces bool `json:"sendOwnerStackTraces"`
DiscordSession *discordgo.Session
Commands map[string]*Command
}
type BotKeys struct {
DuckDuckGoAppName string `json:"ddgAppName"`
ImgurClientID string `json:"imgurClientID"`
SoundCloudAppVersion string `json:"soundcloudAppVersion"`
SoundCloudClientID string `json:"soundcloudClientID"`
WolframAppID string `json:"wolframAppID"`
YouTubeAPIKey string `json:"youtubeAPIKey"`
}
type BotOptions struct {
SendTypingEvent bool `json:"sendTypingEvent"`
UseDuckDuckGo bool `json:"useDuckDuckGo"`
UseGitHub bool `json:"useGitHub"`
UseImgur bool `json:"useImgur"`
UseSoundCloud bool `json:"useSoundCloud"`
UseWolframAlpha bool `json:"useWolframAlpha"`
UseXKCD bool `json:"useXKCD"`
UseYouTube bool `json:"useYouTube"`
WolframDeniedPods []string `json:"wolframDeniedPods"`
YouTubeMaxResults int `json:"youtubeMaxResults"`
}
type CustomResponseQuery struct {
Expression string `json:"expression"`
Regexp *regexp.Regexp
Responses []CustomResponseReply `json:"response"`
}
type CustomResponseReply struct {
Response string `json:"text"`
ImageURL string `json:"imageURL"`
}
type CustomStatus struct {
Type int `json:"type"`
Status string `json:"status"`
URL string `json:"url,omitempty"`
}
func (configData *BotData) PrepConfig() error {
//Bot config checks
if configData.BotName == "" {
return errors.New("config:{botName: \"\"}")
}
if configData.BotToken == "" {
return errors.New("config:{botName: \"\"}")
}
if configData.CommandPrefix == "" {
return errors.New("config:{cmdPrefix: \"\"}")
}
//Bot key checks
if configData.BotOptions.UseDuckDuckGo && configData.BotKeys.DuckDuckGoAppName == "" {
return errors.New("config:{botOptions:{useDuckDuckGo: true}} not permitted, config:{botKeys:{ddgAppName: \"\"}}")
}
if configData.BotOptions.UseImgur && configData.BotKeys.ImgurClientID == "" {
return errors.New("config:{botOptions:{useImgur: true}} not permitted, config:{botKeys:{imgurClientID: \"\"}}")
}
if configData.BotOptions.UseSoundCloud && configData.BotKeys.SoundCloudAppVersion == "" {
return errors.New("config:{botOptions:{useSoundCloud: true}} not permitted, config:{botKeys:{soundcloudAppVersion: \"\"}}")
}
if configData.BotOptions.UseSoundCloud && configData.BotKeys.SoundCloudClientID == "" {
return errors.New("config:{botOptions:{useSoundCloud: true}} not permitted, config:{botKeys:{soundcloudClientID: \"\"}}")
}
if configData.BotOptions.UseWolframAlpha && configData.BotKeys.WolframAppID == "" {
return errors.New("config:{botOptions:{useWolframAlpha: true}} not permitted, config:{botKeys:{wolframAppID: \"\"}}")
}
if configData.BotOptions.UseYouTube && configData.BotKeys.YouTubeAPIKey == "" {
return errors.New("config:{botOptions:{useYouTube: true}} not permitted, config:{botKeys:{youtubeAPIKey: \"\"}}")
}
//Custom response checks
for i, customResponse := range configData.CustomResponses {
regexp, err := regexp.Compile(customResponse.Expression)
if err != nil {
return err
} else {
configData.CustomResponses[i].Regexp = regexp
}
}
return nil
}