gosubscribe

package module
v0.0.0-...-581c68b Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2018 License: MIT Imports: 15 Imported by: 0

README

gosubscribe

Discord Discord osu!

Subscribe to osu! users to be notified about their new/updated maps.

To get started, join the o!subscribe Discord server, invite the bot to your own server, or add the bot as a friend on osu! with the buttons above.

Command Reference

If you're brand new, you may want to skip ahead to authentication for now.

Command Argument(s) Description Example
.sub mapper1, mapper2, ... Subscribe to given mappers. .sub pishifat, monstrata
.unsub mapper1, mapper2, ... Unsubscribe from given mappers. .unsub pishifat, monstrata
.list Display your current subscriptions. .list
.purge Unsubscribe from all mappers. .purge
.count mapper1, mapper2, ... Display subscriber counts for given mappers. .count pishifat, monstrata
.top [n=5] Display subscriber counts for the top n mappers. .top 10
.notifyall y/n Enable or disable notifications all beatmap updates by subscribed mappers (not just new uploads and ranked status updates). .notifyall y
.message discord/osu! Set your preference for where you receive messages. .message osu!
.server Link to the o!subscribe Discord server. .server
.invite Link to a subscription-bot Discord invite. .invite
.osu Link to the bot's userpage. .osu
.help Link to this reference. .help
Authentication

Before you can start using the commands above, you need to complete a quick registration. If you're a brand new user, you'll generally only need .init.

Note: On Discord, authentication is done via PM with the bot; these commands won't work in public channels.

Command Argument(s) Description Example
.init Initialize as a new user. You should not use this command more than once, even if you're on a different platform than the one you first initialized on. .init
.secret Get your unique secret, required for registering on other platforms. .secret
.register secret Register on a new platform, provided that you've initialized elsewhere. .register MySecret

gosubscribe is partially powered by osu!search.

gosubscribe is in no way affiliated with osu!.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// HelpURL is a link to the command reference.
	HelpURL = "https://github.com/christopher-dG/gosubscribe#command-reference"
	// ServerURL is an invite to the Discord server.
	ServerURL = "https://discord.gg/qaUhTKJ"
	// InviteURL is a link to invite subscription-bot to another server.
	InviteURL = "https://discordapp.com/oauth2/authorize?client_id=305550679538401280&scope=bot&permissions=3072"
	// OsuUserURL is a link to the bot's userpage.
	OsuUserURL = "https://osu.ppy.sh/users/3172543"
)
View Source
var DB *gorm.DB

DB (the database instance) cannot be used before Connect is called.

Functions

func Connect

func Connect(host, user, dbname, password string)

Connect connects to a given PostreSQL database. PGxxx environment variables must be set.

func Count

func Count(body, mention string) string

Count displays the subscriber counts for the given mappers.

func FormatCounts

func FormatCounts(counts map[*Mapper]uint) string

FormatCounts converts a mapper -> subscriber count mapping to an evenly spaced table, ordering the counts in descending order.

func GenSecret

func GenSecret() string

GenSecret generates a "random" string that is guaranteed to not already be used. Note: This is not even remotely cryptographically secure, but it'll do for our needs.

func GetCounts

func GetCounts(mappers []*Mapper) map[*Mapper]uint

GetCounts gets the subscriber counts for a list of mappers.

func GetTokens

func GetTokens(input string) []string

GetTokens splits a comma-delimited string into tokens and returns the unique ones in sorted order.

func HasMapper

func HasMapper(mappers map[*Mapper]uint, key string) bool

HasMapper determines whether or not the map contains a mapper key with the given name.

func HasMapset

func HasMapset(mapsets []*Mapset, key *Mapset) bool

HasMapset determines whether or not the given key is contained in a list.

func List

func List(user *User, mention string) string

List displays the mappers that the user is subscribed to.

func NotificationPlatform

func NotificationPlatform(user *User, body, mention string) string

NotificationPlatform sets the user's platform preference for receiving notifications.

func NotificationPreference

func NotificationPreference(user *User, body, mention string) string

NotificationPreference sets the users preference for receiving notifications for map updates that are not new uploads or ranked status changes.

func Purge

func Purge(user *User, mention string) string

Purge unsubscribes the user from all mappers.

func Subscribe

func Subscribe(user *User, body, mention string) string

Subscribe subscribes the user to the given mappers.

func Top

func Top(body string) string

Top displays the subscriber counts for the mappers with the most subscribers.

func TopCounts

func TopCounts(n int) map[*Mapper]uint

TopCounts gets the n mappers with the most subscribers and their subscription counts.

func Unsubscribe

func Unsubscribe(user *User, body, mention string) string

Unsubscribe unsubscribes the user from the given mappers.

Types

type Mapper

type Mapper struct {
	ID       uint   `json:"user_id,string"`
	Username string `gorm:"not null" json:"username"`
}

Mapper is an osu! user.

func GetMapper

func GetMapper(name string) (*Mapper, error)

GetMapper gets a mapper from the osu! API and adds it to the database if necessary.

func MapperFromDB

func MapperFromDB(name string) (*Mapper, error)

MapperFromDB gets a mapper from the database.

func (*Mapper) Count

func (mapper *Mapper) Count() uint

Count gets the number of users that are subscribed to a mapper.

func (*Mapper) GetMapsets

func (mapper *Mapper) GetMapsets() ([]*Mapset, error)

GetMapsets gets all mapsets by the mapper. This will contain duplicates (multiple diffs per set).

func (*Mapper) Insert

func (mapper *Mapper) Insert()

Insert adds a new mapper to the databse.

func (*Mapper) Update

func (mapper *Mapper) Update(newName string)

Update updates a mapper's username.

type Mapset

type Mapset struct {
	ID       uint   `json:"beatmapset_id,string"`
	MapperID uint   `json:"-"` // Need to fill this field manually.
	Status   int    `json:"approved,string"`
	Updated  string `json:"last_update"`
}

Mapset is an osu! beatmapset.

type Subscription

type Subscription struct {
	UserID   uint `gorm:"primary_key"`
	MapperID uint `gorm:"primary_key"`
}

Subscription is a relationship between a User and Mapper.

type User

type User struct {
	ID          uint
	DiscordID   sql.NullInt64  `gorm:"unique;index"`
	OsuUsername sql.NullString `gorm:"unique;index"`
	Secret      string         `gorm:"unique"`
	NotifyAll   bool
	MessageOsu  bool
}

User is a gosubscribe user.

func GetUser

func GetUser(id uint) (*User, error)

GetUser retrieves a user by their ID.

func UserFromSecret

func UserFromSecret(secret string) (*User, error)

UserFromSecret retrieves a user from their unique secret.

func (*User) GetSecret

func (user *User) GetSecret() (string, error)

GetSecret retrieve's a user's secret.

func (*User) ListSubscribed

func (user *User) ListSubscribed() []*Mapper

ListSubscribed gets all mappers that a user is subscribed to.

func (*User) Purge

func (user *User) Purge()

Purge unsubscribes a user from all mappers.

func (*User) SetMessageOsu

func (user *User) SetMessageOsu(pref bool)

SetMessageOsu sets the user's preference for receiving messages via osu! or via Discord.

func (*User) SetNotifyAll

func (user *User) SetNotifyAll(pref bool)

SetNotifyAll sets the users preference for receiving notifications for map updates that are not new uploads or ranked status changes.

func (*User) Subscribe

func (user *User) Subscribe(mappers []*Mapper)

Subscribe subscribes a user to a list of mappers.

func (*User) Unsubscribe

func (user *User) Unsubscribe(mappers []*Mapper)

Unsubscribe unsubscribes a user from a list of mappers.

Directories

Path Synopsis
cmd
irc

Jump to

Keyboard shortcuts

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