- various fixes

Mon, 10 Nov 2014 02:30:31 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Mon, 10 Nov 2014 02:30:31 +0200
changeset 76
a2fe9ba3041a
parent 75
1818d56c8ff5
child 77
8f45af91a4f3

- various fixes

configfile.py file | annotate | diff | comparison | revisions
hgpoll.py file | annotate | diff | comparison | revisions
irc.py file | annotate | diff | comparison | revisions
mod_hgpoll.py file | annotate | diff | comparison | revisions
mod_util.py file | annotate | diff | comparison | revisions
--- a/configfile.py	Mon Nov 10 02:11:57 2014 +0200
+++ b/configfile.py	Mon Nov 10 02:30:31 2014 +0200
@@ -55,6 +55,13 @@
 			json.dump (self.obj, fp, sort_keys = True, indent = 1)
 		
 		print "Config saved."
+	
+	def find_developer_by_email (self, commit_email):
+		for developer, emails in self.get_value ('developer_emails', default={}).iteritems():
+			if commit_email in emails:
+				return developer
+		
+		return ''
 
 def init():
 	print 'Loading configuration...'
--- a/hgpoll.py	Mon Nov 10 02:11:57 2014 +0200
+++ b/hgpoll.py	Mon Nov 10 02:30:31 2014 +0200
@@ -104,13 +104,6 @@
 	
 	return result
 
-def find_developer_by_email (commit_email):
-	for developer, emails in Config.get_value ('developer_emails', default={}).iteritems():
-		if commit_email in emails:
-			return developer
-	
-	return ''
-
 def poll():
 	global repocheck_timeout
 	if time.time() < repocheck_timeout:
@@ -222,7 +215,7 @@
 					commit_author = match.group (1)
 					commit_email = match.group (2)
 				
-				commit_trackeruser = find_developer_by_email (commit_email)
+				commit_trackeruser = Config.find_developer_by_email (commit_email)
 				committer = commit_trackeruser if commit_trackeruser != '' else commit_author
 				
 				for irc_client in Irc.all_clients:
--- a/irc.py	Mon Nov 10 02:11:57 2014 +0200
+++ b/irc.py	Mon Nov 10 02:30:31 2014 +0200
@@ -179,9 +179,9 @@
 		
 		channel = self.cfg.append_nodelist ('channels')
 		channel.set_value ('name', channame)
-		self.channels = cfg.get_nodelist ('channels')
+		self.channels = self.cfg.get_nodelist ('channels')
 		self.write ('JOIN ' + channame)
-		self.save_config()
+		self.cfg.save()
 	
 	def remove_irc_channel (self, channame):
 		for channel in self.channels:
@@ -192,7 +192,7 @@
 			return
 		
 		self.write ('PART ' + channame)
-		self.save_config()
+		self.cfg.save()
 	
 	def handle_command (self, sender, ident, host, replyto, command, args, message):
 		kvargs = {'sender': sender, 'ident': ident, 'host': host, 'replyto': replyto, 'cmdname': command, 'message': message}
--- a/mod_hgpoll.py	Mon Nov 10 02:11:57 2014 +0200
+++ b/mod_hgpoll.py	Mon Nov 10 02:30:31 2014 +0200
@@ -2,6 +2,8 @@
 from datetime import datetime
 import hgpoll as HgPoll
 import re
+import bt as Bt
+from configfile import Config
 
 ModuleData = {
 	'commands':
@@ -27,10 +29,13 @@
 	]
 }
 
+def plural (a):
+	return '' if a == 1 else 's'
+
 def cmd_checkhg (bot, **rest):
 	HgPoll.force_poll()
 
-def cmd_cset (bot, args, **rest):
+def cmd_cset (bot, args, replyto, **rest):
 	repo = Repo ('zandronum-everything')
 	data = ""
 	node = args['key']
@@ -38,7 +43,7 @@
 	# Possibly we're passed a date version instead. Try find the node for this.
 	try:
 		datetime.strptime (args['key'], '%y%m%d-%H%M')
-		make_commits_txt()
+		HgPoll.make_commits_txt()
 		commits_txt = open ('commits.txt', 'r')
 
 		for line in commits_txt:
@@ -82,7 +87,7 @@
 			author = match.group (1)
 			email = match.group (2)
 
-		username = Bt.find_developer_by_email (email)
+		username = Config.find_developer_by_email (email)
 
 		if username != '':
 			author = username
--- a/mod_util.py	Mon Nov 10 02:11:57 2014 +0200
+++ b/mod_util.py	Mon Nov 10 02:30:31 2014 +0200
@@ -1,5 +1,6 @@
 import math
 import urllib2
+import json
 from modulecore import command_error
 
 ModuleData = {
@@ -53,7 +54,7 @@
 
 def cmd_ud (bot, args, replyto, **rest):
 	try:
-		url = 'http://api.urbandictionary.com/v0/define?term=%s' % ('%20'.join (args))
+		url = 'http://api.urbandictionary.com/v0/define?term=%s' % (args['term'].replace (' ', '%20'))
 		response = urllib2.urlopen (url).read()
 		data = json.loads (response)
 		
@@ -67,7 +68,6 @@
 		definition = data['list'][0]['definition'].replace ('\r', ' ').replace ('\n', ' ').replace ('  ', ' ')
 		up = data['list'][0]['thumbs_up']
 		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))
+		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

mercurial