Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ColorCommand = utl.SlashCommand{ CommandData: &discord.ApplicationCommand{ Name: "color", Description: "Changes user's personal role color", Options: []*discord.ApplicationCommandOption{ { Type: discord.ApplicationCommandOptionString, Name: "color", Description: "New role color in HEX format", Required: true, }, }, }, CommandHandler: func(s *discord.Session, i *discord.InteractionCreate) { userID := i.Member.User.ID guildRoles, err := s.GuildRoles(i.GuildID) if err != nil { utl.RespondToInteractionCreateWithString(s, i, "Could not get server roles.") log.Printf("[ERROR] Error fetching guild roles by guildID. %s", err) return } var personalRole *discord.Role if !funk.Contains(funk.Map(guildRoles, func(role *discord.Role) string { return role.Name }), userID) { permissions := int64(0) hoist := false mentionable := false personalRole, err = s.GuildRoleCreate(i.GuildID, &discord.RoleParams{ Name: userID, Permissions: &permissions, Hoist: &hoist, Mentionable: &mentionable, }) if err != nil { log.Printf("[ERROR] Error creating new personal user's role. %s", err) utl.RespondToInteractionCreateWithString(s, i, "Could not create user's personal role.") return } err = s.GuildMemberRoleAdd(i.GuildID, userID, personalRole.ID) if err != nil { utl.RespondToInteractionCreateWithString(s, i, "Could not give newly created personal role to user.") log.Printf("[ERROR] Could not give newly created personal role to user. %s", err) return } } if personalRole == nil { for _, role := range guildRoles { if role.Name == userID { personalRole = role break } } } member, err := s.State.Member(i.GuildID, userID) if err != nil { utl.RespondToInteractionCreateWithString(s, i, "Could not fetch user by ID.") log.Printf("[ERROR] Error fetching member by ID. %s", err) return } if !funk.Contains(member.Roles, personalRole.ID) { err = s.GuildMemberRoleAdd(i.GuildID, userID, personalRole.ID) if err != nil { utl.RespondToInteractionCreateWithString(s, i, "Could not give personal role to user.") log.Printf("[ERROR] Could not give personal role to user. %s", err) return } } optionMap := utl.GetOptionMap(i) colorField := optionMap["color"].StringValue() cleanedHexColor := strings.Replace(colorField, "#", "", -1) uIntColor, err := strconv.ParseUint(cleanedHexColor, 16, 64) if err != nil { utl.RespondToInteractionCreateWithString(s, i, "Invalid color in HEX format has been provided.") log.Printf("[ERROR] Error parsing hexidecimal color. %s", err) return } intColor := int(uIntColor) s.GuildRoleEdit(i.GuildID, personalRole.ID, &discord.RoleParams{ Color: &intColor, }) utl.RespondToInteractionCreateWithString(s, i, fmt.Sprintf("Successfully updated %s's personal role color.", i.Member.Mention())) }, }
View Source
var PingCommand = utl.SlashCommand{ CommandData: &discord.ApplicationCommand{ Name: "ping", Description: "Replies with \"Pong!\"", }, CommandHandler: func(s *discord.Session, i *discord.InteractionCreate) { s.InteractionRespond(i.Interaction, &discord.InteractionResponse{ Type: discord.InteractionResponseChannelMessageWithSource, Data: &discord.InteractionResponseData{ Content: "Pong!", }, }) }, }
View Source
var RegisterBirthdayCommand = utl.SlashCommand{ CommandData: &discord.ApplicationCommand{ Name: "register-birthday", Description: "Register discord user's birthday.", Options: []*discord.ApplicationCommandOption{ { Type: discord.ApplicationCommandOptionString, Name: "user", Description: "Discord user mention", Required: true, }, { Type: discord.ApplicationCommandOptionString, Name: "birthday", Description: "User's birthday date in MM/DD format", Required: true, }, }, }, CommandHandler: func(s *discord.Session, i *discord.InteractionCreate) { optionMap := utl.GetOptionMap(i) userMention := optionMap["user"].StringValue() if len(userMention) != 21 || !(strings.HasPrefix(userMention, "<@") && strings.HasSuffix(userMention, ">")) { log.Println("[ERROR] Supplied \"user\" field is not a discord user mention.") utl.RespondToInteractionCreateWithString(s, i, "Provided \"user\" field is not a valid discord user mention.") return } userID := userMention[2 : len(userMention)-1] birthdayDate := optionMap["birthday"].StringValue() _, err := time.Parse("01/02", birthdayDate) if err != nil { log.Println("[ERROR] Supplied \"birthday\" field is not a valid date.") utl.RespondToInteractionCreateWithString(s, i, "Provided \"birthday\" field is not a valid date.") return } sqliteDatabaseFilepath := os.Getenv("SQLITE_DATABASE_FILEPATH") if sqliteDatabaseFilepath == "" { sqliteDatabaseFilepath = "./userdata/userdata.sqlite3.db" } userData, err := utl.LoadUserFromDBByID(userID) if err != nil { utl.RespondToInteractionCreateWithString(s, i, "An error occured while executing command.") log.Printf("[ERROR] Could not load user from database: %s", err) return } userData.BirthdayDate = birthdayDate err = utl.SaveUserToDB(userData) if err != nil { utl.RespondToInteractionCreateWithString(s, i, "An error occured while executing command.") log.Printf("[ERROR] Could not update user's birthday date: %s", err) return } utl.RespondToInteractionCreateWithString(s, i, fmt.Sprintf("Successfully updated <@%s>'s birthday to be %s.", userID, birthdayDate)) }, }
View Source
var RemoveColorCommand = utl.SlashCommand{ CommandData: &discord.ApplicationCommand{ Name: "remove-color", Description: "Removes user's personal color role", }, CommandHandler: func(s *discord.Session, i *discord.InteractionCreate) { userID := i.Member.User.ID guildRoles, err := s.GuildRoles(i.GuildID) if err != nil { utl.RespondToInteractionCreateWithString(s, i, "Could not get server roles.") log.Printf("[ERROR] Error fetching guild roles by guildID. %s", err) return } var personalRole *discord.Role for _, role := range guildRoles { if role.Name == userID { personalRole = role break } } if personalRole == nil { utl.RespondToInteractionCreateWithString(s, i, "User has no personal role.") return } s.GuildRoleDelete(i.GuildID, personalRole.ID) utl.RespondToInteractionCreateWithString(s, i, fmt.Sprintf("Successfully deleted %s's personal color role.", i.Member.Mention())) }, }
View Source
var ( SlashCommands = map[string]utl.SlashCommand{ PingCommand.CommandData.Name: PingCommand, ColorCommand.CommandData.Name: ColorCommand, RemoveColorCommand.CommandData.Name: RemoveColorCommand, RegisterBirthdayCommand.CommandData.Name: RegisterBirthdayCommand, SwitchGreetingCommand.CommandData.Name: SwitchGreetingCommand, SwitchBirthdayCommand.CommandData.Name: SwitchBirthdayCommand, SwitchDMOnMentionCommand.CommandData.Name: SwitchDMOnMentionCommand, "pipe": utl.GenericVoiceCommand("pipe", "Plays metal pipe sound", "./assets/audio/voice/pipe.ogg"), "fontan": utl.GenericVoiceCommand("fontan", "Plays \"Chocoladniy Fontan\"", "./assets/audio/voice/fontan.ogg"), "women": utl.GenericVoiceCommand("women", "Plays women", "./assets/audio/voice/women.ogg"), "oblivion": utl.GenericVoiceCommand("oblivion", "Plays Oblivion NPC theme", "./assets/audio/voice/oblivion.ogg"), "cave": utl.GenericRandomVoiceCommand("cave", "Plays random minecraft cave sound", "./assets/audio/voice/cave/"), } )
View Source
var SwitchBirthdayCommand = utl.SlashCommand{ CommandData: &discord.ApplicationCommand{ Name: "switch-birthday", Description: "Switch birthday functionality on this server.", }, CommandHandler: func(s *discord.Session, i *discord.InteractionCreate) { guildData, err := utl.LoadGuildFromDBByID(i.GuildID) if err != nil { log.Printf("[ERROR] Could not load guild from database: %s", err) } if guildData.Birthday { guildData.Birthday = false utl.SaveGuildToDB(guildData) utl.RespondToInteractionCreateWithString(s, i, "Birthday functionality is now disabled.") return } guildData.Birthday = true utl.SaveGuildToDB(guildData) utl.RespondToInteractionCreateWithString(s, i, "Birthday functionality is now enabled.") }, }
View Source
var SwitchDMOnMentionCommand = utl.SlashCommand{ CommandData: &discord.ApplicationCommand{ Name: "switch-dm-on-mention", Description: "[NOT CURRNETLY WORKING] Switch DM on mention functionality on this server.", }, CommandHandler: func(s *discord.Session, i *discord.InteractionCreate) { guildData, err := utl.LoadGuildFromDBByID(i.GuildID) if err != nil { log.Printf("[ERROR] Could not load guild from database: %s", err) } if guildData.DMOnMention { guildData.DMOnMention = false utl.SaveGuildToDB(guildData) utl.RespondToInteractionCreateWithString(s, i, "DM on mention functionality is now disabled.") return } guildData.DMOnMention = true utl.SaveGuildToDB(guildData) utl.RespondToInteractionCreateWithString(s, i, "DM on mention functionality is now enabled.") }, }
View Source
var SwitchGreetingCommand = utl.SlashCommand{ CommandData: &discord.ApplicationCommand{ Name: "switch-greeting", Description: "Switch greeting functionality on this server.", }, CommandHandler: func(s *discord.Session, i *discord.InteractionCreate) { guildData, err := utl.LoadGuildFromDBByID(i.GuildID) if err != nil { log.Printf("[ERROR] Could not load guild from database: %s", err) } if guildData.Greeting { guildData.Greeting = false utl.SaveGuildToDB(guildData) utl.RespondToInteractionCreateWithString(s, i, "Greeting functionality is now disabled.") return } guildData.Greeting = true utl.SaveGuildToDB(guildData) utl.RespondToInteractionCreateWithString(s, i, "Greeting functionality is now enabled.") }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.