diff --git a/config/config.go b/config/config.go index d3843a9..6b59878 100644 --- a/config/config.go +++ b/config/config.go @@ -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) { diff --git a/discord/discord.go b/discord/discord.go index c90864d..903c440 100644 --- a/discord/discord.go +++ b/discord/discord.go @@ -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 } diff --git a/discord/echo.go b/discord/echo.go new file mode 100644 index 0000000..f249772 --- /dev/null +++ b/discord/echo.go @@ -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", + } +} diff --git a/discord/links.go b/discord/links.go deleted file mode 100644 index 6a487ca..0000000 --- a/discord/links.go +++ /dev/null @@ -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", - } -} diff --git a/sedbot.example.toml b/sedbot.example.toml index 6e83c34..cc02ab7 100644 --- a/sedbot.example.toml +++ b/sedbot.example.toml @@ -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 = "" +help = "Get the invite link" # message_roles are for messages that should toggle a role when a user selects it [[message_roles]]