2023-07-06 22:21:11 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
2023-07-17 04:27:50 +00:00
|
|
|
"time"
|
2023-07-06 22:21:11 +00:00
|
|
|
|
2023-07-27 02:27:04 +00:00
|
|
|
"github.com/diamondburned/arikawa/v3/discord"
|
|
|
|
"github.com/diamondburned/ningen/v3"
|
2023-07-06 22:21:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ComcordState struct {
|
2023-07-27 02:27:04 +00:00
|
|
|
Client *ningen.State
|
2023-07-09 01:17:47 +00:00
|
|
|
Config map[string]string
|
2023-07-27 02:27:04 +00:00
|
|
|
Readied bool
|
2023-07-06 22:21:11 +00:00
|
|
|
Connected bool
|
|
|
|
RPCConnected bool
|
2023-07-17 00:05:04 +00:00
|
|
|
StartTime time.Time
|
2023-07-06 22:21:11 +00:00
|
|
|
CurrentGuild string
|
|
|
|
CurrentChannel string
|
2023-07-09 01:17:47 +00:00
|
|
|
NameLength int
|
2023-07-06 22:21:11 +00:00
|
|
|
InPrompt bool
|
2023-07-11 03:41:51 +00:00
|
|
|
PromptText string
|
2023-07-06 22:21:11 +00:00
|
|
|
AFK bool
|
2023-07-27 02:27:04 +00:00
|
|
|
MessageQueue []discord.Message
|
2023-07-06 22:21:11 +00:00
|
|
|
LastChannel map[string]string
|
2023-07-08 20:51:26 +00:00
|
|
|
LastDM string
|
2023-07-09 04:42:58 +00:00
|
|
|
NoColor bool
|
2023-07-06 22:21:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var state ComcordState
|
|
|
|
|
2023-07-27 02:27:04 +00:00
|
|
|
func Setup(config map[string]string, client *ningen.State) {
|
2023-07-06 22:21:11 +00:00
|
|
|
state = ComcordState{}
|
2023-07-27 02:27:04 +00:00
|
|
|
state.Client = client
|
2023-07-09 01:17:47 +00:00
|
|
|
state.Config = config
|
2023-07-27 02:27:04 +00:00
|
|
|
state.Readied = false
|
2023-07-06 22:21:11 +00:00
|
|
|
state.Connected = true
|
|
|
|
state.RPCConnected = false
|
2023-07-17 00:05:04 +00:00
|
|
|
state.StartTime = time.Now()
|
2023-07-09 01:17:47 +00:00
|
|
|
state.CurrentGuild = ""
|
|
|
|
state.CurrentChannel = ""
|
2023-07-06 22:21:11 +00:00
|
|
|
state.NameLength = 2
|
|
|
|
state.InPrompt = false
|
2023-07-11 03:41:51 +00:00
|
|
|
state.PromptText = ""
|
2023-07-06 22:21:11 +00:00
|
|
|
state.AFK = false
|
2023-07-27 02:27:04 +00:00
|
|
|
state.MessageQueue = make([]discord.Message, 0)
|
2023-07-06 22:21:11 +00:00
|
|
|
state.LastChannel = make(map[string]string)
|
2023-07-09 01:17:47 +00:00
|
|
|
state.LastDM = ""
|
2023-07-09 04:42:58 +00:00
|
|
|
state.NoColor = false
|
2023-07-06 22:21:11 +00:00
|
|
|
}
|
|
|
|
|
2023-07-27 02:27:04 +00:00
|
|
|
func GetClient() *ningen.State {
|
|
|
|
return state.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func HasReadied() bool {
|
|
|
|
return state.Readied
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetReadied(value bool) {
|
|
|
|
state.Readied = value
|
|
|
|
}
|
|
|
|
|
2023-07-06 22:21:11 +00:00
|
|
|
func IsConnected() bool {
|
|
|
|
return state.Connected
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetConnected(value bool) {
|
|
|
|
state.Connected = value
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsRPCConnected() bool {
|
|
|
|
return state.RPCConnected
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetRPCConnected(value bool) {
|
|
|
|
state.RPCConnected = value
|
|
|
|
}
|
|
|
|
|
2023-07-17 00:05:04 +00:00
|
|
|
func GetStartTime() time.Time {
|
2023-07-06 22:21:11 +00:00
|
|
|
return state.StartTime
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetCurrentGuild() string {
|
|
|
|
return state.CurrentGuild
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetCurrentGuild(value string) {
|
|
|
|
state.CurrentGuild = value
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetCurrentChannel() string {
|
|
|
|
return state.CurrentChannel
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetCurrentChannel(value string) {
|
|
|
|
state.CurrentChannel = value
|
|
|
|
}
|
|
|
|
|
2023-07-09 01:17:47 +00:00
|
|
|
func GetNameLength() int {
|
2023-07-06 22:21:11 +00:00
|
|
|
return state.NameLength
|
|
|
|
}
|
|
|
|
|
2023-07-09 01:17:47 +00:00
|
|
|
func SetNameLength(value int) {
|
2023-07-06 22:21:11 +00:00
|
|
|
state.NameLength = value
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsInPrompt() bool {
|
|
|
|
return state.InPrompt
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetInPrompt(value bool) {
|
|
|
|
state.InPrompt = value
|
|
|
|
}
|
|
|
|
|
2023-07-11 03:41:51 +00:00
|
|
|
func GetPromptText() string {
|
|
|
|
return state.PromptText
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetPromptText(value string) {
|
|
|
|
state.PromptText = value
|
|
|
|
}
|
|
|
|
|
2023-07-06 22:21:11 +00:00
|
|
|
func IsAFK() bool {
|
|
|
|
return state.AFK
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetAFK(value bool) {
|
|
|
|
state.AFK = value
|
|
|
|
}
|
|
|
|
|
2023-07-27 02:27:04 +00:00
|
|
|
func GetMessageQueue() []discord.Message {
|
2023-07-06 22:21:11 +00:00
|
|
|
return state.MessageQueue
|
|
|
|
}
|
|
|
|
|
2023-07-27 02:27:04 +00:00
|
|
|
func AddMessageToQueue(msg discord.Message) {
|
2023-07-06 22:21:11 +00:00
|
|
|
state.MessageQueue = append(state.MessageQueue, msg)
|
|
|
|
}
|
2023-07-08 20:51:26 +00:00
|
|
|
|
2023-07-09 04:42:58 +00:00
|
|
|
func EmptyMessageQueue() {
|
2023-07-27 02:27:04 +00:00
|
|
|
state.MessageQueue = make([]discord.Message, 0)
|
2023-07-09 04:42:58 +00:00
|
|
|
}
|
|
|
|
|
2023-07-09 01:17:47 +00:00
|
|
|
func SetLastChannel(guild string, channel string) {
|
|
|
|
state.LastChannel[guild] = channel
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetLastChannel(guild string) string {
|
|
|
|
channel, has := state.LastChannel[guild]
|
|
|
|
|
|
|
|
if has {
|
|
|
|
return channel
|
|
|
|
} else {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-08 20:51:26 +00:00
|
|
|
func GetLastDM() string {
|
|
|
|
return state.LastDM
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetLastDM(value string) {
|
|
|
|
state.LastDM = value
|
|
|
|
}
|
2023-07-09 01:17:47 +00:00
|
|
|
|
|
|
|
func GetConfigValue(key string) string {
|
|
|
|
value, has := state.Config[key]
|
|
|
|
|
|
|
|
if has {
|
|
|
|
return value
|
|
|
|
} else {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
2023-07-09 04:42:58 +00:00
|
|
|
|
|
|
|
func SetNoColor(value bool) {
|
|
|
|
state.NoColor = value
|
|
|
|
}
|
|
|
|
|
|
|
|
func HasNoColor() bool {
|
|
|
|
return state.NoColor
|
|
|
|
}
|