finished plugin system base
This commit is contained in:
24
shared/form_templates/form_demo.json
Normal file
24
shared/form_templates/form_demo.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"form_type": "form_demo",
|
||||
"title": "Demo form",
|
||||
"form": [
|
||||
{
|
||||
"label": "This is a simple textline",
|
||||
"is_paragraph": false,
|
||||
"placeholder": "...and it is required!",
|
||||
"value": "",
|
||||
"required": true,
|
||||
"min_length": 0,
|
||||
"max_length": 20
|
||||
},
|
||||
{
|
||||
"label": "This is a paragraph",
|
||||
"is_paragraph": true,
|
||||
"placeholder": "...and it is not required!",
|
||||
"value": "We already have some input here",
|
||||
"required": false,
|
||||
"min_length": 0,
|
||||
"max_length": 1024
|
||||
}
|
||||
]
|
||||
}
|
18
shared/form_templates/template_general.json
Normal file
18
shared/form_templates/template_general.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"form_type": "template_general",
|
||||
"title": "Form",
|
||||
"form": [
|
||||
{
|
||||
"label": "Title",
|
||||
"is_paragraph": false,
|
||||
"required": true,
|
||||
"max_length": 20
|
||||
},
|
||||
{
|
||||
"label": "Text",
|
||||
"is_paragraph": true,
|
||||
"required": true,
|
||||
"max_length": 1024
|
||||
}
|
||||
]
|
||||
}
|
20
shared/form_templates/template_ticket.json
Normal file
20
shared/form_templates/template_ticket.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"form_type": "template_ticket",
|
||||
"title": "Submit your Ticket",
|
||||
"mods_can_comment": true,
|
||||
"form": [
|
||||
{
|
||||
"label": "Title",
|
||||
"is_paragraph": false,
|
||||
"required": true,
|
||||
"max_length": 20
|
||||
},
|
||||
{
|
||||
"label": "Ticket information",
|
||||
"is_paragraph": true,
|
||||
"placeholder": "Fill in for what you need help or have issues with and a moderator will reply.",
|
||||
"required": true,
|
||||
"max_length": 1024
|
||||
}
|
||||
]
|
||||
}
|
15
shared/form_templates/template_url.json
Normal file
15
shared/form_templates/template_url.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"form_type": "template_url",
|
||||
"title": "Submit URL",
|
||||
"form": [
|
||||
{
|
||||
"label": "URL",
|
||||
"is_paragraph": false,
|
||||
"placeholder": "https://",
|
||||
"value": "",
|
||||
"required": true,
|
||||
"min_length": 0,
|
||||
"max_length": 100
|
||||
}
|
||||
]
|
||||
}
|
16
shared/go.mod
Normal file
16
shared/go.mod
Normal file
@@ -0,0 +1,16 @@
|
||||
module github.com/vaporvee/acecore/shared
|
||||
|
||||
go 1.22.1
|
||||
|
||||
require github.com/disgoorg/disgo v0.18.2
|
||||
|
||||
require (
|
||||
github.com/disgoorg/json v1.1.0 // indirect
|
||||
github.com/disgoorg/snowflake/v2 v2.0.1 // indirect
|
||||
github.com/gorilla/websocket v1.5.1 // indirect
|
||||
github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad // indirect
|
||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||
golang.org/x/crypto v0.19.0 // indirect
|
||||
golang.org/x/net v0.21.0 // indirect
|
||||
golang.org/x/sys v0.17.0 // indirect
|
||||
)
|
32
shared/go.sum
Normal file
32
shared/go.sum
Normal file
@@ -0,0 +1,32 @@
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/disgoorg/disgo v0.18.2 h1:pZCvaFamfHcnXrj0XA73qtVofP0R8dYEyQfPNgv8dLE=
|
||||
github.com/disgoorg/disgo v0.18.2/go.mod h1:gkl6DBdbKUvmOOJayWPSvS52KPN/8uJGJ2f13gCEB1o=
|
||||
github.com/disgoorg/json v1.1.0 h1:7xigHvomlVA9PQw9bMGO02PHGJJPqvX5AnwlYg/Tnys=
|
||||
github.com/disgoorg/json v1.1.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA=
|
||||
github.com/disgoorg/snowflake/v2 v2.0.1 h1:CuUxGLwggUxEswZOmZ+mZ5i0xSumQdXW9tXW7uGqe+0=
|
||||
github.com/disgoorg/snowflake/v2 v2.0.1/go.mod h1:SPU9c2CNn5DSyb86QcKtdZgix9osEtKrHLW4rMhfLCs=
|
||||
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
|
||||
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad h1:qIQkSlF5vAUHxEmTbaqt1hkJ/t6skqEGYiMag343ucI=
|
||||
github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad/go.mod h1:/pA7k3zsXKdjjAiUhB5CjuKib9KJGCaLvZwtxGC8U0s=
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
|
||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
|
||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
30
shared/main.go
Normal file
30
shared/main.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/disgoorg/disgo/bot"
|
||||
"github.com/disgoorg/disgo/discord"
|
||||
"github.com/disgoorg/disgo/events"
|
||||
)
|
||||
|
||||
type Command struct {
|
||||
Ready func(e *events.Ready)
|
||||
Definition discord.ApplicationCommandCreate
|
||||
Interact func(e *events.ApplicationCommandInteractionCreate)
|
||||
Autocomplete func(e *events.AutocompleteInteractionCreate)
|
||||
ComponentInteract func(e *events.ComponentInteractionCreate)
|
||||
ModalSubmit func(e *events.ModalSubmitInteractionCreate)
|
||||
ComponentIDs []string
|
||||
ModalIDs []string
|
||||
DynamicModalIDs func() []string
|
||||
DynamicComponentIDs func() []string
|
||||
}
|
||||
|
||||
type Plugin struct {
|
||||
Name string
|
||||
Init func(d *sql.DB) error
|
||||
Commands []Command
|
||||
}
|
||||
|
||||
var BotConfigs []bot.ConfigOpt
|
114
shared/tool.go
Normal file
114
shared/tool.go
Normal file
@@ -0,0 +1,114 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/disgoorg/disgo/bot"
|
||||
"github.com/disgoorg/disgo/discord"
|
||||
"github.com/disgoorg/snowflake/v2"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type ModalJsonField struct {
|
||||
Label string `json:"label"`
|
||||
IsParagraph bool `json:"is_paragraph"`
|
||||
Value string `json:"value"`
|
||||
Required bool `json:"required"`
|
||||
Placeholder string `json:"placeholder"`
|
||||
MinLength int `json:"min_length"`
|
||||
MaxLength int `json:"max_length"`
|
||||
}
|
||||
|
||||
type ModalJson struct {
|
||||
FormType string `json:"form_type"`
|
||||
Title string `json:"title"`
|
||||
Form []ModalJsonField `json:"form"`
|
||||
}
|
||||
|
||||
// Why does the golang compiler care about commands??
|
||||
//
|
||||
//go:embed form_templates/*.json
|
||||
var FormTemplates embed.FS
|
||||
|
||||
func GetModalByFormID(formID string) ModalJson {
|
||||
var modal ModalJson
|
||||
if formID == "" {
|
||||
return modal
|
||||
}
|
||||
entries, err := FormTemplates.ReadDir("form_templates")
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return modal
|
||||
}
|
||||
for _, entry := range entries {
|
||||
if strings.HasPrefix(entry.Name(), formID) {
|
||||
jsonFile, err := FormTemplates.ReadFile("form_templates/" + entry.Name())
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
continue
|
||||
}
|
||||
err = json.Unmarshal(jsonFile, &modal)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
return modal
|
||||
}
|
||||
|
||||
func JsonStringBuildModal(userID string, manageID string, formID string, overwrite ...string) discord.ModalCreate {
|
||||
var modal ModalJson = GetModalByFormID(formID)
|
||||
var components []discord.ContainerComponent
|
||||
for index, component := range modal.Form {
|
||||
var style discord.TextInputStyle = discord.TextInputStyleShort
|
||||
if component.IsParagraph {
|
||||
style = discord.TextInputStyleParagraph
|
||||
}
|
||||
components = append(components, discord.ActionRowComponent{
|
||||
discord.TextInputComponent{
|
||||
CustomID: fmt.Sprint(index),
|
||||
Label: component.Label,
|
||||
Style: style,
|
||||
Placeholder: component.Placeholder,
|
||||
Required: component.Required,
|
||||
MaxLength: component.MaxLength,
|
||||
MinLength: &component.MinLength,
|
||||
Value: component.Value,
|
||||
},
|
||||
})
|
||||
}
|
||||
if overwrite != nil && overwrite[0] != "" {
|
||||
modal.Title = overwrite[0]
|
||||
}
|
||||
|
||||
return discord.ModalCreate{
|
||||
CustomID: "form:" + manageID + ":" + userID,
|
||||
Title: modal.Title,
|
||||
Components: components,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func IsIDRole(c bot.Client, guildID snowflake.ID, id snowflake.ID) bool {
|
||||
_, err1 := c.Rest().GetMember(guildID, id)
|
||||
if err1 == nil {
|
||||
return false
|
||||
}
|
||||
roles, err2 := c.Rest().GetRoles(guildID)
|
||||
if err2 == nil {
|
||||
for _, role := range roles {
|
||||
if role.ID == id {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Error(err1)
|
||||
logrus.Error(err2)
|
||||
return false
|
||||
}
|
Reference in New Issue
Block a user