service

package
v0.0.0-...-39504b8 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2017 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultSounds = []*Sound{
	{
		Name:     "airhorn_default",
		Weight:   1000,
		Commands: []string{"airhorn"},
		FilePath: "../audio/airhorn_default.dca",
	},
	{
		Name:     "airhorn_reverb",
		Weight:   800,
		Commands: []string{"airhorn"},
		FilePath: "../audio/airhorn_reverb.dca",
	},
	{
		Name:     "airhorn_spam",
		Weight:   800,
		Commands: []string{"airhorn"},
		FilePath: "../audio/airhorn_spam.dca",
	},
	{
		Name:     "airhorn_tripletap",
		Weight:   800,
		Commands: []string{"airhorn"},
		FilePath: "../audio/airhorn_tripletap.dca",
	},
	{
		Name:     "airhorn_fourtap",
		Weight:   800,
		Commands: []string{"airhorn"},
		FilePath: "../audio/airhorn_fourtap.dca",
	},
	{
		Name:     "airhorn_distant",
		Weight:   500,
		Commands: []string{"airhorn"},
		FilePath: "../audio/airhorn_distant.dca",
	},
	{
		Name:     "airhorn_echo",
		Weight:   500,
		Commands: []string{"airhorn"},
		FilePath: "../audio/airhorn_echo.dca",
	},
	{
		Name:     "airhorn_clownfull",
		Weight:   250,
		Commands: []string{"airhorn"},
		FilePath: "../audio/airhorn_clownfull.dca",
	},
	{
		Name:     "airhorn_clownshort",
		Weight:   250,
		Commands: []string{"airhorn"},
		FilePath: "../audio/airhorn_clownshort.dca",
	},
	{
		Name:     "airhorn_clownspam",
		Weight:   250,
		Commands: []string{"airhorn"},
		FilePath: "../audio/airhorn_clownspam.dca",
	},
	{
		Name:     "airhorn_highfartlong",
		Weight:   200,
		Commands: []string{"airhorn"},
		FilePath: "../audio/airhorn_highfartlong.dca",
	},
	{
		Name:     "airhorn_highfartshort",
		Weight:   200,
		Commands: []string{"airhorn"},
		FilePath: "../audio/airhorn_highfartshot.dca",
	},
	{
		Name:     "airhorn_midshort",
		Weight:   100,
		Commands: []string{"airhorn"},
		FilePath: "../audio/airhorn_midshort.dca",
	},
	{
		Name:     "airhorn_truck",
		Weight:   10,
		Commands: []string{"airhorn"},
		FilePath: "../audio/airhorn_truck.dca",
	},
	{
		Name:     "another_one",
		Weight:   1,
		Commands: []string{"anotha"},
		FilePath: "../audio/another_one.dca",
	},
	{
		Name:     "another_one_classic",
		Weight:   1,
		Commands: []string{"anotha"},
		FilePath: "../audio/another_one_classic.dca",
	},
	{
		Name:     "another_one_echo",
		Weight:   1,
		Commands: []string{"anotha"},
		FilePath: "../audio/another_one_echo.dca",
	},
	{
		Name:     "jc_realfull",
		Weight:   1,
		Commands: []string{"cena"},
		FilePath: "../audio/jc_realfull.dca",
	},
	{
		Name:     "cow_herd",
		Weight:   10,
		Commands: []string{"stan"},
		FilePath: "../audio/cow_herd.dca",
	},
	{
		Name:     "cow_moo",
		Weight:   10,
		Commands: []string{"stan"},
		FilePath: "../audio/cow_moo.dca",
	},
	{
		Name:     "cow_x3",
		Weight:   1,
		Commands: []string{"stan"},
		FilePath: "../audio/cow_x3.dca",
	},
	{
		Name:     "birthday_horn",
		Weight:   50,
		Commands: []string{"bday"},
		FilePath: "../audio/birthday_horn.dca",
	},
	{
		Name:     "birthday_horn3",
		Weight:   30,
		Commands: []string{"bday"},
		FilePath: "../audio/birthday_horn3.dca",
	},
	{
		Name:     "birthday_sadhorn",
		Weight:   25,
		Commands: []string{"bday"},
		FilePath: "../audio/birthday_sadhorn.dca",
	},
	{
		Name:     "birthday_weakhorn",
		Weight:   25,
		Commands: []string{"bday"},
		FilePath: "../audio/birthday_weakhorn.dca",
	},
	{
		Name:     "wow_thatscool",
		Weight:   1,
		Commands: []string{"wtc"},
		FilePath: "../audio/wow_thatscool.dca",
	},
}

DefaultSounds are a set of default sounds available to every servers

Functions

func AddGuild

func AddGuild(gID string) error

AddGuild register a new guild to use Airhorn

func CloseRedis

func CloseRedis()

CloseRedis closes the redis connection

func GetGuildsWithSounds

func GetGuildsWithSounds(session *discordgo.Session) (interface{}, error)

GetGuildsWithSounds retrieves a guild from Discord and its sounds

func GuildHasAirhorn

func GuildHasAirhorn(gID string) (bool, error)

GuildHasAirhorn checks if a guild has already been used with airhorn

func InitRedis

func InitRedis(cfg Cfg) bool

InitRedis try to connect to redis using provided configuration. It does nothing if there's already a connection.

func SaveAudio

func SaveAudio(a io.Reader, n string) error

SaveAudio write the sound to a file

func UtilGetRedisValuesFor

func UtilGetRedisValuesFor(redisPool *redis.Pool, keys []string) (r []interface{}, err error)

UtilGetRedisValuesFor keys

Types

type Cfg

type Cfg struct {
	DBDriver            string
	DBSSL               bool
	DBHost              string
	DBPort              string
	DBUser              string
	DBPassword          string
	DBName              string
	RedisHost           string
	DiscordToken        string
	DiscordClientID     string
	DiscordClientSecret string
	DataPath            string
	PluginPath          string
	DiscordOwnerID      string
}

Cfg represents the app configuration

func LoadConfig

func LoadConfig() (Cfg, error)

LoadConfig read configuration from disk

type CountUpdate

type CountUpdate struct {
	Total          string `json:"total"`
	UniqueUsers    string `json:"unique_users"`
	UniqueGuilds   string `json:"unique_guilds"`
	UniqueChannels string `json:"unique_channels"`
}

CountUpdate represents a JSON struct of stats that are updated every second and pushed to the client

func GetStats

func GetStats() *CountUpdate

GetStats read stats counter from redis

func (*CountUpdate) ToJSON

func (c *CountUpdate) ToJSON() []byte

ToJSON format CountUpdate in JSON

type Guild

type Guild struct {
	ID     string   `json:"id"`
	Name   string   `json:"name"`
	Icon   string   `json:"icon"`
	Sounds []*Sound `json:"sounds"`
}

Guild represents a discord server

func GetGuildWithSounds

func GetGuildWithSounds(session *discordgo.Session, gID string) (Guild, error)

GetGuildWithSounds retrieves a guild from Discord and its sounds

type Sound

type Sound struct {
	ID      string `json:"id"`
	GuildID string `json:"guildId"`
	Name    string `json:"name"`

	// Link to a gif url
	Gif string `json:"gif"`

	// Weight adjust how likely it is this song will play, higher = more likely
	Weight int `json:"weight"`

	// Command to type in channel
	Commands       []string `json:"commands"`
	CommandsString string

	FilePath string `json:"filepath"`
}

Sound represents a sound clip

func FilterByCommand

func FilterByCommand(c string, s []*Sound) (r []*Sound)

FilterByCommand filter a sound array by command

func GetSound

func GetSound(ID string) (*Sound, error)

GetSound retrieve a sound from database

func GetSoundsByCommand

func GetSoundsByCommand(command, guildID string) ([]*Sound, error)

GetSoundsByCommand return all sounds for a given command

func GetSoundsByGuild

func GetSoundsByGuild(guildID string) ([]*Sound, error)

GetSoundsByGuild return all sounds for a given Guild

func (*Sound) Delete

func (s *Sound) Delete() error

Delete delete a sound from the DB

func (*Sound) Save

func (s *Sound) Save() error

Save saves a sound to the db

type UserGuilds

type UserGuilds struct {
	AirhornGuilds []*Guild
	BoringGuilds  []*Guild
}

UserGuilds represents a user's guilds

Jump to

Keyboard shortcuts

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