예제 #1
0
    def caller(self, *args):
        largs = list(args)

        cli, rawnick, chan, rest = largs
        nick, mode, user, cloak = parse_nick(rawnick)

        if cloak is None:
            cloak = ""

        if not self.raw_nick:
            largs[1] = nick

        if not self.pm and chan == nick:
            return # PM command, not allowed

        if not self.chan and chan != nick:
            return # channel command, not allowed

        if chan.startswith("#") and chan != botconfig.CHANNEL and not (self.admin_only or self.owner_only):
            if "" in self.cmds:
                return # don't have empty commands triggering in other channels
            for command in self.cmds:
                if command in botconfig.ALLOWED_ALT_CHANNELS_COMMANDS:
                    break
            else:
                return

        if nick in var.USERS and var.USERS[nick]["account"] != "*":
            acc = var.USERS[nick]["account"]
        else:
            acc = None

        if "" in self.cmds:
            return self.func(*largs)

        if self.phases and var.PHASE not in self.phases:
            return

        if self.playing and (nick not in var.list_players() or nick in var.DISCONNECTED):
            if chan == nick:
                pm(cli, nick, "You're not currently playing.")
            else:
                cli.notice(nick, "You're not currently playing.")
            return

        if self.silenced and nick in var.SILENCED:
            if chan == nick:
                pm(cli, nick, "You have been silenced, and are unable to use any special powers.")
            else:
                cli.notice(nick, "You have been silenced, and are unable to use any special powers.")
            return

        if self.roles:
            for role in self.roles:
                if nick in var.ROLES[role]:
                    break
            else:
                return

            return self.func(*largs) # don't check restrictions for role commands

        if self.owner_only:
            if var.is_owner(nick, cloak):
                adminlog(chan, rawnick, self.name, rest)
                return self.func(*largs)

            if chan == nick:
                pm(cli, nick, "You are not the owner.")
            else:
                cli.notice(nick, "You are not the owner.")
            return

        if var.is_admin(nick, cloak):
            if self.admin_only:
                adminlog(chan, rawnick, self.name, rest)
            return self.func(*largs)

        if not var.DISABLE_ACCOUNTS and acc:
            for pattern in var.DENY_ACCOUNTS:
                if fnmatch.fnmatch(acc.lower(), pattern.lower()):
                    for command in self.cmds:
                        if command in var.DENY_ACCOUNTS[pattern]:
                            if chan == nick:
                                pm(cli, nick, "You do not have permission to use that command.")
                            else:
                                cli.notice(nick, "You do not have permission to use that command.")
                            return

            for pattern in var.ALLOW_ACCOUNTS:
                if fnmatch.fnmatch(acc.lower(), pattern.lower()):
                    for command in self.cmds:
                        if command in var.ALLOW_ACCOUNTS[pattern]:
                            if self.admin_only:
                                adminlog(chan, rawnick, self.name, rest)
                            return self.func(*largs)

        if not var.ACCOUNTS_ONLY and cloak:
            for pattern in var.DENY:
                if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
                    for command in self.cmds:
                        if command in var.DENY[pattern]:
                            if chan == nick:
                                pm(cli, nick, "You do not have permission to use that command.")
                            else:
                                cli.notice(nick, "You do not have permission to use that command.")
                            return

            for pattern in var.ALLOW:
                if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
                    for command in self.cmds:
                        if command in var.ALLOW[pattern]:
                            if self.admin_only:
                                adminlog(chan, rawnick, self.name, rest)
                            return self.func(*largs)

        if self.admin_only:
            if chan == nick:
                pm(cli, nick, "You are not an admin.")
            else:
                cli.notice(nick, "You are not an admin.")
            return

        return self.func(*largs)
예제 #2
0
            def innerf(*args):
                largs = list(args)
                rawnick = largs[1]
                if not permissions:
                    return f(*largs)
                if len(largs) > 1 and largs[1]:
                    nick, _, _, cloak = parse_nick(largs[1])

                    if cloak is None:
                        cloak = ""
                else:
                    nick = ""
                    cloak = ""
                if not raw_nick and len(largs) > 1 and largs[1]:
                    largs[1] = nick
                if nick == "<console>":
                    return f(*largs) # special case; no questions
                if not pm and largs[2] == nick: # PM command
                    return
                if not chan and largs[2] != nick: # channel command
                    return
                if largs[2].startswith("#") and largs[2] != botconfig.CHANNEL and not admin_only and not owner_only:
                    if "" in s:
                        return # Don't have empty commands triggering in other channels
                    allowed = False
                    for cmdname in s:
                        if cmdname in botconfig.ALLOWED_ALT_CHANNELS_COMMANDS:
                            allowed = True
                            break
                    if not allowed:
                        return
                if nick in var.USERS.keys() and var.USERS[nick]["account"] != "*":
                    acc = var.USERS[nick]["account"]
                else:
                    acc = None
                if "" in s:
                    return f(*largs)
                if game and var.PHASE not in ("day", "night") + (("join",) if join else ()):
                    largs[0].notice(nick, "No game is currently running.")
                    return
                if ((join and none and var.PHASE not in ("join", "none"))
                        or (none and not join and var.PHASE != "none")):
                    largs[0].notice(nick, "Sorry, but the game is already running. Try again next time.")
                    return
                if join and not none:
                    if var.PHASE == "none":
                        largs[0].notice(nick, "No game is currently running.")
                        return
                    if var.PHASE != "join" and not game:
                        largs[0].notice(nick, "Werewolf is already in play.")
                        return
                if playing and nick not in var.list_players() or nick in var.DISCONNECTED.keys():
                    largs[0].notice(nick, "You're not currently playing.")
                    return
                if roles:
                    for role in roles:
                        if nick in var.ROLES[role]:
                            break
                    else:
                        return
                if acc:
                    for pattern in var.DENY_ACCOUNTS.keys():
                        if fnmatch.fnmatch(acc.lower(), pattern.lower()):
                            for cmdname in s:
                                if cmdname in var.DENY_ACCOUNTS[pattern]:
                                    largs[0].notice(nick, "You do not have permission to use that command.")
                                    return
                    for pattern in var.ALLOW_ACCOUNTS.keys():
                        if fnmatch.fnmatch(acc.lower(), pattern.lower()):
                            for cmdname in s:
                                if cmdname in var.ALLOW_ACCOUNTS[pattern]:
                                    if admin_only or owner_only:
                                        adminlog(largs[2], rawnick, s[0], largs[3])
                                    return f(*largs)
                if not var.ACCOUNTS_ONLY and cloak:
                    for pattern in var.DENY.keys():
                        if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
                            for cmdname in s:
                                if cmdname in var.DENY[pattern]:
                                    largs[0].notice(nick, "You do not have permission to use that command.")
                                    return
                    for pattern in var.ALLOW.keys():
                        if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
                            for cmdname in s:
                                if cmdname in var.ALLOW[pattern]:
                                    if admin_only or owner_only:
                                        adminlog(largs[2], rawnick, s[0], largs[3])
                                    return f(*largs)  # no questions
                if owner_only:
                    if var.is_owner(nick, cloak):
                        adminlog(largs[2], rawnick, s[0], largs[3])
                        return f(*largs)
                    else:
                        largs[0].notice(nick, "You are not the owner.")
                        return
                if admin_only:
                    if var.is_admin(nick, cloak):
                        adminlog(largs[2], rawnick, s[0], largs[3])
                        return f(*largs)
                    else:
                        largs[0].notice(nick, "You are not an admin.")
                        return
                return f(*largs)
예제 #3
0
파일: decorators.py 프로젝트: io4/lykos
    def caller(self, *args):
        largs = list(args)

        cli, rawnick, chan, rest = largs
        nick, mode, ident, host = parse_nick(rawnick)

        if ident is None:
            ident = ""

        if host is None:
            host = ""

        if not self.raw_nick:
            largs[1] = nick

        if not self.pm and chan == nick:
            return # PM command, not allowed

        if not self.chan and chan != nick:
            return # channel command, not allowed

        if chan.startswith("#") and chan != botconfig.CHANNEL and not (self.admin_only or self.owner_only):
            if "" in self.cmds:
                return # don't have empty commands triggering in other channels
            for command in self.cmds:
                if command in botconfig.ALLOWED_ALT_CHANNELS_COMMANDS:
                    break
            else:
                return

        if nick in var.USERS and var.USERS[nick]["account"] != "*":
            acc = var.USERS[nick]["account"]
        else:
            acc = None

        if "" in self.cmds:
            return self.func(*largs)

        if self.phases and var.PHASE not in self.phases:
            return

        if self.playing and (nick not in var.list_players() or nick in var.DISCONNECTED):
            if chan == nick:
                pm(cli, nick, messages["player_not_playing"])
            else:
                cli.notice(nick, messages["player_not_playing"])
            return

        if self.silenced and nick in var.SILENCED:
            if chan == nick:
                pm(cli, nick, messages["silenced"])
            else:
                cli.notice(nick, messages["silenced"])
            return

        if self.roles:
            for role in self.roles:
                if nick in var.ROLES[role]:
                    break
            else:
                return

            return self.func(*largs) # don't check restrictions for role commands

        forced_owner_only = False
        if hasattr(botconfig, "OWNERS_ONLY_COMMANDS"):
            for command in self.cmds:
                if command in botconfig.OWNERS_ONLY_COMMANDS:
                    forced_owner_only = True
                    break

        if self.owner_only or forced_owner_only:
            if var.is_owner(nick, ident, host):
                adminlog(chan, rawnick, self.name, rest)
                return self.func(*largs)

            if chan == nick:
                pm(cli, nick, messages["not_owner"])
            else:
                cli.notice(nick, messages["not_owner"])
            return

        if var.is_admin(nick, ident, host):
            if self.admin_only:
                adminlog(chan, rawnick, self.name, rest)
            return self.func(*largs)

        if not var.DISABLE_ACCOUNTS and acc:
            if acc in var.DENY_ACCOUNTS:
                for command in self.cmds:
                    if command in var.DENY_ACCOUNTS[acc]:
                        if chan == nick:
                            pm(cli, nick, messages["invalid_permissions"])
                        else:
                            cli.notice(nick, messages["invalid_permissions"])
                        return

            if acc in var.ALLOW_ACCOUNTS:
                for command in self.cmds:
                    if command in var.ALLOW_ACCOUNTS[acc]:
                        if self.admin_only:
                            adminlog(chan, rawnick, self.name, rest)
                        return self.func(*largs)

        if host:
            for pattern in var.DENY:
                if var.match_hostmask(pattern, nick, ident, host):
                    for command in self.cmds:
                        if command in var.DENY[pattern]:
                            if chan == nick:
                                pm(cli, nick, messages["invalid_permissions"])
                            else:
                                cli.notice(nick, messages["invalid_permissions"])
                            return

            for pattern in var.ALLOW:
                if var.match_hostmask(pattern, nick, ident, host):
                    for command in self.cmds:
                        if command in var.ALLOW[pattern]:
                            if self.admin_only:
                                adminlog(chan, rawnick, self.name, rest)
                            return self.func(*largs)

        if self.admin_only:
            if chan == nick:
                pm(cli, nick, messages["not_an_admin"])
            else:
                cli.notice(nick, messages["not_an_admin"])
            return

        return self.func(*largs)
예제 #4
0
    def caller(self, *args):
        largs = list(args)

        cli, rawnick, chan, rest = largs
        nick, mode, ident, host = parse_nick(rawnick)

        if ident is None:
            ident = ""

        if host is None:
            host = ""

        if not self.raw_nick:
            largs[1] = nick

        if not self.pm and chan == nick:
            return  # PM command, not allowed

        if not self.chan and chan != nick:
            return  # channel command, not allowed

        if chan.startswith("#") and chan != botconfig.CHANNEL and not (
                self.admin_only or self.owner_only):
            if "" in self.cmds:
                return  # don't have empty commands triggering in other channels
            for command in self.cmds:
                if command in botconfig.ALLOWED_ALT_CHANNELS_COMMANDS:
                    break
            else:
                return

        if nick in var.USERS and var.USERS[nick]["account"] != "*":
            acc = var.USERS[nick]["account"]
        else:
            acc = None

        if "" in self.cmds:
            return self.func(*largs)

        if self.phases and var.PHASE not in self.phases:
            return

        if self.playing and (nick not in var.list_players()
                             or nick in var.DISCONNECTED):
            if chan == nick:
                pm(cli, nick, "You're not currently playing.")
            else:
                cli.notice(nick, "You're not currently playing.")
            return

        if self.silenced and nick in var.SILENCED:
            if chan == nick:
                pm(
                    cli, nick,
                    "You have been silenced, and are unable to use any special powers."
                )
            else:
                cli.notice(
                    nick,
                    "You have been silenced, and are unable to use any special powers."
                )
            return

        if self.roles:
            for role in self.roles:
                if nick in var.ROLES[role]:
                    break
            else:
                return

            return self.func(
                *largs)  # don't check restrictions for role commands

        if self.owner_only:
            if var.is_owner(nick, ident, host):
                adminlog(chan, rawnick, self.name, rest)
                return self.func(*largs)

            if chan == nick:
                pm(cli, nick, "You are not the owner.")
            else:
                cli.notice(nick, "You are not the owner.")
            return

        if var.is_admin(nick, ident, host):
            if self.admin_only:
                adminlog(chan, rawnick, self.name, rest)
            return self.func(*largs)

        if not var.DISABLE_ACCOUNTS and acc:
            if acc in var.DENY_ACCOUNTS:
                for command in self.cmds:
                    if command in var.DENY_ACCOUNTS[acc]:
                        if chan == nick:
                            pm(
                                cli, nick,
                                "You do not have permission to use that command."
                            )
                        else:
                            cli.notice(
                                nick,
                                "You do not have permission to use that command."
                            )
                        return

            if acc in var.ALLOW_ACCOUNTS:
                for command in self.cmds:
                    if command in var.ALLOW_ACCOUNTS[acc]:
                        if self.admin_only:
                            adminlog(chan, rawnick, self.name, rest)
                        return self.func(*largs)

        if not var.ACCOUNTS_ONLY and host:
            for pattern in var.DENY:
                if var.match_hostmask(pattern, nick, ident, host):
                    for command in self.cmds:
                        if command in var.DENY[pattern]:
                            if chan == nick:
                                pm(
                                    cli, nick,
                                    "You do not have permission to use that command."
                                )
                            else:
                                cli.notice(
                                    nick,
                                    "You do not have permission to use that command."
                                )
                            return

            for pattern in var.ALLOW:
                if var.match_hostmask(pattern, nick, ident, host):
                    for command in self.cmds:
                        if command in var.ALLOW[pattern]:
                            if self.admin_only:
                                adminlog(chan, rawnick, self.name, rest)
                            return self.func(*largs)

        if self.admin_only:
            if chan == nick:
                pm(cli, nick, "You are not an admin.")
            else:
                cli.notice(nick, "You are not an admin.")
            return

        return self.func(*largs)