Documentation ¶
Index ¶
- Variables
- func AddGuildToOrganization(platform string, platformID string, guild string) error
- func AddPlayerToOrganization(platform string, platformID string, uuid string) error
- func CreateAPIClient(key string) *api.Client
- func DeleteFriendsFromOrganization(platform string, platformID string, uuid string) error
- func DeleteGuildFromOrganization(platform string, platformID string, guild string) error
- func DeletePlayerFromOrganization(platform string, platformID string, uuid string) error
- func DeleteUsernames(username string) error
- func EnsureBucketsExist(bucketList []string) error
- func GetCachedPlayerStatus(uuid string) bool
- func GetGuild(name string) (*json.RawMessage, error)
- func GetGuildList(name string) ([]string, error)
- func GetGuildNameWithPlayerUUID(uuid string) (string, error)
- func GetGuildWithPlayerUUID(uuid string) (*json.RawMessage, error)
- func GetPlayerStatus(uuid string) (bool, error)
- func GetRecentGame(uuid string) (string, string, int, error)
- func GetTrackedList(platform string, platformKey string) ([]string, []string, []string, error)
- func GetUsernamesUUID(username string) (string, error)
- func GuildCreate(s *discordgo.Session, event *discordgo.GuildCreate)
- func ListExistingTopBuckets() error
- func ListOnlinePlayers(guilds []string) []string
- func Notify(platform string, channelID string, uuid string, newStatus bool)
- func PutGuild(name string) error
- func PutPlatformOrganization(org PlatformOrganization) error
- func PutUsernames(username string) error
- func RemoveDuplicates(elements []string) []string
- func SendStatusNotifications(uuid string, newStatus bool) error
- func SetOrganizationChannel(platform string, platformID string, channelID string) error
- func StartBolt(path string) error
- func StartDiscord()
- func StopBolt()
- func ToggleOrganizationNotifications(platform string, platformID string) (bool, error)
- func UpdateFriendGuildLists()
- func UpdateStatuses() error
- func UpdateTrackedPlayerList() error
- func UsernameToUUID(username string) (string, error)
- type PlatformOrganization
Constants ¶
This section is empty.
Variables ¶
var DiscordToken = os.Getenv("DISCORD_TOKEN")
var Dsession *discordgo.Session
var Hclient *api.Client
var Iron *bolt.DB
Functions ¶
func AddGuildToOrganization ¶
// 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 AddFriendsToOrganization(platform string, platformID string, uuid string) error { // put friends list err := PutFriends(uuid) if err != nil { log.Println("organizations.AddFriendsToOrganization: error putting friends", err) } // get proper organization org, err := GetPlatformOrganization(platform, platformID) if err != nil { log.Println("Unable to GetPlatformOrganization in AddFriendsToOrganization:", err) return err } newOrg := *org newOrg.Friends = append(newOrg.Friends, uuid) err = PutPlatformOrganization(newOrg) if err != nil { log.Println("Unable to Put newOrg in AddFriendsToOrganization:", err) return err } return nil }
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 ¶
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 DeleteFriendsFromOrganization ¶
DeleteFriendsFromOrganization deletes a friend uuid from an organization's list of tracked friend list. Returns an error.
func DeleteGuildFromOrganization ¶
DeleteGuildFromOrganization deletes a guild from an organization's list of tracked guilds. Returns an error.
func DeletePlayerFromOrganization ¶
DeletePlayerFromOrganization deletes a player uuid from an organization's list of tracked players. Returns an error.
func DeleteUsernames ¶
DeleteUsernames deletes the key matching the given username in the "usernames" bucket. Returns an error if anything goes wrong.
func EnsureBucketsExist ¶
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 GetCachedPlayerStatus ¶ added in v0.0.11
TODO add error checking
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 ¶
GetGuildList returns a slice of strings with the UUIDs of one guild's members. Returns maybe a string slice and error.
func GetGuildNameWithPlayerUUID ¶
GetGuildNameWithPlayerUUID
func GetGuildWithPlayerUUID ¶
func GetGuildWithPlayerUUID(uuid string) (*json.RawMessage, error)
GetGuildWithPlayerUUID
func GetPlayerStatus ¶
func GetRecentGame ¶ added in v0.0.19
Returns: (mode string,
func GetTrackedList ¶
func GetUsernamesUUID ¶
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 ListOnlinePlayers ¶ added in v0.0.15
Returns a string array of the UUIDs of each online player. Currently limited to guild members only!
func PutGuild ¶
// PutFriends fetches the raw JSON friends from the API and stores it in the "friends" bucket. Returns an error.
func PutFriends(uuid string) error { log.Println("STARTING PutFriends()...") rawFriends, err := Hclient.FriendsByUUID(uuid) if err != nil { log.Println("Error calling api.FriendsByUUID in PutFriends:", err) return err } log.Println("PutFriends(): *rawFriends is:", *rawFriends) err = Iron.Update(func(tx *bolt.Tx) error { log.Println("PutFriends(): opened Iron db") b := tx.Bucket([]byte("friends")) putErr := b.Put([]byte(uuid), *rawFriends) if putErr != nil { log.Println("PutFriends(): problem putting. putErr is:", putErr) return putErr } return nil }) if err != nil { log.Println("Error putting friends:", err) return err } log.Println("About to return nil at end of PutFriends()") return nil }
// 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 GetFriends(uuid string) (*json.RawMessage, error) { var result json.RawMessage err := Iron.View(func(tx *bolt.Tx) error { b := tx.Bucket([]byte("friends")) v := b.Get([]byte(uuid)) if v == nil { return errors.New("404") } result = v return nil }) if err != nil { log.Println("GetFriends() ~ UUID not found in BoltDB:", err) putErr := PutFriends(uuid) log.Println("putErr in GetFriends():", putErr) log.Println("GetFriends() ~ Should have just PutFriends():") if putErr != nil { log.Println("Unable to PutFriends in GetFriends:", err) return nil, putErr } err = Iron.View(func(tx *bolt.Tx) error { log.Println("Opened BoltDB in GetFriends()......") b := tx.Bucket([]byte("friends")) v := b.Get([]byte(uuid)) if v == nil { return errors.New("404") } result = v //log.Println("In BoltDB in GetFriends(), the result is:", result) return nil }) if err != nil { log.Println("Redundancy failed in GetFriends:", err) return nil, err } log.Println("GetFriends() ~ UUID *was* found in BoltDB after running PutFriends().") return &result, err } log.Println("GetFriends() returning at the very last. Huh?") return &result, err }
// GetFriendsList returns a slice of strings with the UUIDs of one player's friends. Returns maybe a string slice and error.
func GetFriendsList(uuid string) ([]string, error) { friendsRaw, err := GetFriends(uuid) if err != nil { log.Println("GetFriends failed in GetFriendsList:", err) return nil, err } friendsResults := gjson.GetBytes(*friendsRaw, "#.uuid*") var friendsListNarrowed []string json.Unmarshal([]byte(friendsResults.Raw), &friendsListNarrowed) var friendsList []string for _, f := range friendsListNarrowed { if f != uuid { friendsList = append(friendsList, f) } } return friendsList, nil }
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 ¶
PutUsernames fetches the UUID associated with a username from the API and puts it in the "usernames" bucket. Returns an error.
func RemoveDuplicates ¶ added in v0.0.11
RemoveDuplicates takes a slice of strings and removes any duplicate values. Returns a slice of strings.
func SendStatusNotifications ¶
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 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 UpdateFriendGuildLists ¶
func UpdateFriendGuildLists()
func UpdateStatuses ¶
func UpdateStatuses() error
func UpdateTrackedPlayerList ¶
func UpdateTrackedPlayerList() error
func UsernameToUUID ¶
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.