mirror of
https://github.com/Fluffy-Bean/Lynxie.git
synced 2025-05-14 08:02:17 +00:00
Add command aliases, cleanup types and order
This commit is contained in:
parent
a70ca23e41
commit
10acb07216
4 changed files with 58 additions and 83 deletions
19
app/app.go
19
app/app.go
|
@ -21,14 +21,16 @@ type Config struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type App struct {
|
type App struct {
|
||||||
Config Config
|
Config Config
|
||||||
Commands map[string]Callback
|
Commands map[string]Callback
|
||||||
|
CommandAliases map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewApp(config Config) *App {
|
func NewApp(config Config) *App {
|
||||||
return &App{
|
return &App{
|
||||||
Config: config,
|
Config: config,
|
||||||
Commands: make(map[string]Callback),
|
Commands: make(map[string]Callback),
|
||||||
|
CommandAliases: make(map[string]string),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +38,10 @@ func (a *App) RegisterCommand(cmd string, f Callback) {
|
||||||
a.Commands[cmd] = f
|
a.Commands[cmd] = f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) RegisterCommandAlias(alias, cmd string) {
|
||||||
|
a.CommandAliases[alias] = cmd
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) Run() {
|
func (a *App) Run() {
|
||||||
dg, err := discordgo.New("Bot " + a.Config.Token)
|
dg, err := discordgo.New("Bot " + a.Config.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -92,6 +98,11 @@ func (a *App) handler(session *discordgo.Session, message *discordgo.MessageCrea
|
||||||
cmd = strings.TrimPrefix(cmd, a.Config.Prefix)
|
cmd = strings.TrimPrefix(cmd, a.Config.Prefix)
|
||||||
cmd, args, _ = strings.Cut(cmd, " ")
|
cmd, args, _ = strings.Cut(cmd, " ")
|
||||||
|
|
||||||
|
alias, ok := a.CommandAliases[cmd]
|
||||||
|
if ok {
|
||||||
|
cmd = alias
|
||||||
|
}
|
||||||
|
|
||||||
callback, ok := a.Commands[cmd]
|
callback, ok := a.Commands[cmd]
|
||||||
if !ok {
|
if !ok {
|
||||||
// Falling back to default help command
|
// Falling back to default help command
|
||||||
|
|
|
@ -21,9 +21,46 @@ var client = http.Client{
|
||||||
var username = os.Getenv("E621_USERNAME")
|
var username = os.Getenv("E621_USERNAME")
|
||||||
var password = os.Getenv("E621_PASSWORD")
|
var password = os.Getenv("E621_PASSWORD")
|
||||||
|
|
||||||
|
type post struct {
|
||||||
|
Id int `json:"id"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
|
File struct {
|
||||||
|
Width int `json:"width"`
|
||||||
|
Height int `json:"height"`
|
||||||
|
Ext string `json:"ext"`
|
||||||
|
Size int `json:"size"`
|
||||||
|
Md5 string `json:"md5"`
|
||||||
|
Url string `json:"url"`
|
||||||
|
} `json:"file"`
|
||||||
|
Score struct {
|
||||||
|
Up int `json:"up"`
|
||||||
|
Down int `json:"down"`
|
||||||
|
Total int `json:"total"`
|
||||||
|
} `json:"score"`
|
||||||
|
Tags struct {
|
||||||
|
General []string `json:"general"`
|
||||||
|
Artist []string `json:"artist"`
|
||||||
|
Contributor []interface{} `json:"contributor"`
|
||||||
|
Copyright []string `json:"copyright"`
|
||||||
|
Character []interface{} `json:"character"`
|
||||||
|
Species []string `json:"species"`
|
||||||
|
Invalid []interface{} `json:"invalid"`
|
||||||
|
Meta []string `json:"meta"`
|
||||||
|
Lore []interface{} `json:"lore"`
|
||||||
|
} `json:"tags"`
|
||||||
|
Rating string `json:"rating"`
|
||||||
|
FavCount int `json:"fav_count"`
|
||||||
|
Sources []string `json:"sources"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
CommentCount int `json:"comment_count"`
|
||||||
|
}
|
||||||
|
|
||||||
func RegisterPorbCommands(a *app.App) {
|
func RegisterPorbCommands(a *app.App) {
|
||||||
if username != "" && password != "" {
|
if username != "" && password != "" {
|
||||||
a.RegisterCommand("e621", registerE621(a))
|
a.RegisterCommand("e621", registerE621(a))
|
||||||
|
|
||||||
|
a.RegisterCommandAlias("porb", "e621")
|
||||||
} else {
|
} else {
|
||||||
log.Println("Not registering e621 command...")
|
log.Println("Not registering e621 command...")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,75 +0,0 @@
|
||||||
package porb
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type post struct {
|
|
||||||
Id int `json:"id"`
|
|
||||||
CreatedAt time.Time `json:"created_at"`
|
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
|
||||||
File struct {
|
|
||||||
Width int `json:"width"`
|
|
||||||
Height int `json:"height"`
|
|
||||||
Ext string `json:"ext"`
|
|
||||||
Size int `json:"size"`
|
|
||||||
Md5 string `json:"md5"`
|
|
||||||
Url string `json:"url"`
|
|
||||||
} `json:"file"`
|
|
||||||
Preview struct {
|
|
||||||
Width int `json:"width"`
|
|
||||||
Height int `json:"height"`
|
|
||||||
Url string `json:"url"`
|
|
||||||
} `json:"preview"`
|
|
||||||
Sample struct {
|
|
||||||
Has bool `json:"has"`
|
|
||||||
Height int `json:"height"`
|
|
||||||
Width int `json:"width"`
|
|
||||||
Url string `json:"url"`
|
|
||||||
Alternates struct {
|
|
||||||
} `json:"alternates"`
|
|
||||||
} `json:"sample"`
|
|
||||||
Score struct {
|
|
||||||
Up int `json:"up"`
|
|
||||||
Down int `json:"down"`
|
|
||||||
Total int `json:"total"`
|
|
||||||
} `json:"score"`
|
|
||||||
Tags struct {
|
|
||||||
General []string `json:"general"`
|
|
||||||
Artist []string `json:"artist"`
|
|
||||||
Contributor []interface{} `json:"contributor"`
|
|
||||||
Copyright []string `json:"copyright"`
|
|
||||||
Character []interface{} `json:"character"`
|
|
||||||
Species []string `json:"species"`
|
|
||||||
Invalid []interface{} `json:"invalid"`
|
|
||||||
Meta []string `json:"meta"`
|
|
||||||
Lore []interface{} `json:"lore"`
|
|
||||||
} `json:"tags"`
|
|
||||||
LockedTags []interface{} `json:"locked_tags"`
|
|
||||||
ChangeSeq int `json:"change_seq"`
|
|
||||||
Flags struct {
|
|
||||||
Pending bool `json:"pending"`
|
|
||||||
Flagged bool `json:"flagged"`
|
|
||||||
NoteLocked bool `json:"note_locked"`
|
|
||||||
StatusLocked bool `json:"status_locked"`
|
|
||||||
RatingLocked bool `json:"rating_locked"`
|
|
||||||
Deleted bool `json:"deleted"`
|
|
||||||
} `json:"flags"`
|
|
||||||
Rating string `json:"rating"`
|
|
||||||
FavCount int `json:"fav_count"`
|
|
||||||
Sources []string `json:"sources"`
|
|
||||||
Pools []int `json:"pools"`
|
|
||||||
Relationships struct {
|
|
||||||
ParentId interface{} `json:"parent_id"`
|
|
||||||
HasChildren bool `json:"has_children"`
|
|
||||||
HasActiveChildren bool `json:"has_active_children"`
|
|
||||||
Children []interface{} `json:"children"`
|
|
||||||
} `json:"relationships"`
|
|
||||||
ApproverId interface{} `json:"approver_id"`
|
|
||||||
UploaderId int `json:"uploader_id"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
CommentCount int `json:"comment_count"`
|
|
||||||
IsFavorited bool `json:"is_favorited"`
|
|
||||||
HasNotes bool `json:"has_notes"`
|
|
||||||
Duration interface{} `json:"duration"`
|
|
||||||
}
|
|
|
@ -18,10 +18,6 @@ var client = http.Client{
|
||||||
Timeout: 10 * time.Second,
|
Timeout: 10 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterTinyfoxCommands(a *app.App) {
|
|
||||||
a.RegisterCommand("animal", registerAnimal(a))
|
|
||||||
}
|
|
||||||
|
|
||||||
var animals = []string{
|
var animals = []string{
|
||||||
"fox",
|
"fox",
|
||||||
"yeen",
|
"yeen",
|
||||||
|
@ -85,6 +81,12 @@ var animalAliases = map[string]string{
|
||||||
"opossum": "poss",
|
"opossum": "poss",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RegisterTinyfoxCommands(a *app.App) {
|
||||||
|
a.RegisterCommand("animal", registerAnimal(a))
|
||||||
|
|
||||||
|
a.RegisterCommandAlias("a", "animal")
|
||||||
|
}
|
||||||
|
|
||||||
func registerAnimal(a *app.App) app.Callback {
|
func registerAnimal(a *app.App) app.Callback {
|
||||||
return func(h *app.Handler, args []string) app.Error {
|
return func(h *app.Handler, args []string) app.Error {
|
||||||
var options struct {
|
var options struct {
|
||||||
|
|
Loading…
Add table
Reference in a new issue