Skip to content

Commit

Permalink
status command rough start
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhackett committed Sep 25, 2018
1 parent 971d5e1 commit 9b1e46f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ The easiest way to run Shots is by cloning the `shots-deploy` project and using

* SERVER_ADDRESS
* BOT_KEY
* STORE_ADDRESS
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ module github.com/shots-fired/shots-discord
require (
github.com/bwmarrin/discordgo v0.18.0
github.com/gorilla/websocket v1.4.0 // indirect
github.com/shots-fired/shots-common v0.0.0-20180925012708-830c4055bfaf
golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b // indirect
)
24 changes: 23 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"strings"

"github.com/bwmarrin/discordgo"
"github.com/shots-fired/shots-common/models"
)

var botID string
Expand Down Expand Up @@ -49,7 +54,7 @@ func commandHandler(discord *discordgo.Session, message *discordgo.MessageCreate
case "!register":
registerTwitchHandler(discord, message, split)
case "!status":
discord.ChannelMessageSend(message.ChannelID, "Status is WIP")
statusTwitchHandler(discord, message)
}
}
}
Expand All @@ -61,3 +66,20 @@ func registerTwitchHandler(discord *discordgo.Session, message *discordgo.Messag
discord.ChannelMessageSend(message.ChannelID, "Need to specify a username to register")
}
}

func statusTwitchHandler(discord *discordgo.Session, message *discordgo.MessageCreate) {
str := ""
res, err := http.Get("http://" + os.Getenv("STORE_ADDRESS") + "/streamers")
if err != nil {
panic(err)
}
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
streamers := models.Streamers{}
json.Unmarshal(body, &streamers)
for _, v := range streamers {
str += fmt.Sprintf("%s %s %d\n", v.Name, v.Status, v.Viewers)
log.Printf("%s %s %d\n", v.Name, v.Status, v.Viewers)
}
discord.ChannelMessageSend(message.ChannelID, str)
}

0 comments on commit 9b1e46f

Please sign in to comment.