Пример #1
0
def fstasis(var, wrapper, message):
    """Removes or views stasis penalties."""

    data = re.split(" +", message)
    from src.context import lower as irc_lower

    if data[0]:
        m = users.complete_match(data[0])
        if m:
            acc = m.get().account
        else:
            acc = data[0]
        cur = var.STASISED_ACCS[irc_lower(acc)]

        if len(data) == 1:
            if var.STASISED_ACCS[irc_lower(acc)] == cur and cur > 0:
                wrapper.reply(messages["account_in_stasis"].format(
                    data[0], acc, cur))
            else:
                wrapper.reply(messages["account_not_in_stasis"].format(
                    data[0], acc))
        else:
            try:
                amt = int(data[1])
            except ValueError:
                wrapper.reply(messages["stasis_non_negative"])
                return

            if amt < 0:
                wrapper.reply(messages["stasis_non_negative"])
                return
            elif amt > cur and var.RESTRICT_FSTASIS:
                wrapper.reply(messages["stasis_cannot_increase"])
                return
            elif cur == 0:
                wrapper.reply(messages["account_not_in_stasis"].format(
                    data[0], acc))
                return

            db.set_stasis(amt, acc)
            db.init_vars()
            if amt > 0:
                wrapper.reply(messages["fstasis_account_add"].format(
                    data[0], acc, amt))
            else:
                wrapper.reply(messages["fstasis_account_remove"].format(
                    data[0], acc))
    else:
        stasised = {}
        for acc in var.STASISED_ACCS:
            if var.STASISED_ACCS[acc] > 0:
                stasised[acc] = var.STASISED_ACCS[acc]

        if stasised:
            msg = messages["currently_stasised"].format(", ".join(
                "\u0002{0}\u0002 ({1})".format(usr, number)
                for usr, number in stasised.items()))
            wrapper.reply(msg)
        else:
            wrapper.reply(messages["noone_stasised"])
Пример #2
0
def get_target(var,
               wrapper,
               message,
               *,
               allow_self=False,
               allow_bot=False,
               not_self_message=None):
    if not message:
        wrapper.pm(messages["not_enough_parameters"])
        return

    players = get_players()
    if not allow_self and wrapper.source in players:
        players.remove(wrapper.source)

    if allow_bot:
        players.append(users.Bot)

    match, count = users.complete_match(message, players)
    if match is None:
        if not count and users.lower(wrapper.source.nick).startswith(
                users.lower(message)):
            wrapper.pm(messages[not_self_message or "no_target_self"])
            return
        wrapper.pm(messages["not_playing"].format(message))
        return

    return match
Пример #3
0
def consecrate(var, wrapper, message):
    """Consecrates a corpse, putting its spirit to rest and preventing other unpleasant things from happening."""
    alive = get_players()
    targ = re.split(" +", message)[0]
    if not targ:
        wrapper.pm(messages["not_enough_parameters"])
        return

    dead = set(var.ALL_PLAYERS) - set(alive)
    target, _ = users.complete_match(targ, dead)
    if target is None:
        wrapper.pm(messages["consecrate_fail"].format(targ))
        return

    # we have a target, so mark them as consecrated, right now all this does is silence a VG for a night
    # but other roles that do stuff after death or impact dead players should have functionality here as well
    # (for example, if there was a role that could raise corpses as undead somethings, this would prevent that from working)
    # regardless if this has any actual effect or not, it still removes the priest from being able to vote

    evt = Event("consecrate", {})
    evt.dispatch(var, wrapper.source, target)

    CONSECRATING.add(wrapper.source)
    wrapper.pm(messages["consecrate_success"].format(target))
    debuglog("{0} (priest) CONSECRATE: {1}".format(wrapper.source, target))
    # consecrating can possibly cause game to end, so check for that
    from src.wolfgame import chk_win
    chk_win()
Пример #4
0
def consecrate(var, wrapper, message):
    """Consecrates a corpse, putting its spirit to rest and preventing other unpleasant things from happening."""
    alive = get_players()
    targ = re.split(" +", message)[0]
    if not targ:
        wrapper.pm(messages["not_enough_parameters"])
        return

    dead = set(var.ALL_PLAYERS) - set(alive)
    target, _ = users.complete_match(targ, dead)
    if target is None:
        wrapper.pm(messages["consecrate_fail"].format(targ))
        return

    # we have a target, so mark them as consecrated, right now all this does is silence a VG for a night
    # but other roles that do stuff after death or impact dead players should have functionality here as well
    # (for example, if there was a role that could raise corpses as undead somethings, this would prevent that from working)
    # regardless if this has any actual effect or not, it still removes the priest from being able to vote

    evt = Event("consecrate", {})
    evt.dispatch(var, wrapper.source, target)

    wrapper.pm(messages["consecrate_success"].format(target))
    debuglog("{0} (priest) CONSECRATE: {1}".format(wrapper.source, target))
    add_absent(var, wrapper.source, "consecrating")
    from src.votes import chk_decision
    from src.wolfgame import chk_win
    if not chk_win():
        # game didn't immediately end due to marking as absent, see if we should force through a lynch
        chk_decision(var)
Пример #5
0
def get_target(var,
               wrapper,
               message,
               *,
               allow_self=False,
               allow_bot=False,
               not_self_message=None):
    """Autocomplete a target for an in-game command.

    :param var: Game state
    :param MessageDispatcher wrapper: Message context
    :param str message: Text to complete against
    :param bool allow_self: Whether or not to allow the current player as the target
    :param bool allow_bot: Whether or not to allow the bot as the target
    :param str not_self_message: If allow_self is False, the message key to output if we matched ourselves
    :returns: The matched target, or None if no matches
    :rtype: Optional[User]
    """
    from src import users  # FIXME: we should move get_target elsewhere to avoid circular imports
    if not message:
        wrapper.pm(messages["not_enough_parameters"])
        return

    players = get_players()
    if not allow_self and wrapper.source in players:
        players.remove(wrapper.source)

    if allow_bot:
        players.append(users.Bot)

    match = users.complete_match(message, players)
    if not match:
        if not len(match) and users.lower(wrapper.source.nick).startswith(
                users.lower(message)):
            wrapper.pm(messages[not_self_message or "no_target_self"])
            return
        if not len(match):
            wrapper.pm(messages["not_playing"].format(message))
        else:
            # display some helpful suggestions, including account disambiguation if needed
            nicks = Counter(users.lower(x.nick) for x in match)
            suggestions = []
            for nick, count in nicks.items():
                if count == 1:
                    suggestions.append(nick)
                else:
                    for user in match:
                        luser = user.lower()
                        if luser.nick == nick:
                            suggestions.append("{0}:{1}".format(
                                luser.nick, luser.account))
            suggestions.sort()
            wrapper.pm(messages["not_playing_suggestions"].format(
                message, suggestions))
        return

    return match.get()
Пример #6
0
def fwarn_list(var, wrapper, args):
    if args.help:
        wrapper.reply(messages["fwarn_list_syntax"])
        return

    if args.account or args.nick == "*":
        acc = args.nick
    else:
        m = users.complete_match(args.nick)
        if m:
            acc = m.get().account
        else:
            acc = args.nick

    if not acc:
        wrapper.reply(messages["fwarn_nick_invalid"].format(args.nick))
        return

    if acc == "*":
        warnings = db.list_all_warnings(list_all=args.all,
                                        skip=(args.page - 1) * 10,
                                        show=11)
    else:
        warnings = db.list_warnings(acc,
                                    expired=args.all,
                                    deleted=args.all,
                                    skip=(args.page - 1) * 10,
                                    show=11)
        points = db.get_warning_points(acc)
        wrapper.pm(messages["fwarn_list_header"].format(acc, points))

    for i, warning in enumerate(warnings):
        if i == 10:
            parts = []
            if args.all:
                parts.append(_wall[0])
            parts.append(acc)
            parts.append(str(args.page + 1))
            wrapper.pm(messages["warn_list_footer"].format("fwarn", parts))
            break
        wrapper.pm(messages["fwarn_list"].format(**warning))

    if not warnings:
        wrapper.pm(messages["fwarn_list_empty"])
Пример #7
0
def fwarn_add(var, wrapper, args):
    if args.help:
        wrapper.reply(messages["fwarn_add_syntax"])
        return

    if args.account:
        target = args.nick
    else:
        m = users.complete_match(args.nick)
        if m:
            target = m.get()
        else:
            target = args.nick

    if args.points < 0:
        wrapper.reply(messages["fwarn_points_invalid"])
        return

    try:
        expires = _parse_expires(args.expires)
    except ValueError:
        wrapper.reply(messages["fwarn_expiry_invalid"])
        return

    sanctions = {}

    if args.stasis is not None:
        if args.stasis < 1:
            wrapper.reply(messages["fwarn_stasis_invalid"])
            return
        sanctions["stasis"] = args.stasis

    if args.deny is not None:
        normalized_cmds = set()
        for cmd in args.deny:
            for obj in COMMANDS[cmd]:
                normalized_cmds.add(obj.key)
        # don't allow the warn command to be denied
        # in-game commands bypass deny restrictions as well
        normalized_cmds.discard("warn")
        sanctions["deny"] = normalized_cmds

    if args.ban is not None:
        try:
            sanctions["tempban"] = _parse_expires(args.ban)
        except ValueError:
            try:
                sanctions["tempban"] = int(args.ban)
            except ValueError:
                wrapper.reply(messages["fwarn_tempban_invalid"])
                return

    reason = " ".join(args.reason).strip()

    if args.notes is not None:
        notes = " ".join(args.notes).strip()
    else:
        notes = None

    warn_id = add_warning(target, args.points, wrapper.source, reason, notes,
                          expires, sanctions)
    if not warn_id:
        wrapper.reply(messages["fwarn_cannot_add"])
        return

    wrapper.reply(messages["fwarn_added"].format(warn_id))
    # Log to ops/log channel (even if the warning was placed in that channel)
    if var.LOG_CHANNEL:
        log_reason = reason
        if notes is not None:
            log_reason += " | " + notes
        if expires is None:
            log_exp = messages["fwarn_log_add_noexpiry"]
        else:
            log_exp = messages["fwarn_log_add_expiry"].format(expires)
        log_msg = messages["fwarn_log_add"].format(warn_id, target,
                                                   wrapper.source, log_reason,
                                                   args.points, log_exp)
        channels.get(var.LOG_CHANNEL).send(log_msg, prefix=var.LOG_PREFIX)