Skip to content

Commit d3da512

Browse files
committed
KTBPA: Add loadban command
Ex: `.loadban 10m` bans everyone who joined the guild in the last 10 minutes
1 parent ee00088 commit d3da512

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

ktbpa/ktbpa.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11

2-
from redbot.core import commands
2+
from datetime import datetime, timedelta
3+
4+
from redbot.core import checks, commands
35

46

57
class Ktbpa(commands.Cog):
@@ -31,5 +33,23 @@ async def whoami(self, ctx):
3133
else:
3234
return await ctx.send("%s. Role: %s." % (who.display_name, role.name))
3335

36+
@commands.command()
37+
@commands.guild_only()
38+
@checks.mod_or_permissions(ban_members=True)
39+
@checks.bot_has_permissions(ban_members=True)
40+
async def loadban(self, ctx, period: commands.converter.TimedeltaConverter):
41+
"""Bans everyone who joined the guild in the given time before now."""
42+
limiter = timedelta(hours=12)
43+
if period > limiter:
44+
await ctx.send(f"Error: Loadban can only be used for up to {limiter.seconds / 3600} hours.")
45+
else:
46+
banned = []
47+
async for member in ctx.guild.fetch_members(after=(datetime.now() - period)):
48+
if len([role for role in member.roles if role != ctx.guild.default_role]) == 0:
49+
banned.append(str(member.id))
50+
await member.ban(reason="Loadban", delete_message_days=1)
51+
52+
await ctx.send(f"Banned {len(banned)} users: {', '.join(banned)}")
53+
3454
def cog_unload(self):
3555
self.bot.remove_listener(self.on_message, 'on_message')

0 commit comments

Comments
 (0)