diff options
Diffstat (limited to 'modules')
-rwxr-xr-x | modules/etymology.py | 4 | ||||
-rwxr-xr-x | modules/remind.py | 57 | ||||
-rwxr-xr-x | modules/search.py | 32 | ||||
-rwxr-xr-x | modules/tell.py | 8 | ||||
-rwxr-xr-x | modules/translate.py | 29 |
5 files changed, 113 insertions, 17 deletions
diff --git a/modules/etymology.py b/modules/etymology.py index 4caea12..cc93cfe 100755 --- a/modules/etymology.py +++ b/modules/etymology.py @@ -84,7 +84,7 @@ def etymology(word): sentence = ' '.join(words) + ' [...]' sentence = '"' + sentence.replace('"', "'") + '"' - return sentence + ' - etymonline.com' + return sentence + ' - ' + ('http://etymonline.com/index.php?term=%s' % web.urllib.quote(word)) @deprecated def f_etymology(self, origin, match, args): @@ -102,7 +102,7 @@ def f_etymology(self, origin, match, args): self.msg(origin.sender, result) else: uri = etysearch % word - msg = 'Can\'t find the etymology for "%s". Try %s' % (word, uri) + msg = 'Can\'t find the etymology for "%s". Try %s' % (word, ('http://etymonline.com/index.php?term=%s' % web.urllib.quote(word))) self.msg(origin.sender, msg) # @@ Cf. http://swhack.com/logs/2006-01-04#T01-50-22 f_etymology.rule = (['ety'], r"(.+?)$") diff --git a/modules/remind.py b/modules/remind.py index ec1a4d1..fbfd258 100755 --- a/modules/remind.py +++ b/modules/remind.py @@ -36,7 +36,10 @@ def dump_database(name, data): def setup(phenny): phenny.rfn = filename(phenny) + + # phenny.sending.acquire() phenny.rdb = load_database(phenny.rfn) + # phenny.sending.release() def monitor(phenny): time.sleep(5) @@ -51,7 +54,10 @@ def setup(phenny): phenny.msg(channel, nick + ': ' + message) else: phenny.msg(channel, nick + '!') del phenny.rdb[oldtime] + + # phenny.sending.acquire() dump_database(phenny.rfn, phenny.rdb) + # phenny.sending.release() time.sleep(2.5) targs = (phenny,) @@ -132,5 +138,56 @@ def remind(phenny, input): else: phenny.reply('Okay, will remind in %s secs' % duration) remind.commands = ['in'] +r_time = re.compile(r'^([0-9]{2}[:.][0-9]{2})') +r_zone = re.compile(r'( ?([A-Za-z]+|[+-]\d\d?))') + +import calendar +from clock import TimeZones + +def at(phenny, input): + bytes = input[4:] + + m = r_time.match(bytes) + if not m: + return phenny.reply("Sorry, didn't understand the time spec.") + t = m.group(1).replace('.', ':') + bytes = bytes[len(t):] + + m = r_zone.match(bytes) + if not m: + return phenny.reply("Sorry, didn't understand the zone spec.") + z = m.group(2) + bytes = bytes[len(m.group(1)):].strip().encode("utf-8") + + if z.startswith('+') or z.startswith('-'): + tz = int(z) + + if TimeZones.has_key(z): + tz = TimeZones[z] + else: return phenny.reply("Sorry, didn't understand the time zone.") + + d = time.strftime("%Y-%m-%d", time.gmtime()) + d = time.strptime(("%s %s" % (d, t)).encode("utf-8"), "%Y-%m-%d %H:%M") + + d = int(calendar.timegm(d) - (3600 * tz)) + duration = int((d - time.time()) / 60) + + if duration < 1: + return phenny.reply("Sorry, that date is this minute or in the past. And only times in the same day are supported!") + + # phenny.say("%s %s %s" % (t, tz, d)) + + reminder = (input.sender, input.nick, bytes) + # phenny.say(str((d, reminder))) + try: phenny.rdb[d].append(reminder) + except KeyError: phenny.rdb[d] = [reminder] + + phenny.sending.acquire() + dump_database(phenny.rfn, phenny.rdb) + phenny.sending.release() + + phenny.reply("Reminding at %s %s - in %s minute(s)" % (t, z, duration)) +at.commands = ['at'] + if __name__ == '__main__': print __doc__.strip() diff --git a/modules/search.py b/modules/search.py index 89e57b2..5d038af 100755 --- a/modules/search.py +++ b/modules/search.py @@ -204,7 +204,7 @@ suggest.commands = ['suggest'] def new_gc(query): uri = 'https://www.google.com/search?hl=en&q=' uri = uri + web.urllib.quote(query).replace('+', '%2B') - if '"' in query: uri += '&tbs=li:1' + # if '"' in query: uri += '&tbs=li:1' bytes = web.get(uri) if "did not match any documents" in bytes: return "0" @@ -212,6 +212,26 @@ def new_gc(query): return result return None +def newest_gc(query): + uri = 'https://www.google.com/search?hl=en&q=' + uri = uri + web.urllib.quote(query).replace('+', '%2B') + bytes = web.get(uri + '&tbs=li:1') + if "did not match any documents" in bytes: + return "0" + for result in re.compile(r'(?ims)([0-9,]+) results?').findall(bytes): + return result + return None + +def newerest_gc(query): + uri = 'https://www.google.com/search?hl=en&q=' + uri = uri + web.urllib.quote(query).replace('+', '%2B') + bytes = web.get(uri + '&prmd=imvns&start=950') + if "did not match any documents" in bytes: + return "0" + for result in re.compile(r'(?ims)([0-9,]+) results?').findall(bytes): + return result + return None + def ngc(phenny, input): if not input.group(2): return phenny.reply("No query term.") @@ -229,9 +249,13 @@ def gc(phenny, input): if not input.group(2): return phenny.reply("No query term.") query = input.group(2).encode('utf-8') - old = old_gc(query) or "?" - new = new_gc(query) or "?" - phenny.say(query + ": " + old + " / " + new) + result = query + ": " + result += (old_gc(query) or "?") + " (api)" + result += ", " + (newerest_gc(query) or "?") + " (end)" + result += ", " + (new_gc(query) or "?") + " (site)" + if '"' in query: + result += ", " + (newest_gc(query) or "?") + " (verbatim)" + phenny.say(result) gc.commands = ['gc'] gc.priority = 'high' diff --git a/modules/tell.py b/modules/tell.py index d3ee609..a82fad1 100755 --- a/modules/tell.py +++ b/modules/tell.py @@ -131,9 +131,13 @@ def message(phenny, input): for remkey in remkeys: if not remkey.endswith('*') or remkey.endswith(':'): if tellee.lower() == remkey: + phenny.sending.acquire() reminders.extend(getReminders(phenny, channel, remkey, tellee)) - elif tellee.lower().startswith(remkey.rstrip('*:')): + phenny.sending.release() + elif tellee.lower().strip("0123456789_-[]`") == remkey.rstrip('*:'): + phenny.sending.acquire() reminders.extend(getReminders(phenny, channel, remkey, tellee)) + phenny.sending.release() for line in reminders[:maximum]: phenny.say(line) @@ -144,7 +148,9 @@ def message(phenny, input): phenny.msg(tellee, line) if len(phenny.reminders.keys()) != remkeys: + phenny.sending.acquire() dumpReminders(phenny.tell_filename, phenny.reminders) # @@ tell + phenny.sending.release() message.rule = r'(.*)' message.priority = 'low' diff --git a/modules/translate.py b/modules/translate.py index 927bcb9..11e4f28 100755 --- a/modules/translate.py +++ b/modules/translate.py @@ -93,8 +93,8 @@ def tr2(phenny, input): command = cmd phrase = command - if (len(phrase) > 350) and (not input.admin): - return phenny.reply('Phrase must be under 350 characters.') + # if (len(phrase) > 350) and (not input.admin): + # return phenny.reply('Phrase must be under 350 characters.') src, dest = args if src != dest: @@ -103,6 +103,7 @@ def tr2(phenny, input): msg = msg.decode('utf-8') if msg: msg = web.decode(msg) # msg.replace(''', "'") + if len(msg) > 450: msg = msg[:450] + '[...]' msg = '"%s" (%s to %s, translate.google.com)' % (msg, src, dest) else: msg = 'The %s to %s translation failed, sorry!' % (src, dest) @@ -113,22 +114,30 @@ tr2.commands = ['tr'] tr2.priority = 'low' def mangle(phenny, input): + import time + phrase = input.group(2).encode('utf-8') for lang in ['fr', 'de', 'es', 'it', 'ja']: - backup = phrase - phrase = translate(phrase, 'en', lang) + backup = phrase[:] + phrase, _lang = translate(phrase, 'en', lang) + phrase = phrase.encode("utf-8") + if not phrase: - phrase = backup + phrase = backup[:] break - __import__('time').sleep(0.5) + time.sleep(0.25) + + backup = phrase[:] + phrase, _lang = translate(phrase, lang, 'en') + phrase = phrase.encode("utf-8") - backup = phrase - phrase = translate(phrase, lang, 'en') if not phrase: - phrase = backup + phrase = backup[:] break - __import__('time').sleep(0.5) + time.sleep(0.25) + phrase = phrase.replace(' ,', ',').replace(' .', '.') + phrase = phrase.strip(' ,') phenny.reply(phrase or 'ERRORS SRY') mangle.commands = ['mangle'] |