-
Notifications
You must be signed in to change notification settings - Fork 1
/
web.py
117 lines (95 loc) · 4.41 KB
/
web.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import discord
from discord.ext import commands
import itertools
import asyncio
import os
token = os.getenv("BOT_TOKEN")
staff_role_id = int(os.getenv("BOT_STAFF_ID"))
prefix = os.getenv("BOT_PREFIX")
description = '''A raid managment bot'''
intents = discord.Intents.default()
intents.members = True
allowed_mentions = discord.AllowedMentions.none()
bot = commands.Bot(command_prefix=prefix, description=description, intents=intents, allowed_mentions=allowed_mentions)
bot.remove_command("help")
whitelist = []
class Confirm(discord.ui.View):
def __init__(self, author_id : int):
super().__init__()
self.author_id = author_id
self.value = None
@discord.ui.button(label="Ban Users", style=discord.ButtonStyle.green)
async def confirm(self, button: discord.ui.Button, interaction: discord.Interaction):
if interaction.user.id != self.author_id:
return await interaction.response.send_message("You cannot use this button", ephemeral=True)
await interaction.response.send_message('Banning...', ephemeral=True)
self.value = True
self.stop()
# This one is similar to the confirmation button except sets the inner value to `False`
@discord.ui.button(label='Cancel', style=discord.ButtonStyle.grey)
async def cancel(self, button: discord.ui.Button, interaction: discord.Interaction):
if interaction.user.id != self.author_id:
return await interaction.response.send_message("You cannot use this button", ephemeral=True)
await interaction.response.send_message('Cancelled', ephemeral=False)
self.value = False
self.stop()
@bot.event
async def on_ready():
print(f"Logged in as {bot.user} (ID: {bot.user.id})")
print("------")
@commands.check_any(commands.has_role(staff_role_id), commands.has_permissions(ban_members=True))
@bot.command()
async def ping(ctx):
"""Gets bot ping"""
await ctx.send("Pong :ping_pong:")
@commands.check_any(commands.has_role(staff_role_id), commands.has_permissions(ban_members=True))
@bot.command(name="whitelist")
async def _whitelist(ctx, member: discord.Member):
"""Whistlists a user"""
whitelist.append(member.id)
await ctx.send(f":white_check_mark: `{member}` has been whitelisted.")
# util function
def grouper(n, iterable):
it = iter(iterable)
while True:
chunk = tuple(itertools.islice(it, n))
if not chunk:
return
yield chunk
@commands.check_any(commands.has_role(staff_role_id), commands.has_permissions(ban_members=True))
@bot.command()
async def mass_ban(ctx, starting_member: discord.Member, ending_member: discord.Member):
"""Bans a large amount of members"""
msg = await ctx.send("Caching users, please wait")
await ctx.guild.chunk()
await ctx.send("Caching complete, compiling user list")
watchlist = []
for member in ctx.guild.members:
if (starting_member.joined_at <= member.joined_at <= ending_member.joined_at) and member.id not in whitelist:
watchlist.append(member)
await ctx.send("Watchlist compiled")
watchlist_info_message = f"Watchlist info:\n The watchlist contains **{len(watchlist)}** users.\n"+"\n".join([f"`{x.name} ({x.id})`" for x in watchlist])+"\n"
view = Confirm(author_id = ctx.author.id)
for chunk in [watchlist_info_message[i:i+4000 ] for i in range(0, len(watchlist_info_message), 4000 )]:
await ctx.send(embed=discord.Embed(description=chunk, color=discord.Color.blurple()))
await ctx.send(f"**To ban all of these users, click the green `Ban Users` button. You have 30 seconds.**", view=view)
await view.wait()
if view.value is None:
await ctx.send("Buttons timed out")
elif view.value == False:
return # already handled in the view
if view.value == True:
await ctx.send(f"Ban wave started by {ctx.author} ({ctx.author.id})")
for chunk in grouper(5, watchlist):
await asyncio.gather(*[x.ban(reason=f"Mass ban by {ctx.author} ({ctx.author.id})") for x in chunk])
await ctx.send(f":white_check_mark: **Banned {len(watchlist)} users**")
@bot.event
async def on_command_error(ctx, error):
if isinstance(error,commands.MemberNotFound):
await ctx.send("`I could not find one or more users that you provided`")
elif isinstance(error,commands.CommandNotFound):
return
else:
await ctx.send(str(error))
bot.load_extension("jishaku")
bot.run(token)