Example #1
0
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))
Example #2
0
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))
Example #3
0
def admin_part(event, bot):
    channel, reason = commandSplit(event.argument)

    if not channel:
        bot.say("Bye.")
        channel = event.target
    elif channel[0] not in CHANNEL_PREFIXES:
        channel = '#' + channel

    try:
        for w_event in bot.send_and_wait(None,
                                         stope=(("left", ) +
                                                tuple(PART_ERRORS)),
                                         f=bot.leave,
                                         fargs=(channel, reason),
                                         timeout=WAIT_TIMEOUT):
            if w_event.type == "left" and w_event.target == channel:
                # We already said bye in this case
                if channel != event.target:
                    r_msg = "Successfully parted (%s)" % channel
                    if reason:
                        r_msg += " with reason (%s)" % reason
                    bot.say(r_msg + '.')
                break
            r_msg = 'Failed to part from (%s): %s' % (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 part (%s) in (%d second) timeout." %
                (channel, WAIT_TIMEOUT))
Example #4
0
def timers(event, bot):
    command, args = commandSplit(event.argument)

    if command == "show":
        bot.say("Timers:")
        for timer in Timers.getTimers().itervalues():
            bot.say(" - %s: reps = %s, delay = %s, f = %s" %
                    (timer.name, timer.reps, timer.interval, timer.f))

    elif command == "add":
        args = argumentSplit(args, 4)  #add timername delay reps msg
        if not args:
            bot.say(
                "Not enough arguments. Need: timername delay reps message (reps <= 0 means forever)"
            )
            return
        msg = Timers.addtimer(args[0],
                              float(args[1]),
                              timercallback,
                              reps=int(args[2]),
                              msg=args[3],
                              bot=bot,
                              channel=event.target)[1]
        bot.say("%s (%s)" % (msg, args[0]))

    elif command == "stop":
        bot.say(Timers.deltimer(args)[1])
Example #5
0
def admin_join(event, bot):
    channel, key = commandSplit(event.argument)
    if not channel:
        return bot.say(".%s #channel [key]" % event.command)
    elif channel[0] not in CHANNEL_PREFIXES:
        channel = '#' + channel

    try:
        for w_event in bot.send_and_wait(None,
                                         stope=(("joined", ) +
                                                tuple(JOIN_ERRORS)),
                                         f=bot.join,
                                         fargs=(channel, key),
                                         timeout=WAIT_TIMEOUT):
            if w_event.type == "joined" and w_event.target == channel:
                r_msg = "Successfully joined (%s)" % channel
                if key:
                    r_msg += " with key (%s)" % key
                bot.say(r_msg + '.')
                break
            elif w_event.type in JOIN_ERRORS:
                if w_event.params[1] != channel:
                    continue
                r_msg = 'Failed to join (%s): %s' % (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 join (%s) in (%d second) timeout." %
                (channel, WAIT_TIMEOUT))
Example #6
0
def admin_part(event, bot):
	channel, reason = commandSplit(event.argument)

	if not channel:
		bot.say("Bye.")
		channel = event.target
	elif channel[0] not in CHANNEL_PREFIXES:
		channel = '#' + channel

	try:
		for w_event in bot.send_and_wait(None, stope=(("left",) + tuple(PART_ERRORS)),
						f=bot.leave, fargs=(channel, reason), timeout=WAIT_TIMEOUT):
			if w_event.type == "left" and w_event.target == channel:
				# We already said bye in this case
				if channel != event.target:
					r_msg = "Successfully parted (%s)" % channel
					if reason:
						r_msg += " with reason (%s)" % reason
					bot.say(r_msg + '.')
				break
			r_msg = 'Failed to part from (%s): %s' % (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 part (%s) in (%d second) timeout." % (channel, WAIT_TIMEOUT))
Example #7
0
def admin_join(event, bot):
	channel, key = commandSplit(event.argument)
	if not channel:
		return bot.say(".%s #channel [key]" % event.command)
	elif channel[0] not in CHANNEL_PREFIXES:
		channel = '#' + channel

	try:
		for w_event in bot.send_and_wait(None, stope=(("joined",) + tuple(JOIN_ERRORS)),
						f=bot.join, fargs=(channel, key), timeout=WAIT_TIMEOUT):
			if w_event.type == "joined" and w_event.target == channel:
				r_msg = "Successfully joined (%s)" % channel
				if key:
					r_msg += " with key (%s)" % key
				bot.say(r_msg + '.')
				break
			elif w_event.type in JOIN_ERRORS:
				if w_event.params[1] != channel:
					continue
				r_msg = 'Failed to join (%s): %s' % (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 join (%s) in (%d second) timeout." % (channel, WAIT_TIMEOUT))
Example #8
0
def timers(event, bot):
	command, args = commandSplit(event.argument)
	
	if command == "show":
		bot.say("Timers:")
		for timer in Timers.getTimers().itervalues():
			bot.say(" - %s: reps = %s, delay = %s, f = %s" % (timer.name, timer.reps, timer.interval, timer.f))
		
	elif command == "add":
		args = argumentSplit(args, 4) #add timername delay reps msg
		if not args:
			bot.say("Not enough arguments. Need: timername delay reps message (reps <= 0 means forever)")
			return
		try:
			if Timers.addtimer(args[0], float(args[1]), timercallback, reps=int(args[2]), msg=args[3], bot=bot, channel=event.target):
				bot.say("Timer added (%s)" % args[0])
			else:
				bot.say("Timer not added for some reason?")
		except TimerExists:
			bot.say("Timer not added because it exists already.")
		except TimerInvalidName:
			bot.say("Timer not added because it has an invalid name.")

	elif command == "stop":
		try: 
			Timers.deltimer(args)
			bot.say("Timer stopped (%s)" % args)
		except (TimerNotFound, TimerInvalidName):
			bot.say("Can't stop (%s) because timer not found or internal timer." % args)
Example #9
0
def admin_action(event, bot):
	msg = event.argument

	if event.isPM():
		chan_or_user, msg = commandSplit(msg)
		if not chan_or_user or not msg:
			return bot.say(".%s #channel action" % event.command)
	elif not msg:
		return bot.say(".%s action" % event.command)
	else:
		chan_or_user = event.target

	if send_msg_and_wait(bot, chan_or_user, "\x01ACTION %s\x01" % msg) and event.isPM():
		bot.say("Successfully sent action to (%s)." % chan_or_user)
Example #10
0
def admin_msg(event, bot):
	msg = event.argument

	if event.isPM():
		chan_or_user, msg = commandSplit(msg)
		if not chan_or_user or not msg:
			return bot.say(".%s #channel message" % event.command)
	elif not msg:
		return bot.say(".%s message" % event.command)
	else:
		chan_or_user = event.target

	if send_msg_and_wait(bot, chan_or_user, msg) and event.isPM():
		bot.say("Successfully sent message to (%s)." % chan_or_user)
Example #11
0
def admin_msg(event, bot):
    msg = event.argument

    if event.isPM():
        chan_or_user, msg = commandSplit(msg)
        if not chan_or_user or not msg:
            return bot.say(".%s #channel message" % event.command)
    elif not msg:
        return bot.say(".%s message" % event.command)
    else:
        chan_or_user = event.target

    if send_msg_and_wait(bot, chan_or_user, msg) and event.isPM():
        bot.say("Successfully sent message to (%s)." % chan_or_user)
Example #12
0
def admin_rage(event, bot):
	msg = event.argument

	if event.isPM():
		chan_or_user, msg = commandSplit(msg)
		if not chan_or_user:
			return bot.say(".%s #channel FURIOUS_MESSAGE" % event.command)
	else:
		chan_or_user = event.target

	if not msg:
		msg = 'A' * randint(200, 400)

	if send_msg_and_wait(bot, chan_or_user, AAA(msg)) and event.isPM():
		bot.say("Successfully sent FURIOUS_MESSAGE to (%s)." % chan_or_user)
Example #13
0
def admin_rage(event, bot):
    msg = event.argument

    if event.isPM():
        chan_or_user, msg = commandSplit(msg)
        if not chan_or_user:
            return bot.say(".%s #channel FURIOUS_MESSAGE" % event.command)
    else:
        chan_or_user = event.target

    if not msg:
        msg = 'A' * randint(200, 400)

    if send_msg_and_wait(bot, chan_or_user, AAA(msg)) and event.isPM():
        bot.say("Successfully sent FURIOUS_MESSAGE to (%s)." % chan_or_user)
Example #14
0
def admin_action(event, bot):
    msg = event.argument

    if event.isPM():
        chan_or_user, msg = commandSplit(msg)
        if not chan_or_user or not msg:
            return bot.say(".%s #channel action" % event.command)
    elif not msg:
        return bot.say(".%s action" % event.command)
    else:
        chan_or_user = event.target

    if send_msg_and_wait(bot, chan_or_user,
                         "\x01ACTION %s\x01" % msg) and event.isPM():
        bot.say("Successfully sent action to (%s)." % chan_or_user)
Example #15
0
def samplecommand(event, bot):
	""" samplecommand [option] [argument]. samplecommand will do things depending on what option is used. 
	Available option: something, dothing
	|samplecommand something [argument]: will output "something", and if argument is present, will follow.
	|samplecommand dothing [argument]: will output argument if it exists, followed by "dothing"
	"""
	#do some things
	command, args = commandSplit(event.argument)
	if command == "something":
		if args: bot.say("%s %s" % (command, args))
		else : bot.say("%s" % command)
	elif command == "dothing":
		if args: bot.say("%s %s" % (args, command))
		else : bot.say("%s" % command)
	else:
		bot.say(functionHelp(samplecommand))
Example #16
0
def samplecommand(event, bot):
    """ samplecommand [option] [argument]. samplecommand will do things depending on what option is used. 
	Available option: something, dothing
	|samplecommand something [argument]: will output "something", and if argument is present, will follow.
	|samplecommand dothing [argument]: will output argument if it exists, followed by "dothing"
	"""
    #do some things
    command, args = commandSplit(event.argument)
    if command == "something":
        if args: bot.say("%s %s" % (command, args))
        else: bot.say("%s" % command)
    elif command == "dothing":
        if args: bot.say("%s %s" % (args, command))
        else: bot.say("%s" % command)
    else:
        bot.say(functionHelp(samplecommand))
Example #17
0
def steamchatcmd(event, bot):
	""" steamchat [kick user]. steamchat without arguments will display currently joined/listening steam persons.
	steamchat kick user will kick the supplied user from listening/sending to this channel.
	"""
	if event.argument:
		command, argument = commandSplit(event.argument)
		if command == "kick" and argument:
			cthread = CHAT_THREADS.get(bot.network)
			if cthread: cthread.fromIRC("kickUser", event.nick if event.isPM() else event.target, argument)
			else: bot.say("Error: No Steamchat available for this network.")
		else:
			bot.say(functionHelp(steamchatcmd))
	else:
		#list all
		cthread = CHAT_THREADS.get(bot.network)
		if cthread: cthread.fromIRC("listUsers", event.nick if event.isPM() else event.target)
		else: bot.say("Error: No Steamchat available for this network.")
Example #18
0
def statecommand(event, bot):
    command, args = commandSplit(event.argument)

    if command == "channel":
        if not args:
            for chan in bot.state.channels.keys():
                bot.say("Users on channel (%s): %s" % (chan, ", ".join(
                    bot.state.channels.get(chan).users.keys())))
        else:
            chan = bot.state.channels.get(args, None)
            if chan:
                bot.say("Users on channel (%s): %s" %
                        (args, ", ".join(chan.users.keys())))
            else:
                bot.say("lol dunno channel %s" % args)

    elif command == "bans":
        if not args:
            for chan in bot.state.channels.keys():
                bot.say("Bans on channel (%s): %s" %
                        (chan, ", ".join(bot.state.channels.get(chan).keys())))
        else:
            chan = bot.state.channels.get(args, None)
            if chan:
                bot.say("Bans on channel (%s): %s" %
                        (args, ", ".join(chan.banlist.keys())))
            else:
                bot.say("lol dunno channel %s" % args)

    elif command == "network":
        bot.say("Known users on network: %s" %
                ", ".join(bot.state.users.keys()))

    elif command == "ops":
        for chan in bot.state.channels.keys():
            bot.say(
                "Ops on %s: %s" %
                (chan, list(bot.state.channels.get(chan, None).ops))
            )  # most likely not threadsafe, don't iterate over sets, probably.
    elif command == "channels":
        bot.say("On channels: %s" % ", ".join(bot.state.channels.keys()))
    else:
        bot.say("state: channel, network, channels, ops")
Example #19
0
def timers(event, bot):
    command, args = commandSplit(event.argument)

    if command == "show":
        bot.say("Timers:")
        for timer in Timers.getTimers().itervalues():
            bot.say(" - %s: reps = %s, delay = %s, f = %s" %
                    (timer.name, timer.reps, timer.interval, timer.f))

    elif command == "add":
        args = argumentSplit(args, 4)  #add timername delay reps msg
        if not args:
            bot.say(
                "Not enough arguments. Need: timername delay reps message (reps <= 0 means forever)"
            )
            return
        try:
            if Timers.addtimer(args[0],
                               float(args[1]),
                               timercallback,
                               reps=int(args[2]),
                               msg=args[3],
                               bot=bot,
                               channel=event.target):
                bot.say("Timer added (%s)" % args[0])
            else:
                bot.say("Timer not added for some reason?")
        except TimerExists:
            bot.say("Timer not added because it exists already.")
        except TimerInvalidName:
            bot.say("Timer not added because it has an invalid name.")

    elif command == "stop":
        try:
            Timers.deltimer(args)
            bot.say("Timer stopped (%s)" % args)
        except (TimerNotFound, TimerInvalidName):
            bot.say(
                "Can't stop (%s) because timer not found or internal timer." %
                args)
Example #20
0
def statecommand(event, bot):
	command, args = commandSplit(event.argument)
	
	if command == "channel":
		if not args:
			for chan in bot.state.channels.keys():
				bot.say("Users on channel (%s): %s" % (chan,
					", ".join(bot.state.channels.get(chan).users.keys())))
		else:
			chan = bot.state.channels.get(args, None)
			if chan:
				bot.say("Users on channel (%s): %s" % (args, 
					", ".join(chan.users.keys())))
			else:
				bot.say("lol dunno channel %s" % args)
	
	elif command == "bans":
		if not args:
			for chan in bot.state.channels.keys():
				bot.say("Bans on channel (%s): %s" % (chan,
					", ".join(bot.state.channels.get(chan).keys())))
		else:
			chan = bot.state.channels.get(args, None)
			if chan:
				bot.say("Bans on channel (%s): %s" % (args, 
					", ".join(chan.banlist.keys())))
			else:
				bot.say("lol dunno channel %s" % args)
	
	elif command == "network":
		bot.say("Known users on network: %s" % ", ".join(bot.state.users.keys()))
		
	elif command == "ops":
		for chan in bot.state.channels.keys():
			bot.say("Ops on %s: %s" % (chan, list(bot.state.channels.get(chan, None).ops))) # most likely not threadsafe, don't iterate over sets, probably.
	elif command == "channels":
		bot.say("On channels: %s" % ", ".join(bot.state.channels.keys()))
	else:
		bot.say("state: channel, network, channels, ops")
Example #21
0
def statecommand(event, bot):
    command, args = commandSplit(event.argument)

    if command == "channel":
        if not args:
            for chan in bot.state.channels.itervalues():
                bot.say("Users on channel (%s): %s" %
                        (chan.name, ", ".join(chan.users)))
        else:
            chan = bot.state.channels.get(args, None)
            if chan:
                bot.say("Users on channel (%s): %s" %
                        (args, ", ".join(chan.users)))
            else:
                bot.say("lol dunno channel %s" % args)

    elif command == "bans":
        if not args:
            for chan in bot.state.channels.itervalues():
                bot.say("Bans on channel (%s): %s" %
                        (chan.name, ", ".join(chan.banlist.iterkeys())))
        else:
            chan = bot.state.channels.get(args, None)
            if chan:
                bot.say("Bans on channel (%s): %s" %
                        (args, ", ".join(chan.banlist.iterkeys())))
            else:
                bot.say("lol dunno channel %s" % args)

    elif command == "network":
        bot.say("Known users on network: %s" %
                ", ".join(bot.state.users.keys()))

    elif command == "channels":
        bot.say("On channels: %s" % ", ".join(bot.state.channels.keys()))
    else:
        bot.say("state: channel, network, channels")
Example #22
0
def steamchatcmd(event, bot):
    """ steamchat [kick user]. steamchat without arguments will display currently joined/listening steam persons.
	steamchat kick user will kick the supplied user from listening/sending to this channel.
	"""
    if event.argument:
        command, argument = commandSplit(event.argument)
        if command == "kick" and argument:
            cthread = CHAT_THREADS.get(bot.network)
            if cthread:
                cthread.fromIRC("kickUser",
                                event.nick if event.isPM() else event.target,
                                argument)
            else:
                bot.say("Error: No Steamchat available for this network.")
        else:
            bot.say(functionHelp(steamchatcmd))
    else:
        #list all
        cthread = CHAT_THREADS.get(bot.network)
        if cthread:
            cthread.fromIRC("listUsers",
                            event.nick if event.isPM() else event.target)
        else:
            bot.say("Error: No Steamchat available for this network.")
Example #23
0
	def steamCMD(self, sourceid, msg):
		#stolen from dispatcher
		command, argument = commandSplit(msg)
		command = command[len(self.cmdprefix):].lower()
		u = self.getUser(sourceid)
		# TODO: Someone should clean this up a bit... probably.
		if command == "listen":
			if not argument:
				if not u or not u.channels: return self.steamSay(sourceid, 'Not listening to any channels. Type "listen <#channelname>" to start snooping.')
				else: return self.steamSay(sourceid, "Listening to:%s\n" % "\n".join(u.channels))
			else:
				if argument not in self.container.state.channels:
					return self.steamSay(sourceid, "Can't listen to channel I'm not in.")
				#else listen to channel
				else:
					u.channels.add(argument)
					self.channels.setdefault(argument, set([])).add(u)
					self.ircSay(argument, START_SNOOP % (u.getName(), argument))
					self.steamSay(sourceid, "Listening to (%s)" % argument)
					backlog = self.channelbacklog.get(argument, [])
					if backlog: self.steamSay(sourceid, "\n".join(backlog))
					return
		elif command == "leave":
			if not argument:
				if not u or not u.channels: return self.steamSay(sourceid, 'Not listening to any channels. Type "listen <#channelname>" to start snooping.\n'
					'and "leave <#channelname>" to leave "channelname", or just "leave" if you are only in a single channel.')
				else:
					if len(u.channels) == 1:
						return self.removeUserFromChannel(u, next(iter(u.channels))) # to get item without .pop().next()
					else:
						return self.steamSay(sourceid, "I need to know what channel you want to stop listening to. You are listening to: (%s)."
							'Use "leave #channelname" to leave the channel "channelname"' % ", ".join(u.channels))
			else:
				if not u or not u.channels: self.steamSay(sourceid, 'Not listening to any channels. Type "listen <#channelname>" to start snooping.\n'
					'and "leave <#channelname>" to leave "channelname", or just "leave" if you are only in a single channel.')
				else:
					if argument not in u.channels:
						return self.steamSay(sourceid, "You aren't listening to that channel. You are listening to: (%s)." % ", ".join(u.channels))
					else:
						return self.removeUserFromChannel(u, argument)
		elif command == "quit" or command == "stop":
			if not u or not u.channels: return self.steamSay(sourceid, "You weren't listening to any channels. Bye bye.")
			else:
				for c in list(u.channels):
					self.removeUserFromChannel(u, c)
				self.steamSay(sourceid, "Bye bye.")
		elif command == "help":
			return self.steamSay(sourceid, 'Use "listen" to join channels. Type messages to me to relay them to a channel.\n'
				'If you are listening to multiple channels you need to prefix the target channel in your message e.g. "#channel hello".\n'
				'Use "leave" to stop listening to a channel. Use "quit" or "stop" to stop listening to all channels.\n'
				'To use my normal "help" function, use "hhelp". (Doesn\'t work yet...)')
		elif command == "hhelp":
			msg.replace("hhelp", "help", 1)
		
		cont_or_wrap = None
		u = self.getUser(sourceid)
		event = None
		for mapping in self.cmdMap.get(command,()):
			if not event: event = Event(None, nick=u.getName(), command=command, argument=argument, steamuser=u)
			if not cont_or_wrap: cont_or_wrap = SteamIRCBotWrapper(event, self.container, self) # event, botcont, steamchat
			# massive silliness
			reactor.callFromThread(self.container._settings.dispatcher._dispatchreally,
				mapping.function, event, cont_or_wrap)
			if mapping.priority == 0: break
Example #24
0
    def steamCMD(self, sourceid, msg):
        #stolen from dispatcher
        command, argument = commandSplit(msg)
        command = command[len(self.cmdprefix):].lower()
        u = self.getUser(sourceid)
        # TODO: Someone should clean this up a bit... probably.
        if command == "listen":
            if not argument:
                if not u or not u.channels:
                    return self.steamSay(
                        sourceid,
                        'Not listening to any channels. Type "listen <#channelname>" to start snooping.'
                    )
                else:
                    return self.steamSay(
                        sourceid, "Listening to:%s\n" % "\n".join(u.channels))
            else:
                if argument not in self.container.state.channels:
                    return self.steamSay(
                        sourceid, "Can't listen to channel I'm not in.")
                #else listen to channel
                else:
                    u.channels.add(argument)
                    self.channels.setdefault(argument, set([])).add(u)
                    self.ircSay(argument,
                                START_SNOOP % (u.getName(), argument))
                    self.steamSay(sourceid, "Listening to (%s)" % argument)
                    backlog = self.channelbacklog.get(argument, [])
                    if backlog: self.steamSay(sourceid, "\n".join(backlog))
                    return
        elif command == "leave":
            if not argument:
                if not u or not u.channels:
                    return self.steamSay(
                        sourceid,
                        'Not listening to any channels. Type "listen <#channelname>" to start snooping.\n'
                        'and "leave <#channelname>" to leave "channelname", or just "leave" if you are only in a single channel.'
                    )
                else:
                    if len(u.channels) == 1:
                        return self.removeUserFromChannel(
                            u, next(iter(u.channels))
                        )  # to get item without .pop().next()
                    else:
                        return self.steamSay(
                            sourceid,
                            "I need to know what channel you want to stop listening to. You are listening to: (%s)."
                            'Use "leave #channelname" to leave the channel "channelname"'
                            % ", ".join(u.channels))
            else:
                if not u or not u.channels:
                    self.steamSay(
                        sourceid,
                        'Not listening to any channels. Type "listen <#channelname>" to start snooping.\n'
                        'and "leave <#channelname>" to leave "channelname", or just "leave" if you are only in a single channel.'
                    )
                else:
                    if argument not in u.channels:
                        return self.steamSay(
                            sourceid,
                            "You aren't listening to that channel. You are listening to: (%s)."
                            % ", ".join(u.channels))
                    else:
                        return self.removeUserFromChannel(u, argument)
        elif command == "quit" or command == "stop":
            if not u or not u.channels:
                return self.steamSay(
                    sourceid,
                    "You weren't listening to any channels. Bye bye.")
            else:
                for c in list(u.channels):
                    self.removeUserFromChannel(u, c)
                self.steamSay(sourceid, "Bye bye.")
        elif command == "help":
            return self.steamSay(
                sourceid,
                'Use "listen" to join channels. Type messages to me to relay them to a channel.\n'
                'If you are listening to multiple channels you need to prefix the target channel in your message e.g. "#channel hello".\n'
                'Use "leave" to stop listening to a channel. Use "quit" or "stop" to stop listening to all channels.\n'
                'To use my normal "help" function, use "hhelp". (Doesn\'t work yet...)'
            )
        elif command == "hhelp":
            msg.replace("hhelp", "help", 1)

        cont_or_wrap = None
        u = self.getUser(sourceid)
        event = None
        for mapping in self.cmdMap.get(command, ()):
            if not event:
                event = Event(None,
                              nick=u.getName(),
                              command=command,
                              argument=argument,
                              steamuser=u)
            if not cont_or_wrap:
                cont_or_wrap = SteamIRCBotWrapper(
                    event, self.container, self)  # event, botcont, steamchat
            # massive silliness
            reactor.callFromThread(
                self.container._settings.dispatcher._dispatchreally,
                mapping.function, event, cont_or_wrap)
            if mapping.priority == 0: break