exportcustomcommands

package
v1.31.14 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &commands.YAGCommand{
	Cooldown:             2,
	CmdCategory:          commands.CategoryDebug,
	HideFromCommandsPage: true,
	Name:                 "exportcustomscommands",
	Aliases:              []string{"exportccs", "eccs"},
	RequireDiscordPerms:  []int64{discordgo.PermissionAdministrator},
	Description:          "Exports all your custom commands data's reasonable fields as JSON,\nuser has to be serverAdmin.\nServerID argument is for the owner of the bot...",
	HideFromHelp:         true,
	Arguments: []*dcmd.ArgDef{
		{Name: "ServerID", Type: dcmd.Int},
	},
	ArgSwitches: []*dcmd.ArgDef{
		{Name: "csv", Help: "Export to CSV with TAB as delimiter"},
	},
	RunFunc: func(data *dcmd.Data) (interface{}, error) {
		guildIDToMatch := data.GuildData.GS.ID
		if data.Args[0].Value != nil {
			if common.IsOwner(data.Author.ID) {
				guildIDToMatch = data.Args[0].Int64()
			} else {
				return "Only for owner of the bot", nil
			}

		}
		var exportCSV bool
		if data.Switches["csv"].Value != nil && data.Switches["csv"].Value.(bool) {
			exportCSV = true
		}

		result, err := dbQuery(guildIDToMatch)
		if err != nil {
			return nil, err
		}
		if result != nil {
			send := &discordgo.MessageSend{Content: "Custom Commands Export"}
			if exportCSV {
				in := fmt.Sprintln("GuildID\tCCID\tGroupName\tTriggerType\tTextTrigger\tResponses")
				for _, r := range result {
					in += fmt.Sprintf("%s\t%s\t%s\t%s\t%s\t%s\n", r.GuildID, r.CCID, r.GroupName, r.TriggerType, r.TextTrigger, strings.ReplaceAll(strings.ReplaceAll(r.Responses, "\r\n", " "), "\t", " "))
				}
				send.File = &discordgo.File{
					ContentType: "text/csv",
					Name:        fmt.Sprintf("custom_commands_%d.csv", data.GuildData.GS.ID),
					Reader:      strings.NewReader(in),
				}
			} else {
				buf, _ := json.Marshal(result)
				send.File = &discordgo.File{
					ContentType: "application/json",
					Name:        fmt.Sprintf("custom_commands_%d.json", data.GuildData.GS.ID),
					Reader:      bytes.NewReader(buf),
				}
			}

			_, err = common.BotSession.ChannelMessageSendComplex(data.ChannelID, send)
			return nil, err
		}

		return fmt.Sprintf("No CCs found."), err
	},
}

Functions

This section is empty.

Types

type ExportCC

type ExportCC struct {
	GuildID     string `json:"GuildID"`
	CCID        string `json:"CCID"`
	GroupName   string `json:"GroupName"`
	TriggerType string `json:"TriggerType"`
	TextTrigger string `json:"TextTrigger"`
	Responses   string `json:"Responses"`
}

Jump to

Keyboard shortcuts

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