diff options
author | 2018-07-05 18:28:49 +0100 | |
---|---|---|
committer | 2018-07-05 18:28:49 +0100 | |
commit | 67f8a4fe4c04ad8b935908d981031df3732c9616 (patch) | |
tree | 0d45664af68a3341c065fbbd39957836d821e101 | |
parent | [Announcements] Screw it, we don't need to remove the messages (diff) |
Add defcon cog; disable ClickUp
-rw-r--r-- | bot/__main__.py | 9 | ||||
-rw-r--r-- | bot/cogs/defcon.py | 65 |
2 files changed, 70 insertions, 4 deletions
diff --git a/bot/__main__.py b/bot/__main__.py index 8eb40757d..de82e8482 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -56,12 +56,13 @@ bot.load_extension("bot.cogs.cogs") # Local setups usually don't have the clickup key set, # and loading the cog would simply spam errors in the console. -if ClickUp.key is not None: - bot.load_extension("bot.cogs.clickup") -else: - log.info("`CLICKUP_KEY` not set in the environment, not loading the ClickUp cog.") +# if ClickUp.key is not None: +# bot.load_extension("bot.cogs.clickup") +# else: +# log.info("`CLICKUP_KEY` not set in the environment, not loading the ClickUp cog.") bot.load_extension("bot.cogs.deployment") +bot.load_extension("bot.cogs.defcon") bot.load_extension("bot.cogs.doc") bot.load_extension("bot.cogs.eval") bot.load_extension("bot.cogs.fun") diff --git a/bot/cogs/defcon.py b/bot/cogs/defcon.py new file mode 100644 index 000000000..8d20e6461 --- /dev/null +++ b/bot/cogs/defcon.py @@ -0,0 +1,65 @@ +import logging +from datetime import datetime, timedelta + +from discord import Member +from discord.ext.commands import Bot, Context, command + +from bot.constants import Roles, URLs +from bot.decorators import with_role + +log = logging.getLogger(__name__) + +REJECTION_MESSAGE = """ +Hi, {user}! + +Due to a current or pending cyberattack on our community, we have put in place some restrictions on the accounts that +may join the server. We have detected that you are using a relatively new account, so we are unable to provide access +to the server to you at this time. + +Even so, thanks for your interest! We're excited that you'd like to join us, and we hope that this situation will be +resolved soon. In the meantime, please feel free to peruse the resources on our site at <https://pythondiscord.com>, +and have a nice day! +""" + + +class Defcon: + """Time-sensitive server defense mechanisms""" + days = None # type: timedelta + + def __init__(self, bot: Bot): + self.bot = bot + self.days = timedelta(days=0) + + async def on_ready(self): + pass # TODO: Get duration + + async def on_member_join(self, member: Member): + if self.days.days > 0: + now = datetime.utcnow() + + if now - member.created_at < self.days: + log.info(f"Rejecting user {member}: Account is too old and DEFCON is enabled") + + try: + await member.send(REJECTION_MESSAGE.format(user=member.mention)) + except Exception: + log.exception(f"Unable to send rejection message to user: {member}") + + await member.kick(reason="DEFCON active, user is too new") + + @with_role(Roles.admin, Roles.owner) + @command(name="defcon.days", aliases=["defcon.days()", "defcon_days", "defcon_days()"]) + async def days_command(self, ctx: Context, days: int = None): + if not days: + # TODO: Sync with server + self.days = timedelta(days=0) + await ctx.send("DEFCON disabled.") + else: + # TODO: Sync with server + self.days = timedelta(days=days) + await ctx.send(f"DEFCON enabled; accounts must be {days} days old to join to the server") + + +def setup(bot: Bot): + bot.add_cog(Defcon(bot)) + log.info("Cog loaded: Defcon") |