Пример #1
0
    def chk_win(self, evt, var, lpl, lwolves, lrealwolves):
        lsafes = len(
            var.list_players([
                "oracle", "seer", "guardian angel", "shaman", "hunter",
                "villager"
            ]))
        lcultists = len(var.list_players(["cultist"]))
        evt.stop_processing = True

        if lrealwolves == 0 and lsafes == 0:
            evt.data["winner"] = "none"
            evt.data["message"] = (
                "Game over! All the villagers are dead, but the cult needed to sacrifice "
                +
                "the wolves to accomplish that. The cult disperses shortly thereafter, "
                + "and nobody wins.")
        elif lrealwolves == 0:
            evt.data["winner"] = "villagers"
            evt.data["message"] = (
                "Game over! All the wolves are dead! The villagers " +
                "round up the remaining cultists, hang them, and live " +
                "happily ever after.")
        elif lsafes == 0:
            evt.data["winner"] = "wolves"
            evt.data["message"] = (
                "Game over! All the villagers are dead! The cultists rejoice "
                +
                "with their wolf buddies and start plotting to take over the "
                + "next village.")
        elif lcultists == 0:
            evt.data["winner"] = "villagers"
            evt.data["message"] = (
                "Game over! All the cultists are dead! The now-exposed wolves "
                +
                "are captured and killed by the remaining villagers. A BBQ party "
                + "commences shortly thereafter.")
        elif lsafes >= lpl / 2:
            evt.data["winner"] = "villagers"
            evt.data["message"] = (
                "Game over! There are {0} villagers {1} cultists. They " +
                "manage to regain control of the village and dispose of the remaining "
                + "cultists.").format(
                    "more" if lsafes > lpl / 2 else "the same number of",
                    "than" if lsafes > lpl / 2 else "as")
        else:
            try:
                if evt.data["winner"][0] != "@":
                    evt.data["winner"] = None
            except TypeError:
                evt.data["winner"] = None
Пример #2
0
def reply(cli, nick, chan, msg, private=False):
    if chan == nick:
        pm(cli, nick, msg)
    elif private or (nick not in var.list_players() and var.PHASE not in ("none", "join") and chan == botconfig.CHANNEL):
        cli.notice(nick, msg)
    else:
        cli.msg(chan, msg)
Пример #3
0
def relay_wolfchat_command(cli, nick, message, roles, is_wolf_command=False, is_kill_command=False):
    if not is_wolf_command and var.RESTRICT_WOLFCHAT & var.RW_NO_INTERACTION:
        return
    if not is_kill_command and var.RESTRICT_WOLFCHAT & var.RW_ONLY_KILL_CMD:
        if var.PHASE == "night" and var.RESTRICT_WOLFCHAT & var.RW_DISABLE_NIGHT:
            return
        if var.PHASE == "day" and var.RESTRICT_WOLFCHAT & var.RW_DISABLE_DAY:
            return
    if not in_wolflist(nick, nick):
        return

    wcroles = var.WOLFCHAT_ROLES
    if var.RESTRICT_WOLFCHAT & var.RW_ONLY_SAME_CMD:
        if var.PHASE == "night" and var.RESTRICT_WOLFCHAT & var.RW_DISABLE_NIGHT:
            wcroles = roles
        if var.PHASE == "day" and var.RESTRICT_WOLFCHAT & var.RW_DISABLE_DAY:
            wcroles = roles
    elif var.RESTRICT_WOLFCHAT & var.RW_REM_NON_WOLVES:
        if var.RESTRICT_WOLFCHAT & var.RW_TRAITOR_NON_WOLF:
            wcroles = var.WOLF_ROLES
        else:
            wcroles = var.WOLF_ROLES | {"traitor"}

    wcwolves = var.list_players(wcroles)
    wcwolves.remove(nick)
    mass_privmsg(cli, wcwolves, message)
    mass_privmsg(cli, var.SPECTATING_WOLFCHAT, "[wolfchat] " + message)
Пример #4
0
def relay_wolfchat_command(cli,
                           nick,
                           message,
                           roles,
                           is_wolf_command=False,
                           is_kill_command=False):
    if not is_wolf_command and var.RESTRICT_WOLFCHAT & var.RW_NO_INTERACTION:
        return
    if not is_kill_command and var.RESTRICT_WOLFCHAT & var.RW_ONLY_KILL_CMD:
        if var.PHASE == "night" and var.RESTRICT_WOLFCHAT & var.RW_DISABLE_NIGHT:
            return
        if var.PHASE == "day" and var.RESTRICT_WOLFCHAT & var.RW_DISABLE_DAY:
            return
    if not in_wolflist(nick, nick):
        return

    wcroles = var.WOLFCHAT_ROLES
    if var.RESTRICT_WOLFCHAT & var.RW_ONLY_SAME_CMD:
        if var.PHASE == "night" and var.RESTRICT_WOLFCHAT & var.RW_DISABLE_NIGHT:
            wcroles = roles
        if var.PHASE == "day" and var.RESTRICT_WOLFCHAT & var.RW_DISABLE_DAY:
            wcroles = roles
    elif var.RESTRICT_WOLFCHAT & var.RW_REM_NON_WOLVES:
        if var.RESTRICT_WOLFCHAT & var.RW_TRAITOR_NON_WOLF:
            wcroles = var.WOLF_ROLES
        else:
            wcroles = var.WOLF_ROLES | {"traitor"}

    wcwolves = var.list_players(wcroles)
    wcwolves.remove(nick)
    mass_privmsg(cli, wcwolves, message)
    mass_privmsg(cli, var.SPECTATING_WOLFCHAT, "[wolfchat] " + message)
Пример #5
0
def reply(cli, nick, chan, msg, private=False):
    if chan == nick:
        pm(cli, nick, msg)
    elif private or (nick not in var.list_players()
                     and var.PHASE in var.GAME_PHASES
                     and chan == botconfig.CHANNEL):
        cli.notice(nick, msg)
    else:
        cli.msg(chan, msg)
Пример #6
0
    def chk_win(self, evt, var, lpl, lwolves, lrealwolves):
        lguardians = len(var.list_players(["guardian angel", "bodyguard"]))

        if lpl < 1:
            # handled by default win cond checking
            return
        elif not lguardians and lwolves > lpl / 2:
            evt.data["winner"] = "wolves"
            evt.data["message"] = (
                "Game over! There are more wolves than uninjured villagers. With the ancestral "
                +
                "guardians dead, the wolves overpower the defenseless villagers and win."
            )
        elif not lguardians and lwolves == lpl / 2:
            evt.data["winner"] = "wolves"
            evt.data["message"] = (
                "Game over! There are the same number of wolves as uninjured villagers. With the ancestral "
                +
                "guardians dead, the wolves overpower the defenseless villagers and win."
            )
        elif not lrealwolves and lguardians:
            evt.data["winner"] = "villagers"
            evt.data["message"] = (
                "Game over! All the wolves are dead! The remaining villagers throw a party in honor "
                +
                "of the guardian angels that watched over the village, and live happily ever after."
            )
        elif not lrealwolves and not lguardians:
            evt.data["winner"] = "none"
            evt.data["message"] = (
                "Game over! The remaining villagers managed to destroy the wolves, however the guardians "
                +
                "that used to watch over the village are nowhere to be found. The village lives on in an "
                +
                "uneasy peace, not knowing when they will be destroyed completely now that they are "
                + "defenseless. Nobody wins.")
        elif lwolves == lguardians and lpl - lwolves - lguardians == 0:
            evt.data["winner"] = "none"
            evt.data["message"] = (
                "Game over! The guardians, angered by the loss of everyone they were meant to guard, "
                +
                "engage the wolves in battle and mutually assured destruction. After the dust settles "
                + "the village is completely dead, and nobody wins.")
        else:
            evt.data["winner"] = None
Пример #7
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)
Пример #8
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, 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)
Пример #9
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)
Пример #10
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)