store channels in db and make adding possible
This commit is contained in:
parent
fe0d4ec068
commit
94f037dbf8
3 changed files with 33 additions and 1 deletions
10
main.go
10
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)
|
||||
|
|
11
prod.yml
Normal file
11
prod.yml
Normal file
|
@ -0,0 +1,11 @@
|
|||
version: "3"
|
||||
services:
|
||||
gempbotgo:
|
||||
build: ./
|
||||
restart: always
|
||||
ports:
|
||||
- "8025:8025"
|
||||
env_file:
|
||||
- .env
|
||||
volumes:
|
||||
- /var/twitch_logs:/var/twitch_logs
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue