started adding autojoinroles
This commit is contained in:
54
cmd_autojoinroles.go
Normal file
54
cmd_autojoinroles.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
import "github.com/bwmarrin/discordgo"
|
||||
|
||||
var autojoinroles_command Command = Command{
|
||||
Definition: discordgo.ApplicationCommand{
|
||||
Name: "autojoinroles",
|
||||
Description: "Give users a role when they join",
|
||||
Options: []*discordgo.ApplicationCommandOption{
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionSubCommand,
|
||||
Name: "bot",
|
||||
Description: "Give bots a role when they join (Leave empty to remove current)",
|
||||
Options: []*discordgo.ApplicationCommandOption{
|
||||
{
|
||||
|
||||
Type: discordgo.ApplicationCommandOptionRole,
|
||||
Name: "role",
|
||||
Description: "The role bots should get when they join the server",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionSubCommand,
|
||||
Name: "user",
|
||||
Description: "Give users a role when they join (Leave empty to remove current)",
|
||||
Options: []*discordgo.ApplicationCommandOption{
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionRole,
|
||||
Name: "role",
|
||||
Description: "The role users should get when they join the server",
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
option := i.ApplicationCommandData().Options[0].Name
|
||||
role := i.ApplicationCommandData().Options[0].Options[0].RoleValue(s, i.GuildID).ID
|
||||
var content string
|
||||
if setAutoJoinRole(i.GuildID, option, role) {
|
||||
content = "Setup auto join role for " + option + "s as <@&" + role + ">"
|
||||
} else {
|
||||
content = "Updated auto join role for " + option + "s as <@&" + role + ">"
|
||||
}
|
||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: content,
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
},
|
||||
})
|
||||
|
||||
},
|
||||
}
|
@@ -133,7 +133,7 @@ var form_command Command = Command{
|
||||
for _, opt := range options.Options {
|
||||
switch opt.Name {
|
||||
case "type":
|
||||
formID = options.Options[1].StringValue()
|
||||
formID = opt.StringValue()
|
||||
case "title":
|
||||
overwriteTitle = opt.StringValue()
|
||||
title = overwriteTitle
|
||||
|
@@ -40,6 +40,12 @@ func initTables() {
|
||||
mods_can_comment BOOL,
|
||||
PRIMARY KEY (form_manage_id, form_type)
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS autojoinroles (
|
||||
guild_id TEXT NOT NULL,
|
||||
bot_role TEXT,
|
||||
user_role TEXT,
|
||||
PRIMARY KEY (guild_id)
|
||||
)
|
||||
`
|
||||
|
||||
_, err := db.Exec(createTableQuery)
|
||||
@@ -229,3 +235,23 @@ func getFormType(formManageID string) string {
|
||||
}
|
||||
return formType
|
||||
}
|
||||
|
||||
func setAutoJoinRole(guildID string, option string, roleID string) bool {
|
||||
var exists bool
|
||||
err := db.QueryRow("SELECT EXISTS (SELECT 1 FROM autojoinroles WHERE guild_id = $1)", guildID).Scan(&exists)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
if exists {
|
||||
_, err = db.Exec("UPDATE autojoinroles SET "+option+"_role = $1 WHERE guild_id = $2", roleID, guildID)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
} else {
|
||||
_, err = db.Exec("INSERT INTO autojoinroles (guild_id, "+option+"_role) VALUES ($1, $2)", guildID, roleID)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
return exists
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ type Command struct {
|
||||
ModalIDs []string
|
||||
}
|
||||
|
||||
var commands []Command = []Command{form_command, tag_command, short_get_tag_command, dadjoke_command, ping_command, ask_command, sticky_command, cat_command}
|
||||
var commands []Command = []Command{form_command, tag_command, short_get_tag_command, dadjoke_command, ping_command, ask_command, sticky_command, cat_command, autojoinroles_command}
|
||||
|
||||
func ready(s *discordgo.Session, event *discordgo.Ready) {
|
||||
fmt.Print("\nStarting up...")
|
||||
|
24
tool.go
Normal file
24
tool.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type ModalJsonField struct {
|
||||
Label string `json:"label"`
|
||||
IsParagraph bool `json:"is_paragraph"`
|
||||
Value string `json:"value"`
|
||||
Required bool `json:"required"`
|
||||
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"`
|
||||
}
|
||||
|
||||
func jsonStringShowModal(jsonString string, id string) {
|
||||
var modal ModalJson
|
||||
json.Unmarshal([]byte(jsonString), &modal)
|
||||
|
||||
}
|
Reference in New Issue
Block a user