From 986953131d1e399a9b277984a2234cd0c5f7656c Mon Sep 17 00:00:00 2001
From: "Sean B. Palmer"
Date: Sat, 26 Apr 2008 15:54:35 +0100
Subject: [PATCH] Allow the user to configure the port in the config, and other
fixes.
---
__init__.py | 2 +-
modules/codepoints.py | 4 +++-
modules/dict.py | 5 ++++-
modules/info.py | 4 ++--
modules/search.py | 4 ++++
modules/translate.py | 2 +-
modules/wikipedia.py | 3 ++-
phenny | 5 +++++
8 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/__init__.py b/__init__.py
index 16309f0..3b1c556 100755
--- a/__init__.py
+++ b/__init__.py
@@ -34,7 +34,7 @@ def run_phenny(config):
def connect(config):
p = bot.Phenny(config)
- p.run(config.host)
+ p.run(config.host, config.port)
Watcher()
while True:
diff --git a/modules/codepoints.py b/modules/codepoints.py
index 797fada..9ae06b5 100755
--- a/modules/codepoints.py
+++ b/modules/codepoints.py
@@ -75,7 +75,9 @@ def u(phenny, input):
if set(arg.upper()) - set(
'ABCDEFGHIJKLMNOPQRSTUVWYXYZ0123456789- .?+*{}[]\\/^$'):
printable = False
- else: printable = True
+ elif len(arg) > 1:
+ printable = True
+ else: printable = False
if printable:
extended = False
diff --git a/modules/dict.py b/modules/dict.py
index 7ecaf0a..61fcee9 100755
--- a/modules/dict.py
+++ b/modules/dict.py
@@ -113,7 +113,10 @@ def dict(phenny, input):
if len(results[key]) > 1:
result += ', 2. ' + results[key][1]
result += '; '
- phenny.say(result.rstrip('; '))
+ result = result.rstrip('; ')
+ if result.endswith('-') and (len(result) < 30):
+ phenny.reply('Sorry, no definition found.')
+ else: phenny.say(result)
dict.commands = ['dict']
if __name__ == '__main__':
diff --git a/modules/info.py b/modules/info.py
index a5113ba..c3d13ef 100755
--- a/modules/info.py
+++ b/modules/info.py
@@ -16,8 +16,8 @@ def doc(phenny, input):
phenny.reply(phenny.doc[name][0])
if phenny.doc[name][1]:
phenny.say('e.g. ' + phenny.doc[name][1])
-doc.rule = ('$nick', '(?i)help +([A-Za-z]+)(?:\?+)?$')
-doc.example = '$nickname: help tell?'
+doc.rule = ('$nick', '(?i)(?:help|doc) +([A-Za-z]+)(?:\?+)?$')
+doc.example = '$nickname: doc tell?'
doc.priority = 'low'
def commands(phenny, input):
diff --git a/modules/search.py b/modules/search.py
index fbd6596..1c8dad6 100755
--- a/modules/search.py
+++ b/modules/search.py
@@ -19,6 +19,7 @@ def json(text):
if r_json.match(r_string.sub('', text)):
text = r_string.sub(lambda m: 'u' + m.group(1), text)
return eval(text.strip(' \t\r\n'), env, {})
+ print text
raise ValueError('Input must be serialised JSON.')
def search(query, n=1):
@@ -55,6 +56,9 @@ def g(phenny, input):
uri = result(query)
if uri:
phenny.reply(uri)
+ if not hasattr(phenny.bot, 'last_seen_uri'):
+ phenny.bot.last_seen_uri = {}
+ phenny.bot.last_seen_uri[input.sender] = uri
else: phenny.reply("No results found for '%s'." % query)
g.commands = ['g']
g.priority = 'high'
diff --git a/modules/translate.py b/modules/translate.py
index f7cf0a2..23ce7e9 100755
--- a/modules/translate.py
+++ b/modules/translate.py
@@ -63,7 +63,7 @@ def translate(phrase, lang, target='en'):
translation = translation.replace('\n', ' ')
while ' ' in translation:
translation = translation.replace(' ', ' ')
- return translation
+ return translation.lower()
return None
def tr(phenny, input):
diff --git a/modules/wikipedia.py b/modules/wikipedia.py
index ea32443..1af1c79 100755
--- a/modules/wikipedia.py
+++ b/modules/wikipedia.py
@@ -97,7 +97,8 @@ def wikipedia(term, last=False):
and not '(images and media)' in para
and not 'This article contains a' in para
and not 'id="coordinates"' in para
- and not 'class="thumb' in para]
+ and not 'class="thumb' in para
+ and not 'style="display:none"' in para]
for i, para in enumerate(paragraphs):
para = para.replace('', '|')
diff --git a/phenny b/phenny
index 5a632ed..b8f1386 100755
--- a/phenny
+++ b/phenny
@@ -116,11 +116,16 @@ def main(argv=None):
name = os.path.basename(config_name).split('.')[0] + '_config'
module = imp.load_source(name, config_name)
module.filename = config_name
+
if not hasattr(module, 'prefix'):
module.prefix = r'\.'
+
if not hasattr(module, 'name'):
module.name = 'Phenny Palmersbot, http://inamidst.com/phenny/'
+ if not hasattr(module, 'port'):
+ module.port = 6667
+
if module.host == 'irc.example.net':
error = ('Error: you must edit the config file first!\n' +
"You're currently using %s" % module.filename)