Compare commits

..

2 Commits

Author SHA1 Message Date
Martyn 09d4dc8d64 Slightly different config file formats
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
Signed-off-by: Martyn Ranyard <m@rtyn.berlin>
2020-07-14 21:23:08 +02:00
Martyn f4739ada59 Remove unneeded file
Signed-off-by: Martyn Ranyard <m@rtyn.berlin>
2020-07-14 21:16:41 +02:00
3 changed files with 43 additions and 29 deletions

View File

@ -8,7 +8,6 @@ RUN cd /go/src/git.martyn.berlin/martyn/twitchsingstools/; make deps ; make stat
FROM scratch
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /go/src/git.martyn.berlin/martyn/twitchsingstools /app/
COPY strings.json /app/strings.json
COPY web/ /app/web/
WORKDIR /app
CMD ["/app/twitchsingstools"]

View File

@ -40,13 +40,22 @@ var DirectMsgRegex *regexp.Regexp = regexp.MustCompile(`^:(\w+)!\w+@\w+\.tmi\.tw
// command.
var CmdRegex *regexp.Regexp = regexp.MustCompile(`^!(\w+)\s?(\w+)?`)
type OAuthCred struct {
type IRCOAuthCred struct {
// The bot account's OAuth password.
Password string `json:"password,omitempty"`
// The developer application client ID. Used for API calls to Twitch.
Nick string `json:"nick,omitempty"`
}
type AppOAuthCred struct {
// The bot account's OAuth password.
ClientID string `json:"client_id,omitempty"`
// The developer application client ID. Used for API calls to Twitch.
ClientSecret string `json:"client_secret,omitempty"`
}
type ConfigStruct struct {
@ -61,8 +70,8 @@ type ConfigStruct struct {
type KardBot struct {
Channel string
conn net.Conn
IrcCredentials *OAuthCred
AppCredentials *OAuthCred
IrcCredentials *IRCOAuthCred
AppCredentials *AppOAuthCred
MsgRate time.Duration
Name string
Port string
@ -288,15 +297,21 @@ func (bb *KardBot) ReadCredentials(credType string) error {
}
// parses the file contents
var creds OAuthCred
if credType == "IRC" {
var creds IRCOAuthCred
dec := json.NewDecoder(strings.NewReader(string(credFile)))
if err = dec.Decode(&creds); nil != err && io.EOF != err {
return err
}
if credType == "IRC" {
bb.IrcCredentials = &creds
} else {
var creds AppOAuthCred
dec := json.NewDecoder(strings.NewReader(string(credFile)))
if err = dec.Decode(&creds); nil != err && io.EOF != err {
return err
}
bb.AppCredentials = &creds
}

View File

@ -212,7 +212,7 @@ func TwitchAdminHandler(response http.ResponseWriter, request *http.Request) {
"https://id.twitch.tv/oauth2/token",
url.Values{
"client_id": {ircBot.AppCredentials.ClientID},
"client_secret": {ircBot.AppCredentials.Password},
"client_secret": {ircBot.AppCredentials.ClientSecret},
"code": {vars["code"]},
"grant_type": {"authorization_code"},
"redirect_uri": {"https://" + ircBot.Config.ExternalUrl + "/twitchadmin"}})
@ -306,7 +306,7 @@ func TwitchBackendHandler(response http.ResponseWriter, request *http.Request) {
"https://id.twitch.tv/oauth2/token",
url.Values{
"client_id": {ircBot.AppCredentials.ClientID},
"client_secret": {ircBot.AppCredentials.Password},
"client_secret": {ircBot.AppCredentials.ClientSecret},
"code": {vars["code"]},
"grant_type": {"authorization_code"},
"redirect_uri": {"https://" + ircBot.Config.ExternalUrl + "/twitchadmin"}})