From d814d39cf135748aac4e5c4961740c1577a0bf1f Mon Sep 17 00:00:00 2001 From: vaporvee Date: Sun, 14 Apr 2024 22:26:30 +0200 Subject: [PATCH] made simplefun plugin --- {struct_cmd => cmd}/go.mod | 2 +- {struct_cmd => cmd}/go.sum | 0 {struct_cmd => cmd}/main.go | 2 +- cmd_addemoji.go | 4 +-- cmd_autojoinroles.go | 4 +-- cmd_autopublish.go | 4 +-- cmd_blockpolls.go | 4 +-- cmd_form.go | 6 ++-- cmd_info.go | 4 +-- cmd_ping.go | 4 +-- cmd_sticky.go | 6 ++-- cmd_tag.go | 8 ++--- go.mod | 4 +-- handlers.go | 6 ++-- plugin_src/example/main.go | 6 ++-- cmd_ask.go => plugin_src/simplefun/cmd_ask.go | 4 +-- cmd_cat.go => plugin_src/simplefun/cmd_cat.go | 4 +-- .../simplefun/cmd_dadjoke.go | 4 +-- plugin_src/simplefun/go.mod | 3 ++ plugin_src/simplefun/main.go | 20 +++++++++++ plugin_src/simplefun/tool.go | 34 +++++++++++++++++++ web/html/privacy.html | 2 +- 22 files changed, 96 insertions(+), 39 deletions(-) rename {struct_cmd => cmd}/go.mod (91%) rename {struct_cmd => cmd}/go.sum (100%) rename {struct_cmd => cmd}/main.go (97%) rename cmd_ask.go => plugin_src/simplefun/cmd_ask.go (93%) rename cmd_cat.go => plugin_src/simplefun/cmd_cat.go (94%) rename cmd_dadjoke.go => plugin_src/simplefun/cmd_dadjoke.go (91%) create mode 100644 plugin_src/simplefun/go.mod create mode 100644 plugin_src/simplefun/main.go create mode 100644 plugin_src/simplefun/tool.go diff --git a/struct_cmd/go.mod b/cmd/go.mod similarity index 91% rename from struct_cmd/go.mod rename to cmd/go.mod index 5b621ee..bb7d4bd 100644 --- a/struct_cmd/go.mod +++ b/cmd/go.mod @@ -1,4 +1,4 @@ -module struct_cmd +module github.com/vaporvee/acecore/cmd go 1.22.1 diff --git a/struct_cmd/go.sum b/cmd/go.sum similarity index 100% rename from struct_cmd/go.sum rename to cmd/go.sum diff --git a/struct_cmd/main.go b/cmd/main.go similarity index 97% rename from struct_cmd/main.go rename to cmd/main.go index 3ac7679..b064c88 100644 --- a/struct_cmd/main.go +++ b/cmd/main.go @@ -1,4 +1,4 @@ -package struct_cmd +package cmd import ( "github.com/disgoorg/disgo/discord" diff --git a/cmd_addemoji.go b/cmd_addemoji.go index 3d682ad..f1548e2 100644 --- a/cmd_addemoji.go +++ b/cmd_addemoji.go @@ -11,10 +11,10 @@ import ( "github.com/disgoorg/disgo/events" "github.com/disgoorg/json" "github.com/sirupsen/logrus" - "github.com/vaporvee/acecore/struct_cmd" + "github.com/vaporvee/acecore/cmd" ) -var cmd_addemoji struct_cmd.Command = struct_cmd.Command{ +var cmd_addemoji cmd.Command = cmd.Command{ Definition: discord.SlashCommandCreate{ Name: "add-emoji", Description: "Add an external emoji directly to the server.", diff --git a/cmd_autojoinroles.go b/cmd_autojoinroles.go index edee59b..13772c9 100644 --- a/cmd_autojoinroles.go +++ b/cmd_autojoinroles.go @@ -5,10 +5,10 @@ import ( "github.com/disgoorg/disgo/events" "github.com/disgoorg/json" "github.com/sirupsen/logrus" - "github.com/vaporvee/acecore/struct_cmd" + "github.com/vaporvee/acecore/cmd" ) -var cmd_autojoinroles struct_cmd.Command = struct_cmd.Command{ +var cmd_autojoinroles cmd.Command = cmd.Command{ Definition: discord.SlashCommandCreate{ Name: "autojoinroles", Description: "Give users a role when they join", diff --git a/cmd_autopublish.go b/cmd_autopublish.go index c768916..3f27e4e 100644 --- a/cmd_autopublish.go +++ b/cmd_autopublish.go @@ -5,10 +5,10 @@ import ( "github.com/disgoorg/disgo/events" "github.com/disgoorg/json" "github.com/sirupsen/logrus" - "github.com/vaporvee/acecore/struct_cmd" + "github.com/vaporvee/acecore/cmd" ) -var cmd_autopublish struct_cmd.Command = struct_cmd.Command{ +var cmd_autopublish cmd.Command = cmd.Command{ Definition: discord.SlashCommandCreate{ Name: "autopublish", Description: "Toggle automatically publishing every post in a announcement channel", diff --git a/cmd_blockpolls.go b/cmd_blockpolls.go index 58cf352..3c5d1d9 100644 --- a/cmd_blockpolls.go +++ b/cmd_blockpolls.go @@ -5,10 +5,10 @@ import ( "github.com/disgoorg/disgo/events" "github.com/disgoorg/json" "github.com/sirupsen/logrus" - "github.com/vaporvee/acecore/struct_cmd" + "github.com/vaporvee/acecore/cmd" ) -var cmd_blockpolls struct_cmd.Command = struct_cmd.Command{ +var cmd_blockpolls cmd.Command = cmd.Command{ Definition: discord.SlashCommandCreate{ Name: "block-polls", Description: "Block polls from beeing posted in this channel.", diff --git a/cmd_form.go b/cmd_form.go index 7b49ab2..0f21678 100644 --- a/cmd_form.go +++ b/cmd_form.go @@ -12,11 +12,11 @@ import ( "github.com/disgoorg/snowflake/v2" "github.com/google/uuid" "github.com/sirupsen/logrus" + "github.com/vaporvee/acecore/cmd" "github.com/vaporvee/acecore/custom" - "github.com/vaporvee/acecore/struct_cmd" ) -var cmd_form struct_cmd.Command = struct_cmd.Command{ +var cmd_form cmd.Command = cmd.Command{ Definition: discord.SlashCommandCreate{ Name: "form", DefaultMemberPermissions: json.NewNullablePtr(discord.PermissionManageChannels), @@ -335,7 +335,7 @@ var cmd_form struct_cmd.Command = struct_cmd.Command{ }, } -var cmd_ticket_form struct_cmd.Command = struct_cmd.Command{ +var cmd_ticket_form cmd.Command = cmd.Command{ Definition: discord.SlashCommandCreate{ Name: "ticket", DefaultMemberPermissions: json.NewNullablePtr(discord.PermissionManageChannels), diff --git a/cmd_info.go b/cmd_info.go index f29dd99..120488b 100644 --- a/cmd_info.go +++ b/cmd_info.go @@ -8,8 +8,8 @@ import ( "github.com/disgoorg/disgo/discord" "github.com/disgoorg/disgo/events" "github.com/sirupsen/logrus" + "github.com/vaporvee/acecore/cmd" "github.com/vaporvee/acecore/custom" - "github.com/vaporvee/acecore/struct_cmd" ) type UserExtend struct { @@ -40,7 +40,7 @@ var userFlagsString map[discord.UserFlags]string = map[discord.UserFlags]string{ discord.UserFlagActiveDeveloper: "<:Active_Developer:1224708676611215380>[`Active Developer`](https://support-dev.discord.com/hc/en-us/articles/10113997751447?ref=badge)", } -var cmd_userinfo struct_cmd.Command = struct_cmd.Command{ +var cmd_userinfo cmd.Command = cmd.Command{ Definition: discord.SlashCommandCreate{ Name: "info", Description: "Gives you information about a user or this bot.", diff --git a/cmd_ping.go b/cmd_ping.go index 0fcbbe7..04ce645 100644 --- a/cmd_ping.go +++ b/cmd_ping.go @@ -8,11 +8,11 @@ import ( "github.com/disgoorg/disgo/discord" "github.com/disgoorg/disgo/events" "github.com/sirupsen/logrus" + "github.com/vaporvee/acecore/cmd" "github.com/vaporvee/acecore/custom" - "github.com/vaporvee/acecore/struct_cmd" ) -var cmd_ping struct_cmd.Command = struct_cmd.Command{ +var cmd_ping cmd.Command = cmd.Command{ Definition: discord.SlashCommandCreate{ Name: "ping", Description: "Returns the ping of the bot", diff --git a/cmd_sticky.go b/cmd_sticky.go index b6c10e0..c81e095 100644 --- a/cmd_sticky.go +++ b/cmd_sticky.go @@ -6,11 +6,11 @@ import ( "github.com/disgoorg/json" "github.com/disgoorg/snowflake/v2" "github.com/sirupsen/logrus" + "github.com/vaporvee/acecore/cmd" "github.com/vaporvee/acecore/custom" - "github.com/vaporvee/acecore/struct_cmd" ) -var cmd_sticky struct_cmd.Command = struct_cmd.Command{ +var cmd_sticky cmd.Command = cmd.Command{ Definition: discord.SlashCommandCreate{ Name: "sticky", Description: "Stick or unstick messages to the bottom of the current channel", @@ -56,7 +56,7 @@ var cmd_sticky struct_cmd.Command = struct_cmd.Command{ }, } -var context_sticky struct_cmd.Command = struct_cmd.Command{ +var context_sticky cmd.Command = cmd.Command{ Definition: discord.MessageCommandCreate{ Name: "Stick to channel", DefaultMemberPermissions: json.NewNullablePtr(discord.PermissionManageMessages), diff --git a/cmd_tag.go b/cmd_tag.go index c3447af..2ae0d05 100644 --- a/cmd_tag.go +++ b/cmd_tag.go @@ -5,11 +5,11 @@ import ( "github.com/disgoorg/disgo/events" "github.com/disgoorg/json" "github.com/sirupsen/logrus" - "github.com/vaporvee/acecore/struct_cmd" + "github.com/vaporvee/acecore/cmd" ) // TODO: make user installable tag command using userIDs instead of guildIDs -var cmd_tag struct_cmd.Command = struct_cmd.Command{ +var cmd_tag cmd.Command = cmd.Command{ Definition: discord.SlashCommandCreate{ Name: "tag", DefaultMemberPermissions: json.NewNullablePtr(discord.PermissionManageGuild), @@ -83,7 +83,7 @@ var cmd_tag struct_cmd.Command = struct_cmd.Command{ }, } -var cmd_tag_short struct_cmd.Command = struct_cmd.Command{ +var cmd_tag_short cmd.Command = cmd.Command{ Definition: discord.SlashCommandCreate{ Name: "g", Description: "A short command to get presaved messages.", @@ -109,7 +109,7 @@ var cmd_tag_short struct_cmd.Command = struct_cmd.Command{ }, } -var context_tag struct_cmd.Command = struct_cmd.Command{ +var context_tag cmd.Command = cmd.Command{ Definition: discord.MessageCommandCreate{ Name: "Save as tag", DefaultMemberPermissions: json.NewNullablePtr(discord.PermissionManageGuild), diff --git a/go.mod b/go.mod index 19943b8..3f08a62 100644 --- a/go.mod +++ b/go.mod @@ -15,10 +15,10 @@ require ( require ( github.com/gorilla/websocket v1.5.1 // indirect github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad // indirect - github.com/vaporvee/acecore/struct_cmd v0.0.0-00010101000000-000000000000 + github.com/vaporvee/acecore/cmd v0.0.0-00010101000000-000000000000 golang.org/x/crypto v0.19.0 // indirect golang.org/x/net v0.21.0 // indirect golang.org/x/sys v0.17.0 // indirect ) -replace github.com/vaporvee/acecore/struct_cmd => ./struct_cmd +replace github.com/vaporvee/acecore/cmd => ./cmd diff --git a/handlers.go b/handlers.go index 658c9d4..5a77e3a 100644 --- a/handlers.go +++ b/handlers.go @@ -14,11 +14,11 @@ import ( "github.com/disgoorg/disgo/events" "github.com/disgoorg/snowflake/v2" "github.com/sirupsen/logrus" + "github.com/vaporvee/acecore/cmd" "github.com/vaporvee/acecore/custom" - "github.com/vaporvee/acecore/struct_cmd" ) -var commands []struct_cmd.Command = []struct_cmd.Command{cmd_tag, cmd_tag_short, context_tag, cmd_sticky, context_sticky, cmd_ping, cmd_userinfo, cmd_addemoji, cmd_form, cmd_ask, cmd_cat, cmd_dadjoke, cmd_ticket_form, cmd_blockpolls, cmd_autopublish, cmd_autojoinroles} +var commands []cmd.Command = []cmd.Command{cmd_tag, cmd_tag_short, context_tag, cmd_sticky, context_sticky, cmd_ping, cmd_userinfo, cmd_addemoji, cmd_form, cmd_ask, cmd_cat, cmd_dadjoke, cmd_ticket_form, cmd_blockpolls, cmd_autopublish, cmd_autojoinroles} func ready(e *events.Ready) { logrus.Info("Starting up...") @@ -88,7 +88,7 @@ func loadPlugins(directory string, e *events.Ready) error { continue } - pluginPtr, ok := symPlugin.(**struct_cmd.Plugin) + pluginPtr, ok := symPlugin.(**cmd.Plugin) if !ok { logrus.Errorf("Plugin does not match expected type") continue diff --git a/plugin_src/example/main.go b/plugin_src/example/main.go index 119d053..77885c5 100644 --- a/plugin_src/example/main.go +++ b/plugin_src/example/main.go @@ -4,10 +4,10 @@ import ( "github.com/disgoorg/disgo/discord" "github.com/disgoorg/disgo/events" "github.com/sirupsen/logrus" - "github.com/vaporvee/acecore/struct_cmd" + "github.com/vaporvee/acecore/cmd" ) -var Plugin = &struct_cmd.Plugin{ +var Plugin = &cmd.Plugin{ Name: "testplugin", Register: func(e *events.Ready) error { app, err := e.Client().Rest().GetCurrentApplication() @@ -17,7 +17,7 @@ var Plugin = &struct_cmd.Plugin{ logrus.Infof("%s has a working plugin called \"testplugin\"", app.Bot.Username) return nil }, - Commands: []struct_cmd.Command{ + Commands: []cmd.Command{ { Definition: discord.SlashCommandCreate{ Name: "testplugincommand", diff --git a/cmd_ask.go b/plugin_src/simplefun/cmd_ask.go similarity index 93% rename from cmd_ask.go rename to plugin_src/simplefun/cmd_ask.go index 620fff9..6ba5065 100644 --- a/cmd_ask.go +++ b/plugin_src/simplefun/cmd_ask.go @@ -4,11 +4,11 @@ import ( "github.com/disgoorg/disgo/discord" "github.com/disgoorg/disgo/events" "github.com/sirupsen/logrus" + "github.com/vaporvee/acecore/cmd" "github.com/vaporvee/acecore/custom" - "github.com/vaporvee/acecore/struct_cmd" ) -var cmd_ask = struct_cmd.Command{ +var cmd_ask = cmd.Command{ Definition: discord.SlashCommandCreate{ Name: "ask", Description: "Ask anything and get a gif as response!", diff --git a/cmd_cat.go b/plugin_src/simplefun/cmd_cat.go similarity index 94% rename from cmd_cat.go rename to plugin_src/simplefun/cmd_cat.go index a178c13..d37bf27 100644 --- a/cmd_cat.go +++ b/plugin_src/simplefun/cmd_cat.go @@ -8,11 +8,11 @@ import ( "github.com/disgoorg/disgo/discord" "github.com/disgoorg/disgo/events" "github.com/sirupsen/logrus" + "github.com/vaporvee/acecore/cmd" "github.com/vaporvee/acecore/custom" - "github.com/vaporvee/acecore/struct_cmd" ) -var cmd_cat = struct_cmd.Command{ +var cmd_cat = cmd.Command{ Definition: discord.SlashCommandCreate{ Name: "cat", Description: "Random cat pictures", diff --git a/cmd_dadjoke.go b/plugin_src/simplefun/cmd_dadjoke.go similarity index 91% rename from cmd_dadjoke.go rename to plugin_src/simplefun/cmd_dadjoke.go index 7f9f446..a5cff7c 100644 --- a/cmd_dadjoke.go +++ b/plugin_src/simplefun/cmd_dadjoke.go @@ -4,10 +4,10 @@ import ( "github.com/disgoorg/disgo/discord" "github.com/disgoorg/disgo/events" "github.com/sirupsen/logrus" - "github.com/vaporvee/acecore/struct_cmd" + "github.com/vaporvee/acecore/cmd" ) -var cmd_dadjoke = struct_cmd.Command{ +var cmd_dadjoke = cmd.Command{ Definition: discord.SlashCommandCreate{ Name: "dadjoke", Description: "Gives you a random joke that is as bad as your dad would tell them", diff --git a/plugin_src/simplefun/go.mod b/plugin_src/simplefun/go.mod new file mode 100644 index 0000000..5a4b47c --- /dev/null +++ b/plugin_src/simplefun/go.mod @@ -0,0 +1,3 @@ +module simplefun + +go 1.22.1 diff --git a/plugin_src/simplefun/main.go b/plugin_src/simplefun/main.go new file mode 100644 index 0000000..4034a22 --- /dev/null +++ b/plugin_src/simplefun/main.go @@ -0,0 +1,20 @@ +package main + +import ( + "github.com/disgoorg/disgo/events" + "github.com/sirupsen/logrus" + "github.com/vaporvee/acecore/cmd" +) + +var Plugin = &cmd.Plugin{ + Name: "Simple Fun", + Register: func(e *events.Ready) error { + app, err := e.Client().Rest().GetCurrentApplication() + if err != nil { + return err + } + logrus.Infof("%s has a working plugin called \"testplugin\"", app.Bot.Username) + return nil + }, + Commands: []cmd.Command{cmd_ask, cmd_cat, cmd_dadjoke}, +} diff --git a/plugin_src/simplefun/tool.go b/plugin_src/simplefun/tool.go new file mode 100644 index 0000000..21f19b4 --- /dev/null +++ b/plugin_src/simplefun/tool.go @@ -0,0 +1,34 @@ +package main + +import ( + "encoding/json" + "io" + "net/http" + + "github.com/sirupsen/logrus" +) + +func simpleGetFromAPI(key string, url string) interface{} { + client := &http.Client{} + req, err := http.NewRequest("GET", url, nil) + if err != nil { + logrus.Error("Error creating request:", err) + } + req.Header.Set("Accept", "application/json") + resp, err := client.Do(req) + if err != nil { + logrus.Error("Error making request:", err) + } + defer resp.Body.Close() + body, err := io.ReadAll(resp.Body) + if err != nil { + logrus.Error("Error reading response body:", err) + } + + var result map[string]interface{} + err = json.Unmarshal(body, &result) + if err != nil { + logrus.Error("Error decoding JSON:", err) + } + return result[key] +} diff --git a/web/html/privacy.html b/web/html/privacy.html index d2387e4..38bdc30 100644 --- a/web/html/privacy.html +++ b/web/html/privacy.html @@ -43,7 +43,7 @@ services.
  • - struct_cmd.Command usage: We store data about some commands that you use within + cmd.Command usage: We store data about some commands that you use within acecore in order to make the commands usable and functioning.