Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds basic raid protection. #610

Merged
merged 7 commits into from
Jan 27, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions cdbot/cogs/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re

from discord import AuditLogAction, Member
from discord.ext.commands import Bot, Cog
from discord import AuditLogAction, Member, Embed, Colour
from discord.ext.commands import Bot, Cog, Context, command, has_role

from cdbot.constants import (
ADMIN_MENTOR_ROLE_ID,
Expand All @@ -10,6 +10,8 @@
NICKNAME_PATTERNS,
PLACEHOLDER_NICKNAME,
STATIC_NICKNAME_ROLE_ID,
ROOT_ROLE_ID,
LOGGING_CHANNEL_ID,
)


Expand Down Expand Up @@ -89,6 +91,50 @@ async def on_member_join(self, member: Member):
# assign placeholder nickname
await member.edit(nick=PLACEHOLDER_NICKNAME)

@command()
@has_role(ROOT_ROLE_ID)
Sh3llcod3 marked this conversation as resolved.
Show resolved Hide resolved
async def raidprotect(
self,
ctx: Context
):
"""
Allows an admin user to lock down the server in case of a raid.
This command toggles invite link generation for @everyone and
revokes all existing invite links.
"""
everyone = ctx.channel.guild.default_role
perms = everyone.permissions
logs_channel = self.bot.get_channel(LOGGING_CHANNEL_ID)

if perms.create_instant_invite:
perms.update(create_instant_invite=False)
raidon = 1
else:
perms.update(create_instant_invite=True)
raidon = 0

msgpart = ("OFF", "ON")
msg = f"Toggled raid protection {msgpart[raidon]}."
await everyone.edit(reason=msg, permissions=perms)
await ctx.send(msg, delete_after=10)
embed = Embed(
color=Colour.blue(),
title=f"Raid Protection {msgpart[raidon]}."
)
if raidon:
embed.description = ("Raid protection now ON - All invite "
"links were deleted and members may not "
"create new ones")
else:
embed.description = ("Raid protection now OFF - Members can now "
"create new invite links")
embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar_url)
await logs_channel.send(embed=embed)

if raidon:
Sh3llcod3 marked this conversation as resolved.
Show resolved Hide resolved
for invite in await ctx.channel.guild.invites():
await invite.delete()


def setup(bot):
bot.add_cog(Admin(bot))