Allow the user to configure the port in the config, and other fixes.

master
Sean B. Palmer 2008-04-26 15:54:35 +01:00
parent 286d4a8497
commit 986953131d
8 changed files with 22 additions and 7 deletions

View File

@ -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:

View File

@ -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

View File

@ -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__':

View File

@ -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):

View File

@ -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'

View File

@ -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):

View File

@ -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('<sup>', '|')

5
phenny
View File

@ -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)