simpleembed

package
v1.32.2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &commands.YAGCommand{
	CmdCategory:         commands.CategoryFun,
	Name:                "SimpleEmbed",
	Aliases:             []string{"se"},
	Description:         "A more simpler version of CustomEmbed, controlled completely using switches.",
	RequireDiscordPerms: []int64{discordgo.PermissionManageMessages},
	ArgSwitches: []*dcmd.ArgDef{
		{Name: "channel", Help: "Optional channel to send in", Type: dcmd.Channel},
		{Name: "content", Help: "Text content for the message", Type: dcmd.String, Default: ""},

		{Name: "title", Type: dcmd.String, Default: ""},
		{Name: "desc", Type: dcmd.String, Help: "Text in the 'description' field", Default: ""},
		{Name: "color", Help: "Either hex code or name", Type: dcmd.String, Default: ""},
		{Name: "url", Help: "Url of this embed", Type: dcmd.String, Default: ""},
		{Name: "thumbnail", Help: "Url to a thumbnail", Type: dcmd.String, Default: ""},
		{Name: "image", Help: "Url to an image", Type: dcmd.String, Default: ""},

		{Name: "author", Help: "The text in the 'author' field", Type: dcmd.String, Default: ""},
		{Name: "authoricon", Help: "Url to a icon for the 'author' field", Type: dcmd.String, Default: ""},
		{Name: "authorurl", Help: "Url of the 'author' field", Type: dcmd.String, Default: ""},

		{Name: "footer", Help: "Text content for the footer", Type: dcmd.String, Default: ""},
		{Name: "footericon", Help: "Url to a icon for the 'footer' field", Type: dcmd.String, Default: ""},
	},
	SlashCommandEnabled: true,
	RunFunc: func(data *dcmd.Data) (interface{}, error) {
		content := data.Switch("content").Str()
		embed := &discordgo.MessageEmbed{
			Title:       data.Switch("title").Str(),
			Description: data.Switch("desc").Str(),
			URL:         data.Switch("url").Str(),
		}

		if color := data.Switch("color").Str(); color != "" {
			parsedColor, ok := ParseColor(color)
			if !ok {
				return "Unknown color: " + color + ", can be either hex color code or name for a known color", nil
			}

			embed.Color = parsedColor
		}

		if author := data.Switch("author").Str(); author != "" {
			embed.Author = &discordgo.MessageEmbedAuthor{
				Name:    author,
				IconURL: data.Switch("authoricon").Str(),
				URL:     data.Switch("authorurl").Str(),
			}
		}

		if thumbnail := data.Switch("thumbnail").Str(); thumbnail != "" {
			embed.Thumbnail = &discordgo.MessageEmbedThumbnail{
				URL: thumbnail,
			}
		}

		if image := data.Switch("image").Str(); image != "" {
			embed.Image = &discordgo.MessageEmbedImage{
				URL: image,
			}
		}

		footer := data.Switch("footer").Str()
		footerIcon := data.Switch("footericon").Str()
		if footer != "" || footerIcon != "" {
			embed.Footer = &discordgo.MessageEmbedFooter{
				Text:    footer,
				IconURL: footerIcon,
			}
		}

		cID := data.ChannelID
		c := data.Switch("channel")
		if c.Value != nil {
			cID = c.Value.(*dstate.ChannelState).ID

			hasPerms, err := bot.AdminOrPermMS(data.GuildData.GS.ID, cID, data.GuildData.MS, discordgo.PermissionSendMessages|discordgo.PermissionReadMessages)
			if err != nil {
				return "Failed checking permissions, please try again or join the support server.", err
			}

			if !hasPerms {
				return "You do not have permissions to send messages there", nil
			}
		}

		messageSend := &discordgo.MessageSend{
			Content:         content,
			Embed:           embed,
			AllowedMentions: discordgo.AllowedMentions{},
		}
		_, err := common.BotSession.ChannelMessageSendComplex(cID, messageSend)
		if err != nil {
			return err, err
		}

		if cID != data.ChannelID {
			return "Done", nil
		}

		return nil, nil
	},
}

Functions

func ParseColor

func ParseColor(raw string) (int, bool)

Types

This section is empty.

Jump to

Keyboard shortcuts

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