Пример #1
0
def mode(irc, event, args):
    """[<channel>] <modes>

    Sets <modes> in <channel>. <channel> is only necessary if the command
    isn't sent in the channel itself.
    """
    try:
        if utils.is_private(event) or irc.is_channel(args[0]):
            if args[0] in irc.state["channels"]:
                channel = args[0]
                setmodes = utils.split_modes(args[1:])
            elif not utils.is_private(event):
                channel = event.target
                setmodes = utils.split_modes(args)
            else:
                irc.reply(event, utils.gethelp("mode"))
                return
        else:
            channel = event.target
            setmodes = utils.split_modes(args)

    except IndexError:
        irc.reply(event, utils.gethelp("mode"))

    else:
        if utils.is_allowed(irc, event.source, channel):
            already_op = irc.is_opped(irc.get_nick(), channel)
            if not already_op:
                setmodes.append("-o {}".format(irc.get_nick()))
            gotop = utils.getop(irc, channel)
            if gotop:
                for modes in utils.unsplit_modes(setmodes):
                    irc.mode(channel, modes)
Пример #2
0
def on_mode(irc, conn, event):
    channel = event.target
    modes = utils.split_modes(event.arguments)
    for mode in modes:
        if mode.startswith("+b"):
            if event.source.nick == irc.get_nick():
                continue
            mask = mode.split()[1]
            affects = utils.ban_affects(irc, channel, mask)
            names = irc.state["channels"][channel]["names"]
            if len(affects) >= len(names) / 2:
                setmodes = []
                bmask = utils.banmask(irc, event.source)
                setmodes.append("-b {}".format(mask))
                baffects = utils.ban_affects(irc, channel, bmask)
                for nick in baffects:
                    if irc.is_opped(nick, channel):
                        setmodes.append("-o {}".format(nick))
                    if irc.is_voiced(nick, channel):
                        setmodes.append("-v {}".format(nick))
                setmodes.append("+b {}".format(bmask))
                already_op = irc.is_opped(irc.get_nick(), channel)
                gotop = utils.getop(irc, channel)
                if gotop:
                    for modes in utils.unsplit_modes(setmodes):
                        irc.mode(channel, modes)
                    for nick in baffects:
                        irc.kick(channel, nick)
                    if not already_op:
                        irc.mode(channel, "-o {}".format(irc.get_nick()))
Пример #3
0
def unquiet(irc, event, args):
    """[<channel>] [<nick|hostmask>...]

    Unquiets <nick> (or yourself if no <nick> is specified) in <channel>.
    <channel> is only necessary if the command isn't sent in the channel
    itself.
    """
    setmodes = []
    try:
        if utils.is_private(event):
            channel = args[0]
            if len(args) > 1:
                nicks = args[1:]
            else:
                nicks = [event.source.nick]
        else:
            if len(args) > 0:
                if irc.is_channel(args[0]):
                    channel = args[0]
                    if len(args) > 1:
                        nicks = args[1:]
                    else:
                        nicks = [event.source.nick]
                else:
                    channel = event.target
                    nicks = args
            else:
                channel = event.target
                nicks = [event.source.nick]

    except IndexError:
        irc.reply(event, utils.gethelp("unquiet"))

    else:
        if utils.is_allowed(irc, event.source, channel):
            for nick in nicks:
                if utils.is_hostmask(nick):
                    hmask = nick
                else:
                    hmask = utils.gethm(irc, nick)
                if hmask and channel in irc.state["channels"]:
                    for bmask in irc.state["channels"][channel]["quiets"]:
                        if fnmatch(utils.irclower(hmask), utils.irclower(bmask)):
                            setmodes.append("-q {}".format(bmask))
                else:
                    return
            if len(setmodes) == 0:
                return
            already_op = irc.is_opped(irc.get_nick(), channel)
            if not already_op:
                setmodes.append("-o {}".format(irc.get_nick()))
            gotop = utils.getop(irc, channel)
            if gotop:
                for mode in utils.unsplit_modes(setmodes):
                    irc.mode(channel, mode)
Пример #4
0
def quiet(irc, event, args):
    """[<channel>] <nick|hostmask> [<nick|hostmask>...]

    Quiets <nick> in <channel>. <channel> is only necessary if the command
    isn't sent in the channel itself.
    """
    setmodes = []
    affected = []
    try:
        if utils.is_private(event):
            channel = args[0]
            nicks = args[1:]
        else:
            if irc.is_channel(args[0]):
                channel = args[0]
                nicks = args[1:]
            else:
                channel = event.target
                nicks = args

    except IndexError:
        irc.reply(event, utils.gethelp("quiet"))

    else:
        if utils.is_allowed(irc, event.source, channel):
            for nick in nicks:
                if utils.is_hostmask(nick):
                    bmask = nick
                else:
                    bmask = utils.banmask(irc, nick)
                setmodes.append("+q {}".format(bmask))
                for affect in utils.ban_affects(irc, channel, bmask):
                    if affect not in affected and affect != irc.get_nick():
                        affected.append(affect)
            for nick in affected:
                if irc.is_opped(nick, channel):
                    setmodes.append("-o {}".format(nick))
                if irc.is_voiced(nick, channel):
                    setmodes.append("-v {}".format(nick))
            if len(setmodes) == 0:
                return
            already_op = irc.is_opped(irc.get_nick(), channel)
            if not already_op:
                setmodes.append("-o {}".format(irc.get_nick()))
            gotop = utils.getop(irc, channel)
            if gotop:
                for mode in utils.unsplit_modes(setmodes):
                    irc.mode(channel, mode)
Пример #5
0
def kick(irc, event, args):
    """[<channel>] <nick> [<nick>...] [:][<reason>]

    Kicks <nick> in <channel>. <channel> is only necessary if the
    command isn't sent in the channel itself. It is recommended to
    use ':' as a seperator between <nick> and <reason>, otherwise, if
    there's a nick in the channel matching the first word in reason it
    will be kicked.
    """
    prepare_nicks = []
    reason = None
    try:
        if utils.is_private(event):
            channel = args[0]
            nicks = args[1:]

        else:
            if irc.is_channel(args[0]):
                channel = args[0]
                nicks = args[1:]

            else:
                channel = event.target
                nicks = args

    except IndexError:
        irc.reply(event, utils.gethelp("kick"))

    else:
        if utils.is_allowed(irc, event.source, channel):
            for nick in nicks:
                if nick in irc.state["channels"][channel]["names"] and nick not in prepare_nicks and not nick.startswith(":"):
                    prepare_nicks.append(nick)
                else:
                    reason = " ".join(nicks[len(prepare_nicks):]).lstrip(": ")
                    break
            nicks = prepare_nicks
            already_op = irc.is_opped(irc.get_nick(), channel)
            gotop = utils.getop(irc, channel)
            if gotop:
                for nick in nicks:
                    if reason:
                        irc.kick(channel, nick, reason)
                    else:
                        irc.kick(channel, nick)
                if not already_op:
                    irc.mode(channel, "-o {}".format(irc.get_nick()))
Пример #6
0
def deop(irc, event, args):
    """[<channel>] [<nick>...]

    Deops <nick> (or yourself if no <nick> is specified) in <channel>.
    <channel> is only necessary if the command isn't set in the channel
    itself.
    """
    setmodes = []
    try:
        if len(args) == 0:
            nicks = [event.source.nick]
            channel = event.target
        elif irc.is_channel(args[0]):
            channel = args[0]
            if len(args) > 1:
                nicks = args[1:]
            else:
                nicks = [event.source.nick]
        else:
            nicks = args
            channel = event.target

    except IndexError:
        irc.reply(event, utils.gethelp("deop"))

    else:
        if utils.is_allowed(irc, event.source, channel):
            already_op = irc.is_opped(irc.get_nick(), channel)
            if "*" in nicks:
                nicks = irc.state["channels"][channel]["names"]
                if irc.get_nick() in nicks:
                    nicks.remove(irc.get_nick())
            if irc.channels[channel].get("chanserv", irc.chanserv) and "ChanServ" in nicks:
                nicks.remove("ChanServ")
            for nick in nicks:
                if irc.is_opped(nick, channel):
                    setmodes.append("-o {}".format(nick))
            if len(setmodes) == 0:
                return
            if not already_op:
                setmodes.append("-o {}".format(irc.get_nick()))
            gotop = utils.getop(irc, channel)
            if gotop:
                for mode in utils.unsplit_modes(setmodes):
                    irc.mode(channel, mode)
Пример #7
0
def kban(irc, event, args):
    """[<channel>] <nick|hostmask> [<nick|hostmask>...] [:][<reason>]

    Bans <nick> in <channel> and kicks anyone affected using <reason>
    as the kick message if specified. <channel> is only necessary if
    the command isn't sent in the channel itself. It is recommended to
    use ':' as a seperator between <nick> and <reason>, otherwise, if
    there's a nick in the channel matching the first word in reason it
    will be kicked.
    """
    prepare_nicks = []
    setmodes = []
    affected = []
    reason = None
    try:
        if utils.is_private(event):
            channel = args[0]
            nicks = args[1:]

        else:
            if irc.is_channel(args[0]):
                channel = args[0]
                nicks = args[1:]

            else:
                channel = event.target
                nicks = args

    except IndexError:
        irc.reply(event, utils.gethelp("kban"))

    else:
        if utils.is_allowed(irc, event.source, channel):
            for nick in nicks:
                if nick in irc.state["channels"][channel]["names"] and nick not in prepare_nicks and not nick.startswith(":"):
                    prepare_nicks.append(nick)
                elif utils.is_hostmask(nick):
                    prepare_nicks.append(nick)
                else:
                    reason = " ".join(nicks[len(prepare_nicks):]).lstrip(": ")
                    break
            nicks = prepare_nicks
            for nick in nicks:
                if utils.is_hostmask(nick):
                    bmask = nick
                else:
                    bmask = utils.banmask(irc, nick)
                setmodes.append("+b {}".format(bmask))
                for affect in utils.ban_affects(irc, channel, bmask):
                    if affect not in affected and affect != irc.get_nick():
                        if irc.is_opped(affect, channel):
                            setmodes.append("-o {}".format(affect))
                        if irc.is_voiced(affect, channel):
                            setmodes.append("-v {}".format(affect))
                        affected.append(affect)
            if len(setmodes) == 0:
                return
            already_op = irc.is_opped(irc.get_nick(), channel)
            gotop = utils.getop(irc, channel)
            if gotop:
                for mode in utils.unsplit_modes(setmodes):
                    irc.mode(channel, mode)
                for nick in affected:
                    if reason:
                        irc.kick(channel, nick, reason)
                    else:
                        irc.kick(channel, nick)
                if not already_op:
                    irc.mode(channel, "-o {}".format(irc.get_nick()))