cleardm

package
v2.37.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 7 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:                 "cleardm",
	Description:          "clears the DM chat with a user, owner only command.",
	HideFromHelp:         true,
	RequiredArgs:         1,
	Arguments: []*dcmd.ArgDef{
		{Name: "Target", Type: dcmd.User},
	},
	RunFunc: util.RequireOwner(func(data *dcmd.Data) (interface{}, error) {
		var target = data.Args[0].Value.(*discordgo.User)
		dm, err := common.BotSession.UserChannelCreate(target.ID)
		if err != nil {
			logrus.WithError(err).Errorf("Failed to get DM channel for user %d", target.ID)
			return nil, err
		}
		messages, err := common.BotSession.ChannelMessages(dm.ID, 100, 0, 0, 0)
		if err != nil {
			logrus.WithError(err).Errorf("Failed to get DM messages for user %d", target.ID)
			return nil, err
		}
		if len(messages) == 0 {
			return "No messages found", nil
		}
		count := 0
		for _, message := range messages {
			if message.Author.ID == common.BotUser.ID {
				err = common.BotSession.ChannelMessageDelete(dm.ID, message.ID)
				if err != nil {
					logrus.WithError(err).Errorf("Failed to delete DM messages for user %d", target.ID)
				} else {
					count++
				}
			}
		}
		return fmt.Sprintf("Deleted %d messages for %s in DMs", count, target.Mention()), 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