diff options
| author | 2018-07-18 12:33:32 -0500 | |
|---|---|---|
| committer | 2018-07-18 12:33:32 -0500 | |
| commit | f7161f316b9844321584c126c046196ec5dacd5d (patch) | |
| tree | 85c8dcbcef1bfacde6895ef1f58f340c2b3027c0 | |
| parent | Merge branch 'momo/snekbox-paste' into 'master' (diff) | |
Adds framework for commands and warning command.
| -rw-r--r-- | bot/cogs/moderation.py | 80 | ||||
| -rw-r--r-- | bot/constants.py | 4 |
2 files changed, 84 insertions, 0 deletions
diff --git a/bot/cogs/moderation.py b/bot/cogs/moderation.py new file mode 100644 index 000000000..80712b259 --- /dev/null +++ b/bot/cogs/moderation.py @@ -0,0 +1,80 @@ +import logging +from datetime import datetime, timedelta + +from discord import Colour, Embed, User, utils +from discord.ext.commands import Bot, Context, command + +from bot.constants import Channels, Keys, Roles, URLs +from bot.decorators import with_role + +log = logging.getLogger(__name__) + + +class Defcon: + """ + Rowboat replacement moderation tools. + """ + + def __init__(self, bot: Bot): + self.bot = bot + self.headers = {"X-API-KEY": Keys.site_api} + + + @with_role(Roles.admin, Roles.owner, Roles.moderator) + @command(name="moderation.warn") + async def warn(self, ctx, user: User, reason: str): + """ + Create a warning infraction in the database for a user. + :param user: accepts user mention, ID, etc. + :param reason: Wrap in quotes to make a warning larger than one word. + """ + + try: + response = await self.bot.http_session.put( + URLs.site_infractions, + headers=self.headers, + json={ + "type": "warning", + "reason": reason, + "user_id": str(user.id), + "actor_id": str(ctx.message.author.id) + } + ) + except Exception: + # Same as defcon. Probably not the best but may work for now. + log.Exception("There was an error adding an infraction.") + await ctx.send("There was an error updating the site.") + return + + await ctx.send("Warning added.") + + @with_role(Roles.admin, Roles.owner, Roles.moderator) + @command(name="moderation.ban") + async def ban(self, ctx, user: User, reason: str, duration: str=None): + """ + Create a banning infraction in the database for a user. + :param user: Accepts user mention, ID, etc. + :param reason: Wrap in quotes to make reason larger than one word. + :param duration: Accepts #d, #h, #m, and #s. + """ + + @with_role(Roles.admin, Roles.owner, Roles.moderator) + @command(name="moderation.mute") + async def mute(self, ctx, user: User, reason: str, duration: str=None): + """ + Create a muting infraction in the database for a user. + :param user: Accepts user mention, ID, etc. + :param reason: Wrap in quotes to make reason larger than one word. + :param duration: Accepts #d, #h, #m, and #s. + """ + + + + + +def setup(bot): + bot.add_cog(Moderation(bot)) + # Here we'll need to call a command I haven't made yet + # It'll check the expiry queue and automatically set up tasks for + # temporary bans, mutes, etc. + log.info("Cog loaded: Moderation") diff --git a/bot/constants.py b/bot/constants.py index 17ec1779e..4c7a7f09d 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -262,6 +262,10 @@ class URLs(metaclass=YAMLGetter): site_tags_api: str site_user_api: str site_user_complete_api: str + site_infractions: str + site_infractions_user: str + site_infractions_types: str + site_infractions_by_id: str status: str paste_service: str |