Impl Basc System
This commit is contained in:
		
							
								
								
									
										135
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										135
									
								
								main.go
									
									
									
									
									
								
							@@ -6,6 +6,7 @@ import (
 | 
				
			|||||||
	"log"
 | 
						"log"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"os/signal"
 | 
						"os/signal"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
	"syscall"
 | 
						"syscall"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/BurntSushi/toml"
 | 
						"github.com/BurntSushi/toml"
 | 
				
			||||||
@@ -24,6 +25,7 @@ var (
 | 
				
			|||||||
type Config struct {
 | 
					type Config struct {
 | 
				
			||||||
	Discord    Discord    `toml:"discord"`
 | 
						Discord    Discord    `toml:"discord"`
 | 
				
			||||||
	Database   Database   `toml:"database"`
 | 
						Database   Database   `toml:"database"`
 | 
				
			||||||
 | 
						AdminRoles []string   `toml:"admin_roles"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Discord struct {
 | 
					type Discord struct {
 | 
				
			||||||
@@ -92,6 +94,10 @@ func init() {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func reset(userNickname, softwareType string) {
 | 
				
			||||||
 | 
						log.Printf("Resetting %s for user %s\n", softwareType, userNickname)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var (
 | 
					var (
 | 
				
			||||||
	commands = []discordgo.ApplicationCommand{
 | 
						commands = []discordgo.ApplicationCommand{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@@ -120,7 +126,6 @@ var (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			globalCategoryID = categoryOption.ID
 | 
								globalCategoryID = categoryOption.ID
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		
 | 
					 | 
				
			||||||
			_, err := client.ChannelMessageSendComplex(channelOption.ID, &discordgo.MessageSend{
 | 
								_, err := client.ChannelMessageSendComplex(channelOption.ID, &discordgo.MessageSend{
 | 
				
			||||||
				Content: "Click the button below to request a HWID reset:",
 | 
									Content: "Click the button below to request a HWID reset:",
 | 
				
			||||||
				Components: []discordgo.MessageComponent{
 | 
									Components: []discordgo.MessageComponent{
 | 
				
			||||||
@@ -139,7 +144,6 @@ var (
 | 
				
			|||||||
				log.Println("Error sending message to the specified channel:", err)
 | 
									log.Println("Error sending message to the specified channel:", err)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			err = client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
 | 
								err = client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
 | 
				
			||||||
				Type: discordgo.InteractionResponseChannelMessageWithSource,
 | 
									Type: discordgo.InteractionResponseChannelMessageWithSource,
 | 
				
			||||||
				Data: &discordgo.InteractionResponseData{
 | 
									Data: &discordgo.InteractionResponseData{
 | 
				
			||||||
@@ -156,7 +160,7 @@ var (
 | 
				
			|||||||
			err := client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
 | 
								err := client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
 | 
				
			||||||
				Type: discordgo.InteractionResponseChannelMessageWithSource,
 | 
									Type: discordgo.InteractionResponseChannelMessageWithSource,
 | 
				
			||||||
				Data: &discordgo.InteractionResponseData{
 | 
									Data: &discordgo.InteractionResponseData{
 | 
				
			||||||
					Content: "For what would u like a HWID reset:",
 | 
										Content: "For what would you like a HWID reset:",
 | 
				
			||||||
					Components: []discordgo.MessageComponent{
 | 
										Components: []discordgo.MessageComponent{
 | 
				
			||||||
						discordgo.ActionsRow{
 | 
											discordgo.ActionsRow{
 | 
				
			||||||
							Components: []discordgo.MessageComponent{
 | 
												Components: []discordgo.MessageComponent{
 | 
				
			||||||
@@ -199,7 +203,6 @@ var (
 | 
				
			|||||||
			userID := i.Member.User.ID
 | 
								userID := i.Member.User.ID
 | 
				
			||||||
			userName := i.Member.User.Username
 | 
								userName := i.Member.User.Username
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		
 | 
					 | 
				
			||||||
			channel, err := client.GuildChannelCreateComplex(guildID, discordgo.GuildChannelCreateData{
 | 
								channel, err := client.GuildChannelCreateComplex(guildID, discordgo.GuildChannelCreateData{
 | 
				
			||||||
				Name:     fmt.Sprintf("reset-%s-%s", softwareType, userName),
 | 
									Name:     fmt.Sprintf("reset-%s-%s", softwareType, userName),
 | 
				
			||||||
				Type:     discordgo.ChannelTypeGuildText,
 | 
									Type:     discordgo.ChannelTypeGuildText,
 | 
				
			||||||
@@ -210,11 +213,6 @@ var (
 | 
				
			|||||||
						Type:  discordgo.PermissionOverwriteTypeRole,
 | 
											Type:  discordgo.PermissionOverwriteTypeRole,
 | 
				
			||||||
						Deny:  discordgo.PermissionViewChannel,
 | 
											Deny:  discordgo.PermissionViewChannel,
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					{
 | 
					 | 
				
			||||||
						ID:    userID,
 | 
					 | 
				
			||||||
						Type:  discordgo.PermissionOverwriteTypeMember,
 | 
					 | 
				
			||||||
						Allow: discordgo.PermissionViewChannel,
 | 
					 | 
				
			||||||
					},
 | 
					 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			})
 | 
								})
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
@@ -222,15 +220,125 @@ var (
 | 
				
			|||||||
				return
 | 
									return
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								for _, roleID := range config.AdminRoles {
 | 
				
			||||||
 | 
									client.ChannelPermissionSet(channel.ID, roleID, discordgo.PermissionOverwriteTypeRole, discordgo.PermissionViewChannel, 0)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			err = client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
 | 
								err = client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
 | 
				
			||||||
				Type: discordgo.InteractionResponseChannelMessageWithSource,
 | 
									Type: discordgo.InteractionResponseChannelMessageWithSource,
 | 
				
			||||||
				Data: &discordgo.InteractionResponseData{
 | 
									Data: &discordgo.InteractionResponseData{
 | 
				
			||||||
					Content: fmt.Sprintf("Request created: %s", channel.Mention()),
 | 
										Content: "Request submitted, you'll get a PM when it has been processed",
 | 
				
			||||||
					Flags:   discordgo.MessageFlagsEphemeral,
 | 
										Flags:   discordgo.MessageFlagsEphemeral,
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			})
 | 
								})
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				log.Println("Error sending interaction response:", err)
 | 
									log.Println("Error sending interaction response:", err)
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								_, err = client.ChannelMessageSendComplex(channel.ID, &discordgo.MessageSend{
 | 
				
			||||||
 | 
									Content: fmt.Sprintf("Reset request by %s for %s", userName, softwareType),
 | 
				
			||||||
 | 
									Components: []discordgo.MessageComponent{
 | 
				
			||||||
 | 
										discordgo.ActionsRow{
 | 
				
			||||||
 | 
											Components: []discordgo.MessageComponent{
 | 
				
			||||||
 | 
												discordgo.Button{
 | 
				
			||||||
 | 
													Label:    "Accept",
 | 
				
			||||||
 | 
													Style:    discordgo.PrimaryButton,
 | 
				
			||||||
 | 
													CustomID: fmt.Sprintf("accept_%s_%s", userID, softwareType),
 | 
				
			||||||
 | 
												},
 | 
				
			||||||
 | 
												discordgo.Button{
 | 
				
			||||||
 | 
													Label:    "Decline",
 | 
				
			||||||
 | 
													Style:    discordgo.DangerButton,
 | 
				
			||||||
 | 
													CustomID: fmt.Sprintf("decline_%s_%s", userID, softwareType),
 | 
				
			||||||
 | 
												},
 | 
				
			||||||
 | 
											},
 | 
				
			||||||
 | 
										},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									log.Println("Error sending message to the ticket channel:", err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
					"accept": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
 | 
				
			||||||
 | 
					    data := i.MessageComponentData().CustomID
 | 
				
			||||||
 | 
					    parts := strings.Split(data, "_")
 | 
				
			||||||
 | 
					    if len(parts) != 3 {
 | 
				
			||||||
 | 
					        log.Println("Invalid accept button custom ID")
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    userID := parts[1]
 | 
				
			||||||
 | 
					    softwareType := parts[2]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    member, err := client.GuildMember(i.GuildID, userID)
 | 
				
			||||||
 | 
					    if err != nil {
 | 
				
			||||||
 | 
					        log.Println("Error fetching member info:", err)
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    var userName string
 | 
				
			||||||
 | 
					    if member.Nick != "" {
 | 
				
			||||||
 | 
					        userName = member.Nick
 | 
				
			||||||
 | 
					    } else if member.User.GlobalName != "" {
 | 
				
			||||||
 | 
					        userName = member.User.GlobalName
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
						userName = member.User.Username
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    reset(userName, softwareType)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    err = client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
 | 
				
			||||||
 | 
					        Type: discordgo.InteractionResponseChannelMessageWithSource,
 | 
				
			||||||
 | 
					        Data: &discordgo.InteractionResponseData{
 | 
				
			||||||
 | 
					            Content: "Request accepted and processed.",
 | 
				
			||||||
 | 
					            Flags:   discordgo.MessageFlagsEphemeral,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    if err != nil {
 | 
				
			||||||
 | 
					        log.Println("Error sending interaction response:", err)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    dmChannel, err := client.UserChannelCreate(userID)
 | 
				
			||||||
 | 
					    if err != nil {
 | 
				
			||||||
 | 
					        log.Println("Error creating DM channel:", err)
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    _, err = client.ChannelMessageSend(dmChannel.ID, fmt.Sprintf("Your reset request for %s has been accepted and processed.", softwareType))
 | 
				
			||||||
 | 
					    if err != nil {
 | 
				
			||||||
 | 
					        log.Println("Error sending DM:", err)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							"decline": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
 | 
				
			||||||
 | 
								data := i.MessageComponentData().CustomID
 | 
				
			||||||
 | 
								parts := strings.Split(data, "_")
 | 
				
			||||||
 | 
								if len(parts) != 3 {
 | 
				
			||||||
 | 
									log.Println("Invalid decline button custom ID")
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								userID := parts[1]
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								err := client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
 | 
				
			||||||
 | 
									Type: discordgo.InteractionResponseChannelMessageWithSource,
 | 
				
			||||||
 | 
									Data: &discordgo.InteractionResponseData{
 | 
				
			||||||
 | 
										Content: "Request declined.",
 | 
				
			||||||
 | 
										Flags:   discordgo.MessageFlagsEphemeral,
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									log.Println("Error sending interaction response:", err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								dmChannel, err := client.UserChannelCreate(userID)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									log.Println("Error creating DM channel:", err)
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								_, err = client.ChannelMessageSend(dmChannel.ID, "Your reset request has been declined.")
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									log.Println("Error sending DM:", err)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -263,8 +371,13 @@ func main() {
 | 
				
			|||||||
				h(client, i)
 | 
									h(client, i)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		} else if i.Type == discordgo.InteractionMessageComponent {
 | 
							} else if i.Type == discordgo.InteractionMessageComponent {
 | 
				
			||||||
			if h, ok := componentsHandlers[i.MessageComponentData().CustomID]; ok {
 | 
								customID := i.MessageComponentData().CustomID
 | 
				
			||||||
 | 
								if h, ok := componentsHandlers[customID]; ok {
 | 
				
			||||||
				h(client, i)
 | 
									h(client, i)
 | 
				
			||||||
 | 
								} else if strings.HasPrefix(customID, "accept_") {
 | 
				
			||||||
 | 
									componentsHandlers["accept"](client, i)
 | 
				
			||||||
 | 
								} else if strings.HasPrefix(customID, "decline_") {
 | 
				
			||||||
 | 
									componentsHandlers["decline"](client, i)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user