Make a ticket creation bot as a base
This commit is contained in:
parent
e57d3ff4fe
commit
3abc4f3265
177
main.go
177
main.go
@ -6,7 +6,6 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
@ -18,6 +17,8 @@ var (
|
||||
config Config
|
||||
client *discordgo.Session
|
||||
db *sql.DB
|
||||
|
||||
globalCategoryID string
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@ -91,54 +92,145 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
func searchLink(message, format, sep string) string {
|
||||
return fmt.Sprintf(format, strings.Join(
|
||||
strings.Split(
|
||||
message,
|
||||
" ",
|
||||
),
|
||||
sep,
|
||||
))
|
||||
}
|
||||
|
||||
var (
|
||||
commands = []discordgo.ApplicationCommand{
|
||||
{
|
||||
Name: "rickroll-em",
|
||||
Description: "List all webhooks in the server",
|
||||
Name: "setup",
|
||||
Description: "Setup a channel for ticket creation",
|
||||
Options: []*discordgo.ApplicationCommandOption{
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionChannel,
|
||||
Name: "channel",
|
||||
Description: "Channel for ticket creation",
|
||||
Required: true,
|
||||
},
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionChannel,
|
||||
Name: "category",
|
||||
Description: "Category for tickets",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
commandsHandlers = map[string]func(client *discordgo.Session, i *discordgo.InteractionCreate){
|
||||
"rickroll-em": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
"setup": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
channelOption := i.ApplicationCommandData().Options[0].ChannelValue(client)
|
||||
categoryOption := i.ApplicationCommandData().Options[1].ChannelValue(client)
|
||||
|
||||
globalCategoryID = categoryOption.ID
|
||||
|
||||
|
||||
_, err := client.ChannelMessageSendComplex(channelOption.ID, &discordgo.MessageSend{
|
||||
Content: "Click the button below to request a HWID reset:",
|
||||
Components: []discordgo.MessageComponent{
|
||||
discordgo.ActionsRow{
|
||||
Components: []discordgo.MessageComponent{
|
||||
discordgo.Button{
|
||||
Label: "Request Reset",
|
||||
Style: discordgo.PrimaryButton,
|
||||
CustomID: "create_ticket",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
log.Println("Error sending message to the specified channel:", err)
|
||||
}
|
||||
|
||||
|
||||
err = client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: fmt.Sprintf("Setup completed! Request creation button has been added to %s", channelOption.Mention()),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
log.Println("Error sending interaction response:", err)
|
||||
}
|
||||
},
|
||||
}
|
||||
componentsHandlers = map[string]func(client *discordgo.Session, i *discordgo.InteractionCreate){
|
||||
"create_ticket": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
err := client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "Operation rickroll has begun",
|
||||
Content: "For what would u like a HWID reset:",
|
||||
Components: []discordgo.MessageComponent{
|
||||
discordgo.ActionsRow{
|
||||
Components: []discordgo.MessageComponent{
|
||||
discordgo.SelectMenu{
|
||||
CustomID: "select_software_type",
|
||||
Placeholder: "Choose which software",
|
||||
Options: []discordgo.SelectMenuOption{
|
||||
{
|
||||
Label: "Vanity",
|
||||
Value: "vanity",
|
||||
Description: "Request a vanity reset",
|
||||
},
|
||||
{
|
||||
Label: "Mesa",
|
||||
Value: "mesa",
|
||||
Description: "Request a mesa reset",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
log.Println("Error sending interaction response:", err)
|
||||
}
|
||||
},
|
||||
"select_software_type": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
selectedOption := i.MessageComponentData().Values[0]
|
||||
var softwareType string
|
||||
if selectedOption == "vanity" {
|
||||
softwareType = "Vanity"
|
||||
} else if selectedOption == "mesa" {
|
||||
softwareType = "Mesa"
|
||||
}
|
||||
|
||||
guildID := i.GuildID
|
||||
userID := i.Member.User.ID
|
||||
userName := i.Member.User.Username
|
||||
|
||||
|
||||
channel, err := client.GuildChannelCreateComplex(guildID, discordgo.GuildChannelCreateData{
|
||||
Name: fmt.Sprintf("reset-%s-%s", softwareType, userName),
|
||||
Type: discordgo.ChannelTypeGuildText,
|
||||
ParentID: globalCategoryID,
|
||||
PermissionOverwrites: []*discordgo.PermissionOverwrite{
|
||||
{
|
||||
ID: guildID,
|
||||
Type: discordgo.PermissionOverwriteTypeRole,
|
||||
Deny: discordgo.PermissionViewChannel,
|
||||
},
|
||||
{
|
||||
ID: userID,
|
||||
Type: discordgo.PermissionOverwriteTypeMember,
|
||||
Allow: discordgo.PermissionViewChannel,
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
log.Println("Error creating hwid request channel:", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: fmt.Sprintf("Request created: %s", channel.Mention()),
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
ch, err := client.UserChannelCreate(
|
||||
i.ApplicationCommandData().TargetID,
|
||||
)
|
||||
if err != nil {
|
||||
_, err = client.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
|
||||
Content: fmt.Sprintf("Mission failed. Cannot send a message to this user: %q", err.Error()),
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
_, err = client.ChannelMessageSend(
|
||||
ch.ID,
|
||||
fmt.Sprintf("%s sent you this: https://youtu.be/dQw4w9WgXcQ", i.Member.Mention()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Println("Error sending interaction response:", err)
|
||||
}
|
||||
},
|
||||
}
|
||||
@ -156,7 +248,6 @@ func main() {
|
||||
cmdIDs := make(map[string]string, len(commands))
|
||||
|
||||
for _, cmd := range commands {
|
||||
fmt.Println(cmd)
|
||||
rcmd, err := client.ApplicationCommandCreate(client.State.User.ID, config.Discord.GuildID, &cmd)
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot create slash command %q: %v", cmd.Name, err)
|
||||
@ -167,8 +258,14 @@ func main() {
|
||||
})
|
||||
|
||||
client.AddHandler(func(client *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
if h, ok := commandsHandlers[i.ApplicationCommandData().Name]; ok {
|
||||
h(client, i)
|
||||
if i.Type == discordgo.InteractionApplicationCommand {
|
||||
if h, ok := commandsHandlers[i.ApplicationCommandData().Name]; ok {
|
||||
h(client, i)
|
||||
}
|
||||
} else if i.Type == discordgo.InteractionMessageComponent {
|
||||
if h, ok := componentsHandlers[i.MessageComponentData().CustomID]; ok {
|
||||
h(client, i)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@ -176,7 +273,7 @@ func main() {
|
||||
if err != nil {
|
||||
log.Println("Error opening connection:", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
stop := make(chan os.Signal, 1)
|
||||
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
|
||||
|
Loading…
Reference in New Issue
Block a user