bot

package
v0.0.0-...-edf9d71 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2019 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SkillOverall      Skill = 0
	SkillAttack       Skill = 1
	SkillDefense      Skill = 2
	SkillStrength     Skill = 3
	SkillHitpoints    Skill = 4
	SkillRanged       Skill = 5
	SkillPrayer       Skill = 6
	SkillMagic        Skill = 7
	SkillCooking      Skill = 8
	SkillWoodcutting  Skill = 9
	SkillFletching    Skill = 10
	SkillFishing      Skill = 11
	SkillFiremaking   Skill = 12
	SkillCrafting     Skill = 13
	SkillSmithing     Skill = 14
	SkillMining       Skill = 15
	SkillHerblore     Skill = 16
	SkillAgility      Skill = 17
	SkillThieving     Skill = 18
	SkillSlayer       Skill = 19
	SkillFarming      Skill = 20
	SkillRunecraft    Skill = 21
	SkillHunter       Skill = 22
	SkillConstruction Skill = 23

	ClueOverallClues  Clue = 0
	ClueBeginnerClues Clue = 1
	ClueEasyClues     Clue = 2
	ClueMediumClues   Clue = 3
	ClueHardClues     Clue = 4
	ClueEliteClues    Clue = 5
	ClueMasterClues   Clue = 6
)

Enumerated values for index retrieval of array-based scores

Variables

View Source
var (
	// TableName Name of the table holding Channel records in DynamoDB
	TableName string = "ob-channels"
)

Functions

func FormatHiscoreAPIURL

func FormatHiscoreAPIURL(player string, mode GameMode) string

FormatHiscoreAPIURL Formats the base URL used to request hiscores from the OSRS Hiscore API based on the GameMode and adds the player as a query param

func FormatSkillLookupOutput

func FormatSkillLookupOutput(user, player, skillName string, mode GameMode, skill SkillHiscore) string

FormatSkillLookupOutput Formats the information returned by OziachBot upon a successful skill lookup

func HTTPError

func HTTPError(w http.ResponseWriter, err interface{}, code int) error

HTTPError Converts err into a JSON byte array with key "message", then writes the marshalled JSON into the http.ResponseWriter, along with setting the error code given

This is similar to http.Error, with 2 key differences:

* HTTPError writes JSON instead of a string. Because of this, it sets the Content-Type of the response to application/json

* HTTPError accepts an interface{} err instead of a string. This allows error and fmt.Stringer types to be accepted along with strings. If err is not a string or either of the types mentioned above, it is output as the format specifier `%+v`

func Heartbeat

func Heartbeat(w http.ResponseWriter, r *http.Request)

Heartbeat Returns "ok" to validate the health of the application

func JSONMessage

func JSONMessage(message string) []byte

JSONMessage Converts err into a JSON byte array with key "message"

func SameScores

func SameScores(h1, h2 Hiscores) bool

SameScores Returns true if the hiscores represent the same account, false otherwise

Types

type Channel

type Channel struct {
	Name        string `json:"name"`
	IsConnected bool   `json:"isConnected"`
	RSN         string `json:"rsn"`
}

Channel DynamoDB schema for channel records

func UnmarshalChannel

func UnmarshalChannel(item map[string]*dynamodb.AttributeValue) (Channel, error)

UnmarshalChannel Convenience method to unmarshal a DynamoDB record directly into a Channel object

type ChannelAlreadyExistsError

type ChannelAlreadyExistsError struct {
	Channel string
}

ChannelAlreadyExistsError Returned when an operation requires a channel to be new, but it already exists

func (ChannelAlreadyExistsError) Error

type ChannelDatabase

type ChannelDatabase interface {
	GetChannel(name string) (Channel, error)
	GetAllChannels() ([]Channel, error)
	AddChannel(name string) (Channel, error)
	UpdateChannel(name string, builder expression.Builder) (Channel, error)
}

ChannelDatabase Interface for CRUD operations on Channel database

type ChannelNotFoundError

type ChannelNotFoundError struct {
	Channel string
}

ChannelNotFoundError Returned when an operation requires an existing channel that isn't found

func (ChannelNotFoundError) Error

func (e ChannelNotFoundError) Error() string

type Clue

type Clue int

Clue Enum value for clue type

type DynamoDBChannelDatabase

type DynamoDBChannelDatabase struct {
	Client *dynamodb.DynamoDB
}

DynamoDBChannelDatabase Implementation of ChannelDatabase that uses a DynamoDB client to access the database

func (*DynamoDBChannelDatabase) AddChannel

func (db *DynamoDBChannelDatabase) AddChannel(name string) (Channel, error)

AddChannel Adds a new channel by name to the channel DB. Fails if a record with that Name already exists

func (*DynamoDBChannelDatabase) GetAllChannels

func (db *DynamoDBChannelDatabase) GetAllChannels() ([]Channel, error)

GetAllChannels Gets all channels from the database

func (*DynamoDBChannelDatabase) GetChannel

func (db *DynamoDBChannelDatabase) GetChannel(name string) (Channel, error)

GetChannel Gets the channel record by primary ID (Name)

func (*DynamoDBChannelDatabase) UpdateChannel

func (db *DynamoDBChannelDatabase) UpdateChannel(name string, builder expression.Builder) (Channel, error)

UpdateChannel Updates an existing Channel record in the DB. Builds an expression based on the given builder by adding attribute existence check on the primary key. Returns ChannelNotFoundError if the existence check fails

type GameMode

type GameMode struct {
	Name string
	// contains filtered or unexported fields
}

GameMode struct representing the type of account

var (
	// GameModeNormal Normal game mode
	GameModeNormal GameMode = GameMode{"Normal", ""}
	// GameModeIronman Ironman game mode
	GameModeIronman GameMode = GameMode{"Ironman", "_ironman"}
	// GameModeHardcoreIronman Hardcore Ironman game mode
	GameModeHardcoreIronman GameMode = GameMode{"Hardcore Ironman", "_hardcore_ironman"}
	// GameModeUltimateIronman Ultimate Ironman game mode
	GameModeUltimateIronman GameMode = GameMode{"Ultimate Ironman", "_ultimate"}
)

type HiscoreAPI

type HiscoreAPI struct {
	Client HiscoreAPIClient
}

HiscoreAPI Directs all features that interface with the Hiscore API

func NewOSRSHiscoreAPI

func NewOSRSHiscoreAPI() *HiscoreAPI

NewOSRSHiscoreAPI Returns a Hiscore API with the OSRS API client implementation

func (*HiscoreAPI) LookupHiscores

func (api *HiscoreAPI) LookupHiscores(player string) (Hiscores, GameMode, error)

LookupHiscores Retrieves the hiscore based on the most restrictive GameMode pertaining to the player

For example, a Hardcore Ironman has a Normal, Ironman, and Hardcore Ironman hiscore entry, but here we only return the Hardcore Ironman entry

func (*HiscoreAPI) LookupHiscoresByGameMode

func (api *HiscoreAPI) LookupHiscoresByGameMode(player string, mode GameMode) (Hiscores, error)

LookupHiscoresByGameMode Looks up a player's hiscores ranked according to the given GameMode

type HiscoreAPIClient

type HiscoreAPIClient interface {
	GetAPIResponse(player string, mode GameMode) (string, error)
}

HiscoreAPIClient Interface to abstract from any interactions with the Hiscore API

type HiscoreAPIError

type HiscoreAPIError struct {
	Player string
	Mode   GameMode
}

HiscoreAPIError Returned when a player's hiscores aren't available for the given GameMode

func (*HiscoreAPIError) Error

func (e *HiscoreAPIError) Error() string

type Hiscores

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

Hiscores Model housing all hiscores returned from OSRS Hiscore API

func (Hiscores) GetSkillHiscoreFromName

func (hiscores Hiscores) GetSkillHiscoreFromName(name string) (string, SkillHiscore, error)

GetSkillHiscoreFromName maps string name to a specific hiscore, returns that score with its official name

type IRC

type IRC interface {
	Say(channel, text string)
	Whisper(username, text string)
	Join(channel string)
	Depart(channel string)
	Userlist(channel string) ([]string, error)
	Connect() error
	Disconnect() error
}

IRC Interface for interaction with an IRC Server

type IncorrectFormatError

type IncorrectFormatError struct{}

IncorrectFormatError Returned when a command invocation is malformed

func (*IncorrectFormatError) Error

func (e *IncorrectFormatError) Error() string

type MinigameHiscore

type MinigameHiscore struct {
	Rank  int
	Score int
}

MinigameHiscore struct representing the hiscore of anything that's not a skill

type OSRSHiscoreAPIClient

type OSRSHiscoreAPIClient struct{}

OSRSHiscoreAPIClient Implementation of HiscoreAPIClient that queries the OSRS Hiscore API

func (*OSRSHiscoreAPIClient) GetAPIResponse

func (osrsAPI *OSRSHiscoreAPIClient) GetAPIResponse(player string, mode GameMode) (string, error)

GetAPIResponse Sends a GET request to the OSRS Hiscore API according to the player and GameMode, and returns the response as a CSV string

type OziachBot

type OziachBot struct {
	TwitchClient IRC
	ChannelDB    ChannelDatabase
	HiscoreAPI   *HiscoreAPI
}

OziachBot Object structure containing all necessary clients and connections for OziachBot

func (*OziachBot) APIAddChannel

func (bot *OziachBot) APIAddChannel(w http.ResponseWriter, r *http.Request)

APIAddChannel Endpoint handler function to route to AddChannel

func (*OziachBot) APIChangeRSN

func (bot *OziachBot) APIChangeRSN(w http.ResponseWriter, r *http.Request)

APIChangeRSN Endpoint handler function to route to ChangeRSN

func (*OziachBot) APIConnectToChannel

func (bot *OziachBot) APIConnectToChannel(w http.ResponseWriter, r *http.Request)

APIConnectToChannel Endpoint handler function to route to ConnectToChannel

func (*OziachBot) APIDisconnectFromChannel

func (bot *OziachBot) APIDisconnectFromChannel(w http.ResponseWriter, r *http.Request)

APIDisconnectFromChannel Endpoint handler function to route to DisconnectFromChannel

func (*OziachBot) APIGetChannel

func (bot *OziachBot) APIGetChannel(w http.ResponseWriter, r *http.Request)

APIGetChannel Endpoint handler function to route to GetChannel

func (*OziachBot) ChangeRSN

func (bot *OziachBot) ChangeRSN(name, rsn string) error

ChangeRSN Updates an existing channel by setting rsn

func (*OziachBot) ConnectToChannel

func (bot *OziachBot) ConnectToChannel(name string) error

ConnectToChannel Updates an existing channel by setting IsConnected to true. Then OziachBot joins the channel if it succeeds in doing so

func (*OziachBot) DisconnectFromChannel

func (bot *OziachBot) DisconnectFromChannel(name string) error

DisconnectFromChannel Updates the record corresponding to the named channel by setting IsConnected to false, then OziachBot departs from the channel. Does not delete the DB record

func (*OziachBot) HandleMessage

func (bot *OziachBot) HandleMessage(channel string, user twitch.User, message twitch.Message)

HandleMessage Main callback method to wrap all actions on a PRIVMSG

func (*OziachBot) HandleSkillLookup

func (bot *OziachBot) HandleSkillLookup(channel, user, skillName, player string) error

HandleSkillLookup parses user message and sends the formatted result of a skill lookup

func (*OziachBot) InitBot

func (bot *OziachBot) InitBot() error

InitBot Initalizes OziachBot by querying for channels and joining them

func (*OziachBot) Say

func (bot *OziachBot) Say(channel, text string)

Say Wrapper for Client.Say that prefixes the text with "/me"

func (*OziachBot) ServeAPI

func (bot *OziachBot) ServeAPI()

ServeAPI Serves OziachBot's API

type Skill

type Skill int

Skill Enum value for skill

type SkillHiscore

type SkillHiscore struct {
	Rank  int
	Level int
	Exp   int
}

SkillHiscore struct representing the hiscore of a single skill

type UnrankedError

type UnrankedError struct{}

UnrankedError Returned when a hiscore doesn't exist (player is unranked)

func (*UnrankedError) Error

func (e *UnrankedError) Error() string

Jump to

Keyboard shortcuts

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