Slightly different config file formats
Signed-off-by: Martyn Ranyard <m@rtyn.berlin>
This commit is contained in:
parent
f4739ada59
commit
09d4dc8d64
|
@ -40,13 +40,22 @@ var DirectMsgRegex *regexp.Regexp = regexp.MustCompile(`^:(\w+)!\w+@\w+\.tmi\.tw
|
||||||
// command.
|
// command.
|
||||||
var CmdRegex *regexp.Regexp = regexp.MustCompile(`^!(\w+)\s?(\w+)?`)
|
var CmdRegex *regexp.Regexp = regexp.MustCompile(`^!(\w+)\s?(\w+)?`)
|
||||||
|
|
||||||
type OAuthCred struct {
|
type IRCOAuthCred struct {
|
||||||
|
|
||||||
// The bot account's OAuth password.
|
// The bot account's OAuth password.
|
||||||
Password string `json:"password,omitempty"`
|
Password string `json:"password,omitempty"`
|
||||||
|
|
||||||
// The developer application client ID. Used for API calls to Twitch.
|
// 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"`
|
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 {
|
type ConfigStruct struct {
|
||||||
|
@ -61,8 +70,8 @@ type ConfigStruct struct {
|
||||||
type KardBot struct {
|
type KardBot struct {
|
||||||
Channel string
|
Channel string
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
IrcCredentials *OAuthCred
|
IrcCredentials *IRCOAuthCred
|
||||||
AppCredentials *OAuthCred
|
AppCredentials *AppOAuthCred
|
||||||
MsgRate time.Duration
|
MsgRate time.Duration
|
||||||
Name string
|
Name string
|
||||||
Port string
|
Port string
|
||||||
|
@ -163,8 +172,8 @@ func (bb *KardBot) HandleChat() error {
|
||||||
matches = DirectMsgRegex.FindStringSubmatch(line)
|
matches = DirectMsgRegex.FindStringSubmatch(line)
|
||||||
if nil != matches {
|
if nil != matches {
|
||||||
userName := matches[1]
|
userName := matches[1]
|
||||||
// msgType := matches[2]
|
// msgType := matches[2]
|
||||||
// channel := matches[3]
|
// channel := matches[3]
|
||||||
msg := matches[4]
|
msg := matches[4]
|
||||||
rgb.GPrintf("[%s] Direct message %s: %s\n", TimeStamp(), userName, msg)
|
rgb.GPrintf("[%s] Direct message %s: %s\n", TimeStamp(), userName, msg)
|
||||||
|
|
||||||
|
@ -226,7 +235,7 @@ func (bb *KardBot) HandleChat() error {
|
||||||
)
|
)
|
||||||
err := bb.Msg("Welcome to Karaokards, your admin panel is https://karaokards.ing.martyn.berlin/admin/"+userName+"/"+magicCode, userName)
|
err := bb.Msg("Welcome to Karaokards, your admin panel is https://karaokards.ing.martyn.berlin/admin/"+userName+"/"+magicCode, userName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rgb.RPrintf("[%s] ERROR %s\n",err)
|
rgb.RPrintf("[%s] ERROR %s\n", err)
|
||||||
}
|
}
|
||||||
bb.Say("Ack.")
|
bb.Say("Ack.")
|
||||||
default:
|
default:
|
||||||
|
@ -288,15 +297,21 @@ func (bb *KardBot) ReadCredentials(credType string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// parses the file contents
|
// parses the file contents
|
||||||
var creds OAuthCred
|
if credType == "IRC" {
|
||||||
|
var creds IRCOAuthCred
|
||||||
dec := json.NewDecoder(strings.NewReader(string(credFile)))
|
dec := json.NewDecoder(strings.NewReader(string(credFile)))
|
||||||
if err = dec.Decode(&creds); nil != err && io.EOF != err {
|
if err = dec.Decode(&creds); nil != err && io.EOF != err {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if credType == "IRC" {
|
|
||||||
bb.IrcCredentials = &creds
|
bb.IrcCredentials = &creds
|
||||||
} else {
|
} 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
|
bb.AppCredentials = &creds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,7 +398,7 @@ func (bb *KardBot) Start() {
|
||||||
bb.Connect()
|
bb.Connect()
|
||||||
bb.Login()
|
bb.Login()
|
||||||
if len(bb.ChannelData) > 0 {
|
if len(bb.ChannelData) > 0 {
|
||||||
for channelName,channelData := range bb.ChannelData {
|
for channelName, channelData := range bb.ChannelData {
|
||||||
if !channelData.HasLeft {
|
if !channelData.HasLeft {
|
||||||
bb.JoinChannel(channelName)
|
bb.JoinChannel(channelName)
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,7 +212,7 @@ func TwitchAdminHandler(response http.ResponseWriter, request *http.Request) {
|
||||||
"https://id.twitch.tv/oauth2/token",
|
"https://id.twitch.tv/oauth2/token",
|
||||||
url.Values{
|
url.Values{
|
||||||
"client_id": {ircBot.AppCredentials.ClientID},
|
"client_id": {ircBot.AppCredentials.ClientID},
|
||||||
"client_secret": {ircBot.AppCredentials.Password},
|
"client_secret": {ircBot.AppCredentials.ClientSecret},
|
||||||
"code": {vars["code"]},
|
"code": {vars["code"]},
|
||||||
"grant_type": {"authorization_code"},
|
"grant_type": {"authorization_code"},
|
||||||
"redirect_uri": {"https://" + ircBot.Config.ExternalUrl + "/twitchadmin"}})
|
"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",
|
"https://id.twitch.tv/oauth2/token",
|
||||||
url.Values{
|
url.Values{
|
||||||
"client_id": {ircBot.AppCredentials.ClientID},
|
"client_id": {ircBot.AppCredentials.ClientID},
|
||||||
"client_secret": {ircBot.AppCredentials.Password},
|
"client_secret": {ircBot.AppCredentials.ClientSecret},
|
||||||
"code": {vars["code"]},
|
"code": {vars["code"]},
|
||||||
"grant_type": {"authorization_code"},
|
"grant_type": {"authorization_code"},
|
||||||
"redirect_uri": {"https://" + ircBot.Config.ExternalUrl + "/twitchadmin"}})
|
"redirect_uri": {"https://" + ircBot.Config.ExternalUrl + "/twitchadmin"}})
|
||||||
|
|
Loading…
Reference in New Issue