bot

package
v0.0.0-...-e7fbf99 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2020 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CHANNELS count of audio channels
	CHANNELS int = 2
	// FRAME_RATE ...
	FRAME_RATE int = 48000
	// FRAME_SIZE ...
	FRAME_SIZE int = 960
	// MAX_BYTES max bytes per sample
	MAX_BYTES int = (FRAME_SIZE * 2) * 2
)
View Source
const (
	// ERROR_TYPE returns if error
	ERROR_TYPE = -1
	// VIDEO_TYPE returns if video
	VIDEO_TYPE = 0
	// PLAYLIST_TYPE returns if playlist
	PLAYLIST_TYPE = 1
)

Variables

This section is empty.

Functions

func GetPlayerByName

func GetPlayerByName(name string) string

GetPlayerByID returns player ID by player name

func Greetings

func Greetings(discord *discordgo.Session, event *discordgo.GuildMemberAdd, guild *GuildData)

Greetings sends greetings for user

func SendKill

func SendKill(session *discordgo.Session, conf *Config, kill *AlbionKill, userID, lang string)

SendKill sends kill to user

func SendPlayerKills

func SendPlayerKills(session *discordgo.Session, worker *DBWorker, conf *Config, updater *AlbionUpdater, userID string)

SendPlayerKills sends player kills

Types

type AlbionEquipment

type AlbionEquipment struct {
	MainHand AlbionItem `json:"MainHand"`
	OffHand  AlbionItem `json:"OffHand"`
	Head     AlbionItem `json:"Head"`
	Armor    AlbionItem `json:"Armor"`
	Shoes    AlbionItem `json:"Shoes"`
	Bag      AlbionItem `json:"Bag"`
	Cape     AlbionItem `json:"Cape"`
	Mount    AlbionItem `json:"Mount"`
	Potion   AlbionItem `json:"Potion"`
	Food     AlbionItem `json:"Food"`
}

Equipment contains items in slots

type AlbionGuildSearch

type AlbionGuildSearch struct {
	ID           string `json:"Id"`
	Name         string `json:"Name"`
	AllianceID   string `json:"AllianceId"`
	AllianceName string `json:"AllianceName"`
	KillFame     int    `json:"KillFame"`
	DeathFame    int    `json:"DeathFame"`
}

GuildSearch contains guild data from search response

type AlbionItem

type AlbionItem struct {
	Type    string `json:"Type"`
	Count   int    `json:"Count"`
	Quality int    `json:"Quality"`
}

Item contains item data

type AlbionKill

type AlbionKill struct {
	GroupMemberCount     int            `json:"groupMemberCount"`
	NumberOfParticipants int            `json:"numberOfParticipants"`
	EventID              int            `json:"EventId"`
	TimeStamp            string         `json:"TimeStamp"`
	Version              int            `json:"Version"`
	Killer               AlbionPlayer   `json:"Killer"`
	Victim               AlbionPlayer   `json:"Victim"`
	TotalVictimKillFame  int            `json:"TotalVictimKillFame"`
	Location             string         `json:"Location"`
	Participants         []AlbionPlayer `json:"Participants"`
	GroupMembers         []AlbionPlayer `json:"GroupMembers"`
	BattleID             int            `json:"BattleId"`
	Type                 string         `json:"Type"`
}

Kill contains kill data

func AlbionGetKillID

func AlbionGetKillID(id string) (kill *AlbionKill, err error)

AlbionGetKillID returns kill by ID

func AlbionGetPlayerKills

func AlbionGetPlayerKills(id string) (result []AlbionKill, err error)

GetPlayerKills returns array of kills by player id

type AlbionPlayer

type AlbionPlayer struct {
	AverageItemPower float64         `json:"AverageItemPower"`
	Equipment        AlbionEquipment `json:"Equipment"`
	Inventory        []AlbionItem    `json:"Inventory"`
	Name             string          `json:"Name"`
	Id               string          `json:"Id"`
	GuildName        string          `json:"GuildName"`
	GuildId          string          `json:"GuildId"`
	AllianceName     string          `json:"AllianceName"`
	AllianceId       string          `json:"AllianceId"`
	AllianceTag      string          `json:"AllianceTag"`
	Avatar           string          `json:"Avatar"`
	AvatarRing       string          `json:"AvatarRing"`
	DeathFame        int             `json:"DeathFame"`
	KillFame         int             `json:"KillFame"`
	FameRatio        float64         `json:"FameRatio"`
	DamageDone       float64         `json:"DamageDone"`
}

Player data

type AlbionPlayerSearch

type AlbionPlayerSearch struct {
	ID           string  `json:"Id"`
	Name         string  `json:"Name"`
	AllianceID   string  `json:"AllianceId"`
	AllianceName string  `json:"AllianceName"`
	KillFame     int     `json:"KillFame"`
	DeathFame    int     `json:"DeathFame"`
	Avatar       string  `json:"Avatar"`
	AvatarRing   string  `json:"AvatarRing"`
	FameRation   float64 `json:"FameRatio"`
	TotalKills   int     `json:"totalKills"`
	GVGKills     int     `json:"gvgKills"`
	GVGWon       int     `json:"gvgWon"`
}

PlayerSearch contains player data from search response

type AlbionPlayerUpdater

type AlbionPlayerUpdater struct {
	PlayerID string
	UserID   string
	Language string
	LastKill int64
	StartAt  int64
}

type AlbionSearchResult

type AlbionSearchResult struct {
	Guilds  []AlbionGuildSearch  `json:"guilds"`
	Players []AlbionPlayerSearch `json:"players"`
}

SearchResult contains search response

func AlbionSearchPlayers

func AlbionSearchPlayers(name string) (result *AlbionSearchResult, err error)

SearchPlayers returns player list by name

type AlbionUpdater

type AlbionUpdater struct {
	Players map[string]*AlbionPlayerUpdater
}

func AlbionGetUpdater

func AlbionGetUpdater(db *DBWorker) *AlbionUpdater

AlbionGetUpdater creates and returns albion kills updater

func (*AlbionUpdater) Update

func (u *AlbionUpdater) Update(session *discordgo.Session, worker *DBWorker, conf *Config)

Update updates players kills and sends to users

type BlackListElement

type BlackListElement struct {
	ID string
}

type BlackListStruct

type BlackListStruct struct {
	Guilds []string
	Users  []string
}

BlackList contains ignored guilds and users

func (BlackListStruct) CheckGuild

func (b BlackListStruct) CheckGuild(id string) bool

CheckGuild returns true if guild in blacklist

func (BlackListStruct) CheckUser

func (b BlackListStruct) CheckUser(id string) bool

CheckUser returns true if user in blacklist

type BotMessages

type BotMessages struct {
	Messages map[string][]string
}

BotMessages contains map with key = guild ID, value = array of messages IDs

func NewMessagesMap

func NewMessagesMap() *BotMessages

NewMessagesMap creates map of bot's messages

func (*BotMessages) Add

func (m *BotMessages) Add(ctx *Context, messageID string)

Add adds bot message to index

func (*BotMessages) Clear

func (m *BotMessages) Clear(ctx *Context, from int)

Clear deletes bot messages

type CmdMap

type CmdMap map[string]Command

CmdMap : Map with executable functions

type Command

type Command func(Context)

Command : Executable command function

type CommandHandler

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

CommandHandler : Command handler struct

func NewCommandHandler

func NewCommandHandler() *CommandHandler

NewCommandHandler creates command handler

func (CommandHandler) Get

func (handler CommandHandler) Get(name string) (*Command, bool)

Get returns command by command name

func (CommandHandler) GetCmds

func (handler CommandHandler) GetCmds() CmdMap

GetCmds returns handler commands

func (CommandHandler) Register

func (handler CommandHandler) Register(name string, command Command)

Register adds new command in handler

type CommandSignature

type CommandSignature struct {
	Path        []string
	Command     func(Context)
	Middlewares []func(*Context) bool
}

CommandSignature contains data of command

type Config

type Config struct {
	Weather      WeatherConfig
	General      GeneralConfig
	News         NewsConfig
	Translate    TranslateConfig
	Locales      LocalesMap
	Currency     CurrencyConfig
	WeatherCodes WeatherCodesMap
	Metrics      MetricsConfig
	DBL          DBLConfig
	Twitch       TwitchConfig
	DarkSky      DarkSkyConfig
	Voice        VoiceConfig
}

Config Main config struct. Contains all another config structs data.

func LoadConfig

func LoadConfig() *Config

LoadConfig loads configs from file 'config.toml'. Terminate program if error.

func (*Config) GetLocale

func (c *Config) GetLocale(key string) string

GetLocale returns locale string by key

func (*Config) GetLocaleLang

func (c *Config) GetLocaleLang(key, lang string) string

GetLocaleLang returns translation on specified language

func (*Config) LoadLocales

func (c *Config) LoadLocales()

LoadLocales loads locales from file 'locales.json'. Terminate program if error.

func (*Config) LoadWeatherCodes

func (c *Config) LoadWeatherCodes()

LoadWeatherCodes loads weather font codes from file 'codes.json' in map. Terminate program if error.

type Connection

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

Connection : Voice connection struct

func NewConnection

func NewConnection(voiceConnection *discordgo.VoiceConnection) *Connection

NewConnection creates and returns new voice connection

func (*Connection) Disconnect

func (c *Connection) Disconnect()

Disconnect remove from voice channel and connection

func (*Connection) EncodeOpusAndSend

func (connection *Connection) EncodeOpusAndSend(reader io.Reader) error

func (*Connection) Stop

func (connection *Connection) Stop()

Stop stops playback

type Context

type Context struct {
	BotID string

	Discord      *discordgo.Session
	Guild        *discordgo.Guild
	VoiceChannel *discordgo.Channel
	TextChannel  *discordgo.Channel
	User         *discordgo.User
	Message      *discordgo.MessageCreate
	Args         []string

	DB   *DBWorker
	Cron *cron.Cron

	Conf       *Config
	CmdHandler *CommandHandler
	Sessions   *SessionManager
	Youtube    *Youtube
	BotMsg     *BotMessages
	Data       *DataType
	Guilds     *GuildsMap
	Twitch     *Twitch
	Albion     *AlbionUpdater
	BlackList  *BlackListStruct
}

Context : Bot context structure

func NewContext

func NewContext(botID string, discord *discordgo.Session, guild *discordgo.Guild, textChannel *discordgo.Channel,
	user *discordgo.User, message *discordgo.MessageCreate, conf *Config, cmdHandler *CommandHandler,
	sessions *SessionManager, youtube *Youtube, botMsg *BotMessages, dataType *DataType, dbWorker *DBWorker,
	guilds *GuildsMap, botCron *cron.Cron, twitch *Twitch, albion *AlbionUpdater, blacklist *BlackListStruct) *Context

NewContext create new context

func (*Context) AddGreetings

func (ctx *Context) AddGreetings(text string)

AddGreetings adds new greetings to guild

func (*Context) AlbionAddPlayer

func (ctx *Context) AlbionAddPlayer() error

AlbionAddPlayer adds player to updater

func (*Context) AlbionShowKill

func (ctx *Context) AlbionShowKill()

AlbionShowKill sends kill embed to user

func (*Context) AlbionShowKills

func (ctx *Context) AlbionShowKills()

ShowKills sends embed message in discord

func (*Context) Arg

func (ctx *Context) Arg(index int) string

Arg returns argument by index. If argument not exists returns empty string

func (*Context) BlacklistAddGuild

func (ctx *Context) BlacklistAddGuild(id string)

BlacklistAddGuild adds guild in blacklist

func (*Context) BlacklistAddUser

func (ctx *Context) BlacklistAddUser(id string)

BlacklistAddUser adds user in blacklist

func (*Context) BlacklistRemoveGuild

func (ctx *Context) BlacklistRemoveGuild(id string)

BlacklistRemoveGuild removes guild from blacklist

func (*Context) BlacklistRemoveUser

func (ctx *Context) BlacklistRemoveUser(id string)

BlacklistRemoveUser removes user from blacklist

func (*Context) EditEmbed

func (ctx *Context) EditEmbed(ID, name, value string, inline bool)

EditEmbed edits embed message by id

func (*Context) GetGuild

func (ctx *Context) GetGuild() *GuildData

GetGuild return data about current guild

func (*Context) GetGuildUser

func (ctx *Context) GetGuildUser(id string) *discordgo.User

func (*Context) GetRoles

func (ctx *Context) GetRoles() *UserRoles

GetRoles returns UserRoles struct pointer

func (*Context) GetVoiceChannel

func (ctx *Context) GetVoiceChannel() *discordgo.Channel

GetVoiceChannel returns user voice channel

func (*Context) GuildConf

func (ctx *Context) GuildConf() *GuildData

GuildConf returns config of guild

func (*Context) IsAdmin

func (ctx *Context) IsAdmin() bool

IsAdmin returns true if user is admin

func (*Context) IsServerAdmin

func (ctx *Context) IsServerAdmin() bool

func (*Context) Loc

func (ctx *Context) Loc(key string) string

Loc returns translated string by key

func (*Context) Log

func (ctx *Context) Log(module, guildID, text string)

Log saves log in database

func (*Context) MetricsCommand

func (ctx *Context) MetricsCommand(command, state string)

MetricsCommand sends command metrics

func (*Context) MetricsLog

func (ctx *Context) MetricsLog(module string)

MetricsLog sends log metrics

func (*Context) MetricsMessage

func (ctx *Context) MetricsMessage()

MetricsMessage sends message metrics

func (*Context) RemoveGreetings

func (ctx *Context) RemoveGreetings()

RemoveGreetings removes greetings from guild

func (*Context) Reply

func (ctx *Context) Reply(content string) *discordgo.Message

Reply reply on massage

func (*Context) ReplyEmbed

func (ctx *Context) ReplyEmbed(name, content string) *discordgo.Message

ReplyEmbed reply on message with embed message

func (*Context) ReplyEmbedAttachment

func (ctx *Context) ReplyEmbedAttachment(name, content, fileName string, file io.Reader) *discordgo.Message

ReplyEmbedAttachment reply on message with embed message with attachment

func (*Context) ReplyEmbedAttachmentImageURL

func (ctx *Context) ReplyEmbedAttachmentImageURL(title, desc, imageUrl string) *discordgo.Message

ReplyEmbedAttachment reply on message with embed message with attachment

func (*Context) ReplyEmbedPM

func (ctx *Context) ReplyEmbedPM(name, content string) *discordgo.Message

ReplyEmbedPM sends embed in personal channel

func (*Context) ReplyFile

func (ctx *Context) ReplyFile(name string, r io.Reader) *discordgo.Message

ReplyFile reply on massage with file

func (*Context) ReplyPM

func (ctx *Context) ReplyPM(content string) *discordgo.Message

ReplyPM sends reply message to user personal channel

func (*Context) WeatherCode

func (ctx *Context) WeatherCode(code string) string

WeatherCode returns unicode symbol of weather font icon

type CurrencyConfig

type CurrencyConfig struct {
	Default []string
}

CurrencyConfig Currency config struct

type DBLConfig

type DBLConfig struct {
	Token string
	BotID string
}

DBLConfig contains bot list configs

type DBWorker

type DBWorker struct {
	DBSession *mgo.Session
	DBName    string
}

DBWorker MongoDB instance

func NewDBSession

func NewDBSession(dbname string) *DBWorker

NewDBSession creates new MongoDB instance

func (*DBWorker) AddAlbionPlayer

func (db *DBWorker) AddAlbionPlayer(player *AlbionPlayerUpdater)

AddAlbionPlayer adds new player in database

func (*DBWorker) AddBlacklistGuild

func (db *DBWorker) AddBlacklistGuild(id string)

AddBlacklistGuild adds guild in database blacklist

func (*DBWorker) AddBlacklistUser

func (db *DBWorker) AddBlacklistUser(id string)

AddBlacklistUser adds user in database blacklist

func (*DBWorker) AddRadioStation

func (db *DBWorker) AddRadioStation(name, url, key, category string) error

AddRadioStation adds new radio station

func (*DBWorker) AddStream

func (db *DBWorker) AddStream(stream *TwitchStream)

AddStream adds stream in mongodb

func (*DBWorker) GetAlbionPlayers

func (db *DBWorker) GetAlbionPlayers() []AlbionPlayerUpdater

GetAlbionPlayers gets players from database

func (*DBWorker) GetBlacklist

func (db *DBWorker) GetBlacklist() *BlackListStruct

GetBlackList gets blacklist from database

func (*DBWorker) GetNewsCountry

func (db *DBWorker) GetNewsCountry(guild string) string

GetNewsCountry returns news country string

func (*DBWorker) GetRadioStationByKey

func (db *DBWorker) GetRadioStationByKey(key string) (*RadioStation, error)

GetRadioStationByKey returns one station by key

func (*DBWorker) GetRadioStations

func (db *DBWorker) GetRadioStations(category string) []RadioStation

GetRadioStations gets stations from database and returns slice of them

func (*DBWorker) GetTwitchStreams

func (db *DBWorker) GetTwitchStreams(guildID string) map[string]*TwitchStream

GetTwitchStreams returns twitch streams from mongodb

func (*DBWorker) GetTwitchToken

func (db *DBWorker) GetTwitchToken() *TwitchDBConfig

func (*DBWorker) Guilds

func (db *DBWorker) Guilds() *mgo.Collection

Guilds returns guilds collection from mongodb

func (*DBWorker) InitGuilds

func (db *DBWorker) InitGuilds(sess *discordgo.Session, conf *Config) *GuildsMap

InitGuilds initialize guilds in database

func (*DBWorker) InitNewGuild

func (db *DBWorker) InitNewGuild(guildID string, conf *Config, data *GuildsMap)

InitNewGuild creates new guild in database

func (*DBWorker) Log

func (db *DBWorker) Log(module, guildID, text string)

Log saves log in database

func (*DBWorker) LogGet

func (db *DBWorker) LogGet(count int) []dbLog

LogGet returns last N log rows

func (*DBWorker) RemoveAlbionPlayer

func (db *DBWorker) RemoveAlbionPlayer(id string)

RemoveAlbionPlayer removes player from database

func (*DBWorker) RemoveBlacklistGuild

func (db *DBWorker) RemoveBlacklistGuild(id string)

RemoveBlacklistGuild removes guild from database blacklist

func (*DBWorker) RemoveBlacklistUser

func (db *DBWorker) RemoveBlacklistUser(id string)

RemoveBlacklistUser removes user from database blacklist

func (*DBWorker) RemoveRadioStation

func (db *DBWorker) RemoveRadioStation(key string) error

RemoveRadioStation removes radio station by key

func (*DBWorker) RemoveStream

func (db *DBWorker) RemoveStream(stream *TwitchStream)

RemoveStream removes stream from mongodb

func (*DBWorker) UpdateAlbionPlayerLast

func (db *DBWorker) UpdateAlbionPlayerLast(userID string, lastKill int64)

UpdateAlbionPlayerLast updates last kill of albion player

func (*DBWorker) UpdateStream

func (db *DBWorker) UpdateStream(stream *TwitchStream)

UpdateStream updates stream in mongodb

func (*DBWorker) UpdateTwitchToken

func (db *DBWorker) UpdateTwitchToken(token string, expire time.Time)

type DarkSkyConfig

type DarkSkyConfig struct {
	Token string
}

DarkSkyConfig Dark Sky weather api config

type DataType

type DataType struct {
	Polls          map[string]*PollType
	GuildSchedules map[string]*GuildSchedule
}

DataType contains some data

func NewDataType

func NewDataType() *DataType

NewDataType creates data type

func (*DataType) AddCronJob

func (data *DataType) AddCronJob(ctx *Context, id cron.EntryID, cmd string) error

AddCronJob adds new cron job to guild

func (*DataType) AddPollVote

func (data *DataType) AddPollVote(ctx *Context, vote int) error

AddPollVote votes in poll

func (*DataType) CreatePoll

func (data *DataType) CreatePoll(ctx *Context, fields []string) error

CreatePoll creates new poll in guild

func (*DataType) CronIsFull

func (data *DataType) CronIsFull(ctx *Context) bool

CronIsFull checks if cron jobs is maximum count

func (*DataType) CronList

func (data *DataType) CronList(ctx *Context) (*GuildSchedule, error)

CronList shows cron jobs

func (*DataType) CronRemove

func (data *DataType) CronRemove(ctx *Context, id cron.EntryID) error

CronRemove removes job from guild

func (*DataType) EndPoll

func (data *DataType) EndPoll(ctx *Context) (results map[string]int, err error)

EndPoll ends poll and returns results

type GeneralConfig

type GeneralConfig struct {
	Language         string
	Timezone         int
	GeonamesUsername string
	Game             string
	EmbedColor       int
	ServiceURL       string
	MessagePool      int
	DatabaseName     string
	GeocodingApiKey  string
	AdminID          string
}

GeneralConfig General config struct

type GuildData

type GuildData struct {
	ID          string
	WeatherCity string
	NewsCounty  string
	Language    string
	Timezone    int
	EmbedColor  int
	VoiceVolume float32
	Greeting    string
}

GuildData contains data about guild settings

type GuildSchedule

type GuildSchedule struct {
	CronJobs map[cron.EntryID]string
}

GuildSchedule contains map with cron jobs

type GuildsMap

type GuildsMap struct {
	Guilds map[string]*GuildData
}

GuildsMap contains guilds settings

type JoinProperties

type JoinProperties struct {
	Muted    bool
	Deafened bool
}

JoinProperties voice connection properties struct

type LocalesMap

type LocalesMap map[string]map[string]string

LocalesMap Map with locales

type MetricsConfig

type MetricsConfig struct {
	Address  string
	Database string
	User     string
	Password string
}

MetricsConfig InfluxDB connection settings

type NewEmbedStruct

type NewEmbedStruct struct {
	*discordgo.MessageSend
	// contains filtered or unexported fields
}

NewEmbedStruct generated embed

func NewEmbed

func NewEmbed(title string) *NewEmbedStruct

NewEmbed creates new embed

func (*NewEmbedStruct) AttachImg

func (emb *NewEmbedStruct) AttachImg(name string, file io.Reader) *NewEmbedStruct

AttachImg adds attached image to embed from io.Reader

func (*NewEmbedStruct) AttachImgURL

func (emb *NewEmbedStruct) AttachImgURL(url string) *NewEmbedStruct

AttachImgURL adds attached image to embed from url

func (*NewEmbedStruct) AttachThumbURL

func (emb *NewEmbedStruct) AttachThumbURL(url string) *NewEmbedStruct

AttachThumbURL adds attached thumbnail to embed from url

func (*NewEmbedStruct) Author

func (emb *NewEmbedStruct) Author(name, url, iconURL string) *NewEmbedStruct

Author adds author to embed

func (*NewEmbedStruct) CheckLength

func (emb *NewEmbedStruct) CheckLength(newLength int) bool

CheckLength returns true if length of embed chars less then 6000

func (*NewEmbedStruct) Color

func (emb *NewEmbedStruct) Color(color int) *NewEmbedStruct

Color adds color to embed

func (*NewEmbedStruct) Desc

func (emb *NewEmbedStruct) Desc(desc string) *NewEmbedStruct

Desc adds description to embed

func (*NewEmbedStruct) Field

func (emb *NewEmbedStruct) Field(name, value string, inline bool) *NewEmbedStruct

Field adds field to embed

func (*NewEmbedStruct) Footer

func (emb *NewEmbedStruct) Footer(text string) *NewEmbedStruct

Footer adds footer text

func (*NewEmbedStruct) GetEmbed

func (emb *NewEmbedStruct) GetEmbed() *discordgo.MessageEmbed

GetEmbed returns discords embed

func (*NewEmbedStruct) Send

func (emb *NewEmbedStruct) Send(ctx *Context) *discordgo.Message

Send send embed message to Discord

func (*NewEmbedStruct) SendPM

func (emb *NewEmbedStruct) SendPM(ctx *Context) *discordgo.Message

SendPM send embed personal message to Discord

func (*NewEmbedStruct) TimeStamp

func (emb *NewEmbedStruct) TimeStamp(ts string) *NewEmbedStruct

TimeStamp adds timestamp to footer of embed

func (*NewEmbedStruct) URL

func (emb *NewEmbedStruct) URL(url string) *NewEmbedStruct

URL adds url to embed description

type NewsConfig

type NewsConfig struct {
	APIKey   string
	Country  string
	Articles int
}

NewsConfig News config struct

type NodeElement

type NodeElement struct {
	Current  string
	Elements map[string]*NodeElement
	Workers  []NodeWorker
}

func (*NodeElement) AddElement

func (n *NodeElement) AddElement(element string)

func (*NodeElement) GetElement

func (n *NodeElement) GetElement(element string) *NodeElement

type NodeTree

type NodeTree struct {
	Elements map[string]*NodeElement
}

New command handler

func NewTree

func NewTree() NodeTree

NodeTree creates new node tree

func (*NodeTree) AddCommand

func (t *NodeTree) AddCommand(command *CommandSignature)

func (*NodeTree) Execute

func (t *NodeTree) Execute(ctx Context)

func (*NodeTree) GetElement

func (t *NodeTree) GetElement(element string) *NodeElement

type NodeWorker

type NodeWorker struct {
	CommandWorker func(Context)
	Middlewares   []func(*Context) bool
}

NodeWorker contains workers of command

func (*NodeWorker) CheckMiddlewares

func (w *NodeWorker) CheckMiddlewares(ctx *Context) bool

type PlaylistVideo

type PlaylistVideo struct {
	Id string `json:"id"`
}

PlaylistVideo contains playlist ID

type PollType

type PollType struct {
	// Fields array of field names
	Fields []string
	// Votes map of votes Key: UserID Value: FieldKey
	Votes map[string]int
}

PollType contains poll's data

type RadioPlayer

type RadioPlayer struct {
	Running bool
}

RadioPlayer radio player struct

func (*RadioPlayer) Start

func (player *RadioPlayer) Start(sess *Session, source string, callback func(string), volume float32)

Start starts radio playback

type RadioStation

type RadioStation struct {
	Name     string
	URL      string
	Key      string
	Category string
}

RadioStation contains info about radio station

type Session

type Session struct {
	Queue     *SongQueue
	Player    RadioPlayer
	ChannelID string

	Volume float32
	// contains filtered or unexported fields
}

Session structure with radio player and voice connection

func (*Session) GetConnection

func (sess *Session) GetConnection() *Connection

GetConnection returns vice connection struct

func (*Session) IsOk

func (s *Session) IsOk() bool

func (*Session) Play

func (sess *Session) Play(source string, volume float32) error

Play starts to play the thing in source

func (*Session) Stop

func (sess *Session) Stop()

Stop stops radio

type SessionManager

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

SessionManager contains all sessions

func NewSessionManager

func NewSessionManager() *SessionManager

NewSessionManager creates and returns new session manager

func (*SessionManager) Count

func (manager *SessionManager) Count() int

Count returns count of voice sessions

func (*SessionManager) GetAll

func (manager *SessionManager) GetAll() map[string]*Session

func (*SessionManager) GetByChannel

func (manager *SessionManager) GetByChannel(channelID string) (*Session, bool)

GetByChannel returns session by channel ID

func (*SessionManager) GetByGuild

func (manager *SessionManager) GetByGuild(guildID string) *Session

GetByGuild returns session by guild ID

func (*SessionManager) GetChannels

func (manager *SessionManager) GetChannels() []string

func (*SessionManager) GetGuilds

func (manager *SessionManager) GetGuilds() []string

func (*SessionManager) Join

func (manager *SessionManager) Join(discord *discordgo.Session, guildID, channelID string,
	properties JoinProperties, volume float32) (*Session, error)

Join add bot to voice channel

func (*SessionManager) Leave

func (manager *SessionManager) Leave(discord *discordgo.Session, session Session)

Leave remove bot from voice channel

type Song

type Song struct {
	Media    string
	Title    string
	Duration *string
	Id       string
}

Song contains information about song

func NewSong

func NewSong(media, title, id string) *Song

NewSong creates and returns new song

func (Song) Ffmpeg

func (song Song) Ffmpeg(volume float32) *exec.Cmd

Ffmpeg returns ffmpeg executable command

type SongQueue

type SongQueue struct {
	Running bool
	// contains filtered or unexported fields
}

SongQueue struct contains songs array

func (*SongQueue) Add

func (queue *SongQueue) Add(song *Song)

Add adds one song in songs array

func (*SongQueue) Clear

func (queue *SongQueue) Clear()

Clear removes all songs from queue

func (*SongQueue) Current

func (queue *SongQueue) Current() *Song

Current returns current song

func (*SongQueue) Get

func (queue *SongQueue) Get() []Song

Get returns songs array

func (*SongQueue) HasNext

func (queue *SongQueue) HasNext() bool

HasNext check if exist newx song in queue

func (*SongQueue) Next

func (queue *SongQueue) Next() Song

Next returns next song from queue

func (*SongQueue) Pause

func (queue *SongQueue) Pause()

Pause pauses queue playing

func (*SongQueue) Set

func (queue *SongQueue) Set(list []Song)

Set sets songs array

func (SongQueue) Start

func (queue SongQueue) Start(sess *Session, callback func(string))

Start starts queue playing

type TranslateConfig

type TranslateConfig struct {
	APIKey string
}

TranslateConfig Yandex translate config struct

type Twitch

type Twitch struct {
	Guilds  map[string]*TwitchGuild
	DB      *DBWorker
	Conf    *Config
	Discord *discordgo.Session
}

Twitch contains streams

func TwitchInit

func TwitchInit(session *discordgo.Session, conf *Config, db *DBWorker) *Twitch

TwitchInit makes new instance of twitch api worker

func (*Twitch) AddStreamer

func (t *Twitch) AddStreamer(guild, channel, login, message string) (string, error)

AddStreamer adds new streamer to list

func (*Twitch) OAuthToken

func (t *Twitch) OAuthToken() string

func (*Twitch) RemoveStreamer

func (t *Twitch) RemoveStreamer(login, guild string) error

RemoveStreamer removes streamer from list

func (*Twitch) Update

func (t *Twitch) Update()

Update updates status of streamers and notify

type TwitchConfig

type TwitchConfig struct {
	ClientID     string
	ClientSecret string
}

TwitchConfig contains twitch api configs

type TwitchDBConfig

type TwitchDBConfig struct {
	Type   string
	Token  string
	Expire time.Time
}

type TwitchGameData

type TwitchGameData struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	ArtURL string `json:"box_art_url"`
}

TwitchGameData Twitch API response struct

type TwitchGameResult

type TwitchGameResult struct {
	Data []TwitchGameData `json:"data"`
}

TwitchGameResult contains response of Twitch API for games

type TwitchGuild

type TwitchGuild struct {
	ID      string
	Streams map[string]*TwitchStream
}

TwitchGuild contains streams from specified guild

type TwitchStream

type TwitchStream struct {
	Login           string
	UserID          string
	Name            string
	Guild           string
	Channel         string
	ProfileImageURL string
	IsOnline        bool
	IsCustom        bool
	CustomMessage   string
	CustomImageURL  string
}

TwitchStream contains stream data

type TwitchStreamData

type TwitchStreamData struct {
	ID           string `json:"id"`
	UserID       string `json:"user_id"`
	UserName     string `json:"user_name"`
	GameID       string `json:"game_id"`
	Type         string `json:"type"`
	Title        string `json:"title"`
	Viewers      int    `json:"viewer_count"`
	Language     string `json:"language"`
	ThumbnailURL string `json:"thumbnail_url"`
}

TwitchStreamData Twitch API response struct

type TwitchStreamResult

type TwitchStreamResult struct {
	Data []TwitchStreamData `json:"data"`
}

TwitchStreamResult contains response of Twitch API for streams

type TwitchUserData

type TwitchUserData struct {
	ID              string `json:"id"`
	Login           string `json:"login"`
	Name            string `json:"display_name"`
	Type            string `json:"type"`
	BroadcasterType string `json:"broadcaster_type"`
	Description     string `json:"description"`
	ProfileImgURL   string `json:"profile_image_url"`
	OfflineImgURL   string `json:"offline_image_url"`
	Views           int    `json:"view_count"`
}

TwitchUserData Twitch API response struct

type TwitchUserResult

type TwitchUserResult struct {
	Data []TwitchUserData `json:"data"`
}

TwitchUserResult contains response of Twitch API for users

type UserRoles

type UserRoles struct {
	Roles []*discordgo.Role
}

UserRoles struct with array of user roles in guild

func (*UserRoles) ExistsName

func (r *UserRoles) ExistsName(name string) bool

ExistsName checks if user role nema exists on user

type VideoResult

type VideoResult struct {
	Media string
	Title string
}

VideoResult contains information about video

type VoiceConfig

type VoiceConfig struct {
	Volume float32
}

VoiceConfig some voice settings

type WeatherCodesMap

type WeatherCodesMap map[string]string

WeatherCodesMap symbols for font

type WeatherConfig

type WeatherConfig struct {
	WeatherToken string
	City         string
}

WeatherConfig Weather config struct

type YTSearchContent

type YTSearchContent struct {
	Id           string `json:"id"`
	Title        string `json:"title"`
	Description  string `json:"description"`
	ChannelTitle string `json:"channel_title"`
	Duration     string `json:"duration"`
}

YTSearchContent contains Youtube search result

type Youtube

type Youtube struct {
	Conf *Config
}

Youtube contains pointer to bot configuration struct

func (Youtube) Get

func (youtube Youtube) Get(link string) (int, *string, error)

Get returns data grabbed from youtube

func (Youtube) Playlist

func (youtube Youtube) Playlist(input string) (*[]PlaylistVideo, error)

Playlist returns Playlist

func (Youtube) Search

func (youtube Youtube) Search(query string) ([]YTSearchContent, error)

Search returns array of search results

func (Youtube) Video

func (youtube Youtube) Video(input string) (*VideoResult, error)

Video returns unmarshaled data from Youtube

Jump to

Keyboard shortcuts

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