Compare commits
	
		
			No commits in common. "09d4dc8d6435c324202507d4bc42e8e06338ea5c" and "13f599c3b138d2c94fb74c118561c56f65bab968" have entirely different histories.
		
	
	
		
			09d4dc8d64
			...
			13f599c3b1
		
	
		
					 3 changed files with 29 additions and 43 deletions
				
			
		| 
						 | 
				
			
			@ -8,6 +8,7 @@ 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"]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -40,22 +40,13 @@ var DirectMsgRegex *regexp.Regexp = regexp.MustCompile(`^:(\w+)!\w+@\w+\.tmi\.tw
 | 
			
		|||
// command.
 | 
			
		||||
var CmdRegex *regexp.Regexp = regexp.MustCompile(`^!(\w+)\s?(\w+)?`)
 | 
			
		||||
 | 
			
		||||
type IRCOAuthCred struct {
 | 
			
		||||
type OAuthCred 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 {
 | 
			
		||||
| 
						 | 
				
			
			@ -68,21 +59,21 @@ type ConfigStruct struct {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
type KardBot struct {
 | 
			
		||||
	Channel        string
 | 
			
		||||
	conn           net.Conn
 | 
			
		||||
	IrcCredentials *IRCOAuthCred
 | 
			
		||||
	AppCredentials *AppOAuthCred
 | 
			
		||||
	MsgRate        time.Duration
 | 
			
		||||
	Name           string
 | 
			
		||||
	Port           string
 | 
			
		||||
	Channel     string
 | 
			
		||||
	conn        net.Conn
 | 
			
		||||
	IrcCredentials *OAuthCred
 | 
			
		||||
	AppCredentials *OAuthCred
 | 
			
		||||
	MsgRate     time.Duration
 | 
			
		||||
	Name        string
 | 
			
		||||
	Port        string
 | 
			
		||||
	IrcPrivatePath string
 | 
			
		||||
	AppPrivatePath string
 | 
			
		||||
	Server         string
 | 
			
		||||
	startTime      time.Time
 | 
			
		||||
	Prompts        []string
 | 
			
		||||
	Database       scribble.Driver
 | 
			
		||||
	ChannelData    map[string]ChannelData
 | 
			
		||||
	Config         ConfigStruct
 | 
			
		||||
	Server      string
 | 
			
		||||
	startTime   time.Time
 | 
			
		||||
	Prompts     []string
 | 
			
		||||
	Database    scribble.Driver
 | 
			
		||||
	ChannelData map[string]ChannelData
 | 
			
		||||
	Config      ConfigStruct
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type ChannelData struct {
 | 
			
		||||
| 
						 | 
				
			
			@ -92,7 +83,7 @@ type ChannelData struct {
 | 
			
		|||
	ExtraStrings   string    `json:"extrastrings,omitempty"`
 | 
			
		||||
	JoinTime       time.Time `json:"jointime"`
 | 
			
		||||
	ControlChannel bool
 | 
			
		||||
	HasLeft        bool `json:"hasleft"`
 | 
			
		||||
	HasLeft        bool      `json:"hasleft"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Connects the bot to the Twitch IRC server. The bot will continue to try to connect until it
 | 
			
		||||
| 
						 | 
				
			
			@ -172,8 +163,8 @@ func (bb *KardBot) HandleChat() error {
 | 
			
		|||
			matches = DirectMsgRegex.FindStringSubmatch(line)
 | 
			
		||||
			if nil != matches {
 | 
			
		||||
				userName := matches[1]
 | 
			
		||||
				//				msgType := matches[2]
 | 
			
		||||
				//				channel := matches[3]
 | 
			
		||||
//				msgType := matches[2]
 | 
			
		||||
//				channel := matches[3]
 | 
			
		||||
				msg := matches[4]
 | 
			
		||||
				rgb.GPrintf("[%s] Direct message %s: %s\n", TimeStamp(), userName, msg)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -235,7 +226,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)
 | 
			
		||||
								if err != nil {
 | 
			
		||||
									rgb.RPrintf("[%s] ERROR %s\n", err)
 | 
			
		||||
									rgb.RPrintf("[%s] ERROR %s\n",err)
 | 
			
		||||
								}
 | 
			
		||||
								bb.Say("Ack.")
 | 
			
		||||
							default:
 | 
			
		||||
| 
						 | 
				
			
			@ -285,7 +276,7 @@ func (bb *KardBot) JoinChannel(channels ...string) {
 | 
			
		|||
func (bb *KardBot) ReadCredentials(credType string) error {
 | 
			
		||||
 | 
			
		||||
	var err error
 | 
			
		||||
	var credFile []byte
 | 
			
		||||
    var credFile []byte
 | 
			
		||||
	// reads from the file
 | 
			
		||||
	if credType == "IRC" {
 | 
			
		||||
		credFile, err = ioutil.ReadFile(bb.IrcPrivatePath)
 | 
			
		||||
| 
						 | 
				
			
			@ -297,21 +288,15 @@ func (bb *KardBot) ReadCredentials(credType string) error {
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	// parses the file contents
 | 
			
		||||
	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
 | 
			
		||||
		}
 | 
			
		||||
	var creds OAuthCred
 | 
			
		||||
	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
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -398,7 +383,7 @@ func (bb *KardBot) Start() {
 | 
			
		|||
		bb.Connect()
 | 
			
		||||
		bb.Login()
 | 
			
		||||
		if len(bb.ChannelData) > 0 {
 | 
			
		||||
			for channelName, channelData := range bb.ChannelData {
 | 
			
		||||
			for channelName,channelData := range bb.ChannelData {
 | 
			
		||||
				if !channelData.HasLeft {
 | 
			
		||||
					bb.JoinChannel(channelName)
 | 
			
		||||
				}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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.ClientSecret},
 | 
			
		||||
				"client_secret": {ircBot.AppCredentials.Password},
 | 
			
		||||
				"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.ClientSecret},
 | 
			
		||||
				"client_secret": {ircBot.AppCredentials.Password},
 | 
			
		||||
				"code":          {vars["code"]},
 | 
			
		||||
				"grant_type":    {"authorization_code"},
 | 
			
		||||
				"redirect_uri":  {"https://" + ircBot.Config.ExternalUrl + "/twitchadmin"}})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue