diff options
Diffstat (limited to 'pysite')
| -rw-r--r-- | pysite/constants.py | 48 | ||||
| -rw-r--r-- | pysite/tables.py | 8 | ||||
| -rw-r--r-- | pysite/views/api/bot/clean.py | 48 | ||||
| -rw-r--r-- | pysite/views/main/bot/cleanlog.py | 35 | 
4 files changed, 130 insertions, 9 deletions
diff --git a/pysite/constants.py b/pysite/constants.py index 69c73492..7d8dbf6e 100644 --- a/pysite/constants.py +++ b/pysite/constants.py @@ -31,17 +31,27 @@ class BotEventTypes(Enum):  DEBUG_MODE = "FLASK_DEBUG" in environ  # All snowflakes should be strings as RethinkDB rounds them as ints -OWNER_ROLE = "267627879762755584" -ADMIN_ROLE = "267628507062992896" -MODERATOR_ROLE = "267629731250176001" +ADMIN_BOTS_ROLE = "270988689419665409" +ADMINS_ROLE = "267628507062992896" +ANNOUNCEMENTS_ROLE = "463658397560995840" +BOTS_ROLE = "277546923144249364" +CODE_JAM_CHAMPIONS_ROLE = "430492892331769857" +CONTRIBS_ROLE = "295488872404484098"  DEVOPS_ROLE = "409416496733880320" -HELPER_ROLE = "267630620367257601" -CONTRIB_ROLE = "295488872404484098" +DEVELOPERS_ROLE = "352427296948486144" +HELPERS_ROLE = "267630620367257601"  JAMMERS_ROLE = "423054537079783434" - -ALL_STAFF_ROLES = (OWNER_ROLE, ADMIN_ROLE, MODERATOR_ROLE, DEVOPS_ROLE) -TABLE_MANAGER_ROLES = (OWNER_ROLE, ADMIN_ROLE, DEVOPS_ROLE) -EDITOR_ROLES = ALL_STAFF_ROLES + (HELPER_ROLE, CONTRIB_ROLE) +MODERATORS_ROLE = "267629731250176001" +MUTED_ROLE = "277914926603829249" +OWNERS_ROLE = "267627879762755584" +PARTNERS_ROLE = "323426753857191936" +PYTHON_ROLE = "458226699344019457" +STREAMERS_ROLE = "462650825978806274" +SUBREDDIT_MOD_ROLE = "458226413825294336" + +ALL_STAFF_ROLES = (OWNERS_ROLE, ADMINS_ROLE, MODERATORS_ROLE, DEVOPS_ROLE) +TABLE_MANAGER_ROLES = (OWNERS_ROLE, ADMINS_ROLE, DEVOPS_ROLE) +EDITOR_ROLES = ALL_STAFF_ROLES + (HELPERS_ROLE, CONTRIBS_ROLE)  SERVER_ID = 267624335836053506 @@ -101,6 +111,26 @@ JAM_QUESTION_TYPES = [      "slider"  ] +# Server role colors +ROLE_COLORS = { +    ADMIN_BOTS_ROLE: "#6f9fed", +    ADMINS_ROLE: "#e76e6c", +    BOTS_ROLE: "#6f9fed", +    CODE_JAM_CHAMPIONS_ROLE: "#b108b4", +    CONTRIBS_ROLE: "#55cc6c", +    DEVOPS_ROLE: "#a1d1ff", +    DEVELOPERS_ROLE: "#fcfcfc", +    HELPERS_ROLE: "#e0b000", +    JAMMERS_ROLE: "#258639", +    MODERATORS_ROLE: "#ce3c42", +    MUTED_ROLE: "#fcfcfc", +    OWNERS_ROLE: "#ffa3a1", +    PARTNERS_ROLE: "#b66fed", +    PYTHON_ROLE: "#6f9fed", +    STREAMERS_ROLE: "#833cba", +    SUBREDDIT_MOD_ROLE: "#d897ed", +} +  # CSRF  CSRF = CSRFProtect() diff --git a/pysite/tables.py b/pysite/tables.py index 6eeda60e..65a4db16 100644 --- a/pysite/tables.py +++ b/pysite/tables.py @@ -16,6 +16,14 @@ TABLES = {          ])      ), +    "clean_logs": Table(  # Logs of cleanups done by the clean bot commands +        primary_key="id", +        keys=sorted([ +            "id", +            "log_data" +        ]) +    ), +      "hiphopify": Table(  # Users in hiphop prison          primary_key="user_id",          keys=sorted([ diff --git a/pysite/views/api/bot/clean.py b/pysite/views/api/bot/clean.py new file mode 100644 index 00000000..82d1e735 --- /dev/null +++ b/pysite/views/api/bot/clean.py @@ -0,0 +1,48 @@ +from flask import jsonify +from schema import Schema + +from pysite.base_route import APIView +from pysite.constants import ValidationTypes +from pysite.decorators import api_key, api_params +from pysite.mixins import DBMixin + +POST_SCHEMA = Schema({ +    'log_data': [ +        { +            "author": str, +            "user_id": str, +            "content": str, +            "role_id": str, +            "timestamp": str, +            "embeds": object, +            "attachments": [str], +        } +    ] +}) + + +class CleanView(APIView, DBMixin): +    path = '/bot/clean' +    name = 'bot.clean' +    table_name = 'clean_logs' + +    @api_key +    @api_params(schema=POST_SCHEMA, validation_type=ValidationTypes.json) +    def post(self, data): +        """ +        Receive some log_data from a bulk deletion, +        and store it in the database. + +        Returns an ID which can be used to get the data +        from the /bot/clean_logs/<id> endpoint. +        """ + +        # Insert and return the id to use for GET +        insert = self.db.insert( +            self.table_name, +            { +                "log_data": data["log_data"] +            } +        ) + +        return jsonify({"log_id": insert['generated_keys'][0]}) diff --git a/pysite/views/main/bot/cleanlog.py b/pysite/views/main/bot/cleanlog.py new file mode 100644 index 00000000..9c719b3e --- /dev/null +++ b/pysite/views/main/bot/cleanlog.py @@ -0,0 +1,35 @@ +import logging + +from pysite.base_route import RouteView +from pysite.constants import ALL_STAFF_ROLES, DEVELOPERS_ROLE, ROLE_COLORS +from pysite.decorators import require_roles +from pysite.mixins import DBMixin, OAuthMixin + +log = logging.getLogger(__name__) + + +class CleanLogView(RouteView, DBMixin, OAuthMixin): +    path = "/bot/clean_logs/<log_id>" +    name = "bot.clean_logs" + +    table_name = "clean_logs" +    template = "main/bot/clean_logs.html" + +    @require_roles(ALL_STAFF_ROLES) +    def get(self, log_id): +        """ +        Get the requested clean log and spit it out +        in a beautiful template. +        """ + +        data = self.db.get(self.table_name, log_id) + +        if data is None: +            return "ID could not be found in the database", 404 + +        messages = data["log_data"] + +        for message in messages: +            message['color'] = ROLE_COLORS.get(message['role_id'], ROLE_COLORS[DEVELOPERS_ROLE]) + +        return self.render(self.template, messages=messages)  |