bot

package
v8.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnlinkEmojiName = "auunlink"
	X               = "❌"
	ThumbsUp        = "👍"
	Hourglass       = "⌛"
)
View Source
const DeferredEditSeconds = 2

bumped for public rollout. Don't need to update the status message more than once every 2 secs prob

View Source
const GameTimeoutSeconds = 900

15 minute timeout

View Source
const ISO8601 = "2006-01-02T15:04:05-0700"
View Source
const LinearBackoffMs = 100
View Source
const LockTimeoutMs = 250
View Source
const MaxRetries = 10
View Source
const SnowflakeLockMs = 3000

Variables

View Source
var DeferredEdits = make(map[string]*discordgo.MessageEmbed)
View Source
var DeferredEditsLock = sync.Mutex{}
View Source
var DownloadPermissions = []int64{
	discordgo.PermissionAttachFiles,
}
View Source
var EmojiLock = sync.Mutex{}
View Source
var GlobalAlivenessEmojis = AlivenessEmojis{
	// contains filtered or unexported fields
}

GlobalAlivenessEmojis keys are IsAlive, Color

View Source
var MatchIDRegex = regexp.MustCompile(`^[A-Z0-9]{8}:[0-9]+$`)

Functions

func EmojisToSelectMenuOptions

func EmojisToSelectMenuOptions(emojis []Emoji, unlinkEmoji string) (arr []discordgo.SelectMenuOption)

func MessageDeleteWorker

func MessageDeleteWorker(s *discordgo.Session, msgChannelID, msgID string, waitDur time.Duration)

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 AlivenessEmojis

type AlivenessEmojis map[bool][]Emoji

AlivenessEmojis map

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 *Bot) CheckOrFetchCachedUserData(userID, guildID string) (string, string, string)

func (*Bot) Close

func (bot *Bot) Close()

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 *Bot) HandleSettingsCommand(guildID string, sett *settings.GuildSettings, settType string, args []string, prem bool) interface{}

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 *Bot) StartAPIServer(port string)

func (*Bot) StartMetricsServer

func (bot *Bot) StartMetricsServer(nodeID string) error

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

type Emoji struct {
	Name string
	ID   string
}

Emoji struct for discord

func (*Emoji) DownloadAndBase64Encode

func (e *Emoji) DownloadAndBase64Encode() string

DownloadAndBase64Encode does what it sounds like

func (*Emoji) FormatForInline

func (e *Emoji) FormatForInline() string

FormatForInline does what it sounds like

func (*Emoji) GetDiscordCDNUrl

func (e *Emoji) GetDiscordCDNUrl() string

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 NewDiscordGameState(guildID string) *GameState

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 (dgs *GameState) ClearPlayerData(userID string) bool

func (*GameState) ClearPlayerDataByPlayerName

func (dgs *GameState) ClearPlayerDataByPlayerName(playerName string)

func (*GameState) CreateMessage

func (dgs *GameState) CreateMessage(s *discordgo.Session, me *discordgo.MessageEmbed, channelID string, authorID string) bool

func (*GameState) DeleteGameStateMsg

func (dgs *GameState) DeleteGameStateMsg(s *discordgo.Session, reset bool) bool

func (*GameState) GetCountLinked

func (dgs *GameState) GetCountLinked() int

func (*GameState) GetUser

func (dgs *GameState) GetUser(userID string) (UserData, error)

func (*GameState) Reset

func (dgs *GameState) Reset()

func (*GameState) ToEmojiEmbedFields

func (dgs *GameState) ToEmojiEmbedFields(emojis AlivenessEmojis, sett *settings.GuildSettings) []*discordgo.MessageEmbedField

func (*GameState) UnlinkAllUsers

func (dgs *GameState) UnlinkAllUsers()

func (*GameState) UpdateUserData

func (dgs *GameState) UpdateUserData(userID string, data UserData)

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 GameStateRequest struct {
	GuildID      string
	TextChannel  string
	VoiceChannel string
	ConnectCode  string
}

type HandlePriority

type HandlePriority int
const (
	NoPriority    HandlePriority = 0
	AlivePriority HandlePriority = 1
	DeadPriority  HandlePriority = 2
)

type HttpError

type HttpError struct {
	StatusCode int
	Error      string
}

type RedisInterface

type RedisInterface struct {
	// contains filtered or unexported fields
}

func (*RedisInterface) AddUniqueGuildCounter

func (redisInterface *RedisInterface) AddUniqueGuildCounter(guildID string)
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 *RedisInterface) LockVoiceChanges(connectCode string, dur time.Duration) *redislock.Lock

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 MakeUserDataFromDiscordUser

func MakeUserDataFromDiscordUser(dUser *discordgo.User, nick string) UserData

func (*UserData) GetID

func (user *UserData) GetID() string

func (*UserData) GetNickName

func (user *UserData) GetNickName() string

func (*UserData) GetPlayerName

func (user *UserData) GetPlayerName() string

func (*UserData) GetUserName

func (user *UserData) GetUserName() string
func (user *UserData) Link(player amongus.PlayerData)

func (*UserData) SetShouldBeMuteDeaf

func (user *UserData) SetShouldBeMuteDeaf(mute, deaf bool)

type UserDataSet

type UserDataSet map[string]UserData

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL