comcord/state/main.go

182 lines
3 KiB
Go
Raw Normal View History

package state
import (
"time"
"github.com/diamondburned/arikawa/v3/discord"
"github.com/diamondburned/ningen/v3"
)
type ComcordState struct {
Client *ningen.State
Config map[string]string
Readied bool
Connected bool
RPCConnected bool
2023-07-17 00:05:04 +00:00
StartTime time.Time
CurrentGuild string
CurrentChannel string
NameLength int
InPrompt bool
2023-07-11 03:41:51 +00:00
PromptText string
AFK bool
MessageQueue []discord.Message
LastChannel map[string]string
2023-07-08 20:51:26 +00:00
LastDM string
2023-07-09 04:42:58 +00:00
NoColor bool
}
var state ComcordState
func Setup(config map[string]string, client *ningen.State) {
state = ComcordState{}
state.Client = client
state.Config = config
state.Readied = false
state.Connected = true
state.RPCConnected = false
2023-07-17 00:05:04 +00:00
state.StartTime = time.Now()
state.CurrentGuild = ""
state.CurrentChannel = ""
state.NameLength = 2
state.InPrompt = false
2023-07-11 03:41:51 +00:00
state.PromptText = ""
state.AFK = false
state.MessageQueue = make([]discord.Message, 0)
state.LastChannel = make(map[string]string)
state.LastDM = ""
2023-07-09 04:42:58 +00:00
state.NoColor = false
}
func GetClient() *ningen.State {
return state.Client
}
func HasReadied() bool {
return state.Readied
}
func SetReadied(value bool) {
state.Readied = value
}
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 {
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
}
func GetNameLength() int {
return state.NameLength
}
func SetNameLength(value int) {
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
}
func IsAFK() bool {
return state.AFK
}
func SetAFK(value bool) {
state.AFK = value
}
func GetMessageQueue() []discord.Message {
return state.MessageQueue
}
func AddMessageToQueue(msg discord.Message) {
state.MessageQueue = append(state.MessageQueue, msg)
}
2023-07-08 20:51:26 +00:00
2023-07-09 04:42:58 +00:00
func EmptyMessageQueue() {
state.MessageQueue = make([]discord.Message, 0)
2023-07-09 04:42:58 +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
}
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
}