Signed-off-by: Martyn Ranyard <m@rtyn.berlin>
This commit is contained in:
Martyn 2020-02-22 14:08:01 +01:00
parent 4803122aad
commit 11c96d20d0
3 changed files with 244 additions and 244 deletions

View File

@ -2,8 +2,8 @@ package irc
import ( import (
"bufio" "bufio"
"encoding/json"
"encoding/base64" "encoding/base64"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"io" "io"
@ -16,8 +16,8 @@ import (
"time" "time"
rgb "github.com/foresthoffman/rgblog" rgb "github.com/foresthoffman/rgblog"
scribble "github.com/nanobox-io/golang-scribble"
uuid "github.com/google/uuid" uuid "github.com/google/uuid"
scribble "github.com/nanobox-io/golang-scribble"
) )
const PSTFormat = "Jan 2 15:04:05 PST" const PSTFormat = "Jan 2 15:04:05 PST"
@ -64,6 +64,7 @@ type ChannelData struct {
Command string `json:"customcommand,omitempty"` Command string `json:"customcommand,omitempty"`
ExtraStrings string `json:"extrastrings,omitempty"` ExtraStrings string `json:"extrastrings,omitempty"`
JoinTime time.Time `json:"jointime"` JoinTime time.Time `json:"jointime"`
ControlChannel bool
} }
// Connects the bot to the Twitch IRC server. The bot will continue to try to connect until it // Connects the bot to the Twitch IRC server. The bot will continue to try to connect until it
@ -185,7 +186,6 @@ func (bb *KardBot) Login() {
bb.conn.Write([]byte("NICK " + bb.Name + "\r\n")) bb.conn.Write([]byte("NICK " + bb.Name + "\r\n"))
} }
func (bb *KardBot) LeaveChannel(channels ...string) { func (bb *KardBot) LeaveChannel(channels ...string) {
for _, channel := range channels { for _, channel := range channels {
rgb.YPrintf("[%s] Leaving #%s...\n", TimeStamp(), channel) rgb.YPrintf("[%s] Leaving #%s...\n", TimeStamp(), channel)
@ -275,7 +275,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 := range(bb.ChannelData) { for channelName := range bb.ChannelData {
bb.JoinChannel(channelName) bb.JoinChannel(channelName)
} }
} else { } else {
@ -304,13 +304,13 @@ func (bb *KardBot) readChannelData() error {
return err return err
} }
bb.ChannelData = make(map[string]ChannelData) bb.ChannelData = make(map[string]ChannelData)
bb.ChannelData[bb.Channel] = record; bb.ChannelData[bb.Channel] = record
} else { } else {
bb.ChannelData = make(map[string]ChannelData) bb.ChannelData = make(map[string]ChannelData)
} }
for _, data := range records { for _, data := range records {
record := ChannelData{} record := ChannelData{}
err := json.Unmarshal([]byte(data), &record); err := json.Unmarshal([]byte(data), &record)
if err != nil { if err != nil {
return err return err
} }
@ -346,7 +346,7 @@ func (bb *KardBot) readOrCreateChannelKey(channel string) string {
var record ChannelData var record ChannelData
if record, ok := bb.ChannelData[channel]; !ok { if record, ok := bb.ChannelData[channel]; !ok {
rgb.YPrintf("[%s] No channel data for #%s exists, creating\n", TimeStamp(), channel) rgb.YPrintf("[%s] No channel data for #%s exists, creating\n", TimeStamp(), channel)
err = bb.Database.Read("channelData", channel, &record); err = bb.Database.Read("channelData", channel, &record)
if err == nil { if err == nil {
bb.ChannelData[channel] = record bb.ChannelData[channel] = record
} }

View File

@ -124,7 +124,7 @@ func AdminHandler(response http.ResponseWriter, request *http.Request) {
td.ExtraStrings = sourceData.ExtraStrings td.ExtraStrings = sourceData.ExtraStrings
ircBot.ChannelData[vars["channel"]] = sourceData ircBot.ChannelData[vars["channel"]] = sourceData
} }
ircBot.Database.Write("channelData", vars["channel"], sourceData); ircBot.Database.Write("channelData", vars["channel"], sourceData)
} }
tmpl := template.Must(template.ParseFiles("web/admin.html")) tmpl := template.Must(template.ParseFiles("web/admin.html"))
tmpl.Execute(response, td) tmpl.Execute(response, td)