-
Notifications
You must be signed in to change notification settings - Fork 0
/
guild.go
70 lines (59 loc) · 1.51 KB
/
guild.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
package main
import (
"context"
"github.com/disgoorg/disgolink/v3/lavalink"
"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"
)
type GuildPlayer struct {
channelID *snowflake.ID
messageID *snowflake.ID
}
type Guild struct {
guildPlayer *GuildPlayer
queue *Queue
}
type GuildManager struct {
bot *Bot
guilds map[snowflake.ID]*Guild
}
func (gm *GuildManager) Get(guildID snowflake.ID) *Guild {
guild, ok := gm.guilds[guildID]
if !ok {
queue := &Queue{
Tracks: make([]lavalink.Track, 0),
Type: QueueTypeNoRepeat,
}
dbGuild, err := gm.bot.EntClient.Guild.Get(context.TODO(), guildID)
if err != nil {
log.Error(err)
}
guildPlayer := &GuildPlayer{
channelID: dbGuild.PlayerChannelID,
messageID: dbGuild.PlayerMessageID,
}
gm.guilds[guildID] = &Guild{
queue: queue,
guildPlayer: guildPlayer,
}
guild, _ = gm.guilds[guildID]
}
return guild
}
func (gm *GuildManager) GetQueue(guildID snowflake.ID) *Queue {
guild := gm.Get(guildID)
return guild.queue
}
func (gm *GuildManager) GetGuildPlayer(guildID snowflake.ID) *GuildPlayer {
guild := gm.Get(guildID)
return guild.guildPlayer
}
func (gm *GuildManager) Delete(guildID snowflake.ID) {
delete(gm.guilds, guildID)
}
func (gp *GuildPlayer) IsPlayerChannel(channelID snowflake.ID) bool {
return gp.channelID != nil && gp.channelID.String() == channelID.String()
}
func (gp *GuildPlayer) IsPlayerMessage(messageID snowflake.ID) bool {
return gp.messageID != nil && gp.messageID.String() == messageID.String()
}