Documentation
¶
Index ¶
- Constants
- Variables
- func EmojisToSelectMenuOptions(emojis []Emoji, unlinkEmoji string) (arr []discordgo.SelectMenuOption)
- func MessageDeleteWorker(s *discordgo.Session, msgChannelID, msgID string, waitDur time.Duration)
- func RemovePendingDGSEdit(messageID string)
- func TrimEmbedFields(fields []*discordgo.MessageEmbedField) []*discordgo.MessageEmbedField
- func ValidFields(me *discordgo.MessageEmbed) bool
- type AlivenessEmojis
- type Bot
- func (bot *Bot) CheckOrFetchCachedUserData(userID, guildID string) (string, string, string)
- func (bot *Bot) Close()
- func (bot *Bot) DispatchRefreshOrEdit(readOnlyDgs *GameState, dgsRequest GameStateRequest, ...)
- func (bot *Bot) GameStatsEmbed(guildID, matchID, connectCode string, isPrem bool, ...) *discordgo.MessageEmbed
- func (bot *Bot) GuildStatsEmbed(guildID string, sett *settings.GuildSettings, isPrem bool) *discordgo.MessageEmbed
- func (bot *Bot) HandleSettingsCommand(guildID string, sett *settings.GuildSettings, settType string, args []string, ...) interface{}
- func (bot *Bot) InitTokenProvider(tp *tokenprovider.TokenProvider)
- func (bot *Bot) MentionWithCacheData(userID, guildID string, sett *settings.GuildSettings) string
- func (bot *Bot) RefreshGameStateMessage(gsr GameStateRequest, sett *settings.GuildSettings) bool
- func (bot *Bot) StartAPIServer(port string)
- func (bot *Bot) StartMetricsServer(nodeID string) error
- func (bot *Bot) SubscribeToGameByConnectCode(guildID, connectCode string, endGameChannel chan EndGameMessage)
- func (bot *Bot) UserStatsEmbed(userID, guildID string, sett *settings.GuildSettings, isPrem bool) *discordgo.MessageEmbed
- type Emoji
- type EndGameMessage
- type GameState
- func (dgs *GameState) AttemptPairingByMatchingNames(data amongus.PlayerData) string
- func (dgs *GameState) AttemptPairingByUserIDs(data amongus.PlayerData, userIDs map[string]interface{}) string
- func (dgs *GameState) ClearPlayerData(userID string) bool
- func (dgs *GameState) ClearPlayerDataByPlayerName(playerName string)
- func (dgs *GameState) CreateMessage(s *discordgo.Session, me *discordgo.MessageEmbed, channelID string, ...) bool
- func (dgs *GameState) DeleteGameStateMsg(s *discordgo.Session, reset bool) bool
- func (dgs *GameState) GetCountLinked() int
- func (dgs *GameState) GetUser(userID string) (UserData, error)
- func (dgs *GameState) Reset()
- func (dgs *GameState) ToEmojiEmbedFields(emojis AlivenessEmojis, sett *settings.GuildSettings) []*discordgo.MessageEmbedField
- func (dgs *GameState) UnlinkAllUsers()
- func (dgs *GameState) UpdateUserData(userID string, data UserData)
- type GameStateMessage
- type GameStateRequest
- type HandlePriority
- type HttpError
- type RedisInterface
- func (redisInterface *RedisInterface) AddUniqueGuildCounter(guildID string)
- func (redisInterface *RedisInterface) AddUsernameLink(guildID, userID, userName string) error
- func (redisInterface *RedisInterface) CheckPointer(pointer string) string
- func (redisInterface *RedisInterface) Close() error
- func (redisInterface *RedisInterface) DeleteDiscordGameState(dgs *GameState)
- func (redisInterface *RedisInterface) DeleteLinksByUserID(guildID, userID string) error
- func (redisInterface *RedisInterface) GetDiscordGameStateAndLock(gsr GameStateRequest) (*redislock.Lock, *GameState)
- func (redisInterface RedisInterface) GetDiscordGameStateAndLockRetries(gsr GameStateRequest, retries int) (*redislock.Lock, *GameState)
- func (redisInterface *RedisInterface) GetReadOnlyDiscordGameState(gsr GameStateRequest) *GameState
- func (redisInterface *RedisInterface) GetUsernameOrUserIDMappings(guildID, key string) (map[string]interface{}, error)
- func (redisInterface *RedisInterface) Init(params interface{}) error
- func (redisInterface *RedisInterface) LeaveUniqueGuildCounter(guildID string)
- func (redisInterface *RedisInterface) LoadAllActiveGames(guildID string) []string
- func (redisInterface *RedisInterface) LockSnowflake(snowflake string) *redislock.Lock
- func (redisInterface *RedisInterface) LockVoiceChanges(connectCode string, dur time.Duration) *redislock.Lock
- func (redisInterface *RedisInterface) RefreshActiveGame(guildID, connectCode string)
- func (redisInterface *RedisInterface) RemoveOldGame(guildID, connectCode string)
- func (redisInterface *RedisInterface) SetDiscordGameState(data *GameState, lock *redislock.Lock)
- type User
- type UserData
- type UserDataSet
Constants ¶
const ( UnlinkEmojiName = "auunlink" X = "❌" ThumbsUp = "👍" Hourglass = "⌛" )
const DeferredEditSeconds = 2
bumped for public rollout. Don't need to update the status message more than once every 2 secs prob
const GameTimeoutSeconds = 900
15 minute timeout
const ISO8601 = "2006-01-02T15:04:05-0700"
const LinearBackoffMs = 100
const LockTimeoutMs = 250
const MaxRetries = 10
const SnowflakeLockMs = 3000
Variables ¶
var DeferredEdits = make(map[string]*discordgo.MessageEmbed)
var DeferredEditsLock = sync.Mutex{}
var DownloadPermissions = []int64{ discordgo.PermissionAttachFiles, }
var EmojiLock = sync.Mutex{}
var GlobalAlivenessEmojis = AlivenessEmojis{ // contains filtered or unexported fields }
GlobalAlivenessEmojis keys are IsAlive, Color
var MatchIDRegex = regexp.MustCompile(`^[A-Z0-9]{8}:[0-9]+$`)
var RequiredPermissions = []int64{ discordgo.PermissionViewChannel, discordgo.PermissionSendMessages, discordgo.PermissionManageMessages, discordgo.PermissionEmbedLinks, discordgo.PermissionUseExternalEmojis, }
var VoicePermissions = []int64{ discordgo.PermissionVoiceMuteMembers, discordgo.PermissionVoiceDeafenMembers, }
Functions ¶
func EmojisToSelectMenuOptions ¶
func EmojisToSelectMenuOptions(emojis []Emoji, unlinkEmoji string) (arr []discordgo.SelectMenuOption)
func MessageDeleteWorker ¶
func RemovePendingDGSEdit ¶
func RemovePendingDGSEdit(messageID string)
func TrimEmbedFields ¶
func TrimEmbedFields(fields []*discordgo.MessageEmbedField) []*discordgo.MessageEmbedField
func ValidFields ¶
func ValidFields(me *discordgo.MessageEmbed) bool
Types ¶
type Bot ¶
type Bot struct { // mapping of socket connections to the game connect codes ConnsToGames map[string]string StatusEmojis AlivenessEmojis EndGameChannels map[string]chan EndGameMessage ChannelsMapLock sync.RWMutex PrimarySession *discordgo.Session TokenProvider *tokenprovider.TokenProvider TopGGClient *dbl.Client RedisInterface *RedisInterface StorageInterface *storage.StorageInterface PostgresInterface *storageutils.PsqlInterface // contains filtered or unexported fields }
func MakeAndStartBot ¶
func MakeAndStartBot(version, commit, botToken, topGGToken, url, emojiGuildID string, numShards, shardID int, redisInterface *RedisInterface, storageInterface *storage.StorageInterface, psql *storageutils.PsqlInterface, logPath string) *Bot
MakeAndStartBot does what it sounds like TODO collapse these fields into proper structs?
func (*Bot) CheckOrFetchCachedUserData ¶
func (*Bot) DispatchRefreshOrEdit ¶
func (bot *Bot) DispatchRefreshOrEdit(readOnlyDgs *GameState, dgsRequest GameStateRequest, sett *settings.GuildSettings)
func (*Bot) GameStatsEmbed ¶
func (bot *Bot) GameStatsEmbed(guildID, matchID, connectCode string, isPrem bool, sett *settings.GuildSettings) *discordgo.MessageEmbed
func (*Bot) GuildStatsEmbed ¶
func (bot *Bot) GuildStatsEmbed(guildID string, sett *settings.GuildSettings, isPrem bool) *discordgo.MessageEmbed
func (*Bot) HandleSettingsCommand ¶
func (*Bot) InitTokenProvider ¶
func (bot *Bot) InitTokenProvider(tp *tokenprovider.TokenProvider)
func (*Bot) MentionWithCacheData ¶
func (bot *Bot) MentionWithCacheData(userID, guildID string, sett *settings.GuildSettings) string
func (*Bot) RefreshGameStateMessage ¶
func (bot *Bot) RefreshGameStateMessage(gsr GameStateRequest, sett *settings.GuildSettings) bool
func (*Bot) StartAPIServer ¶
func (*Bot) StartMetricsServer ¶
func (*Bot) SubscribeToGameByConnectCode ¶
func (bot *Bot) SubscribeToGameByConnectCode(guildID, connectCode string, endGameChannel chan EndGameMessage)
func (*Bot) UserStatsEmbed ¶
func (bot *Bot) UserStatsEmbed(userID, guildID string, sett *settings.GuildSettings, isPrem bool) *discordgo.MessageEmbed
type Emoji ¶
Emoji struct for discord
func (*Emoji) DownloadAndBase64Encode ¶
DownloadAndBase64Encode does what it sounds like
func (*Emoji) FormatForInline ¶
FormatForInline does what it sounds like
func (*Emoji) GetDiscordCDNUrl ¶
GetDiscordCDNUrl does what it sounds like
type EndGameMessage ¶
type EndGameMessage bool
type GameState ¶
type GameState struct { GuildID string `json:"guildID"` ConnectCode string `json:"connectCode"` Linked bool `json:"linked"` Running bool `json:"running"` Subscribed bool `json:"subscribed"` MatchID int64 `json:"matchID"` MatchStartUnix int64 `json:"matchStartUnix"` UserData UserDataSet `json:"userData"` VoiceChannel string `json:"voiceChannel"` GameStateMsg GameStateMessage `json:"gameStateMessage"` GameData amongus.GameData `json:"amongUsData"` }
GameState represents a full record of the entire current game's state. It is intended to be fully JSON-serializable, so that any shard/worker can pick up the game state and operate upon it (using locks as necessary)
func NewDiscordGameState ¶
func (*GameState) AttemptPairingByMatchingNames ¶
func (dgs *GameState) AttemptPairingByMatchingNames(data amongus.PlayerData) string
func (*GameState) AttemptPairingByUserIDs ¶
func (dgs *GameState) AttemptPairingByUserIDs(data amongus.PlayerData, userIDs map[string]interface{}) string
func (*GameState) ClearPlayerData ¶
func (*GameState) ClearPlayerDataByPlayerName ¶
func (*GameState) CreateMessage ¶
func (*GameState) DeleteGameStateMsg ¶
func (*GameState) GetCountLinked ¶
func (*GameState) ToEmojiEmbedFields ¶
func (dgs *GameState) ToEmojiEmbedFields(emojis AlivenessEmojis, sett *settings.GuildSettings) []*discordgo.MessageEmbedField
func (*GameState) UnlinkAllUsers ¶
func (dgs *GameState) UnlinkAllUsers()
func (*GameState) UpdateUserData ¶
type GameStateMessage ¶
type GameStateMessage struct { MessageID string `json:"messageID"` MessageChannelID string `json:"messageChannelID"` LeaderID string `json:"leaderID"` CreationTimeUnix int64 `json:"creationTimeUnix"` }
func MakeGameStateMessage ¶
func MakeGameStateMessage() GameStateMessage
func (*GameStateMessage) Exists ¶
func (gsm *GameStateMessage) Exists() bool
type GameStateRequest ¶
type HandlePriority ¶
type HandlePriority int
const ( NoPriority HandlePriority = 0 AlivePriority HandlePriority = 1 DeadPriority HandlePriority = 2 )
type RedisInterface ¶
type RedisInterface struct {
// contains filtered or unexported fields
}
func (*RedisInterface) AddUniqueGuildCounter ¶
func (redisInterface *RedisInterface) AddUniqueGuildCounter(guildID string)
func (*RedisInterface) AddUsernameLink ¶
func (redisInterface *RedisInterface) AddUsernameLink(guildID, userID, userName string) error
func (*RedisInterface) CheckPointer ¶
func (redisInterface *RedisInterface) CheckPointer(pointer string) string
func (*RedisInterface) Close ¶
func (redisInterface *RedisInterface) Close() error
func (*RedisInterface) DeleteDiscordGameState ¶
func (redisInterface *RedisInterface) DeleteDiscordGameState(dgs *GameState)
func (*RedisInterface) DeleteLinksByUserID ¶
func (redisInterface *RedisInterface) DeleteLinksByUserID(guildID, userID string) error
func (*RedisInterface) GetDiscordGameStateAndLock ¶
func (redisInterface *RedisInterface) GetDiscordGameStateAndLock(gsr GameStateRequest) (*redislock.Lock, *GameState)
func (RedisInterface) GetDiscordGameStateAndLockRetries ¶
func (redisInterface RedisInterface) GetDiscordGameStateAndLockRetries(gsr GameStateRequest, retries int) (*redislock.Lock, *GameState)
func (*RedisInterface) GetReadOnlyDiscordGameState ¶
func (redisInterface *RedisInterface) GetReadOnlyDiscordGameState(gsr GameStateRequest) *GameState
need at least one of these fields to fetch
func (*RedisInterface) GetUsernameOrUserIDMappings ¶
func (redisInterface *RedisInterface) GetUsernameOrUserIDMappings(guildID, key string) (map[string]interface{}, error)
func (*RedisInterface) Init ¶
func (redisInterface *RedisInterface) Init(params interface{}) error
func (*RedisInterface) LeaveUniqueGuildCounter ¶
func (redisInterface *RedisInterface) LeaveUniqueGuildCounter(guildID string)
func (*RedisInterface) LoadAllActiveGames ¶
func (redisInterface *RedisInterface) LoadAllActiveGames(guildID string) []string
only deletes from the guild's responsibility, NOT the entire guild counter!
func (*RedisInterface) LockSnowflake ¶
func (redisInterface *RedisInterface) LockSnowflake(snowflake string) *redislock.Lock
func (*RedisInterface) LockVoiceChanges ¶
func (*RedisInterface) RefreshActiveGame ¶
func (redisInterface *RedisInterface) RefreshActiveGame(guildID, connectCode string)
func (*RedisInterface) RemoveOldGame ¶
func (redisInterface *RedisInterface) RemoveOldGame(guildID, connectCode string)
func (*RedisInterface) SetDiscordGameState ¶
func (redisInterface *RedisInterface) SetDiscordGameState(data *GameState, lock *redislock.Lock)
type User ¶
type User struct { Nick string `json:"Nick"` UserID string `json:"UserID"` UserName string `json:"UserName"` }
User struct
type UserData ¶
type UserData struct { User User `json:"User"` ShouldBeMute bool `json:"ShouldBeMute"` ShouldBeDeaf bool `json:"ShouldBeDeaf"` InGameName string `json:"PlayerName"` }
UserData struct
func (*UserData) GetNickName ¶
func (*UserData) GetPlayerName ¶
func (*UserData) GetUserName ¶
func (*UserData) Link ¶
func (user *UserData) Link(player amongus.PlayerData)