lib

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NoArtistURL is the URL to a blank image for no artist images found
	// on metal archives.
	NoArtistURL = "https://cdn.persephonebot.net/images/bm.png"

	// LfmStarImage is the image name for the default Last.fm star pic.
	LfmStarImage = "2a96cbd8b46e442fc41c2b86b821562f.png"
)

Variables

This section is empty.

Functions

func AddEmbedFooter

func AddEmbedFooter(msg *disgord.Message) (f *disgord.EmbedFooter, t disgord.Time)

AddEmbedFooter returns a footer and timestamp for disgord embeds

func BrandImage

func BrandImage(dc *gg.Context)

BrandImage tags an image with a discord link and bot's name

func CanRun

func CanRun(ctx atlas.Context) bool

CanRun checks if a user can run a given elevated command.

func Check

func Check(err error)

Check is a super simple error handler.

func CheckStar

func CheckStar(sURL string) bool

CheckStar checks if a URL (for last.fm) is their stock star image.

func DrawStringWithShadow

func DrawStringWithShadow(s string, x float64, y float64, dc *gg.Context)

DrawStringWithShadow draws a string with text shadow.

func DrawWrappedStringWithShadow

func DrawWrappedStringWithShadow(s string, x float64, y float64, ax float64,
	ay float64, width float64, lineSpacing float64, align gg.Align, dc *gg.Context)

DrawWrappedStringWithShadow draws a wrapped string with text shadow.

func GenAvatarURL deprecated

func GenAvatarURL(user *disgord.User) string

GenAvatarURL generates a URL used to get a user avatar.

Deprecated: Use AvatarURL method from Disgord instead

func GenerateMessageURL

func GenerateMessageURL(guildID disgord.Snowflake, msg *disgord.Message) string

GenerateMessageURL returns the URL for a specific Discord message.

func GetArtistImage

func GetArtistImage(artist Artist) image.Image

GetArtistImage scrapes metal-archives for an artist image.

func GetArtistImageFromFmArtist

func GetArtistImageFromFmArtist(artist lastfm.ArtistGetInfo) image.Image

GetArtistImageFromFmArtist scrapes metal-archives for an artist image.

func GetArtistImageURL

func GetArtistImageURL(artist Artist) string

GetArtistImageURL returns the URL for an artist scraped from metal-archives.

func GetArtistImageURLFromFmArtist

func GetArtistImageURLFromFmArtist(artist lastfm.ArtistGetInfo) string

GetArtistImageURLFromFmArtist returns the URL for an artist scraped from metal-archives.

func GetAvatarImage

func GetAvatarImage(user *disgord.User) (image.Image, *os.File)

GetAvatarImage returns an image.Image of a user's avatar.

func GetDiscordIDFromMention

func GetDiscordIDFromMention(mention string) (ID disgord.Snowflake, err error)

GetDiscordIDFromMention gets the snowflake id from a mention.

func GetExt

func GetExt(filename string) string

GetExt returns the extension of a given file name

func GetLastfmUserInfo

func GetLastfmUserInfo(user *disgord.User, lfm *lastfm.API) (lastfm.UserGetInfo, error)

GetLastfmUserInfo gets user info from last.fm.

func GetUInt64ID

func GetUInt64ID(user *disgord.User) uint64

GetUInt64ID returns a uint64 version of the Discord user ID.

func Grab

func Grab(sURL string) (res *grab.Response, err error)

Grab overrides grab.Get to implement CheckStar.

func HTMLParse

func HTMLParse(s string) string

HTMLParse parses an html string, and replaces anchor tags with bbcode links.

func HumanNumber

func HumanNumber(i interface{}) string

HumanNumber converts a number into a human readable one.

func IsMention

func IsMention(mention string) bool

IsMention checks if a string is a discord mention.

func JoinString

func JoinString(strs []string, char string) string

JoinString joins a string slice with a char, and removes the end char.

func JoinStringMap

func JoinStringMap(strs map[int]string, char string) string

JoinStringMap joins a string map with a char, and removes the end char.

func LocGet

func LocGet(file string) string

LocGet returns file location within bot's storage directory.

func Migrate

func Migrate()

Migrate migrates database tables (only run on database creation)

func OpenDB

func OpenDB() (*genmai.DB, error)

OpenDB opens a database connection

func OpenImage

func OpenImage(filename string) (image.Image, *os.File)

OpenImage returns an image.Image instance of a given file

func RandomColor

func RandomColor() int

RandomColor returns a random color.

func RegisterEvents

func RegisterEvents(client *atlas.Atlas)

RegisterEvents registers any client events.

func SaveImage

func SaveImage(dc *gg.Context, ctx atlas.Context, name string) (*os.File, error)

SaveImage saves a generated image.

func ShortStr

func ShortStr(str string, n int, els ...string) string

ShortStr truncates a string by n length.

func SnowflakeToUInt64

func SnowflakeToUInt64(snowflake disgord.Snowflake) uint64

SnowflakeToUInt64 returns a uint64 version of a snowflake.

func Storage

func Storage() string

Storage returns storage locations for configuration and static folders

func StrToSnowflake

func StrToSnowflake(str string) disgord.Snowflake

StrToSnowflake returns a Snowflake from a string.

func TagImageName

func TagImageName(ctx atlas.Context, name string) string

TagImageName generates an image filename to uniquely identify it.

func UInt64ToSnowflake

func UInt64ToSnowflake(i uint64) disgord.Snowflake

UInt64ToSnowflake converts a uint64 to a snowflake.

func Ucwords

func Ucwords(str string) string

Ucwords capitalizes the first letter in each word. (Mirror's PHP's ucwords function)

Types

type AlbumPosition

type AlbumPosition struct {
	X      int
	Y      int
	Shadow Shadow
	Info   InfoText
}

AlbumPosition holds album art positions.

type Artist

type Artist struct {
	Rank       string `xml:"rank,attr"`
	Name       string `xml:"name"`
	PlayCount  string `xml:"playcount"`
	Mbid       string `xml:"mbid"`
	URL        string `xml:"url"`
	Streamable string `xml:"streamable"`
	Images     []struct {
		Size string `xml:"size,attr"`
		URL  string `xml:",chardata"`
	} `xml:"image"`
}

Artist holds simple artist info.

type ArtistImages

type ArtistImages struct {
	ID     int64 `db:"pk"`
	Artist string
	MaID   int64 `db:"unique"`
	Time
}

ArtistImages object.

type Artists

type Artists []struct {
	Rank       string `xml:"rank,attr"`
	Name       string `xml:"name"`
	PlayCount  string `xml:"playcount"`
	Mbid       string `xml:"mbid"`
	URL        string `xml:"url"`
	Streamable string `xml:"streamable"`
	Images     []struct {
		Size string `xml:"size,attr"`
		URL  string `xml:",chardata"`
	} `xml:"image"`
}

Artists holds simple artist info in slice format.

type Configuration

type Configuration struct {
	Token        string `yaml:"token"`
	BotOwner     string `yaml:"bot_owner"`
	BotID        string `yaml:"bot_id"`
	GuildID      string `yaml:"guild_id"`
	LogChannelID string `yaml:"log_channel_id"`
	ElevatedRole string `yaml:"elevated_role"`
	Prefix       string `yaml:"prefix"`
	// Starboard string `json:"starboard"`
	Starboard struct {
		Channel         string `yaml:"channel"`
		ActivationCount int    `yaml:"activation_count"`
	} `yaml:"starboard"`
	Lastfm struct {
		APIKey string `yaml:"apikey"`
		Secret string `yaml:"secret"`
	} `yaml:"lastfm"`
	Database struct {
		Hostname string `yaml:"hostname"`
		Port     int    `yaml:"port"`
		Username string `yaml:"username"`
		Password string `yaml:"password"`
		Name     string `yaml:"name"`
	} `yaml:"database"`
	YouTube struct {
		APIKey string `yaml:"apikey"`
	} `yaml:"youtube"`
	Website struct {
		AppURL string `yaml:"app_url"`
		APIURL string `yaml:"api_url"`
	} `yaml:"website"`
}

Configuration is the base yaml object.

func Config

func Config() Configuration

Config retrieves the app's configuration form config.json.

type Crowns

type Crowns struct {
	ID        int64 `db:"pk"`
	DiscordID uint64
	Artist    string
	PlayCount int
	Time
}

Crowns object.

func GetCrownsList

func GetCrownsList() (crowns []Crowns)

GetCrownsList returns a list of all crowns in database.

func (Crowns) GetUserCrowns

func (c Crowns) GetUserCrowns(sql ...interface{}) (crowns []Crowns)

GetUserCrowns is a relational method that returns a list of crowns for a given user.

func (Crowns) User

func (c Crowns) User() (user Users)

User is a relational method to retrieve the user from a given crown.

type InfoText

type InfoText struct {
	X     float64
	Y     float64
	Plays PlaysText
}

InfoText holds info text positions.

type MaArtist

type MaArtist struct {
	Name string `yaml:"name"`
	ID   int    `yaml:"id"`
}

MaArtist is an artist struct for metal-archives artist

func GetMaArtist

func GetMaArtist(artist string) MaArtist

GetMaArtist returns an artist listed in artists.json for metal-archives

func GetMaArtistList

func GetMaArtistList() []MaArtist

GetMaArtistList returns a list of artists defined in artists.json for metal-archives

type PlaysText

type PlaysText struct {
	X float64
	Y float64
}

PlaysText holds play count text positions.

type Servers

type Servers struct {
	ID           int64 `db:"pk"`
	GuildID      uint64
	LogChannelID uint64
	ElevatedRole uint64
	Time
}

Servers object.

func GetServer

func GetServer(guildID disgord.Snowflake) (server Servers)

GetServer returns a server logged in the database.

type Shadow

type Shadow struct {
	X float64
	Y float64
	R float64
}

Shadow holds image shadow positions.

type Time

type Time struct {
	CreatedAt *time.Time
	UpdatedAt *time.Time
}

Time is a timestamp struct for models.

type TrackPosition

type TrackPosition struct {
	X     float64
	Y     float64
	Plays PlaysText
}

TrackPosition holds track label positions.

type Users

type Users struct {
	ID                  int64 `db:"pk"`
	Username            string
	Email               string
	DiscordID           uint64 `db:"unique"`
	DiscordToken        string
	DiscordRefreshToken string
	Lastfm              string
	LastfmToken         string
	RememberToken       *string
	Time
}

Users object.

func GetUser

func GetUser(user *disgord.User) Users

GetUser gets the database user via a Discord user.

func GetUserFromString

func GetUserFromString(username string) Users

GetUserFromString returns a user from a string username.

func GetUsers

func GetUsers() []Users

GetUsers returns all the users in the database.

func (Users) Crown

func (c Users) Crown(id int64) Crowns

Crown is a relational function to get crowns model

func (Users) Crowns

func (c Users) Crowns() (crowns []Crowns)

Crowns is a relational function to get crowns model

func (Users) Delete

func (c Users) Delete() (bool, bool)

Delete deletes a user.

func (Users) GetDiscordID

func (c Users) GetDiscordID() disgord.Snowflake

GetDiscordID returns a discord ID snowflake.

Jump to

Keyboard shortcuts

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