twirc

package module
v0.0.0-...-0e455c3 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2015 License: MIT Imports: 16 Imported by: 0

README

twirc

A very simple stand-alone Twitch bot that does some basic interactions with the Steam API.

Commands

!mvm returns the current total and individual tour counts as well as total completed missions for any individual tour.

< !mvm
> [MvM Info] Tours: 470 | Mecha(4): 1/3 | TwoCities(446): 2/4 | GearGrinder(20): 0/3
< !mvm manofsnow
> [MvM Info] Tours: 102 | TwoCities(102): 0/4

!steamid returns the numeric steam id for a given vanity name.

< !steamid b4nny
> Steam ID: b4nny => 76561197970669109

!setsteamid Allows a user to associate their steamid with their twitch username

< !setsteamid 76561197970669109
> Set steam id successfully

!viewers Fetch and return the current active viewer counts for the channel.

< !viewers
> [Viewers] Currently 0 viewers online.

!ip Returns the current game info including server ip. Only works for some games using steam api.

< !ip
> [Game] Team Fortress 2 - 192.69.96.156:27021

!scm Returns the most recent steam community market data for the requested item.

< !scm Strange Rocket Launcher
> [Market] Strange Rocket Launcher Lowest: $0.55 Volume: 133

!startip [Owner only] Start the background monitoring service that will announce whenever you connect or change game servers.

< !startip
> [Game] Started monitoring game state

!stopip [Owner only] Stop the background game info updater.

< !stopip
> [Game] Stopped monitoring game state

!quit [Owner only] Quit the server and shutdown the bot cleanly.

< !quit
> [Death Scene] Twas a scratch!

Configuration

Create a config.toml file from the config_dist.toml example file. Edit the fields as you see fit. See below for a description of all the available fields.

// The Twitch IRC server, shouldn't need to change this
Server   string

// Twitch username
Name     string

// Twitch oauth IRC key
// See: http://www.twitchapps.com/tmi/
Password string

// Steam API Key
// See: http://steamcommunity.com/dev/apikey
ApiKey   string

// Streamers steam ID, used as defaults for some commands
SteamID string

// Join these extra channels automatically, your own channel is joined by default already
AutoJoin []string

// Send error and debugging messages to this channel
// You probably want to use a different channel from your main
DebugChannel string

// Print callback handler debug info to the console. Prints event handler debug
// info to the console. You should never need this unless developing yourself.
VerboseCallbackHandler bool

// Print debug irc info to the console. Shows all raw irc traffic.
Debug bool

// Path to database file to use as permanent storage
Database = "twirc.db"

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidArguments = errors.New("Incomplete arguments supplied")
	InvalidResponse  = errors.New("Invalid response from remote")
	InternalError    = errors.New("Internal error processing request")
)
View Source
var (
	LastGameIP     = "*"
	UpdateGameData = true
)
View Source
var (
	SqlDB *sqlx.DB
)

Functions

func DecodeInventory

func DecodeInventory(resp_body []byte, inv *Inventory) error

func DeleteUserByName

func DeleteUserByName(db *sqlx.DB, username string) bool

func GetViewer

func GetViewer(name string)

func HandleCommands

func HandleCommands(fields []string, e *irc.Event) (string, error)

func HandleGetSteamID

func HandleGetSteamID(fields []string, e *irc.Event) (string, error)

func HandleIP

func HandleIP(fields []string, e *irc.Event) (string, error)

func HandleMVM

func HandleMVM(fields []string, e *irc.Event) (string, error)

func HandleMVMLobby

func HandleMVMLobby(fields []string, e *irc.Event) (string, error)

func HandleMyProfile

func HandleMyProfile(fields []string, e *irc.Event) (string, error)

func HandleMySteamID

func HandleMySteamID(fields []string, e *irc.Event) (string, error)

func HandleProfile

func HandleProfile(fields []string, e *irc.Event) (string, error)

func HandleQuit

func HandleQuit(fields []string, e *irc.Event) (string, error)

func HandleSCM

func HandleSCM(fields []string, e *irc.Event) (string, error)

func HandleSetSteamID

func HandleSetSteamID(fields []string, e *irc.Event) (string, error)

func HandleStartIP

func HandleStartIP(fields []string, e *irc.Event) (string, error)

func HandleStopIP

func HandleStopIP(fields []string, e *irc.Event) (string, error)

func HandleViewers

func HandleViewers(fields []string, e *irc.Event) (string, error)

func New

func New(config Config) (*irc.Connection, error)

func NormalizeItemName

func NormalizeItemName(name string) string

func PrettyPrint

func PrettyPrint(i interface{})

func SetSteamID

func SetSteamID(username string, steam_id SteamID) error

func Shutdown

func Shutdown()

Types

type Action

type Action struct {
	Name string `json:"name"`
	Link string `json:"link"`
}

type ActiveViewers

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

func (*ActiveViewers) Add

func (av *ActiveViewers) Add(viewer *Viewer) bool

type ApiPlayerSumResponse

type ApiPlayerSumResponse struct {
	Response Players `json:"response"`
}

type ApiVanityResponse

type ApiVanityResponse struct {
	Response Vanity `json:"response"`
}

type AppData

type AppData struct {
	Def_index string `json:"def_index"`
	Quality   string `json:"quality"`
}

type BPCurrency

type BPCurrency struct {
	Value      float64 `json:"value"`
	ValueHigh  float64 `json:"Value_high"`
	Currency   string  `json:"currency"`
	Difference float64 `json:"difference"`
}

type BPCurrencyBase

type BPCurrencyBase struct {
	Success    int                            `json:"success"`
	Currencies map[string]BPCurrencyContainer `json:"currencies"`
	Name       string                         `json:"name"`
	URL        string                         `json:"url"`
}

type BPCurrencyContainer

type BPCurrencyContainer struct {
	Quality    int        `json:"quality"`
	PriceIndex int        `json:"priceindex"`
	Single     string     `json:"single"`
	Plural     string     `json:"plural"`
	Round      int        `json:"round"`
	Blanket    int        `json:"blanket"`
	Craftable  string     `json:"craftable"`
	Tradable   string     `json:"tradable"`
	DefIndex   int        `json:"defindex"`
	Price      BPCurrency `json:"price"`
}

type BPCurrencyResponse

type BPCurrencyResponse struct {
	Response BPCurrencyBase `json:"response"`
}

type ChatMsg

type ChatMsg struct {
	MessageID int       `db:message_id`
	UserID    int       `db:user_id`
	Message   string    `db:message`
	Emotes    int       `db:emotes`
	CreatedAt time.Time `db:created_at`
}

func NewChatMsg

func NewChatMsg(user *User, message string) *ChatMsg

func (*ChatMsg) Save

func (msg *ChatMsg) Save(db *sqlx.DB)

type Chatter

type Chatter string

type ChatterResponse

type ChatterResponse struct {
	ChatterCount int          `json:"chatter_count"`
	Chatters     ChatterTypes `json:"chatters"`
}

func Chatters

func Chatters(channel string) (*ChatterResponse, error)

func (*ChatterResponse) Count

func (c *ChatterResponse) Count() int

type ChatterTypes

type ChatterTypes struct {
	Moderators []Chatter `json:"moderators"`
	Staff      []Chatter `json:"staff"`
	Admins     []Chatter `json:"admins"`
	GlobalMods []Chatter `json:"global_mods"`
	Viewers    []Chatter `json:"viewers"`
}

type Config

type Config struct {
	// The Twitch IRC server, shouldn't need to change this
	Server string

	// Twitch username
	Name string

	// Twitch oauth IRC key
	// See: http://www.twitchapps.com/tmi/
	Password string

	// Steam API Key
	// See: http://steamcommunity.com/dev/apikey
	ApiKey string

	// Streamers steam ID, used as defaults for some commands
	SteamID string

	// Join these channels automatically
	AutoJoin []string

	// Send error and debugging messages to this channel
	// You probably want to use a different channel from your main
	DebugChannel string

	// Print callback handler debug info to the console
	VerboseCallbackHandler bool

	// Print debug irc info to the console
	Debug bool

	// Database file path to use
	Database string

	// Prefix for IRC commands, "!" default
	Prefix string
}
var (
	Conf Config

	Handlers = map[string]IRCHandlerFunc{
		"viewers":    HandleViewers,
		"steamid":    HandleGetSteamID,
		"setsteamid": HandleSetSteamID,
		"mysteamid":  HandleMySteamID,
		"profile":    HandleProfile,
		"myprofile":  HandleMyProfile,
		"commands":   HandleCommands,
		"mvm":        HandleMVM,
		"mymvm":      HandleMVM,
		"ip":         HandleIP,
		"startip":    HandleStartIP,
		"stopip":     HandleStopIP,
		"quit":       HandleQuit,
		"mvmlobby":   HandleMVMLobby,
		"scm":        HandleSCM,
	}
)

func (*Config) ChannelName

func (c *Config) ChannelName() string

type Description

type Description struct {
	Type  string `json:"type,omitempty"`
	Value string `json:"value,omitempty"`
	Color string `json:"color,omitempty"`
}

type Detail

type Detail struct {
	Appid                         string         `json:"appid"`
	Classid                       string         `json:"classid"`
	Instanceid                    string         `json:"instanceid"`
	Icon_url                      string         `json:"icon_url"`
	Icon_url_large                string         `json:"icon_url_large"`
	Icon_drag_url                 string         `json:"icon_drag_url"`
	Name                          string         `json:"name"`
	Market_hash_name              string         `json:"market_hash_name"`
	Market_name                   string         `json:"market_name"`
	Name_colour                   string         `json:"name_color"`
	Background_color              string         `json:"background_color"`
	Type                          string         `json:"type"`
	Tradable                      uint64         `json:"tradable"`
	Marketable                    uint64         `json:"marketable"`
	Commodity                     uint64         `json:"commodity"`
	Market_tradable_restriction   string         `json:"market_tradable_restriction"`
	Market_marketable_restriction string         `json:"market_marketable_restriction"`
	Descriptions                  []Description  `json:"descriptions"`
	Actions                       []Action       `json:"actions"`
	MarketActions                 []MarketAction `json:"market_actions"`
	Tags                          []Tag          `json:"-"`
	AppData                       AppData        `json:"app_data"`
}

type EmotesContainer

type EmotesContainer struct {
	Regex  string        `json:"regex"`
	Images []EmotesImage `json:"images"`
}

type EmotesImage

type EmotesImage struct {
	EmoticonSet int    `json:"emoticon_set"`
	Height      int    `json:"height"`
	Width       int    `json:"width"`
	Url         string `json:"url"`
}

type EmotesResp

type EmotesResp struct {
	Emoticons []EmotesContainer `json:"emoticons"`
	// contains filtered or unexported fields
}

func FetchEmotes

func FetchEmotes() (*EmotesResp, error)

type EntryList

type EntryList []string

type IRCHandlerFunc

type IRCHandlerFunc func([]string, *irc.Event) (string, error)

type IRCMessage

type IRCMessage struct {
	Sent    time.Time
	Message string
}

type Inventory

type Inventory struct {
	Success      bool              `json:"success"`
	Inventory    map[string]Item   `json:"rgInventory"`
	Descriptions map[string]Detail `json:"rgDescriptions"`
	More         bool              `json:"more"`
	More_start   bool              `json:"more_start"`
}

func FetchInventory

func FetchInventory(steam_id SteamID) (*Inventory, error)

func (*Inventory) FindMVMData

func (inv *Inventory) FindMVMData() []MvMTour

type Item

type Item struct {
	Id         string `json:"id"`
	ClassId    string `json:"classid"`
	InstanceID string `json:"instanceid"`
	Amount     string `json:"amount"`
	Pos        uint64 `json:"pos"`
}

type MarketAction

type MarketAction struct {
	Name string `json:"name"`
	Link string `json:"link"`
}

type MarketPrice

type MarketPrice struct {
	Success     bool `json:"success"`
	Name        string
	LowestPrice string `json:"lowest_price"`
	Volume      int    `json:"volume,string"`
	MedianPrice string `json:"median_price"`
}

func GetPrice

func GetPrice(hash_name string) (*MarketPrice, error)

type MvMTour

type MvMTour struct {
	Name      string
	Tours     uint64
	Missions  []string
	Completed []string
}

func NewMvMTour

func NewMvMTour(name string, tours uint64, missions []string) MvMTour

func (*MvMTour) AddCompleted

func (mvm *MvMTour) AddCompleted(mission string)

func (*MvMTour) InfoStr

func (mvm *MvMTour) InfoStr() string

func (*MvMTour) ShortName

func (mvm *MvMTour) ShortName() string

type PlayerInfo

type PlayerInfo struct {
	SteamID                  SteamID `json:"steamid"`
	CommunityVisibilityState int     `json:"communityvisibilitystate"`
	ProfileState             int     `json:"profilestate"`
	PersonaName              string  `json:"personaname"`
	LastLogoff               int     `json:"lastlogoff"`
	CommentPermission        int     `json:"commentpermission"`
	ProfileURL               string  `json:"profileurl"`
	Avatar                   string  `json:"avatar"`
	AvatarMedium             string  `json:"avatarmedium"`
	AvatarFull               string  `json:"avatarfull"`
	PersonaState             int     `json:"personastate"`
	RealName                 string  `json:"realname"`
	PrimaryClanID            string  `json:"primaryclanid"`
	TimeCreated              int     `json:"timecreated"`
	PersonaStateFlags        int     `json:"personastateflags"`
	GameServerIP             string  `json:"gameserverip"`
	GameExtraInfo            string  `json:"gameextrainfo"`
	GameID                   string  `json:"gameid"`
}

func GetPlayerInfo

func GetPlayerInfo(api_key string, steam_id SteamID) (*PlayerInfo, error)

type Players

type Players struct {
	Players []PlayerInfo `json:"players"`
}

type SteamID

type SteamID string

func GetSteamID

func GetSteamID(username string) SteamID

func NewSteamID

func NewSteamID(steam_id string) (SteamID, error)

func ResolveVanity

func ResolveVanity(name string) (SteamID, error)

func (SteamID) MVMLobbyURL

func (sid SteamID) MVMLobbyURL() string

func (SteamID) ProfileURL

func (sid SteamID) ProfileURL() string

type Tag

type Tag struct {
	Internal_name string `json:"internal_name"`
	Name          string `json:"name"`
	Category      string `json:"category,omitempty"`
	Color         string `json:"color"`
	Category_name string `json:"category_name"`
}

type User

type User struct {
	UserID    int       `db:user_id`
	Username  string    `db:username`
	SteamID   string    `db:steamid`
	CreatedAt time.Time `db:created_at`
}

func GetOrCreateUser

func GetOrCreateUser(username string) *User

func GetUser

func GetUser(username string) (*User, error)

type Vanity

type Vanity struct {
	SteamID string `json:"steamid,omitempty"`
	Success int    `json:"success"`
	Message string `json:"message,omitempty"`
}

type Viewer

type Viewer struct {
	Name        string
	HostMask    string
	ConnectedAt time.Time
	History     []string
}

func NewViewer

func NewViewer(name string, host_mask string) *Viewer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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