Commit 62aa786e authored by Jeremy Pallats's avatar Jeremy Pallats 💬
Browse files

FIX #110: Improve Admin Rules

- Allow adding rules for cmd and channel/role combos in bulk.
- Add command to show existing rules.
- Change commands to be checked against their parsed name rather than
  internal class name.
parent f02b7203
Loading
Loading
Loading
Loading
Loading
+33 −20
Original line number Diff line number Diff line
@@ -149,12 +149,19 @@ class Admin(Action):
    """
    def check_cmd(self):
        """ Sanity check that cmd exists. """
        cmd_set = sorted([cls.__name__ for cls in cog.actions.Action.__subclasses__()]
                         + ['Snipe', 'SnipeHold'])
        cmd_set.remove('Admin')  # Admin cannot be restricted even by admins
        if not self.args.rule_cmd or self.args.rule_cmd not in cmd_set:
            raise cog.exc.InvalidCommandArgs("Rules require a command in following set: \n\n%s"
                                             % str(cmd_set))
        self.args.rule_cmds = [x.replace(',', '') for x in self.args.rule_cmds]
        cmd_set = set(cog.parse.CMD_MAP.values())
        cmd_set.remove('admin')
        not_found = set(self.args.rule_cmds) - cmd_set
        if not self.args.rule_cmds or len(not_found) != 0:
            msg = """Rules require a command in following set:

            {cmds}

            The following were not matched:
            {not_found}
            """.format(cmds=str(sorted(list(cmd_set))), not_found=', '.join(list(not_found)))
            raise cog.exc.InvalidCommandArgs(msg)

    async def add(self):
        """
@@ -163,7 +170,7 @@ class Admin(Action):
            2) Add a single channel rule
            3) Add a single role rule
        """
        if not self.args.rule_cmd and self.msg.mentions:
        if not self.args.rule_cmds and self.msg.mentions:
            for member in self.msg.mentions:
                cogdb.query.add_admin(self.session, member)
            response = "Admins added:\n\n" + '\n'.join([member.name for member in self.msg.mentions])
@@ -172,15 +179,15 @@ class Admin(Action):
            self.check_cmd()

            if self.msg.channel_mentions:
                cogdb.query.add_channel_perm(self.session, self.args.rule_cmd,
                cogdb.query.add_channel_perms(self.session, self.args.rule_cmds,
                                              self.msg.channel.guild,
                                             self.msg.channel_mentions[0])
                                              self.msg.channel_mentions)
                response = "Channel permission added."

            else:
                cogdb.query.add_role_perm(self.session, self.args.rule_cmd,
                cogdb.query.add_role_perms(self.session, self.args.rule_cmds,
                                           self.msg.channel.guild,
                                          self.msg.role_mentions[0])
                                           self.msg.role_mentions)
                response = "Role permission added."

        return response
@@ -192,7 +199,7 @@ class Admin(Action):
            2) Remove a single channel rule
            3) Remove a single role rule
        """
        if not self.args.rule_cmd and self.msg.mentions:
        if not self.args.rule_cmds and self.msg.mentions:
            for member in self.msg.mentions:
                admin.remove(self.session, cogdb.query.get_admin(self.session, member))
            response = "Admins removed:\n\n" + '\n'.join([member.name for member in self.msg.mentions])
@@ -201,19 +208,25 @@ class Admin(Action):
            self.check_cmd()

            if self.msg.channel_mentions:
                cogdb.query.remove_channel_perm(self.session, self.args.rule_cmd,
                cogdb.query.remove_channel_perms(self.session, self.args.rule_cmds,
                                                 self.msg.channel.guild,
                                                self.msg.channel_mentions[0])
                                                 self.msg.channel_mentions)
                response = "Channel permission removed."

            else:
                cogdb.query.remove_role_perm(self.session, self.args.rule_cmd,
                cogdb.query.remove_role_perms(self.session, self.args.rule_cmds,
                                              self.msg.channel.guild,
                                             self.msg.role_mentions[0])
                                              self.msg.role_mentions)
                response = "Role permission removed."

        return response

    async def show_rules(self):
        """
        Show all rules currently in effect for the guild.
        """
        return cogdb.query.show_guild_perms(self.session, self.msg.guild)

    async def active(self):  # pragma: no cover
        """
        Analyze the activity of users going back months for the mentioned channels.
+32 −4
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ import cog.util
from cogdb.schema import EUMSheet

PARSERS = []
CMD_MAP = {}  # Maps the command names in either direction.


class ThrowArggumentParser(argparse.ArgumentParser):
@@ -71,6 +72,8 @@ def subs_admin(subs, prefix):
        Whitelist bgs command for members with role mentioned FRC Member.
**{prefix}admin remove Drop FRC Member**
        Remove whitelist for bgs command of users with role "FRC Member".
**{prefix}admin show_rules**
        Show all active rules limiting commands.
**{prefix}admin active -d 90 #hudson_operations #hudson_bgs**
        Generate an activity report on cmdrs in listed channels,
        look back over last 90 days of messages.
@@ -99,14 +102,14 @@ def subs_admin(subs, prefix):
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'admin', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='Admin')
    CMD_MAP['Admin'] = 'admin'
    subcmds = sub.add_subparsers(title='subcommands',
                                 description='Admin subcommands', dest='subcmd')
    subcmd = subcmds.add_parser('add', help='Add an admin or permission.')
    subcmd.add_argument('rule_cmd', nargs='?', help='The the command to restrict.')
    subcmd.add_argument('role', nargs='*', help='The role name, if a role restriction.')
    subcmd.add_argument('rule_cmds', nargs='*', help='The the command to restrict.')
    subcmd = subcmds.add_parser('remove', help='Remove an admin or permission.')
    subcmd.add_argument('rule_cmd', nargs='?', help='The the command to restrict.')
    subcmd.add_argument('role', nargs='*', help='The role name, if a role restriction.')
    subcmd.add_argument('rule_cmds', nargs='*', help='The the command to restrict.')
    subcmds.add_parser('show_rules', help='Show existing command rules.')
    subcmd = subcmds.add_parser('cast', help='Broadcast a message to all channels.')
    subcmd.add_argument('content', nargs='+', help='The message to send, no hyphens.')
    subcmds.add_parser('cycle', help='Roll sheets to new cycle.')
@@ -168,6 +171,7 @@ def subs_bgs(subs, prefix):
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'bgs', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='BGS', system=[])
    CMD_MAP['BGS'] = 'bgs'
    subcmds = sub.add_subparsers(title='subcommands',
                                 description='BGS subcommands', dest='subcmd')
    subcmd = subcmds.add_parser('age', help='Get the age of exploiteds around a control.')
@@ -205,6 +209,7 @@ def subs_dist(subs, prefix):
        Display the distance from Sol to Frey and Rana.
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'dist', description=desc, formatter_class=RawHelp)
    CMD_MAP['Dist'] = 'dist'
    sub.set_defaults(cmd='Dist')
    sub.add_argument('system', nargs='+', help='The systems in question.')

@@ -230,6 +235,7 @@ def subs_drop(subs, prefix):
    """.format(prefix=prefix, num=cog.util.CONF.constants.max_drop)
    sub = subs.add_parser(prefix + 'drop', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='Drop')
    CMD_MAP['Drop'] = 'drop'
    sub.add_argument('amount', type=int, help='The amount to drop.')
    sub.add_argument('system', nargs='+', help='The system to drop at.')
    sub.add_argument('-s', '--set',
@@ -246,6 +252,7 @@ def subs_feedback(subs, prefix):
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'feedback', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='Feedback')
    CMD_MAP['Feedback'] = 'feedback'
    sub.add_argument('content', nargs='+', help='The bug description or feedback.')


@@ -280,6 +287,7 @@ def subs_fort(subs, prefix):
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'fort', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='Fort')
    CMD_MAP['Fort'] = 'fort'
    sub.add_argument('system', nargs='*', help='Select this system.')
    sub.add_argument('-s', '--set',
                     help='Set the fort:um status of system. Example-> --set 3400:200')
@@ -303,6 +311,7 @@ def subs_help(subs, prefix):
    """ Subcommand parsing for help """
    sub = subs.add_parser(prefix + 'help', description='Show overall help message.')
    sub.set_defaults(cmd='Help')
    CMD_MAP['Help'] = 'help'


@register_parser
@@ -329,6 +338,7 @@ and 130% opposition.
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'hold', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='Hold', sheet_src=EUMSheet.main)
    CMD_MAP['Hold'] = 'hold'
    sub.add_argument('amount', nargs='?', type=int, help='The amount of merits held.')
    sub.add_argument('system', nargs='*', help='The system merits are held in.')
    sub.add_argument('-r', '--redeem', action='store_true', help='Redeem all held merits.')
@@ -365,6 +375,7 @@ and 130% opposition.
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'shold', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='SnipeHold', sheet_src=EUMSheet.snipe)
    CMD_MAP['SnipeHold'] = 'shold'
    sub.add_argument('amount', nargs='?', type=int, help='The amount of merits held.')
    sub.add_argument('system', nargs='*', help='The system merits are held in.')
    sub.add_argument('-r', '--redeem', action='store_true', help='Redeem all held merits.')
@@ -390,6 +401,7 @@ def subs_kos(subs, prefix):
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'kos', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='KOS', system=[])
    CMD_MAP['KOS'] = 'kos'
    subcmds = sub.add_subparsers(title='subcommands',
                                 description='KOS subcommands', dest='subcmd')
    subcmd = subcmds.add_parser('report', help='Report user to KOS.')
@@ -418,6 +430,7 @@ def subs_near(subs, prefix):
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'near', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='Near')
    CMD_MAP['Near'] = 'near'
    subcmds = sub.add_subparsers(title='subcommands',
                                 description='Near subcommands', dest='subcmd')

@@ -435,6 +448,7 @@ def subs_ocr(subs, prefix):
    """ Subcommand parsing for ocr """
    sub = subs.add_parser(prefix + 'ocr', description='Manage the OCR system and query things.')
    sub.set_defaults(cmd='OCR')
    CMD_MAP['OCR'] = 'ocr'
    subcmds = sub.add_subparsers(title='subcommands',
                                 description='OCR Subcommands', dest='subcmd')

@@ -447,6 +461,7 @@ def subs_pin(subs, prefix):
    """ Subcommand parsing for pin """
    sub = subs.add_parser(prefix + 'pin', description='Make an objectives pin and keep updating.')
    sub.set_defaults(cmd='Pin')
    CMD_MAP['Pin'] = 'pin'


@register_parser
@@ -482,6 +497,7 @@ def subs_recruits(subs, prefix):
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'recruits', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='Recruits')
    CMD_MAP['Recruits'] = 'recruits'
    subcmds = sub.add_subparsers(title='subcommands',
                                 description='Recruits subcommands', dest='subcmd')
    subcmd = subcmds.add_parser('add', help='Report user to KOS.')
@@ -513,6 +529,7 @@ def subs_repair(subs, prefix):
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'repair', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='Repair')
    CMD_MAP['Repair'] = 'repair'
    sub.add_argument('system', nargs="+", help='The reference system.')
    sub.add_argument('-a', '--arrival', type=int, default=1000, help='Station must be within arrival ls.')
    sub.add_argument('-d', '--distance', type=int, default=15, help='Max system distance')
@@ -532,6 +549,7 @@ def subs_route(subs, prefix):
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'route', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='Route')
    CMD_MAP['Route'] = 'route'
    sub.add_argument('system', nargs="+", help='The systems to plot.')
    sub.add_argument('-o', '--optimum', action="store_true", help="Determine the optimum solution.")

@@ -549,6 +567,7 @@ def subs_scout(subs, prefix):
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'scout', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='Scout')
    CMD_MAP['Scout'] = 'scout'
    sub.add_argument('-r', '--round', type=int, help='The round to run.', choices=[1, 2, 3])
    sub.add_argument('-c', '--custom', nargs='+', help='Run a custom scout of systems.')

@@ -558,6 +577,7 @@ def subs_status(subs, prefix):
    """ Subcommand parsing for status """
    sub = subs.add_parser(prefix + 'status', description='Info about this bot.')
    sub.set_defaults(cmd='Status')
    CMD_MAP['Status'] = 'status'


@register_parser
@@ -565,6 +585,7 @@ def subs_time(subs, prefix):
    """ Subcommand parsing for time """
    sub = subs.add_parser(prefix + 'time', description='Time in game and to ticks.')
    sub.set_defaults(cmd='Time')
    CMD_MAP['Time'] = 'time'


@register_parser
@@ -591,6 +612,7 @@ def subs_track(subs, prefix):
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'track', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='Track')
    CMD_MAP['Track'] = 'track'
    subcmds = sub.add_subparsers(title='subcommands',
                                 description='Track subcommands', dest='subcmd')
    subcmd = subcmds.add_parser('channel', help='Set the channel to send notifications to of important changes.')
@@ -621,6 +643,7 @@ def subs_trigger(subs, prefix):
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'trigger', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='Trigger')
    CMD_MAP['Trigger'] = 'trigger'
    sub.add_argument('system', nargs='+', help='The system(s) to calculate triggers for.')
    sub.add_argument('-p', '--power', nargs='+', default=["hudson"], help='The power to calculate from.')

@@ -649,6 +672,7 @@ def subs_um(subs, prefix):
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'um', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='UM', sheet_src=EUMSheet.main)
    CMD_MAP['UM'] = 'um'
    sub.add_argument('system', nargs='*', help='The system to update or show.')
    sub.add_argument('-s', '--set',
                     help='Set the status of the system, us:them. Example-> --set 3500:200')
@@ -684,6 +708,7 @@ Examples:
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'snipe', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='Snipe', sheet_src=EUMSheet.snipe)
    CMD_MAP['Snipe'] = 'snipe'
    sub.add_argument('system', nargs='*', help='The system to update or show.')
    sub.add_argument('-s', '--set',
                     help='Set the status of the system, us:them. Example-> --set 3500:200')
@@ -706,6 +731,7 @@ def subs_user(subs, prefix):
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'user', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='User')
    CMD_MAP['User'] = 'user'
    sub.add_argument('--cry', nargs='+', help='Set your tag/cry in the sheets.')
    sub.add_argument('--name', nargs='+', help='Set your name in the sheets.')

@@ -725,6 +751,7 @@ def subs_vote(subs, prefix):
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'vote', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='Voting')
    CMD_MAP['Voting'] = 'vote'
    sub.add_argument('vote_type', nargs='?', help='Vote type, either Cons or Prep', choices=['cons', 'prep'])
    sub.add_argument('amount', nargs='?', type=int, help='Vote power (either 1 or a multiple of 5)')
    sub.add_argument('--set', '-s', type=int, help='Set vote goal.')
@@ -745,4 +772,5 @@ def subs_whois(subs, prefix):
    """.format(prefix=prefix)
    sub = subs.add_parser(prefix + 'whois', description=desc, formatter_class=RawHelp)
    sub.set_defaults(cmd='WhoIs')
    CMD_MAP['WhoIs'] = 'whois'
    sub.add_argument('cmdr', nargs='+', help='Commander name.')
+124 −38
Original line number Diff line number Diff line
@@ -660,46 +660,131 @@ def add_admin(session, member):
        raise cog.exc.InvalidCommandArgs("Member {} is already an admin.".format(member.display_name)) from exc


def add_channel_perm(session, cmd, server, channel):
def show_guild_perms(session, guild, prefix='!'):
    """
    Find all existing rules and format a summary to display.

    Args:
        session: A session onto the db.
        guild: The guild that set restrictions.

    Returns: A formatted string summarizing rules for guild.
    """
    msg = f"__Existing Rules For {guild.name}__"

    rules = session.query(ChannelPerm).filter(ChannelPerm.guild_id == guild.id).all()
    if rules:
        msg += "\n\n__Channel Rules__\n"
        for rule in rules:
            msg += "`{prefix}{cmd}` limited to channel: {chan}\n".format(prefix=prefix, cmd=rule.cmd, chan=guild.get_channel(rule.channel_id).mention)

    rules = session.query(RolePerm). filter(RolePerm.guild_id == guild.id).all()
    if rules:
        msg += "\n\n__Role Rules__\n"
        for rule in rules:
            msg += "`{prefix}{cmd}` limited to role: {role}\n".format(prefix=prefix, cmd=rule.cmd, role=guild.get_role(rule.role_id).name)

    return msg.rstrip()


def add_channel_perms(session, cmds, guild, channels):
    """
    Add channel restrictions to an existing commands.

    Args:
        session: A session onto the db.
        cmds: A list of command names, as seen by user (i.e. ['fort', 'um']).
        guild: The guild to set restrictions.
        channels: A list of Channels on the guild where the commands should be restricted.

    Raises:
        InvalidCommandArgs: Tells user of any existing rules, adds all others.
    """
    msg = ""
    for cmd in cmds:
        for channel in channels:
            try:
        session.add(ChannelPerm(cmd=cmd, server_id=server.id, channel_id=channel.id))
                session.add(ChannelPerm(cmd=cmd, guild_id=guild.id, channel_id=channel.id))
                session.commit()
    except (sqla_exc.IntegrityError, sqla_oexc.FlushError) as exc:
        raise cog.exc.InvalidCommandArgs("Channel permission already exists.") from exc
            except (sqla_exc.IntegrityError, sqla_oexc.FlushError):
                msg += f"Channel permission exists for: {cmd} on {channel.name}\n"

    if msg:
        raise cog.exc.InvalidCommandArgs("Existing rules below, remaining rules added:\n\n" + msg)


def add_role_perms(session, cmds, guild, roles):
    """
    Add role restrictions to existing commands.

def add_role_perm(session, cmd, server, role):
    Args:
        session: A session onto the db.
        cmds: A list of command names, as seen by user (i.e. ['fort', 'um']).
        guild: The guild to set restrictions.
        roles: A list of Roles on the guild where the commands should be restricted.

    Raises:
        InvalidCommandArgs: Tells user of any existing rules, adds all others.
    """
    msg = ""
    for cmd in cmds:
        for role in roles:
            try:
        session.add(RolePerm(cmd=cmd, server_id=server.id, role_id=role.id))
                session.add(RolePerm(cmd=cmd, guild_id=guild.id, role_id=role.id))
                session.commit()
    except (sqla_exc.IntegrityError, sqla_oexc.FlushError) as exc:
        raise cog.exc.InvalidCommandArgs("Role permission already exists.") from exc
            except (sqla_exc.IntegrityError, sqla_oexc.FlushError):
                msg += f"Role permission exists for: {cmd} on {role.name}\n"

    if msg:
        raise cog.exc.InvalidCommandArgs("Existing rules below, remaining rules added:\n\n" + msg)


def remove_channel_perms(session, cmds, guild, channels):
    """
    Remove channel restrictions to existing commands.
    Attempting to remove non existant rules is ignored silently.

def remove_channel_perm(session, cmd, server, channel):
    Args:
        session: A session onto the db.
        cmds: A list of command names, as seen by user (i.e. ['fort', 'um']).
        guild: The guild to set restrictions.
        roles: A list of Roles on the guild where the commands should be restricted.
    """
    for cmd in cmds:
        for channel in channels:
            try:
        perm = session.query(ChannelPerm).\
                session.query(ChannelPerm).\
                    filter(ChannelPerm.cmd == cmd,
                   ChannelPerm.server_id == server.id,
                           ChannelPerm.guild_id == guild.id,
                           ChannelPerm.channel_id == channel.id).\
            one()
        session.delete(perm)
                    delete()
            except sqla_oexc.NoResultFound:
                pass
    session.commit()
    except sqla_oexc.NoResultFound as exc:
        raise cog.exc.InvalidCommandArgs("Channel permission does not exist.") from exc


def remove_role_perm(session, cmd, server, role):
def remove_role_perms(session, cmds, guild, roles):
    """
    Remove role restrictions to existing commands.
    Attempting to remove non existant rules is ignored silently.

    Args:
        session: A session onto the db.
        cmds: A list of command names, as seen by user (i.e. ['fort', 'um']).
        guild: The guild to set restrictions.
        roles: A list of Roles on the guild where the commands should be restricted.
    """
    for cmd in cmds:
        for role in roles:
            try:
        perm = session.query(RolePerm).\
                session.query(RolePerm).\
                    filter(RolePerm.cmd == cmd,
                   RolePerm.server_id == server.id,
                           RolePerm.guild_id == guild.id,
                           RolePerm.role_id == role.id).\
            one()
        session.delete(perm)
                    delete()
            except sqla_oexc.NoResultFound:
                pass
    session.commit()
    except sqla_oexc.NoResultFound as exc:
        raise cog.exc.InvalidCommandArgs("Role permission does not exist.") from exc


def check_perms(session, msg, args):
@@ -709,8 +794,9 @@ def check_perms(session, msg, args):

    Raises InvalidPerms if any permission issue.
    """
    check_channel_perms(session, args.cmd, msg.channel.guild, msg.channel)
    check_role_perms(session, args.cmd, msg.channel.guild, msg.author.roles)
    cmd = cog.parse.CMD_MAP[args.cmd]
    check_channel_perms(session, cmd, msg.channel.guild, msg.channel)
    check_role_perms(session, cmd, msg.channel.guild, msg.author.roles)


def check_channel_perms(session, cmd, server, channel):
@@ -723,7 +809,7 @@ def check_channel_perms(session, cmd, server, channel):
    """
    perms = session.query(ChannelPerm).\
        filter(ChannelPerm.cmd == cmd,
               ChannelPerm.server_id == server.id).\
               ChannelPerm.guild_id == server.id).\
        all()
    channels = [perm.channel_id for perm in perms]
    if channels and channel.id not in channels:
@@ -741,7 +827,7 @@ def check_role_perms(session, cmd, server, member_roles):
    """
    perms = session.query(RolePerm).\
        filter(RolePerm.cmd == cmd,
               RolePerm.server_id == server.id).\
               RolePerm.guild_id == server.id).\
        all()
    perm_roles = {perm.role_id for perm in perms}
    member_roles = {role.id for role in member_roles}
+6 −6
Original line number Diff line number Diff line
@@ -960,11 +960,11 @@ class ChannelPerm(Base):
    __tablename__ = 'perms_channels'

    cmd = sqla.Column(sqla.String(LEN_CMD), primary_key=True)
    server_id = sqla.Column(sqla.BigInteger, primary_key=True)
    guild_id = sqla.Column(sqla.BigInteger, primary_key=True)
    channel_id = sqla.Column(sqla.BigInteger, primary_key=True)

    def __repr__(self):
        keys = ['cmd', 'server_id', 'channel_id']
        keys = ['cmd', 'guild_id', 'channel_id']
        kwargs = ['{}={!r}'.format(key, getattr(self, key)) for key in keys]

        return "{}({})".format(self.__class__.__name__, ', '.join(kwargs))
@@ -973,7 +973,7 @@ class ChannelPerm(Base):
        return isinstance(other, ChannelPerm) and hash(self) == hash(other)

    def __hash__(self):
        return hash("{}_{}_{}".format(self.cmd, self.server_id, self.channel_id))
        return hash("{}_{}_{}".format(self.cmd, self.guild_id, self.channel_id))


class RolePerm(Base):
@@ -983,11 +983,11 @@ class RolePerm(Base):
    __tablename__ = 'perms_roles'

    cmd = sqla.Column(sqla.String(LEN_CMD), primary_key=True)
    server_id = sqla.Column(sqla.BigInteger, primary_key=True)
    guild_id = sqla.Column(sqla.BigInteger, primary_key=True)
    role_id = sqla.Column(sqla.BigInteger, primary_key=True)

    def __repr__(self):
        keys = ['cmd', 'server_id', 'role_id']
        keys = ['cmd', 'guild_id', 'role_id']
        kwargs = ['{}={!r}'.format(key, getattr(self, key)) for key in keys]

        return "{}({})".format(self.__class__.__name__, ', '.join(kwargs))
@@ -996,7 +996,7 @@ class RolePerm(Base):
        return isinstance(other, RolePerm) and hash(self) == hash(other)

    def __hash__(self):
        return hash("{}_{}_{}".format(self.cmd, self.server_id, self.role_id))
        return hash("{}_{}_{}".format(self.cmd, self.guild_id, self.role_id))


class TrackSystem(Base):
+11 −11

File changed.

Preview size limit exceeded, changes collapsed.

Loading