From 94f037dbf84d5bba41722e197669dede994171bf Mon Sep 17 00:00:00 2001 From: gempir Date: Sun, 19 Nov 2017 15:28:09 +0100 Subject: [PATCH] store channels in db and make adding possible --- main.go | 10 +++++++++- prod.yml | 11 +++++++++++ store/client.go | 13 +++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 prod.yml diff --git a/main.go b/main.go index 16bfdb9..a3db2f0 100644 --- a/main.go +++ b/main.go @@ -31,7 +31,7 @@ func main() { apiServer := api.NewServer() go apiServer.Init() - time.Sleep(time.Second * 3) + time.Sleep(time.Second * 10) store, err := store.NewClient(os.Getenv("DSN")) if err != nil { log.Fatal(err) @@ -68,6 +68,14 @@ func main() { twitchClient.Say(channel, "uptime: "+uptime) } + if user.Username == admin && strings.HasPrefix(message.Text, "!join ") { + joinChannel := strings.Replace(message.Text, "!join ", "", 1) + store.AddChannel(joinChannel) + fmt.Println("Joining " + joinChannel) + twitchClient.Join(joinChannel) + twitchClient.Say(channel, admin+", joining: #"+joinChannel) + } + if user.Username == admin && strings.HasPrefix(message.Text, "!status") { uptime := humanize.TimeSince(startTime) twitchClient.Say(channel, admin+", uptime: "+uptime) diff --git a/prod.yml b/prod.yml new file mode 100644 index 0000000..e26322e --- /dev/null +++ b/prod.yml @@ -0,0 +1,11 @@ +version: "3" +services: + gempbotgo: + build: ./ + restart: always + ports: + - "8025:8025" + env_file: + - .env + volumes: + - /var/twitch_logs:/var/twitch_logs diff --git a/store/client.go b/store/client.go index d72269c..69f416e 100644 --- a/store/client.go +++ b/store/client.go @@ -42,3 +42,16 @@ func (c *Client) GetAllChannels() []string { return channels } + +// AddChannel persist channel +func (c *Client) AddChannel(channel string) { + stmt, err := c.db.Prepare("INSERT channels SET name=?") + if err != nil { + log.Println(err.Error()) + } + + _, err = stmt.Exec(channel) + if err != nil { + log.Println(err.Error()) + } +}