- merged

Sat, 29 Nov 2014 10:45:51 -0500

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sat, 29 Nov 2014 10:45:51 -0500
changeset 104
27294de7b0d3
parent 103
e4891ab34fb1 (current diff)
parent 102
2bad379cd416 (diff)
child 105
84bd617a2520

- merged

--- a/hgpoll.py	Sat Nov 29 10:11:42 2014 -0500
+++ b/hgpoll.py	Sat Nov 29 10:45:51 2014 -0500
@@ -169,8 +169,7 @@
 		for channel in irc_client.channels:
 			if channel.get_value ('btannounce', default=True):
 				irc_client.privmsg (channel.get_value ('name'),
-					"%s: commit %s fixes issue %d: %s"
-					% (repo_name, commit_node, ticket_id, commit_message))
+					"%s: commit %s FIXES issue %d" % (repo_name, commit_node, ticket_id))
 				irc_client.privmsg (channel.get_value ('name'),
 					"Read all about it here: " + Bt.get_ticket_url (ticket_id))
 
--- a/mod_util.py	Sat Nov 29 10:11:42 2014 -0500
+++ b/mod_util.py	Sat Nov 29 10:45:51 2014 -0500
@@ -2,6 +2,7 @@
 import urllib2
 import json
 from modulecore import command_error
+import modulecore as ModuleCore
 
 ModuleData = {
 	'commands':
@@ -19,6 +20,20 @@
 			'args': '<term...>',
 			'level': 'normal',
 		},
+
+		{
+			'name': 'commands',
+			'description': 'Lists commands available to the calling user',
+			'args': None,
+			'level': 'normal',
+		},
+
+		{
+			'name': 'help',
+			'description': 'Prints help about a given command',
+			'args': '<command>',
+			'level': 'normal',
+		},
 	]
 }
 
@@ -70,4 +85,26 @@
 		down = data['list'][0]['thumbs_down']
 		bot.privmsg (replyto, "\002%s\002: %s\0033 %d\003 up,\0035 %d\003 down" % (word, definition, up, down))
 	except Exception as e:
-		command_error ('Urban dictionary lookup failed: %s' % e)
\ No newline at end of file
+		command_error ('Urban dictionary lookup failed: %s' % e)
+
+def cmd_commands (bot, replyto, ident, host, **rest):
+	commandlist = ModuleCore.get_available_commands (ident, host)
+	partitioned=[]
+
+	while len (commandlist) > 0:
+		partitioned.append (commandlist[0:15])
+		commandlist = commandlist[15:]
+
+	for part in partitioned:
+		bot.privmsg (replyto, 'Available commands: %s' % (", ".join (part)))
+
+def cmd_help (bot, replyto, ident, host, args, **rest):
+	cmd = ModuleCore.get_command_by_name (args['command'])
+
+	if not cmd:
+		command_error ('unknown command \'%s\'' % args['command'])
+
+	if not ModuleCore.is_available (cmd, ident, host):
+		command_error ('you may not use %s' % cmd['name'])
+
+	bot.privmsg (replyto, '%s %s: %s' % (cmd['name'], cmd['args'], cmd['description']))
--- a/modulecore.py	Sat Nov 29 10:11:42 2014 -0500
+++ b/modulecore.py	Sat Nov 29 10:45:51 2014 -0500
@@ -67,6 +67,18 @@
 	raise CommandError (message)
 
 #
+# is_available (cmd, ident, host)
+#
+# Is the given command available to the given user?
+#
+def is_available (cmd, ident, host):
+	if cmd['level'] == 'admin' \
+	and not "%s@%s" % (ident, host) in Config.get_value ('admins', default=[]):
+		return False
+
+	return True
+
+#
 # call_command (bot, message, cmdname, **kvargs)
 #
 # Calls a cobalt command
@@ -77,8 +89,7 @@
 	except KeyError:
 		return False
 	
-	if cmd['level'] == 'admin' \
-	and not "%s@%s" % (kvargs['ident'], kvargs['host']) in Config.get_value ('admins', default=[]):
+	if not is_available (cmd, kvargs['ident'], kvargs['host']):
 		command_error ("you may not use %s" % cmdname)
 	
 	match = re.compile (cmd['regex']).match (message)
@@ -99,6 +110,33 @@
 	return True
 
 #
+# get_available_commands
+#
+# Gets a list of commands available to the given user
+#
+def get_available_commands (ident, host):
+	result=[]
+
+	for cmdname,cmd in Commands.iteritems():
+		if not is_available (cmd, ident, host):
+			continue
+
+		result.append (cmdname)
+
+	return result
+
+#
+# get_command_by_name
+#
+# Gets a command by name
+#
+def get_command_by_name (name):
+	try:
+		return Commands[name]
+	except:
+		return None
+
+#
 # make_regex
 #
 # Takes the argument list and returns a corresponding regular expression
@@ -156,4 +194,4 @@
 	#done
 
 	return '^[^ ]+%s$' % regex
-#enddef
\ No newline at end of file
+#enddef

mercurial