commands

package
v0.0.0-...-f00225b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2024 License: OSL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Help = &dgc.Command{
	Name:        "help",
	Aliases:     []string{"help", "h", "?", "cmds", "commands", "cmd", "command"},
	Category:    "Bot",
	Description: "Show all commands or help for a command",
	Usage:       "help [command]",
	Domain:      "astral.bot.help",
	Example:     "help",
	Handler: func(ctx *dgc.Ctx) {
		embed := discordgo.MessageEmbed{}
		if ctx.Arguments.Amount() == 0 {
			embed.Title = "Command List"

			categories := make(map[string][]dgc.Command)
			for _, command := range ctx.Router.Commands {
				if command.Category != "" {
					categories[command.Category] = append(categories[command.Category], *command)
				}
			}

			for category, commands := range categories {

				field := discordgo.MessageEmbedField{
					Name:   category,
					Value:  "",
					Inline: false,
				}

				for _, command := range commands {

					field.Value += "`" + command.Name + "` "
				}

				embed.Fields = append(embed.Fields, &field)
			}

			ctx.ReplyEmbed(utils.GenerateEmbed(*ctx, embed))
			return
		}

		command := ctx.Router.GetCmd(ctx.Arguments.Get(0).Raw())

		if command == nil {
			ctx.ReplyEmbed(utils.GenerateEmbed(*ctx, discordgo.MessageEmbed{
				Title:       "Command Not Found",
				Color:       0xff0000,
				Description: "The command `" + ctx.Arguments.Get(0).Raw() + "` was not found.",
			}))
			return
		}

		embed.Title = "Command: " + command.Name
		embed.Fields = []*discordgo.MessageEmbedField{
			{
				Name:  "Aliases",
				Value: "`" + strings.Join(command.Aliases, "` `") + "`",
			},
			{
				Name:   "Category",
				Value:  command.Category,
				Inline: true,
			},
			{
				Name:   "Domain",
				Value:  "`" + command.Domain + "`",
				Inline: true,
			},
			{
				Name:   "Description",
				Value:  command.Description,
				Inline: false,
			},
			{
				Name:   "Usage",
				Value:  "`" + command.Usage + "`",
				Inline: false,
			},
			{
				Name:   "Example",
				Value:  "`" + command.Example + "`",
				Inline: false,
			},
		}

		ctx.ReplyEmbed(utils.GenerateEmbed(*ctx, embed))
	},
}
View Source
var Info = &dgc.Command{
	Name:        "info",
	Description: "Get information about the bot.",
	Usage:       "info",
	Category:    "Bot",
	Aliases:     []string{"info", "i", "about"},
	Domain:      "astral.bot.info",
	Example:     "info",
	Handler: func(ctx *dgc.Ctx) {
		mu := utils.GetMemoryUsage()
		uptime, err := uptime.Get()
		if err != nil {
			ctx.ReplyEmbed(utils.GenerateEmbed(*ctx, discordgo.MessageEmbed{
				Title:       "Error",
				Color:       0xff0000,
				Description: "Unable to get uptime information.",
			}))
			return
		}

		isWindows := runtime.GOOS == "windows"
		cpu, err := cpu.Get()
		if err != nil && !isWindows {
			ctx.ReplyEmbed(utils.GenerateEmbed(*ctx, discordgo.MessageEmbed{
				Title:       "Error",
				Color:       0xff0000,
				Description: "Unable to get CPU information.",
			}))
			return
		}

		var cpuString string
		if isWindows {
			cpuString = "N/A"
		} else {
			cpuString = fmt.Sprintf("**Usage:** %.2f%%", float64(cpu.User)/1024/1024)
		}

		self := ctx.CustomObjects.MustGet("self").(types.Bot)

		embed := discordgo.MessageEmbed{}
		embed.Title = "Bot Information"
		embed.Description = "This bot is running via [Astral](https://astralapp.io/).\n\nFramework: DiscordGo v" + discordgo.VERSION
		embed.Fields = []*discordgo.MessageEmbedField{
			{
				Name:  "Region",
				Value: "Fetching...",
			},
			{
				Name:  "Bot ID",
				Value: fmt.Sprintf("`%s`", *self.ID),
			},
			{
				Name:  "Version",
				Value: constants.VERSION,
			},
			{
				Name:  "Developers",
				Value: "AmusedGrape#0001",
			},
			{
				Name:  "Server",
				Value: os.Getenv("SERVER"),
			},
			{
				Name:  "Memory Usage",
				Value: "**Used**: " + mu.Allocated + "\n**Total**: " + mu.Sys,
			},
			{
				Name:  "CPU Usage",
				Value: cpuString,
			},
			{
				Name:  "Uptime",
				Value: uptime.String(),
			},
		}
		err = ctx.ReplyEmbed(utils.GenerateEmbed(*ctx, embed))

		if err != nil {
			utils.ErrorHandler(err)
			return
		}

		database := db.New()

		var regionName string

		if self.Region == "" {
			regionName = "Unknown"
		} else {
			r, err := database.GetRegion(self.Region)

			if err != nil {
				utils.ErrorHandler(err)
				regionName = "Error Fetching Region"
			} else {
				regionName = r.Flag + " " + strings.ToUpper(strings.Split(r.ID, ".")[0]) + " (" + r.City + ", " + r.Region + ", " + r.Country + ")"
			}
		}

		embed.Fields[0].Value = regionName

		_, err = ctx.Session.ChannelMessageEditEmbed(ctx.Message.ChannelID, ctx.Message.ID, utils.GenerateEmbed(*ctx, embed))
		if err != nil {
			utils.ErrorHandler(err)
		}
	},
}
View Source
var Ping = &dgc.Command{
	Name:        "ping",
	Domain:      "astral.bot.ping",
	Aliases:     []string{"ping", "p"},
	Description: "Retrieves the bot's API and gateway latency to Discord's servers.",
	Category:    "Bot",
	Usage:       "ping",
	Slash:       true,
	SlashGuilds: []string{os.Getenv("DEV_GUILD")},
	Handler: func(ctx *dgc.Ctx) {
		start := time.Now()

		err := ctx.ReplyEmbed(utils.GenerateEmbed(*ctx, discordgo.MessageEmbed{
			Title: "Pinging...",
			Color: 0xffff00,
		}))

		if err != nil {
			utils.ErrorHandler(err)
		}

		end := time.Now()
		diff := end.Sub(start)

		_, err = ctx.Session.ChannelMessageEditEmbed(ctx.Message.ChannelID, ctx.Message.ID, utils.GenerateEmbed(*ctx, discordgo.MessageEmbed{
			Title:       "Pong!",
			Description: fmt.Sprintf(":ping_pong: Gateway Ping: `%dms`\n:desktop: API Ping: `%dms`", ctx.Session.HeartbeatLatency().Milliseconds(), diff.Milliseconds()),
			Color:       0x00ff00,
			Fields: []*discordgo.MessageEmbedField{
				{
					Name:  "Region",
					Value: "Fetching...",
				},
			},
		}))

		if err != nil {
			utils.ErrorHandler(err)
		}

		database := db.New()

		self := ctx.CustomObjects.MustGet("self").(types.Bot)

		var regionName string

		if self.Region == "" {
			regionName = "Unknown"
		} else {
			r, err := database.GetRegion(self.Region)

			if err != nil {
				utils.ErrorHandler(err)
				regionName = "Error Fetching Region"
			} else {
				regionName = r.Flag + " " + strings.ToUpper(strings.Split(r.ID, ".")[0]) + " (" + r.City + ", " + r.Region + ", " + r.Country + ")"
			}
		}

		_, err = ctx.Session.ChannelMessageEditEmbed(ctx.Message.ChannelID, ctx.Message.ID, utils.GenerateEmbed(*ctx, discordgo.MessageEmbed{
			Title:       "Pong!",
			Description: fmt.Sprintf(":ping_pong: Gateway Ping: `%dms`\n:desktop: API Ping: `%dms`", ctx.Session.HeartbeatLatency().Milliseconds(), diff.Milliseconds()),
			Color:       0x00ff00,
			Fields: []*discordgo.MessageEmbedField{
				{
					Name:  "Region",
					Value: regionName,
				},
			},
		}))

		if err != nil {
			utils.ErrorHandler(err)
		}
	},
}
View Source
var Region = &dgc.Command{
	Name:        "region",
	Domain:      "astral.bot.region",
	Aliases:     []string{"region", "r"},
	Description: "Retrieves the bot's region, or fetches a provided one.",
	Category:    "Bot",
	Usage:       "region [bot]",
	Slash:       true,
	SlashGuilds: []string{os.Getenv("DEV_GUILD")},
	Handler: func(ctx *dgc.Ctx) {
		database := db.New()

		self := ctx.CustomObjects.MustGet("self").(types.Bot)

		var region types.Region

		err := ctx.ReplyEmbed(utils.GenerateEmbed(*ctx, discordgo.MessageEmbed{
			Title: "Fetching region...",
			Color: 0xffff00,
		}))

		if err != nil {
			utils.ErrorHandler(err)
		}

		if ctx.Arguments.Amount() == 0 {
			r, err := database.GetRegion(self.Region)

			if err != nil {
				ctx.ReplyEmbed(utils.GenerateEmbed(*ctx, discordgo.MessageEmbed{
					Title:       "Error",
					Description: "An error occurred while fetching the region.",
					Color:       0xff0000,
				}))
				return
			}

			region = r
		} else {
			r, err := database.GetRegion(ctx.Arguments.Get(0).Raw())

			if err != nil {
				ctx.ReplyEmbed(utils.GenerateEmbed(*ctx, discordgo.MessageEmbed{
					Title:       "Region Not Found",
					Description: "The region you provided was not found.",
					Color:       0xff0000,
				}))

				return
			}

			region = r
		}

		_, err = ctx.Session.ChannelMessageEditEmbed(ctx.Message.ChannelID, ctx.Message.ID, utils.GenerateEmbed(*ctx, discordgo.MessageEmbed{
			Title: "Region Info for " + region.Flag + " `" + region.ID + "`",
			Color: 0x00ff00,
			Fields: []*discordgo.MessageEmbedField{
				{
					Name:  "Location",
					Value: fmt.Sprintf("%s, %s, %s", region.City, region.Region, region.Country),
				},
			},
		}))

		if err != nil {
			utils.ErrorHandler(err)
		}
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL