-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.go
33 lines (28 loc) · 935 Bytes
/
cache.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
package main
import (
"context"
"fmt"
"github.com/bwmarrin/discordgo"
"strings"
"time"
"github.com/theovidal/onyxcord"
)
var expiringGames = map[string]string{
"connectfour": "Le puissance 4",
"hangman": "Le jeu du pendu",
"verbs": "Le quiz Verbes irréguliers",
"tic_tac_toe": "Le morpion",
}
func subscribe(bot *onyxcord.Bot) {
time.Sleep(10 * time.Second)
pubsub := bot.Cache.Subscribe(context.Background(), "__keyevent@0__:expired")
for message := range pubsub.Channel() {
parts := strings.Split(message.Payload, ":")
gameString, channelID := parts[0], parts[1]
bot.ChannelMessageSendEmbed(channelID, bot.MakeEmbed(&discordgo.MessageEmbed{
Color: bot.Config.Bot.ErrorColor,
Title: "⏳ Temps écoulé",
Description: fmt.Sprintf(" %s a expiré dans ce salon, soit car aucun membre n'a participé ou car il s'agit de la durée maximale!", expiringGames[gameString]),
}))
}
}