Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ServerInfoCommand = &dgc.Command{ Name: "serverinfo", Aliases: []string{"serverinfo", "server", "guild", "guildinfo"}, Domain: "astral.utility.serverinfo", Category: "Utility", Usage: "serverinfo", Description: "Get information about the server.", Slash: true, SlashGuilds: []string{os.Getenv("DEV_GUILD")}, Handler: func(ctx *dgc.Ctx) { guild, err := ctx.Session.GuildWithCounts(ctx.Event.GuildID) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } guildOwner, err := ctx.Session.User(guild.OwnerID) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } p := message.NewPrinter(language.English) ts, err := discordgo.SnowflakeTimestamp(guild.ID) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } channels, err := ctx.Session.GuildChannels(guild.ID) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } ctx.ReplyEmbed(utils.GenerateEmbed(*ctx, discordgo.MessageEmbed{ Title: "Server Information", Thumbnail: &discordgo.MessageEmbedThumbnail{URL: guild.IconURL()}, Fields: []*discordgo.MessageEmbedField{ {Name: "Name", Value: guild.Name, Inline: true}, {Name: "ID", Value: guild.ID, Inline: true}, {Name: "Owner", Value: guildOwner.Mention(), Inline: true}, {Name: "Members", Value: p.Sprintf("%d", guild.ApproximateMemberCount), Inline: true}, {Name: "Channels", Value: p.Sprintf("%d", len(channels)), Inline: true}, {Name: "Roles", Value: p.Sprintf("%d", len(guild.Roles)), Inline: true}, {Name: "Created", Value: fmt.Sprintf("<t:%d>", ts.Unix()), Inline: true}, }, })) }, }
View Source
var StatsCommand = &dgc.Command{ Name: "stats", Aliases: []string{"stats"}, Domain: "astral.utility.stats", Category: "Utility", Usage: "stats", Description: "View command statistics", Example: "stats", Handler: func(ctx *dgc.Ctx) { database := db.New() self := ctx.CustomObjects.MustGet("self").(types.Bot) stats, err := database.GetStatistics(*self.ID) if err != nil { ctx.ReplyEmbed(utils.GenerateEmbed(*ctx, discordgo.MessageEmbed{ Title: "Error", Description: "An error occurred while fetching the statistics.", Fields: []*discordgo.MessageEmbedField{ { Name: "Error", Value: err.Error(), Inline: false, }, }, Color: 0xff0000, })) return } if len(stats) == 0 { ctx.ReplyEmbed(utils.GenerateEmbed(*ctx, discordgo.MessageEmbed{ Title: "No Statistics", Description: "No statistics were found.", Color: 0xff0000, })) return } embed := discordgo.MessageEmbed{ Title: "Bot Statistics", Description: "Since the bot was added to the server", Color: 0x00ff00, } var commandStats []string botStats := types.BotAnalytics{ Commands: make(map[string]int), Messages: 0, Members: 0, } for _, stat := range stats { if stat.Commands != nil { for domain, times := range stat.Commands { if _, ok := botStats.Commands[domain]; !ok { botStats.Commands[domain] = 0 } botStats.Commands[domain] += times } } botStats.Messages += stat.Messages botStats.Members += stat.Members } var keys []string for k := range botStats.Commands { keys = append(keys, k) } sort.Slice(keys, func(i, j int) bool { return botStats.Commands[keys[i]] > botStats.Commands[keys[j]] }) for i, k := range keys { if i > 5 { break } commandStats = append(commandStats, fmt.Sprintf("`%s`: %d", FindCommand(*ctx, k).Name, botStats.Commands[k])) } var commandsExecuted int for _, times := range botStats.Commands { commandsExecuted += times } embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{ Name: "Commands Executed", Value: fmt.Sprintf("%d", commandsExecuted), Inline: true, }) embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{ Name: "Most Used Commands", Value: strings.Join(commandStats, "\n"), Inline: false, }) ctx.ReplyEmbed(utils.GenerateEmbed(*ctx, embed)) }, }
View Source
var WhoisCommand = &dgc.Command{ Name: "whois", Aliases: []string{"whois", "user", "userinfo"}, Domain: "astral.utility.whois", Category: "Utility", Usage: "whois <user>", Description: "View information about a user.", Example: "whois @AmusedGrape", Handler: func(ctx *dgc.Ctx) { userId := ctx.Arguments.Get(0).AsUserMentionID() if userId == "" { userId = ctx.Arguments.Get(0).Raw() } if userId == "" { userId = ctx.Event.Author.ID } user, err := ctx.Session.User(userId) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } member, err := ctx.Session.GuildMember(ctx.Event.GuildID, userId) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } userJoined, err := discordgo.SnowflakeTimestamp(member.User.ID) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } var roleText []string for _, role := range member.Roles { roleText = append(roleText, fmt.Sprintf("<@&%s>", role)) } var highestRole string if len(member.Roles) > 0 { highestRole = fmt.Sprintf("<@&%s>", member.Roles[0]) } else { highestRole = "None" } var roles string if len(roleText) > 0 { roles = strings.Join(roleText, ", ") } else { roles = "None" } err = ctx.ReplyEmbed(utils.GenerateEmbed(*ctx, discordgo.MessageEmbed{ Title: fmt.Sprintf("%s#%s's Information", user.Username, user.Discriminator), Thumbnail: &discordgo.MessageEmbedThumbnail{ URL: user.AvatarURL(""), }, Fields: []*discordgo.MessageEmbedField{ {Name: "ID", Value: user.ID, Inline: true}, {Name: "Joined", Value: fmt.Sprintf("<t:%d>", member.JoinedAt.Unix()), Inline: true}, {Name: "Created", Value: fmt.Sprintf("<t:%d>", userJoined.Unix()), Inline: true}, {Name: "Roles", Value: roles, Inline: true}, {Name: "Highest Role", Value: highestRole, Inline: true}, {Name: "Bot", Value: fmt.Sprintf("%t", user.Bot), Inline: true}, {Name: "Discord Tag", Value: member.Mention(), Inline: true}, {Name: "Discord Username", Value: user.Username, Inline: true}, {Name: "Discord Discriminator", Value: user.Discriminator, Inline: true}, }, })) }, }
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.