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()))
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)
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()))