from random import SystemRandom

from pyaib.plugins import keyword

@keyword('insult')
def keyword_insult(context, msg, trigger, args, kargs):
	""" be insulting """
	
	# determine target user
	target_user = ""
	if args:
		target_user = args[0]
	else:
		target_user = msg.sender
	
	# pick a random insult and give it to the target user
	rand = SystemRandom()
	insult = context.config.plugin.insults[rand.randint(0, len(context.config.plugin.insults)-1)]
	msg.reply("%s: %s" % (target_user, insult))

@@ -205,66 +205,24 @@
  = %22
-%22%0A%09if args:%0A%09%09target_user = args%5B0%5D%0A%09else:%0A%09%09target_user =
+ %22.join(args) or
  msg

simplify target user determination