Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var CommandHandlers = map[string]shrouter.CommandHandler{ "ping": func(c *shrouter.Context) { err := c.InteractionRespond(c.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionApplicationCommandResponseData{ Content: fmt.Sprintf("Pong %dms!", c.HeartbeatLatency()/time.Millisecond), }, }) if err != nil { log.Printf("Error sending message: %s", err) } }, "warn": func(c *shrouter.Context) { var u *discordgo.User if ok, o := shrouter.FindOption("user", c.Data.Options); ok { u = o.UserValue(c.Session) } ms := c.Vars["memberService"] s := ms.(mater.MemberService) mCh := make(chan *mater.Member) errCh := make(chan error) go s.GetMember(mCh, errCh, u.ID) m, err := <-mCh, <-errCh close(mCh) if err != nil { c.InteractionRespond(c.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionApplicationCommandResponseData{ Content: fmt.Sprintf("Error executing command: %s", err), }, }) } var reason string if ok, o := shrouter.FindOption("reason", c.Data.Options); ok { reason = o.StringValue() } m.Warns = append(m.Warns, reason) go s.UpdateMember(errCh, m) err = <-errCh close(errCh) if err != nil { c.InteractionRespond(c.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionApplicationCommandResponseData{ Content: fmt.Sprintf("Error executing command: %s", err), }, }) } c.InteractionRespond(c.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionApplicationCommandResponseData{ Content: fmt.Sprintf("Warned %s for **'%s'**", u.Mention(), reason), }, }) }, "ban": func(c *shrouter.Context) { if !shrouter.CanBan(c.Session, c.GuildID, c.Member) { err := c.InteractionRespond(c.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionApplicationCommandResponseData{ Content: fmt.Sprintf("You lack the permissions to run this command."), }, }) if err != nil { log.Printf("Error sending message: %s", err) } return } var user *discordgo.User var reason string = "" var days int = 0 if found, o := shrouter.FindOption("user", c.Data.Options); found { user = o.UserValue(c.Session) } if found, o := shrouter.FindOption("reason", c.Data.Options); found { reason = o.StringValue() } if found, o := shrouter.FindOption("days", c.Data.Options); found { days = int(o.IntValue()) } if err := c.GuildBanCreateWithReason(c.GuildID, user.ID, reason, days); err != nil { log.Printf("Error banning user '%s': %s", c.Data.Options[0].UserValue(c.Session).ID, err) } if err := c.InteractionRespond(c.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionApplicationCommandResponseData{ Content: fmt.Sprintf("%s was banned", user.Mention()), }, }); err != nil { log.Printf("Error responding to interaction: %s", err) } }, "embed": func(c *shrouter.Context) { if !shrouter.IsAdmin(c.Session, c.GuildID, c.Member) { c.ChannelMessageSend(c.ChannelID, "You lack the permissions to run this command.") return } switch c.Data.Options[0].Name { case "create": var title string var desc string var color int var author discordgo.MessageEmbedAuthor var thumbnail discordgo.MessageEmbedThumbnail var footer discordgo.MessageEmbedFooter var timestamp string if found, o := shrouter.FindOption("title", c.Data.Options[0].Options); found { title = fmt.Sprintf("%v", o.Value) } if found, o := shrouter.FindOption("description", c.Data.Options[0].Options); found { desc = fmt.Sprintf("%v", o.Value) } if found, o := shrouter.FindOption("color", c.Data.Options[0].Options); found { color = int(o.IntValue()) } if found, o := shrouter.FindOption("author", c.Data.Options[0].Options); found { u := o.UserValue(c.Session) author.Name = u.String() author.IconURL = u.AvatarURL("") } if found, o := shrouter.FindOption("thumbnail", c.Data.Options[0].Options); found { thumbnail.URL = o.StringValue() } if found, o := shrouter.FindOption("footertext", c.Data.Options[0].Options); found { footer.Text = o.StringValue() } if found, o := shrouter.FindOption("footericon", c.Data.Options[0].Options); found { if o.StringValue() == "server" { g, err := c.Guild(c.GuildID) if err != nil { log.Printf("Error retrieving guild: %s", err) return } footer.IconURL = g.IconURL() } else { footer.IconURL = o.StringValue() } } if found, o := shrouter.FindOption("timestamp", c.Data.Options[0].Options); found { if o.BoolValue() { timestamp = time.Now().Format(time.RFC3339) } } embed := &discordgo.MessageEmbed{ Title: title, Description: desc, Color: color, Author: &author, Thumbnail: &thumbnail, Footer: &footer, Timestamp: timestamp, } found, o := shrouter.FindOption("channel", c.Data.Options[0].Options) if !found { log.Printf("Unable to find channel option") return } if _, err := c.ChannelMessageSendEmbed(o.ChannelValue(c.Session).ID, embed); err != nil { log.Printf("Error sending message: %s", err) } if err := c.InteractionRespond(c.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseDeferredChannelMessageWithSource, }); err != nil { log.Printf("Error responding to interaction: %s", err) } case "edit": found, o := shrouter.FindOption("channel", c.Data.Options[0].Options) if !found { log.Printf("Unable to find channel option") return } channelID := o.ChannelValue(c.Session).ID found, o = shrouter.FindOption("messageid", c.Data.Options[0].Options) if !found { log.Printf("Unable to find messageID option") return } messageID := o.StringValue() m, err := c.ChannelMessage(channelID, messageID) if err != nil { log.Printf("Error finding message: %s", err) return } title := m.Embeds[0].Title desc := m.Embeds[0].Description color := m.Embeds[0].Color author := m.Embeds[0].Author thumbnail := m.Embeds[0].Thumbnail footer := m.Embeds[0].Footer timestamp := m.Embeds[0].Timestamp if found, o := shrouter.FindOption("title", c.Data.Options[0].Options); found { title = fmt.Sprintf("%v", o.Value) } if found, o := shrouter.FindOption("description", c.Data.Options[0].Options); found { desc = fmt.Sprintf("%v", o.Value) } if found, o := shrouter.FindOption("color", c.Data.Options[0].Options); found { color = int(o.IntValue()) } if found, o := shrouter.FindOption("author", c.Data.Options[0].Options); found { u := o.UserValue(c.Session) author.Name = u.String() author.IconURL = u.AvatarURL("") } if found, o := shrouter.FindOption("thumbnail", c.Data.Options[0].Options); found { thumbnail.URL = o.StringValue() } if found, o := shrouter.FindOption("footertext", c.Data.Options[0].Options); found { footer.Text = o.StringValue() } if found, o := shrouter.FindOption("footericon", c.Data.Options[0].Options); found { if o.StringValue() == "server" { g, err := c.Guild(c.GuildID) if err != nil { log.Printf("Error retrieving guild: %s", err) return } footer.IconURL = g.IconURL() } else { footer.IconURL = o.StringValue() } } if found, o := shrouter.FindOption("timestamp", c.Data.Options[0].Options); found { if o.BoolValue() { timestamp = time.Now().Format(time.RFC3339) } } embed := &discordgo.MessageEmbed{ Title: title, Description: desc, Color: color, Author: author, Thumbnail: thumbnail, Footer: footer, Timestamp: timestamp, } if _, err := c.ChannelMessageEditEmbed(channelID, messageID, embed); err != nil { log.Printf("Error sending message: %s", err) } err = c.InteractionRespond(c.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseDeferredChannelMessageWithSource, }) if err != nil { log.Printf("Interaction response error: %s", err) } case "append": found, o := shrouter.FindOption("channel", c.Data.Options[0].Options) if !found { log.Printf("Unable to find channel option") return } channelID := o.ChannelValue(c.Session).ID found, o = shrouter.FindOption("messageid", c.Data.Options[0].Options) if !found { log.Printf("Unable to find messageID option") return } messageID := o.StringValue() m, err := c.ChannelMessage(channelID, messageID) if err != nil { log.Printf("Error finding message: %s", err) return } found, o = shrouter.FindOption("text", c.Data.Options[0].Options) if !found { log.Printf("Unable to find text option") return } text := o.StringValue() title := m.Embeds[0].Title desc := m.Embeds[0].Description + "\n" + text color := m.Embeds[0].Color author := m.Embeds[0].Author thumbnail := m.Embeds[0].Thumbnail footer := m.Embeds[0].Footer timestamp := m.Embeds[0].Timestamp if _, err := c.ChannelMessageEditEmbed(channelID, messageID, &discordgo.MessageEmbed{ Title: title, Description: desc, Color: color, Author: author, Thumbnail: thumbnail, Footer: footer, Timestamp: timestamp, }); err != nil { log.Printf("Error sending message: %s", err) } err = c.InteractionRespond(c.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseDeferredChannelMessageWithSource, }) if err != nil { log.Printf("Interaction response error: %s", err) } } }, "avatar": func(c *shrouter.Context) { var u *discordgo.User if found, o := shrouter.FindOption("user", c.Data.Options); found { u = o.UserValue(c.Session) } err := c.InteractionRespond(c.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseDeferredChannelMessageWithSource, }) if err != nil { log.Printf("Error sending message: %s", err) } c.ChannelMessageSendEmbed(c.ChannelID, &discordgo.MessageEmbed{ Author: &discordgo.MessageEmbedAuthor{ Name: u.String(), IconURL: u.AvatarURL(""), }, Image: &discordgo.MessageEmbedImage{ URL: u.AvatarURL("2048"), }, }) }, }
CommandHandlers is a slice of all my command handlers
View Source
var Commands = []*discordgo.ApplicationCommand{ { Name: "ping", Description: "Pings the mater. Returns Pong with latency.", }, { Name: "ban", Description: "Bans a user", Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionUser, Name: "user", Description: "The user you want to ban", Required: true, }, { Type: discordgo.ApplicationCommandOptionString, Name: "reason", Description: "The ban reason", Required: false, }, { Type: discordgo.ApplicationCommandOptionInteger, Name: "days", Description: "The number of days of messages to delete", Required: false, }, }, }, { Name: "warn", Description: "Warns a user", Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionUser, Name: "user", Description: "The user you want to warn", Required: true, }, { Type: discordgo.ApplicationCommandOptionString, Name: "reason", Description: "The warn reason", Required: true, }, }, }, { Name: "close", Description: "Closes a modmail ticket", Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionInteger, Name: "ticket", Description: "The ticket number you want to close", Required: false, }, }, }, { Name: "reply", Description: "Replies to a modmail ticket", Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionString, Name: "content", Description: "The reply content", Required: true, }, { Type: discordgo.ApplicationCommandOptionInteger, Name: "ticket", Description: "The ticket number you want to close", Required: false, }, }, }, { Name: "mute", Description: "Mutes a user", Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionUser, Name: "user", Description: "The user you want to mute", }, }, }, { Name: "avatar", Description: "Returns the avatar of the user", Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionUser, Name: "user", Description: "The user whose avatar you want", Required: false, }, }, }, { Name: "embed", Description: "Creates, edits, or appends to an embed.", Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionSubCommand, Name: "create", Required: false, Description: "Creates an embed", Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionChannel, Name: "channel", Description: "The channel the embed will be posted in", Required: true, }, { Type: discordgo.ApplicationCommandOptionString, Name: "title", Description: "The title of your embed", Required: false, }, { Type: discordgo.ApplicationCommandOptionString, Name: "description", Description: "The description of your embed (One line only, use append subcommand to add more.)", Required: false, }, { Type: discordgo.ApplicationCommandOptionInteger, Name: "color", Description: "The color of your embed", Required: false, }, { Type: discordgo.ApplicationCommandOptionUser, Name: "author", Description: "The author of your embed", Required: false, }, { Type: discordgo.ApplicationCommandOptionString, Name: "footertext", Description: "The footer text of your embed", Required: false, }, { Type: discordgo.ApplicationCommandOptionString, Name: "footericon", Description: "The icon URL of the footer", Required: false, }, { Type: discordgo.ApplicationCommandOptionString, Name: "thumbnail", Description: "The thumbnail of your embed", Required: false, }, { Type: discordgo.ApplicationCommandOptionBoolean, Name: "timestamp", Description: "The timestamp of your embed (if true, it will set the current time)", Required: false, }, }, }, { Type: discordgo.ApplicationCommandOptionSubCommand, Name: "edit", Required: false, Description: "Edits an embed", Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionChannel, Name: "channel", Description: "The channel the embed is in", Required: true, }, { Type: discordgo.ApplicationCommandOptionString, Name: "messageid", Description: "The message ID of the embed", Required: true, }, { Type: discordgo.ApplicationCommandOptionString, Name: "title", Description: "The new title of your embed", Required: false, }, { Type: discordgo.ApplicationCommandOptionString, Name: "description", Description: "The new description of your embed", Required: false, }, { Type: discordgo.ApplicationCommandOptionInteger, Name: "color", Description: "The new color of your embed", Required: false, }, { Type: discordgo.ApplicationCommandOptionUser, Name: "author", Description: "The new author of your embed", Required: false, }, { Type: discordgo.ApplicationCommandOptionString, Name: "footertext", Description: "The new footer text of your embed", Required: false, }, { Type: discordgo.ApplicationCommandOptionString, Name: "footericon", Description: "The new icon URL of the footer", Required: false, }, { Type: discordgo.ApplicationCommandOptionString, Name: "thumbnail", Description: "The new thumbnail of your embed", Required: false, }, { Type: discordgo.ApplicationCommandOptionBoolean, Name: "timestamp", Description: "Change the timestamp of your embed (if true, it will set the current time)", Required: false, }, }, }, { Type: discordgo.ApplicationCommandOptionSubCommand, Name: "append", Required: false, Description: "Appends a line to the embed description.", Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionChannel, Name: "channel", Description: "The channel the embed is in", Required: true, }, { Type: discordgo.ApplicationCommandOptionString, Name: "messageid", Description: "The message ID of the embed", Required: true, }, { Type: discordgo.ApplicationCommandOptionString, Name: "text", Description: "The text to be appended", Required: true, }, }, }, }, }, }
Commands is a slice of all my commands
View Source
var Handlers = []mater.Handler{ func(b *mater.Bot) interface{} { return func(s *discordgo.Session, r *discordgo.Ready) { log.Printf("Logged in as %v\n", r.User) fmt.Println("-------------------------------------------------") } }, func(b *mater.Bot) interface{} { return func(s *discordgo.Session, g *discordgo.GuildCreate) { for _, m := range g.Members { errCh := make(chan error) go b.MemberService.AddMember(errCh, mater.NewMember(m)) err := <-errCh if err != nil { log.Printf("Error adding member '%s': %s", m.User.ID, err) } } log.Print("Finished adding members to database.") } }, func(b *mater.Bot) interface{} { return func(s *discordgo.Session, m *discordgo.MessageCreate) { dmChannel, err := s.Channel(m.ChannelID) if err != nil { log.Printf("Error getting dm channel: %s", err) return } if dmChannel.Type != discordgo.ChannelTypeDM || m.Author.ID == s.State.User.ID { return } chName := strings.NewReplacer("#", " ").Replace(m.Author.String()) guild, err := s.Guild(mater.GuildID) if err != nil { log.Printf("Error finding guild: %s", err) return } logFooter := &discordgo.MessageEmbedFooter{ Text: m.Author.String() + " | " + m.Author.ID, IconURL: guild.IconURL(), } logNewTicket := &discordgo.MessageEmbed{ Title: "New Ticket", Color: 0x2ecc71, Footer: logFooter, Timestamp: time.Now().Format(time.RFC3339), } author := &discordgo.MessageEmbedAuthor{ Name: m.Author.String(), IconURL: m.Author.AvatarURL(""), } replyFooter := &discordgo.MessageEmbedFooter{ Text: "ID: " + m.Author.ID, IconURL: s.State.User.AvatarURL(""), } reply := &discordgo.MessageEmbed{ Title: "Message Sent", Description: m.Content, Color: 0xff4949, Author: author, Footer: replyFooter, Timestamp: time.Now().Format(time.RFC3339), } mmFooter := &discordgo.MessageEmbedFooter{ Text: guild.Name + " | " + guild.ID, IconURL: guild.IconURL(), } mm := &discordgo.MessageEmbed{ Title: "Message Received", Description: m.Content, Color: 0x2ecc71, Author: author, Footer: mmFooter, Timestamp: time.Now().Format(time.RFC3339), } s.ChannelMessageSendEmbed(mater.ModmailLogID, logNewTicket) s.ChannelMessageSendEmbed(m.ChannelID, reply) data := discordgo.GuildChannelCreateData{ Name: chName, ParentID: mater.ModmailCatID, } ch, err := s.GuildChannelCreateComplex(mater.GuildID, data) if err != nil { log.Print(err) return } _, err = s.ChannelMessageSendEmbed(ch.ID, mm) if err != nil { log.Print(err) return } } }, }
Handlers is a a slice of all my handlers
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.