Skip to content

Commit

Permalink
Merge pull request #9 from Kesuaheli/twitch
Browse files Browse the repository at this point in the history
twitch bot integration
  • Loading branch information
Kesuaheli authored Jan 12, 2024
2 parents 96d97e2 + ddcf2f4 commit 0ad2ff5
Show file tree
Hide file tree
Showing 28 changed files with 1,524 additions and 227 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# IDE
.vscode/

# Binaries for programs and plugins
*.exe
*.exe~
Expand Down
18 changes: 18 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,23 @@ event:
#emoji.id:
#emoji.animated: true

twitch_giveaway:
# The amount of points a single giveaway ticket costs.
ticket_cost: 1000
# Cooldown in minutes before beeing able to by another ticket
cooldown: 15
# the filepath for of the json giveaway prizes
prizes: twitch/prizes.json
# the filepath for storing the giveaway cooldown times
times: twitch/times.json

webserver:
favicon: webserver/favicon.png
birthday_hour: 8 # Time to trigger daily birthday check (24h format)

twitch:
name: c4e_bot
channels:
- kesuaheli
- taomi_
- c4e_bot
12 changes: 12 additions & 0 deletions config_env.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,15 @@ discord:
token: PUT.TOKEN.HERE
# ID of guild currently used for adding commands
guildID: 0

twitch:
# username of the bot account
name: twitch_username
# twitch oauth token, starts with "oauth:"
token:
# a custom secret for the webhook, used for verifying hashes
webhookSecret:

streamelements:
# Streamelements JSON Web Token (JWT)
token: PUT TOKEN.HERE
37 changes: 37 additions & 0 deletions data/lang/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,40 @@ module:
youtube:
embed_footer: YouTube Glocke
msg.new_vid: "%s hat ein neues Video hochgeladen"

twitch.command:
generic:
error: Upsi, da ist was schief gelaufen! 🙃 @Kesuaheli Hilfe!

join:
msg.no_prizes: "@%s es gibt momentan keine Preise zu gewinnen. Du kannst diesen Befehl momentan nicht ausführen."
msg.won: "@%s, du hast schon etwas gewonnen und kannst keine Tickets mehr kaufen."
msg.max_tickets: "@%s, du hast bereits schon alle 10/10 Tickets gekauft. Lass anderen auch eine Chance ;)"
msg.cooldown:
- "@%s, du musst noch %s warten um dir ein weiteres Ticket kaufen zu können."
- "@%s, du bist mir zu schnell. Warte noch so %s um wieder eins zu kaufen."
- "@%s Ein Ticket kannst du zwar erst in %s kaufen, aber den Stream kannst du in der Zwischenzeit durchgehend schauen ;)"
- Schon wieder, @%s? Du hattest doch erst ein Ticket gekauft. Warte noch %s.
- "@%s Ein weiteres Ticket ist in Arbeit... du kannst es dir in %s abholen."
- "@%s Beep Boop 🤖 Dein Ticket wird gedruckt. Vorraussichtliche Druckzeit: noch %s verbleibend"
- "@%s, damit du mehr vom Stream genießen kannst, kannst du erst in %s wieder ein Ticket kaufen."
msg.too_few_points: "@%s du nicht genügend Punkte (%d)! Du brauchst noch %d mehr um den Preis von %d zu bezahlen."
msg.success: "@%s du hast dir erfolgreich ein Ticket für %d Punkte gekauft. Du hast nun %d Tickets und noch %d Punkte über."

tickets:
msg.won: "@%s, du hast schon etwas gewonnen und kannst keine Tickets mehr besitzen."
msg.won.user: "@%s %s hat schon etwas gewonnen und kann keine Tickets mehr besitzen."
msg.max_tickets: "@%s, du hast alle 10/10 Tickets gekauft."
msg.max_tickets.user: "@%s, %s hat alle 10/10 Tickets gekauft."
msg.num.0: "@%s, du hast noch keine Tickets."
msg.num.0.user: "@%s, %s hat noch keine Tickets."
msg.num: "@%s, du hast %d/10 Tickets."
msg.num.user: "@%s, %s hat %d/10 Tickets."
msg.extra.need_points: Für ein weiteres Ticket brauchst du noch %d Punkte.
msg.extra.can_buy: Du kannst dir ein weiteres Ticket mit !ticket kaufen.
msg.extra.cooldown: Momentan bist du aber noch %s im Cooldown, bevor du den Ticket-Befehl benutzen kannst.

draw:
msg.no_prizes: "@%s es gibt momentan keine Preise zu gewinnen. Du kannst diesen Befehl momentan nicht ausführen."
msg.no_entries: "@%s es gibt momentan keine Einträge und somit kann kein Gewinner gezogen werden."
msg.winner: Glückwunsch! @%s hat %s gewonnen. Du hattest %d/10 Tickets und eine Gewinnchance von %.2f%%.
37 changes: 37 additions & 0 deletions data/lang/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,40 @@ module:
youtube:
embed_footer: YouTube notification bell
msg.new_vid: "%s just uploaded a new video"

twitch.command:
generic:
error: Whoops, something is not right here! 🙃 @Kesuaheli Help!

join:
msg.no_prizes: "@%s there's nothing to win at the moment. You can't use this command at the moment."
msg.won: "@%s, you've won a price already and aren't allow to buy more tickets ."
msg.max_tickets: "@%s, you've bought all 10/10 tickets already. Give others a chance too ;)"
msg.cooldown:
- "@%s, you have to wait %s to buy another ticket."
- "@%s, you're too fast! Wait like %s to buy another one."
- "@%s Although you won't be able to buy another ticket for %s, you can watch the stream continuously in the meantime ;)"
- Already, @%s? Didn't you just bought a ticket? Wait another %s.
- "@%s Another ticket is in progress... you can claim it in %s."
- "@%s Beep boop 🤖 Your ticket will be printed. Estimated printing time: %s remaining"
- "@%s, to enjoy more of the stream, you can only buy a ticket again in %s."
msg.too_few_points: "@%s you don't have enough points (%d)! You need %d more to pay the costs of %d points."
msg.success: "@%s you successfully bought a ticket for %d points. Now you have %d tickets and %d points left."

tickets:
msg.won: "@%s, you already won something and can no longer own tickets."
msg.won.user: "@%s %s already won something and can no longer own tickets."
msg.max_tickets: "@%s, you bought all 10/10 tickets."
msg.max_tickets.user: "@%s, %s bought all 10/10 tickets."
msg.num.0: "@%s, you don't have any tickets yet."
msg.num.0.user: "@%s, %s doesn't have any tickets yet."
msg.num: "@%s, you have %d/10 tickets."
msg.num.user: "@%s, %s has %d/10 tickets."
msg.extra.need_points: For your next ticket, you'll need %d points more.
msg.extra.can_buy: You can buy a ticket with !ticket.
msg.extra.cooldown: But right now you're still %s in cooldown, before you can use the ticket command.

draw:
msg.no_prizes: "@%s There're currently no prizes available. You can't perfrom this command now."
msg.no_entries: "@%s There're currently no entries and therefore no winner can be drawn."
msg.winner: Congratulations! @%s won %s. You had %d/10 tickets and a win probability of %.2f%%.
36 changes: 32 additions & 4 deletions data/lang/lang.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func GetDefault(key string) string {
return Get(key, FallbackLang())
}

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

s := v.GetStringSlice(key)
Expand All @@ -218,7 +218,35 @@ func GetSlice(key string, i int, lang string) string {
return key
}
log.Printf("WARNING: key '%s' is not defined in language '%s', using '%s' as fallback instead\n", key, lang, fLang)
return Get(key, fLang)
return GetSliceElement(key, i, fLang)
}

// GetSlice is similar sto GetSliceElement, but instead returns the hole sting slice without any
// checks.
func GetSlice(key string, lang string) []string {
if len(langsMap) == 0 {
log.Println()
log.Printf("ERROR: Tried to get translation, but no language loaded\n")
log.Println()
return []string{key}
}

lang = Unify(lang)

v, ok := langsMap[lang]
fLang := FallbackLang()
if !ok {
if lang == fLang {
log.Println()
log.Printf("ERROR: Tried to get key from fallback language ('%s'), but its not load\n", fLang)
log.Println()
return []string{key}
}
log.Printf("WARNING: language '%s' is not loaded, using '%s' as fallback instead\n", lang, fLang)
return GetSlice(key, fLang)
}

return v.GetStringSlice(key)
}

// GetLangs returns all loaded languages
Expand Down
Loading

0 comments on commit 0ad2ff5

Please sign in to comment.