undelete

package
v1.11.4 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &commands.YAGCommand{
	CmdCategory:  commands.CategoryTool,
	Name:         "Undelete",
	Aliases:      []string{"ud"},
	Description:  "Views your recent deleted messages, or all users deleted messages (with \"-a\" and manage messages perm) in this channel",
	RequiredArgs: 0,
	ArgSwitches: []*dcmd.ArgDef{
		{Switch: "a", Name: "all"},
	},
	RunFunc: func(data *dcmd.Data) (interface{}, error) {
		allUsers := data.Switch("a").Value != nil && data.Switch("a").Value.(bool)

		if allUsers {
			perms, err := data.GS.MemberPermissions(true, data.CS.ID, data.Msg.Author.ID)
			if err != nil {
				return nil, err
			}

			if perms&discordgo.PermissionManageMessages != discordgo.PermissionManageMessages {
				return "You need `Manage Messages` permissions to view all users deleted messages", nil
			}
		}

		resp := "Up to 10 last deleted messages (last hour or 12 hours for premium): \n\n"
		numFound := 0

		data.GS.RLock()
		defer data.GS.RUnlock()

		for i := len(data.CS.Messages) - 1; i >= 0 && numFound < 10; i-- {
			msg := data.CS.Messages[i]

			if !msg.Deleted {
				continue
			}

			if !allUsers && msg.Message.Author.ID != data.Msg.Author.ID {
				continue
			}

			precision := common.DurationPrecisionHours
			if time.Since(msg.ParsedCreated) < time.Hour {
				precision = common.DurationPrecisionMinutes
				if time.Since(msg.ParsedCreated) < time.Minute {
					precision = common.DurationPrecisionSeconds
				}
			}

			timeSince := common.HumanizeDuration(precision, time.Since(msg.ParsedCreated))

			resp += fmt.Sprintf("`%s ago (%s)` **%s**#%s: %s\n\n", timeSince, msg.ParsedCreated.UTC().Format(time.ANSIC), msg.Message.Author.Username, msg.Message.Author.Discriminator, msg.Message.ContentWithMentionsReplaced())
			numFound++
		}

		if numFound == 0 {
			resp += "none..."
		}

		return resp, nil
	},
}

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