def admin_kick(event, bot): channel, user = commandSplit(event.argument) user, reason = commandSplit(user) if not channel or not user: return bot.say(".%s #channel user [reason]" % event.command) elif channel[0] not in CHANNEL_PREFIXES: channel = '#' + channel l_user = user.lower() try: for w_event in bot.send_and_wait(None, stope=(("userKicked", ) + tuple(KICK_ERRORS)), f=bot.kick, fargs=(channel, user, reason), timeout=WAIT_TIMEOUT): if w_event.type == "userKicked" and w_event.target == channel and w_event.kicked.lower( ) == l_user: r_msg = "Successfully kicked (%s) from (%s)" % (user, channel) if reason: r_msg += " with reason (%s)" % esc(reason) bot.say(r_msg + '.') break r_msg = 'Failed to kick (%s) from (%s): %s' % (user, channel, w_event.type) if w_event.params[2]: r_msg += ' - %s' % w_event.params[2] bot.say(r_msg) break except TimeoutException: bot.say("Failed to kick (%s) in (%d second) timeout." % (channel, WAIT_TIMEOUT))
def admin_kick(event, bot): channel, user = commandSplit(event.argument) user, reason = commandSplit(user) if not channel or not user: return bot.say(".%s #channel user [reason]" % event.command) elif channel[0] not in CHANNEL_PREFIXES: channel = '#' + channel l_user = user.lower() try: for w_event in bot.send_and_wait(None, stope=(("userKicked",) + tuple(KICK_ERRORS)), f=bot.kick, fargs=(channel, user, reason), timeout=WAIT_TIMEOUT): if w_event.type == "userKicked" and w_event.target == channel and w_event.kicked.lower() == l_user: r_msg = "Successfully kicked (%s) from (%s)" % (user, channel) if reason: r_msg += " with reason (%s)" % esc(reason) bot.say(r_msg + '.') break r_msg = 'Failed to kick (%s) from (%s): %s' % (user, channel, w_event.type) if w_event.params[2]: r_msg += ' - %s' % w_event.params[2] bot.say(r_msg) break except TimeoutException: bot.say("Failed to kick (%s) in (%d second) timeout." % (channel, WAIT_TIMEOUT))
def send_msg_and_wait(bot, chan_or_user, msg): """ Helper method to send a PRIVMSG and check for errors/success """ try: for w_event in bot.send_and_wait(None, stope=(PRIVMSG_ERRORS), f=bot.sendmsg, fargs=(chan_or_user, msg), timeout=PRIVMSG_WAIT_TIMEOUT): r_msg = 'Message (%s) to (%s) failed: %s' % (esc(msg), chan_or_user, w_event.type) if w_event.params[2]: r_msg += ' - %s' % w_event.params[2] bot.say(r_msg) return False except TimeoutException: # Assume success return True
def send_msg_and_wait(bot, chan_or_user, msg): """ Helper method to send a PRIVMSG and check for errors/success """ try: for w_event in bot.send_and_wait(None, stope=(PRIVMSG_ERRORS), f=bot.sendmsg, fargs=(chan_or_user, msg), timeout=PRIVMSG_WAIT_TIMEOUT): r_msg = 'Message (%s) to (%s) failed: %s' % ( esc(msg), chan_or_user, w_event.type) if w_event.params[2]: r_msg += ' - %s' % w_event.params[2] bot.say(r_msg) return False except TimeoutException: # Assume success return True