Move links to echoes, print better OAuth URL

Signed-off-by: Etzelia <etzelia@hotmail.com>
rate-insult
Etzelia 2020-06-12 11:38:18 -05:00
parent 98391aeafd
commit ea5237fd16
No known key found for this signature in database
GPG Key ID: 3CAEB74806C4ADE5
5 changed files with 58 additions and 55 deletions

View File

@ -17,7 +17,7 @@ type Config struct {
DBPath string `toml:"db_path"`
StaffRoles []string `toml:"staff_roles"`
Links []Link `toml:"links"`
Echoes []Echo `toml:"echoes"`
MessageRoles []MessageRole `toml:"message_roles"`
RegisterRole string `toml:"register_role"`
RegisteredChannel string `toml:"registered_channel"`
@ -31,10 +31,11 @@ type MessageRole struct {
Emoji string `toml:"emoji"`
}
type Link struct {
type Echo struct {
Name string `toml:"name"`
Aliases []string `toml:"aliases"`
URL string `toml:"url"`
Message string `toml:"message"`
Help string `toml:"help"`
}
func Load(configPath string) (*Config, error) {

View File

@ -43,14 +43,13 @@ func Bot(cfg *config.Config, db *database.Database) (*discordgo.Session, error)
messageRoleMap[messageRole.MessageID][messageRole.Emoji] = messageRole.RoleID
}
Links(cfg)
Echo(cfg)
bot.AddHandler(commandHandler(cfg, db))
bot.AddHandler(messageHandler(cfg, db))
bot.AddHandler(reactionAddHandler())
bot.AddHandler(reactionRemoveHandler())
beaver.Info("https://discord.com/api/oauth2/authorize?client_id=718905104643784825&permissions=0&redirect_uri=https%3A%2F%2Fbirbmc.com&scope=bot")
beaver.Infof("https://discord.com/api/oauth2/authorize?client_id=%s&permissions=0&redirect_uri=https://birbmc.com&scope=bot", bot.State.User.ID)
return bot, nil
}

48
discord/echo.go 100644
View File

@ -0,0 +1,48 @@
package discord
import (
"fmt"
"strings"
"go.etztech.xyz/sedbot/config"
)
func Echo(cfg *config.Config) {
echoes := make([]string, 0)
for _, e := range cfg.Echoes {
echo := e
commands[echo.Name] = command{
validate: func(cmd commandInit) bool {
return true
},
run: func(cmd commandInit) (string, error) {
return echo.Message, nil
},
help: echo.Help,
}
for _, a := range echo.Aliases {
alias := a
commands[alias] = command{
validate: func(cmd commandInit) bool {
return true
},
run: func(cmd commandInit) (string, error) {
return echo.Message, nil
},
help: echo.Help,
}
}
combined := append([]string{echo.Name}, echo.Aliases...)
echoes = append(echoes, fmt.Sprintf("%s: %s", strings.Join(combined, ", "), echo.Help))
}
commands["echoes"] = command{
validate: func(cmd commandInit) bool {
return true
},
run: func(cmd commandInit) (string, error) {
return strings.Join(echoes, "\n"), nil
},
help: "Get all dynamic messages",
}
}

View File

@ -1,46 +0,0 @@
package discord
import (
"fmt"
"strings"
"go.etztech.xyz/sedbot/config"
)
func Links(cfg *config.Config) {
links := make([]string, 0)
for _, link := range cfg.Links {
commands[link.Name] = command{
validate: func(cmd commandInit) bool {
return true
},
run: func(cmd commandInit) (string, error) {
return fmt.Sprintf("<%s>", link.URL), nil
},
help: fmt.Sprintf("Returns the link for %s", link.Name),
}
links = append(links, fmt.Sprintf("%s -> <%s>", link.Name, link.URL))
for _, alias := range link.Aliases {
commands[alias] = command{
validate: func(cmd commandInit) bool {
return true
},
run: func(cmd commandInit) (string, error) {
return fmt.Sprintf("<%s>", link.URL), nil
},
help: fmt.Sprintf("Returns the link for %s", alias),
}
links = append(links, fmt.Sprintf("%s -> <%s>", alias, link.URL))
}
}
commands["links"] = command{
validate: func(cmd commandInit) bool {
return true
},
run: func(cmd commandInit) (string, error) {
return strings.Join(links, "\n"), nil
},
help: "Get all dynamic links",
}
}

View File

@ -25,11 +25,12 @@ registered_channel = "0"
# staff_roles are for staff commands
staff_roles = []
# links are any basic link -> URL commands
[[links]]
# echoes are any basic command -> message
[[echoes]]
name = "discord"
aliases = ["invite", "gib"]
url = "https://birbmc.com/discord"
message = "<https://birbmc.com/discord>"
help = "Get the invite link"
# message_roles are for messages that should toggle a role when a user selects it
[[message_roles]]