This repository has been archived by the owner on Dec 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_handler.go
88 lines (73 loc) · 2.31 KB
/
command_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"encoding/json"
"fmt"
"tpbt/dal"
"tpbt/models"
"tpbt/services"
)
func ProcessToggleBot(prv *services.Provider, user *models.BTStreamer, cmd *models.Command) {
user.IsBotInChannel = !user.IsBotInChannel
err := dal.UpdateBotInChannel(prv, user)
if err != nil {
fmt.Println(err)
}
err = SendCommand(user, "SET_USER", user)
if err != nil {
fmt.Println(err)
}
if user.IsBotInChannel {
fmt.Printf("[%v] Joining channel\n", user.TwitchName)
prv.Twitch.Join(user.TwitchName)
prv.Twitch.Say(user.TwitchName, "Bonsoir bonsoir, je suis de retour!")
} else {
fmt.Printf("[%v] Leaving channel\n", user.TwitchName)
prv.Twitch.Say(user.TwitchName, "J'y vais moi, la bise!")
prv.Twitch.Depart(user.TwitchName)
}
}
func ProcessToggleTurn(prv *services.Provider, user *models.BTStreamer, cmd *models.Command) {
if user.Game.Running {
concludeGame(user, prv)
} else {
game := &models.Game{}
err := json.Unmarshal([]byte(cmd.Arguments), game)
if err != nil {
fmt.Println(err)
}
game.Running = true
game.Players = []*models.BTPlayer{}
user.Game = game
_ = SendCommand(user, "SET_FOUND", game.Players)
if game.IsTimed {
game.TimeLeft = game.TimeSet
go RunCountdown(game, user, func() {
concludeGame(user, prv)
})
}
prv.Twitch.Say(user.TwitchName, "C'est parti ! Écoutez la musique et devinez le titre et l'artiste.")
}
_ = SendCommand(user, "SET_GAME", user.Game)
}
func concludeGame(user *models.BTStreamer, prv *services.Provider) {
fmt.Println("Concluding a game")
user.Game.Running = false
scores, err := dal.FetchScoreboard(prv, user)
if err != nil {
fmt.Println("Something went wrong fetching scores")
} else {
_ = SendCommand(user, "SET_LEADERBOARD", scores)
}
lbTurn := "La manche est terminé. La musique était " + user.Game.Title + " de " + user.Game.Artist + "."
length := len(user.Game.Players)
if length > 0 {
if length == 1 {
lbTurn = lbTurn + " Le gagnant est " + user.Game.Players[0].Name
} else if length == 2 {
lbTurn = lbTurn + " Voici le podium: #1 " + user.Game.Players[0].Name + ", #2 " + user.Game.Players[1].Name
} else {
lbTurn = lbTurn + " Voici le podium: #1 " + user.Game.Players[0].Name + ", #2 " + user.Game.Players[1].Name + ", #3 " + user.Game.Players[2].Name
}
}
prv.Twitch.Say(user.TwitchName, lbTurn)
}