Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
62 lines (54 sloc) 2.1 KB
#! ========================================
#! Purge
handler = (msg, match, Haruka) ->
args = match.input.tokenize()[1]
# First, check if the user can even delete messages
allowed = (
if not allowed then return [
"You don’t have permission to manage messages
in this channel, #{}."
"#{}, You can’t do that, you don’t have permissions to do so."
"Sorry #{}, but you’re not allowed to delete messages."
# 2nd, check if quantity was specified and if it's within 0 and 100
if not args then return msg.reply [
"Please specify the amount of messages to purge."
"You didn’t specify how many messages to delete."
"How many messages do you want me to delete?"
amount = parseInt(args)
if not (1 <= amount <= 100) then return msg.reply [
"The amount specified must be a positive integer less than 100."
"The amount of messages to delete must be a number greater than
0 and less than or equal to 100."
].choose() amount)
.then (msgs) -> msgs
.then -> [
"#{}, I deleted #{amount} messages."
"#{}, Deleted #{amount} messages successfully."
"Purged #{amount} messages as requested by #{}"
.catch (err) -> "Failed to delete messages: \n```\n#{err}\n```"
module.exports = {
name: "Purge"
regex: /^(purge|delete)(\s+|$)/i
handler: handler
short: "-h purge <n> ::
Deletes messages in bulk."
long: """
=== Help for Purge ===
*Aliases*: purge, delete
-h purge <amount> :: Deletes specified amount of \
messages in that channel.
*Note:* Both you and I must have permission to delete messages.
You can’t perform that action at this time.