Skip to content

Commit 0ad2ff5

Browse files
authored
Merge pull request #9 from Kesuaheli/twitch
twitch bot integration
2 parents 96d97e2 + ddcf2f4 commit 0ad2ff5

28 files changed

+1524
-227
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# IDE
2+
.vscode/
3+
14
# Binaries for programs and plugins
25
*.exe
36
*.exe~

config.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,23 @@ event:
4040
#emoji.id:
4141
#emoji.animated: true
4242

43+
twitch_giveaway:
44+
# The amount of points a single giveaway ticket costs.
45+
ticket_cost: 1000
46+
# Cooldown in minutes before beeing able to by another ticket
47+
cooldown: 15
48+
# the filepath for of the json giveaway prizes
49+
prizes: twitch/prizes.json
50+
# the filepath for storing the giveaway cooldown times
51+
times: twitch/times.json
52+
4353
webserver:
4454
favicon: webserver/favicon.png
55+
birthday_hour: 8 # Time to trigger daily birthday check (24h format)
56+
57+
twitch:
58+
name: c4e_bot
59+
channels:
60+
- kesuaheli
61+
- taomi_
62+
- c4e_bot

config_env.yaml.example

+12
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,15 @@ discord:
1111
token: PUT.TOKEN.HERE
1212
# ID of guild currently used for adding commands
1313
guildID: 0
14+
15+
twitch:
16+
# username of the bot account
17+
name: twitch_username
18+
# twitch oauth token, starts with "oauth:"
19+
token:
20+
# a custom secret for the webhook, used for verifying hashes
21+
webhookSecret:
22+
23+
streamelements:
24+
# Streamelements JSON Web Token (JWT)
25+
token: PUT TOKEN.HERE

data/lang/de.yaml

+37
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,40 @@ module:
140140
youtube:
141141
embed_footer: YouTube Glocke
142142
msg.new_vid: "%s hat ein neues Video hochgeladen"
143+
144+
twitch.command:
145+
generic:
146+
error: Upsi, da ist was schief gelaufen! 🙃 @Kesuaheli Hilfe!
147+
148+
join:
149+
msg.no_prizes: "@%s es gibt momentan keine Preise zu gewinnen. Du kannst diesen Befehl momentan nicht ausführen."
150+
msg.won: "@%s, du hast schon etwas gewonnen und kannst keine Tickets mehr kaufen."
151+
msg.max_tickets: "@%s, du hast bereits schon alle 10/10 Tickets gekauft. Lass anderen auch eine Chance ;)"
152+
msg.cooldown:
153+
- "@%s, du musst noch %s warten um dir ein weiteres Ticket kaufen zu können."
154+
- "@%s, du bist mir zu schnell. Warte noch so %s um wieder eins zu kaufen."
155+
- "@%s Ein Ticket kannst du zwar erst in %s kaufen, aber den Stream kannst du in der Zwischenzeit durchgehend schauen ;)"
156+
- Schon wieder, @%s? Du hattest doch erst ein Ticket gekauft. Warte noch %s.
157+
- "@%s Ein weiteres Ticket ist in Arbeit... du kannst es dir in %s abholen."
158+
- "@%s Beep Boop 🤖 Dein Ticket wird gedruckt. Vorraussichtliche Druckzeit: noch %s verbleibend"
159+
- "@%s, damit du mehr vom Stream genießen kannst, kannst du erst in %s wieder ein Ticket kaufen."
160+
msg.too_few_points: "@%s du nicht genügend Punkte (%d)! Du brauchst noch %d mehr um den Preis von %d zu bezahlen."
161+
msg.success: "@%s du hast dir erfolgreich ein Ticket für %d Punkte gekauft. Du hast nun %d Tickets und noch %d Punkte über."
162+
163+
tickets:
164+
msg.won: "@%s, du hast schon etwas gewonnen und kannst keine Tickets mehr besitzen."
165+
msg.won.user: "@%s %s hat schon etwas gewonnen und kann keine Tickets mehr besitzen."
166+
msg.max_tickets: "@%s, du hast alle 10/10 Tickets gekauft."
167+
msg.max_tickets.user: "@%s, %s hat alle 10/10 Tickets gekauft."
168+
msg.num.0: "@%s, du hast noch keine Tickets."
169+
msg.num.0.user: "@%s, %s hat noch keine Tickets."
170+
msg.num: "@%s, du hast %d/10 Tickets."
171+
msg.num.user: "@%s, %s hat %d/10 Tickets."
172+
msg.extra.need_points: Für ein weiteres Ticket brauchst du noch %d Punkte.
173+
msg.extra.can_buy: Du kannst dir ein weiteres Ticket mit !ticket kaufen.
174+
msg.extra.cooldown: Momentan bist du aber noch %s im Cooldown, bevor du den Ticket-Befehl benutzen kannst.
175+
176+
draw:
177+
msg.no_prizes: "@%s es gibt momentan keine Preise zu gewinnen. Du kannst diesen Befehl momentan nicht ausführen."
178+
msg.no_entries: "@%s es gibt momentan keine Einträge und somit kann kein Gewinner gezogen werden."
179+
msg.winner: Glückwunsch! @%s hat %s gewonnen. Du hattest %d/10 Tickets und eine Gewinnchance von %.2f%%.

data/lang/en.yaml

+37
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,40 @@ module:
140140
youtube:
141141
embed_footer: YouTube notification bell
142142
msg.new_vid: "%s just uploaded a new video"
143+
144+
twitch.command:
145+
generic:
146+
error: Whoops, something is not right here! 🙃 @Kesuaheli Help!
147+
148+
join:
149+
msg.no_prizes: "@%s there's nothing to win at the moment. You can't use this command at the moment."
150+
msg.won: "@%s, you've won a price already and aren't allow to buy more tickets ."
151+
msg.max_tickets: "@%s, you've bought all 10/10 tickets already. Give others a chance too ;)"
152+
msg.cooldown:
153+
- "@%s, you have to wait %s to buy another ticket."
154+
- "@%s, you're too fast! Wait like %s to buy another one."
155+
- "@%s Although you won't be able to buy another ticket for %s, you can watch the stream continuously in the meantime ;)"
156+
- Already, @%s? Didn't you just bought a ticket? Wait another %s.
157+
- "@%s Another ticket is in progress... you can claim it in %s."
158+
- "@%s Beep boop 🤖 Your ticket will be printed. Estimated printing time: %s remaining"
159+
- "@%s, to enjoy more of the stream, you can only buy a ticket again in %s."
160+
msg.too_few_points: "@%s you don't have enough points (%d)! You need %d more to pay the costs of %d points."
161+
msg.success: "@%s you successfully bought a ticket for %d points. Now you have %d tickets and %d points left."
162+
163+
tickets:
164+
msg.won: "@%s, you already won something and can no longer own tickets."
165+
msg.won.user: "@%s %s already won something and can no longer own tickets."
166+
msg.max_tickets: "@%s, you bought all 10/10 tickets."
167+
msg.max_tickets.user: "@%s, %s bought all 10/10 tickets."
168+
msg.num.0: "@%s, you don't have any tickets yet."
169+
msg.num.0.user: "@%s, %s doesn't have any tickets yet."
170+
msg.num: "@%s, you have %d/10 tickets."
171+
msg.num.user: "@%s, %s has %d/10 tickets."
172+
msg.extra.need_points: For your next ticket, you'll need %d points more.
173+
msg.extra.can_buy: You can buy a ticket with !ticket.
174+
msg.extra.cooldown: But right now you're still %s in cooldown, before you can use the ticket command.
175+
176+
draw:
177+
msg.no_prizes: "@%s There're currently no prizes available. You can't perfrom this command now."
178+
msg.no_entries: "@%s There're currently no entries and therefore no winner can be drawn."
179+
msg.winner: Congratulations! @%s won %s. You had %d/10 tickets and a win probability of %.2f%%.

data/lang/lang.go

+32-4
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func GetDefault(key string) string {
167167
return Get(key, FallbackLang())
168168
}
169169

170-
// GetSlice returns the configured translation for index i in the
170+
// GetSliceElement returns the configured translation for index i in the
171171
// list at key in the given language lang.
172172
// - If lang is not a loaded language, Get translates key with the
173173
// fallback language.
@@ -180,7 +180,7 @@ func GetDefault(key string) string {
180180
//
181181
// In all four of these 'fail cases', Get will print a warning
182182
// message in the log
183-
func GetSlice(key string, i int, lang string) string {
183+
func GetSliceElement(key string, i int, lang string) string {
184184
if len(langsMap) == 0 {
185185
log.Println()
186186
log.Printf("ERROR: Tried to get translation, but no language loaded\n")
@@ -200,7 +200,7 @@ func GetSlice(key string, i int, lang string) string {
200200
return key
201201
}
202202
log.Printf("WARNING: language '%s' is not loaded, using '%s' as fallback instead\n", lang, fLang)
203-
return Get(key, fLang)
203+
return GetSliceElement(key, i, fLang)
204204
}
205205

206206
s := v.GetStringSlice(key)
@@ -218,7 +218,35 @@ func GetSlice(key string, i int, lang string) string {
218218
return key
219219
}
220220
log.Printf("WARNING: key '%s' is not defined in language '%s', using '%s' as fallback instead\n", key, lang, fLang)
221-
return Get(key, fLang)
221+
return GetSliceElement(key, i, fLang)
222+
}
223+
224+
// GetSlice is similar sto GetSliceElement, but instead returns the hole sting slice without any
225+
// checks.
226+
func GetSlice(key string, lang string) []string {
227+
if len(langsMap) == 0 {
228+
log.Println()
229+
log.Printf("ERROR: Tried to get translation, but no language loaded\n")
230+
log.Println()
231+
return []string{key}
232+
}
233+
234+
lang = Unify(lang)
235+
236+
v, ok := langsMap[lang]
237+
fLang := FallbackLang()
238+
if !ok {
239+
if lang == fLang {
240+
log.Println()
241+
log.Printf("ERROR: Tried to get key from fallback language ('%s'), but its not load\n", fLang)
242+
log.Println()
243+
return []string{key}
244+
}
245+
log.Printf("WARNING: language '%s' is not loaded, using '%s' as fallback instead\n", lang, fLang)
246+
return GetSlice(key, fLang)
247+
}
248+
249+
return v.GetStringSlice(key)
222250
}
223251

224252
// GetLangs returns all loaded languages

0 commit comments

Comments
 (0)