Exemplo n.º 1
0
def warn_ack(var, wrapper, args):
    if args.help:
        wrapper.reply(messages["warn_ack_syntax"])
        return

    acc = wrapper.source.account
    if not acc:
        return

    warning = db.get_warning(args.id, acc)
    if not warning:
        wrapper.reply(messages["fwarn_invalid_warning"])
        return

    # only add stasis if this is the first time this warning is being acknowledged
    if not warning["ack"] and warning["sanctions"].get("stasis", 0) > 0:
        db.set_stasis(warning["sanctions"]["stasis"], acc, relative=True)
        db.init_vars()

    db.acknowledge_warning(args.id)
    wrapper.reply(messages["fwarn_done"])
Exemplo n.º 2
0
def warn(var, wrapper, message):
    """View and acknowledge your warnings."""
    # !warn list [-all] [page] - lists all active warnings, or all warnings if all passed
    # !warn view <id> - views details on warning id
    # !warn ack <id> - acknowledges warning id
    # Default if only !warn is given is to do !warn list.
    params = re.split(" +", message)

    try:
        command = params.pop(0)
        if command == "":
            command = "list"
    except IndexError:
        command = "list"

    if command not in ("list", "view", "ack", "help"):
        wrapper.reply(messages["warn_usage"])
        return

    if command == "help":
        try:
            subcommand = params.pop(0)
        except IndexError:
            wrapper.reply(messages["warn_help_syntax"])
            return
        if subcommand not in ("list", "view", "ack", "help"):
            wrapper.reply(messages["warn_usage"])
            return
        wrapper.reply(messages["warn_{0}_syntax".format(subcommand)])
        return

    if command == "list":
        list_all = False
        page = 1
        try:
            list_all = params.pop(0)
            target = params.pop(0)
            page = int(params.pop(0))
        except IndexError:
            pass
        except ValueError:
            wrapper.reply(messages["fwarn_page_invalid"])
            return

        try:
            if list_all and list_all != "-all":
                page = int(list_all)
                list_all = False
            elif list_all == "-all":
                list_all = True
        except ValueError:
            wrapper.reply(messages["fwarn_page_invalid"])
            return

        acc, hm = parse_warning_target(wrapper.source.nick)
        warnings = db.list_warnings(acc,
                                    hm,
                                    expired=list_all,
                                    skip=(page - 1) * 10,
                                    show=11)
        points = db.get_warning_points(acc, hm)
        wrapper.pm(messages["warn_list_header"].format(
            points, "" if points == 1 else "s"))

        i = 0
        for warn in warnings:
            i += 1
            if (i == 11):
                parts = []
                if list_all:
                    parts.append("-all")
                parts.append(str(page + 1))
                wrapper.pm(messages["warn_list_footer"].format(
                    " ".join(parts)))
                break
            start = ""
            end = ""
            ack = ""
            if warn["expires"] is not None:
                if warn["expired"]:
                    expires = messages["fwarn_list_expired"].format(
                        warn["expires"])
                else:
                    expires = messages["fwarn_view_expires"].format(
                        warn["expires"])
            else:
                expires = messages["fwarn_never_expires"]
            if warn["expired"]:
                start = "\u000314"
                end = " [\u00037{0}\u000314]\u0003".format(
                    messages["fwarn_expired"])
            if not warn["ack"]:
                ack = "\u0002!\u0002 "
            wrapper.pm(messages["warn_list"].format(
                start, ack, warn["id"], warn["issued"], warn["reason"],
                warn["amount"], "" if warn["amount"] == 1 else "s", expires,
                end))
        if i == 0:
            wrapper.pm(messages["fwarn_list_empty"])
        return

    if command == "view":
        try:
            warn_id = params.pop(0)
            if warn_id[0] == "#":
                warn_id = warn_id[1:]
            warn_id = int(warn_id)
        except (IndexError, ValueError):
            wrapper.reply(messages["warn_view_syntax"])
            return

        acc, hm = parse_warning_target(wrapper.source.nick)
        warning = db.get_warning(warn_id, acc, hm)
        if warning is None:
            wrapper.reply(messages["fwarn_invalid_warning"])
            return

        if warning["expired"]:
            expires = messages["fwarn_view_expired"].format(warning["expires"])
        elif warning["expires"] is None:
            expires = messages["fwarn_view_active"].format(
                messages["fwarn_never_expires"])
        else:
            expires = messages["fwarn_view_active"].format(
                messages["fwarn_view_expires"].format(warning["expires"]))

        wrapper.pm(messages["warn_view_header"].format(
            warning["id"], warning["issued"], warning["amount"],
            "" if warning["amount"] == 1 else "s", expires))
        wrapper.pm(warning["reason"])

        sanctions = []
        if not warning["ack"]:
            sanctions.append(messages["warn_view_ack"].format(warning["id"]))
        if warning["sanctions"]:
            sanctions.append(messages["fwarn_view_sanctions"])
            if "stasis" in warning["sanctions"]:
                if warning["sanctions"]["stasis"] != 1:
                    sanctions.append(
                        messages["fwarn_view_stasis_plural"].format(
                            warning["sanctions"]["stasis"]))
                else:
                    sanctions.append(messages["fwarn_view_stasis_sing"])
            if "deny" in warning["sanctions"]:
                sanctions.append(messages["fwarn_view_deny"].format(", ".join(
                    warning["sanctions"]["deny"])))
        if sanctions:
            wrapper.pm(" ".join(sanctions))
        return

    if command == "ack":
        try:
            warn_id = params.pop(0)
            if warn_id[0] == "#":
                warn_id = warn_id[1:]
            warn_id = int(warn_id)
        except (IndexError, ValueError):
            wrapper.reply(messages["warn_ack_syntax"])
            return

        acc, hm = parse_warning_target(wrapper.source.nick)
        warning = db.get_warning(warn_id, acc, hm)
        if warning is None:
            wrapper.reply(messages["fwarn_invalid_warning"])
            return

        # only add stasis if this is the first time this warning is being acknowledged
        if not warning["ack"] and warning["sanctions"].get("stasis", 0) > 0:
            db.set_stasis(warning["sanctions"]["stasis"],
                          acc,
                          hm,
                          relative=True)
            db.init_vars()
        db.acknowledge_warning(warn_id)
        wrapper.reply(messages["fwarn_done"])
        return
Exemplo n.º 3
0
def warn(var, wrapper, message):
    """View and acknowledge your warnings."""
    # !warn list [-all] [page] - lists all active warnings, or all warnings if all passed
    # !warn view <id> - views details on warning id
    # !warn ack <id> - acknowledges warning id
    # Default if only !warn is given is to do !warn list.
    params = re.split(" +", message)

    try:
        command = params.pop(0)
        if command == "":
            command = "list"
    except IndexError:
        command = "list"

    if command not in ("list", "view", "ack", "help"):
        wrapper.reply(messages["warn_usage"])
        return

    if command == "help":
        try:
            subcommand = params.pop(0)
        except IndexError:
            wrapper.reply(messages["warn_help_syntax"])
            return
        if subcommand not in ("list", "view", "ack", "help"):
            wrapper.reply(messages["warn_usage"])
            return
        wrapper.reply(messages["warn_{0}_syntax".format(subcommand)])
        return

    if command == "list":
        list_all = False
        page = 1
        try:
            list_all = params.pop(0)
            target = params.pop(0)
            page = int(params.pop(0))
        except IndexError:
            pass
        except ValueError:
            wrapper.reply(messages["fwarn_page_invalid"])
            return

        try:
            if list_all and list_all != "-all":
                page = int(list_all)
                list_all = False
            elif list_all == "-all":
                list_all = True
        except ValueError:
            wrapper.reply(messages["fwarn_page_invalid"])
            return

        acc, hm = parse_warning_target(wrapper.source.nick)
        warnings = db.list_warnings(acc, hm, expired=list_all, skip=(page-1)*10, show=11)
        points = db.get_warning_points(acc, hm)
        wrapper.pm(messages["warn_list_header"].format(points, "" if points == 1 else "s"))

        i = 0
        for warn in warnings:
            i += 1
            if (i == 11):
                parts = []
                if list_all:
                    parts.append("-all")
                parts.append(str(page + 1))
                wrapper.pm(messages["warn_list_footer"].format(" ".join(parts)))
                break
            start = ""
            end = ""
            ack = ""
            if warn["expires"] is not None:
                if warn["expired"]:
                    expires = messages["fwarn_list_expired"].format(warn["expires"])
                else:
                    expires = messages["fwarn_view_expires"].format(warn["expires"])
            else:
                expires = messages["fwarn_never_expires"]
            if warn["expired"]:
                start = "\u000314"
                end = " [\u00037{0}\u000314]\u0003".format(messages["fwarn_expired"])
            if not warn["ack"]:
                ack = "\u0002!\u0002 "
            wrapper.pm(messages["warn_list"].format(
                start, ack, warn["id"], warn["issued"], warn["reason"], warn["amount"],
                "" if warn["amount"] == 1 else "s", expires, end))
        if i == 0:
            wrapper.pm(messages["fwarn_list_empty"])
        return

    if command == "view":
        try:
            warn_id = params.pop(0)
            if warn_id[0] == "#":
                warn_id = warn_id[1:]
            warn_id = int(warn_id)
        except (IndexError, ValueError):
            wrapper.reply(messages["warn_view_syntax"])
            return

        acc, hm = parse_warning_target(wrapper.source.nick)
        warning = db.get_warning(warn_id, acc, hm)
        if warning is None:
            wrapper.reply(messages["fwarn_invalid_warning"])
            return

        if warning["expired"]:
            expires = messages["fwarn_view_expired"].format(warning["expires"])
        elif warning["expires"] is None:
            expires = messages["fwarn_view_active"].format(messages["fwarn_never_expires"])
        else:
            expires = messages["fwarn_view_active"].format(messages["fwarn_view_expires"].format(warning["expires"]))

        wrapper.pm(messages["warn_view_header"].format(
            warning["id"], warning["issued"], warning["amount"],
            "" if warning["amount"] == 1 else "s", expires))
        wrapper.pm(warning["reason"])

        sanctions = []
        if not warning["ack"]:
            sanctions.append(messages["warn_view_ack"].format(warning["id"]))
        if warning["sanctions"]:
            sanctions.append(messages["fwarn_view_sanctions"])
            if "stasis" in warning["sanctions"]:
                if warning["sanctions"]["stasis"] != 1:
                    sanctions.append(messages["fwarn_view_stasis_plural"].format(warning["sanctions"]["stasis"]))
                else:
                    sanctions.append(messages["fwarn_view_stasis_sing"])
            if "deny" in warning["sanctions"]:
                sanctions.append(messages["fwarn_view_deny"].format(", ".join(warning["sanctions"]["deny"])))
        if sanctions:
            wrapper.pm(" ".join(sanctions))
        return

    if command == "ack":
        try:
            warn_id = params.pop(0)
            if warn_id[0] == "#":
                warn_id = warn_id[1:]
            warn_id = int(warn_id)
        except (IndexError, ValueError):
            wrapper.reply(messages["warn_ack_syntax"])
            return

        acc, hm = parse_warning_target(wrapper.source.nick)
        warning = db.get_warning(warn_id, acc, hm)
        if warning is None:
            wrapper.reply(messages["fwarn_invalid_warning"])
            return

        # only add stasis if this is the first time this warning is being acknowledged
        if not warning["ack"] and warning["sanctions"].get("stasis", 0) > 0:
            db.set_stasis(warning["sanctions"]["stasis"], acc, hm, relative=True)
            db.init_vars()
        db.acknowledge_warning(warn_id)
        wrapper.reply(messages["fwarn_done"])
        return