engine

package module
v0.0.0-...-d5b6de5 Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DiscordToken = os.Getenv("DISCORD_TOKEN")
View Source
var Dsession *discordgo.Session
View Source
var Hclient *api.Client
View Source
var Iron *bolt.DB

Functions

func AddFriendsToOrganization

func AddFriendsToOrganization(platform string, platformID string, uuid string) error

AddFriendsToOrganization appends a new player uuid to the organizations list of tracked friend lists. First, it Gets the proper organization. Then it appends and Puts the new org structure into BoltDB. Returns an error.

func AddGuildToOrganization

func AddGuildToOrganization(platform string, platformID string, guild string) error

AddGuildToOrganization appends a new guild name to the organizations list of tracked guild lists. First, it Gets the proper organization. Then it appends and Puts the new org structure into BoltDB. Returns an error.

func AddPlayerToOrganization

func AddPlayerToOrganization(platform string, platformID string, uuid string) error

AddPlayerToOrganization appends a new player uuid to the organizations list of tracked players. First, it Gets the proper organization. Then it appends and Puts the new org structure into BoltDB. Returns an error.

func CreateAPIClient

func CreateAPIClient(key string) *api.Client

func DeleteFriendsFromOrganization

func DeleteFriendsFromOrganization(platform string, platformID string, uuid string) error

DeleteFriendsFromOrganization deletes a friend uuid from an organization's list of tracked friend list. Returns an error.

func DeleteGuildFromOrganization

func DeleteGuildFromOrganization(platform string, platformID string, guild string) error

DeleteGuildFromOrganization deletes a guild from an organization's list of tracked guilds. Returns an error.

func DeletePlayerFromOrganization

func DeletePlayerFromOrganization(platform string, platformID string, uuid string) error

DeletePlayerFromOrganization deletes a player uuid from an organization's list of tracked players. Returns an error.

func DeleteUsernames

func DeleteUsernames(username string) error

DeleteUsernames deletes the key matching the given username in the "usernames" bucket. Returns an error if anything goes wrong.

func EnsureBucketsExist

func EnsureBucketsExist(bucketList []string) error

EnsureBucketsExist creates buckets in BoltDB if they do not yet exist. Takes a slice of string bucket names. Returns an error if problem occurs.

func GetFriends

func GetFriends(uuid string) (*json.RawMessage, error)

GetFriends retrieves the raw JSON friends response to a UUID. If the database does not have it, GetFriends calls PutFriends() to add it to the database. Returns maybe the *json.RawMessage and error.

func GetFriendsList

func GetFriendsList(uuid string) ([]string, error)

GetFriendsList returns a slice of strings with the UUIDs of one player's friends. Returns maybe a string slice and error.

func GetGuild

func GetGuild(name string) (*json.RawMessage, error)

GetGuild retrieves the raw JSON guild response to a guild name. If the database does not have it, GetGuild calls PutGuild() to add it to the database. Returns maybe the *json.RawMessage and error.

func GetGuildList

func GetGuildList(name string) ([]string, error)

GetGuildList returns a slice of strings with the UUIDs of one guild's members. Returns maybe a string slice and error.

func GetGuildNameWithPlayerUUID

func GetGuildNameWithPlayerUUID(uuid string) (string, error)

GetGuildNameWithPlayerUUID

func GetGuildWithPlayerUUID

func GetGuildWithPlayerUUID(uuid string) (*json.RawMessage, error)

GetGuildWithPlayerUUID

func GetPlayerStatus

func GetPlayerStatus(uuid string) (bool, error)

func GetTrackedList

func GetTrackedList(platform string, platformKey string) ([]string, []string, []string, error)

func GetUsernamesUUID

func GetUsernamesUUID(username string) (string, error)

GetUsernamesUUID gets a uuid from a username in the "usernames" bucket.

func GuildCreate

func GuildCreate(s *discordgo.Session, event *discordgo.GuildCreate)

GuildCreate will be called (due to AddHandler above) every time a new guild is joined. It adds a new PlatformOrganization to BoltDB if this is a new guild.

func ListExistingTopBuckets

func ListExistingTopBuckets() error

ListExistingTopBuckets lists all the top level buckets in the open database to stdout. Returns an error if

func Notify

func Notify(platform string, channelID string, uuid string, newStatus bool)

func PutFriends

func PutFriends(uuid string) error

PutFriends fetches the raw JSON friends from the API and stores it in the "friends" bucket. Returns an error.

func PutGuild

func PutGuild(name string) error

PutGuild fetches the raw JSON guild from the API and stores it in the "guilds" bucket. Returns an error.

func PutPlatformOrganization

func PutPlatformOrganization(org PlatformOrganization) error

PutPlatformOrganization puts a PlatformOrganization struct into BoltDB.

func PutUsernames

func PutUsernames(username string) error

PutUsernames fetches the UUID associated with a username from the API and puts it in the "usernames" bucket. Returns an error.

func SendStatusNotifications

func SendStatusNotifications(uuid string, newStatus bool) error

SendStatusNotifications takes a uuid and new status and sends notifications to all guilds tracking the player directly, or by virtue of friends or guilds.

func SetOrganizationChannel

func SetOrganizationChannel(platform string, platformID string, channelID string) error

func StartBolt

func StartBolt(path string) error

StartBolt opens the Bolt database. Returns an error if opening goes wrong.

func StartDiscord

func StartDiscord()

StartDiscord creates the main Discord session, registers commands, and initializes the router. This function can be supplanted by, e.g. StartIRC(), to use a different (or multiple) bot(s). This will require multiple changes to other functions as well.

func StopBolt

func StopBolt()

StopBolt closes the database. This should be deferred in the main application.

func ToggleOrganizationNotifications

func ToggleOrganizationNotifications(platform string, platformID string) (bool, error)

func UpdateFriendGuildLists

func UpdateFriendGuildLists()

func UpdateStatuses

func UpdateStatuses() error

func UpdateTrackedPlayerList

func UpdateTrackedPlayerList() error

func UsernameToUUID

func UsernameToUUID(username string) (string, error)

UsernameToUUID guarantees returning a UUID from a username if no error occurs. First, it runs GetUsernamesUUID() to use cache in BoltDB. If the username is not in BoltDB, it will Put it there and then Get it.

Types

type PlatformOrganization

type PlatformOrganization struct {
	Platform       string // e.g. “discord” or “text message”
	PlatformID     string // e.g. discord guild id or phone number ~ unique BoltDB ID
	DefaultChannel string
	Notifications  bool
	Players        []string // slice of players to be notified of
	Friends        []string // slice of players whose friends are to be notified of
	Guilds         []string // slice of guilds whose members are to be notified of
	Active         bool
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

PlatformOrganization is the basic structure for each end point (e.g. a Discord group). It stores the settings for that group as well as lists of its tracked entities (players, friend lists, and guilds).

func GetPlatformOrganization

func GetPlatformOrganization(platform string, platformID string) (*PlatformOrganization, error)

GetPlatformOrganization fetches a PlatformOrganization struct from BoltDB.

Jump to

Keyboard shortcuts

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