mirror of
https://github.com/myned/modufur.git
synced 2025-01-19 22:25:20 +00:00
Add purge user from channel command
This commit is contained in:
parent
09c09199bd
commit
e2bc1e650b
1 changed files with 51 additions and 0 deletions
|
@ -38,6 +38,57 @@ class Administration:
|
||||||
async def _prune_user(self, ctx):
|
async def _prune_user(self, ctx):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@_prune_user.command(name='channel', aliases=['channels', 'chans', 'chan', 'ch', 'c'])
|
||||||
|
async def _prune_user_channel(self, ctx, user: d.User, *channels: d.TextChannel):
|
||||||
|
def confirm(r, u):
|
||||||
|
if u is ctx.author:
|
||||||
|
if r.emoji == '\N{OCTAGONAL SIGN}':
|
||||||
|
raise exc.Abort
|
||||||
|
if r.emoji == '\N{THUMBS UP SIGN}':
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not channels:
|
||||||
|
channels = [ctx.channel]
|
||||||
|
|
||||||
|
try:
|
||||||
|
pruning = await ctx.send(f'\N{HOURGLASS} **Pruning** {user.mention}**\'s messages from** {"**,** ".join([channel.mention for channel in channels])} **might take some time.** Proceed, {ctx.author.mention}?')
|
||||||
|
await pruning.add_reaction('\N{THUMBS UP SIGN}')
|
||||||
|
await pruning.add_reaction('\N{OCTAGONAL SIGN}')
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
await self.bot.wait_for('reaction_add', check=confirm, timeout=10 * 60)
|
||||||
|
|
||||||
|
deleting = await ctx.send(f'\N{WASTEBASKET} **Deleting** {user.mention}**\'s messages...**')
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
c = 0
|
||||||
|
for channel in channels:
|
||||||
|
await deleting.edit(content=f'\N{WASTEBASKET} **Deleting** {user.mention}**\'s messages from** {channel.mention}')
|
||||||
|
|
||||||
|
deleted = await channel.purge(check=lambda m: m.author.id == user.id, before=pruning, limit=None)
|
||||||
|
c += len(deleted)
|
||||||
|
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
for channel in channels:
|
||||||
|
missed = 0
|
||||||
|
async for message in channel.history(before=pruning, limit=None):
|
||||||
|
if message.author.id == user.id:
|
||||||
|
missed += 1
|
||||||
|
|
||||||
|
if missed > 0:
|
||||||
|
await ctx.send(f'\N{DOUBLE EXCLAMATION MARK} `{missed}` **messages were not deleted in** {channel.mention}')
|
||||||
|
|
||||||
|
await ctx.send(f'\N{WHITE HEAVY CHECK MARK} **Finished deleting** `{c}` **of** {user.mention}**\'s messages**')
|
||||||
|
|
||||||
|
except exc.Abort:
|
||||||
|
await ctx.send('**Deletion aborted**', delete_after=7)
|
||||||
|
await ctx.message.add_reaction('\N{CROSS MARK}')
|
||||||
|
except TimeoutError:
|
||||||
|
await ctx.send('**Deletion timed out**', delete_after=7)
|
||||||
|
await ctx.message.add_reaction('\N{CROSS MARK}')
|
||||||
|
|
||||||
@_prune_user.command(name='all', aliases=['a'], brief='Prune a user\'s messages from the guild', description='about flag centers on message 50 of 101 messages\n\npfg \{user id\} [before|after|about] [\{message id\}]\n\nExample:\npfg \{user id\} before \{message id\}', hidden=True)
|
@_prune_user.command(name='all', aliases=['a'], brief='Prune a user\'s messages from the guild', description='about flag centers on message 50 of 101 messages\n\npfg \{user id\} [before|after|about] [\{message id\}]\n\nExample:\npfg \{user id\} before \{message id\}', hidden=True)
|
||||||
@cmds.is_owner()
|
@cmds.is_owner()
|
||||||
async def _prune_user_all(self, ctx, user, when=None, reference=None):
|
async def _prune_user_all(self, ctx, user, when=None, reference=None):
|
||||||
|
|
Loading…
Add table
Reference in a new issue