aboutsummaryrefslogtreecommitdiffstats
path: root/local/utility.py
diff options
context:
space:
mode:
authorkongr45gpen <electrovesta@gmail.com>2014-04-25 12:57:02 +0300
committerkongr45gpen <electrovesta@gmail.com>2014-04-25 12:57:02 +0300
commit02409d18d3604a87b53b70181246b6b92b27b4c2 (patch)
treedae0077e6a0095fe168501d49e07a6f12287aa5a /local/utility.py
parentd3c6bc9f317b284b010d9be50d1d82849f598917 (diff)
downloadsupybot_github-02409d18d3604a87b53b70181246b6b92b27b4c2.tar.gz
supybot_github-02409d18d3604a87b53b70181246b6b92b27b4c2.tar.bz2
supybot_github-02409d18d3604a87b53b70181246b6b92b27b4c2.zip
Separate the bot's logic into different files
Diffstat (limited to 'local/utility.py')
-rw-r--r--local/utility.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/local/utility.py b/local/utility.py
new file mode 100644
index 0000000..c6a6c60
--- /dev/null
+++ b/local/utility.py
@@ -0,0 +1,62 @@
+import urllib2
+
+import supybot.conf as conf
+import supybot.ircutils as ircutils
+import supybot.registry as registry
+
+def registryValue(plugin, name, channel=None, value=True):
+ group = conf.supybot.plugins.get(plugin)
+ names = registry.split(name)
+ for name in names:
+ group = group.get(name)
+ if channel is not None:
+ if ircutils.isChannel(channel):
+ group = group.get(channel)
+ else:
+ self.log.debug('registryValue got channel=%r', channel)
+ if value:
+ return group()
+ else:
+ return group
+
+
+def configValue(name, channel=None, repo=None, type=None, module=None):
+ return registryValue("Github", name, channel)
+
+def plural(number, s, p):
+ if number != 1:
+ return p
+ return s
+
+def maxLen(msg, maxn=400):
+ """Cut down a string if its longer than `maxn` chars"""
+ if len(msg) > maxn:
+ ret = "%s..." % (msg[0:(maxn-3)])
+ else:
+ ret = msg
+ return ret
+
+def colorAction(action):
+ """Give an action string (e.g. created, edited) and get a nice IRC colouring"""
+ if action == "created" or action == "opened" or action == "tagged":
+ return ircutils.bold(ircutils.mircColor(action, "green"))
+ if action == "deleted" or action == "closed" or action == "re-tagged" or \
+ action == "deleted tag" or action == "failed" or action == "still failing":
+ return ircutils.bold(ircutils.mircColor(action, "red"))
+ if action == "merged":
+ return ircutils.bold(ircutils.mircColor(action, "light blue"))
+ if action == "reopened":
+ return ircutils.bold(ircutils.mircColor(action, "blue"))
+ if action == "forced the creation of" or action == "forced the deletion of":
+ return ircutils.bold(ircutils.mircColor(action,"brown"))
+ return action
+
+def getShortURL(longurl):
+ if configValue("shortURL") is False:
+ url = longurl
+ else:
+ data = 'url=%s' % (longurl)
+ req = urllib2.Request("http://git.io", data)
+ response = urllib2.urlopen(req)
+ url = response.info().getheader('Location')
+ return ircutils.mircColor(url, "purple")

© 2014-2024 Faster IT GmbH | imprint | privacy policy