Remove all that code that was deprecated by the previous commit

master
sfan5 2014-06-22 12:32:15 +02:00
parent 499177069c
commit 4fb9723396
19 changed files with 134 additions and 277 deletions

View File

@ -34,10 +34,6 @@ for lib in libs:
setattr(env[lib], funcn, getattr(globals()[lib], funcn))
def c(phenny, input):
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
if not input.group(2):
return phenny.reply("Nothing to calculate.")
q = input.group(2).encode('ascii', 'ignore')
@ -52,5 +48,5 @@ def c(phenny, input):
c.commands = ['c']
c.example = '.c 5 + 3'
if __name__ == '__main__':
if __name__ == '__main__':
print __doc__.strip()

View File

@ -21,30 +21,30 @@ r_redirect = re.compile(
r'(?ims)class=.redirectText.>\s*<a\s*href=./wiki/([^"/]+)'
)
abbrs = ['etc', 'ca', 'cf', 'Co', 'Ltd', 'Inc', 'Mt', 'Mr', 'Mrs',
'Dr', 'Ms', 'Rev', 'Fr', 'St', 'Sgt', 'pron', 'approx', 'lit',
abbrs = ['etc', 'ca', 'cf', 'Co', 'Ltd', 'Inc', 'Mt', 'Mr', 'Mrs',
'Dr', 'Ms', 'Rev', 'Fr', 'St', 'Sgt', 'pron', 'approx', 'lit',
'syn', 'transl', 'sess', 'fl', 'Op', 'Dec', 'Brig', 'Gen'] \
+ list('ABCDEFGHIJKLMNOPQRSTUVWXYZ') \
+ list('abcdefghijklmnopqrstuvwxyz')
t_sentence = r'^.{5,}?(?<!\b%s)(?:\.(?=[\[ ][A-Z0-9]|\Z)|\Z)'
r_sentence = re.compile(t_sentence % r')(?<!\b'.join(abbrs))
def unescape(s):
def unescape(s):
s = s.replace('&gt;', '>')
s = s.replace('&lt;', '<')
s = s.replace('&amp;', '&')
s = s.replace('&#160;', ' ')
return s
def text(html):
def text(html):
html = r_tag.sub('', html)
html = r_whitespace.sub(' ', html)
return unescape(html).strip()
def devwikipedia(term, language='en', last=False):
def devwikipedia(term, language='en', last=False):
global devwikiuri
if not '%' in term:
if isinstance(term, unicode):
if not '%' in term:
if isinstance(term, unicode):
t = term.encode('utf-8')
else: t = term
q = urllib.quote(t)
@ -52,7 +52,7 @@ def devwikipedia(term, language='en', last=False):
bytes = web.get(u)
else: bytes = web.get(devwikiuri % (term))
if bytes.startswith('\x1f\x8b\x08\x00\x00\x00\x00\x00'):
if bytes.startswith('\x1f\x8b\x08\x00\x00\x00\x00\x00'):
f = StringIO.StringIO(bytes)
f.seek(0)
gzip_file = gzip.GzipFile(fileobj=f)
@ -62,56 +62,56 @@ def devwikipedia(term, language='en', last=False):
bytes = r_tr.sub('', bytes)
if not last:
if not last:
r = r_redirect.search(bytes[:4096])
if r:
if r:
term = urllib.unquote(r.group(1))
return devwikipedia(term, language=language, last=True)
paragraphs = r_paragraph.findall(bytes)
if not paragraphs:
if not last:
if not paragraphs:
if not last:
term = search(term)
return devwikipedia(term, language=language, last=True)
return None
# Pre-process
paragraphs = [para for para in paragraphs
if (para and 'technical limitations' not in para
and 'window.showTocToggle' not in para
and 'Deletion_policy' not in para
and 'Template:AfD_footer' not in para
and not (para.startswith('<p><i>') and
paragraphs = [para for para in paragraphs
if (para and 'technical limitations' not in para
and 'window.showTocToggle' not in para
and 'Deletion_policy' not in para
and 'Template:AfD_footer' not in para
and not (para.startswith('<p><i>') and
para.endswith('</i></p>'))
and not 'disambiguation)"' in para)
and not 'disambiguation)"' in para)
and not '(images and media)' in para
and not 'This article contains a' in para
and not 'This article contains a' in para
and not 'id="coordinates"' in para
and not 'class="thumb' in para]
# and not 'style="display:none"' in para]
for i, para in enumerate(paragraphs):
for i, para in enumerate(paragraphs):
para = para.replace('<sup>', '|')
para = para.replace('</sup>', '|')
paragraphs[i] = text(para).strip()
# Post-process
paragraphs = [para for para in paragraphs if
paragraphs = [para for para in paragraphs if
(para and not (para.endswith(':') and len(para) < 150))]
para = text(paragraphs[0])
m = r_sentence.match(para)
if not m:
if not last:
if not m:
if not last:
term = search(term)
return devwikipedia(term, language=language, last=True)
return None
sentence = m.group(0)
maxlength = 275
if len(sentence) > maxlength:
if len(sentence) > maxlength:
sentence = sentence[:maxlength]
words = sentence[:-5].split(' ')
words.pop()
@ -119,8 +119,8 @@ def devwikipedia(term, language='en', last=False):
if (('using the Article Wizard if you wish' in sentence)
or ('or add a request for it' in sentence)
or ('in existing articles' in sentence)):
if not last:
or ('in existing articles' in sentence)):
if not last:
term = search(term)
return devwikipedia(term, language=language, last=True)
return None
@ -132,37 +132,33 @@ def devwikipedia(term, language='en', last=False):
return sentence + ' - ' + (devwikiuri % (term))
def devwik(phenny, input):
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
origterm = input.groups()[1]
if not origterm:
if not origterm:
return phenny.say('Perhaps you meant "!devwik Zen"?')
origterm = origterm.encode('utf-8')
print("[LOG]: %s queried Minetest Dev Wiki for '%s'" % (input.nick,origterm))
term = urllib.unquote(origterm)
language = 'en'
if term.startswith(':') and (' ' in term):
if term.startswith(':') and (' ' in term):
a, b = term.split(' ', 1)
a = a.lstrip(':')
if a.isalpha():
if a.isalpha():
language, term = a, b
term = term.replace(' ', '_')
try: result = devwikipedia(term, language)
except IOError:
except IOError:
args = (language, devwikiuri % (term))
error = "Can't connect to dev.minetest.net (%s)" % args
return phenny.say(error)
if result is not None:
if result is not None:
phenny.say(result)
else: phenny.say('Can\'t find anything in Dev Wiki for "%s".' % origterm)
devwik.commands = ['dev', 'devwik', 'devwiki']
devwik.priority = 'high'
if __name__ == '__main__':
if __name__ == '__main__':
print __doc__.strip()

View File

@ -55,7 +55,7 @@ def formartirc_user(name,rank,posts,regdate,userid,with_userid=False):
return name + " "+chr(3)+"8"+ rank.replace("New","New"+chr(3)) +" " + posts + " posts, registered on " + regdate + ap
else:
return name + " " + rank + " " + posts + " posts, registered on " + regdate + ap
def formatirc_user_a(arr):
if len(arr) <= 4:
return formartirc_user(arr[0],arr[1],arr[2],arr[3])
@ -63,10 +63,6 @@ def formatirc_user_a(arr):
return formartirc_user(arr[0],arr[1],arr[2],arr[3],arr[4],with_userid=True)
def search_forumuser(phenny, input):
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
arg = input.group(2)
if not arg:
return phenny.reply("Give me a username")

View File

@ -1,9 +1,5 @@
def help(phenny, input):
def help(phenny, input):
"""Help command"""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
phenny.say("https://github.com/sfan5/minetestbot-modules/blob/master/COMMANDS.md")
help.commands = ['help']

18
ping.py
View File

@ -8,32 +8,20 @@ About: http://inamidst.com/phenny/
import random
def hello(phenny, input):
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
greeting = random.choice(('Hi', 'Hey', 'Hello', 'sup'))
punctuation = random.choice(('', '!', '.'))
phenny.say(greeting + ' ' + input.nick + punctuation)
hello.rule = r'(?i)(hi|hello|hey) $nickname[ \t]*$'
def interjection(phenny, input):
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
def interjection(phenny, input):
phenny.say(input.nick + '!')
interjection.rule = r'$nickname!'
interjection.priority = 'high'
def l3(phenny, input):
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
def l3(phenny, input):
phenny.say('<3 ' + input.nick)
l3.rule = r'<3 $nickname'
l3.priority = 'low'
if __name__ == '__main__':
if __name__ == '__main__':
print __doc__.strip()

View File

@ -6,7 +6,7 @@ Copyright 2013, sfan5
import random
rainbowcolors = ["4", "7", "8", "3", "12", "6", "13"]
#TODO: make this rainbow better (can't really make it that better because IRC colors suck)
#maybe TODO: make this rainbow better (can't really make it that better because IRC colors suck)
def colorize(text):
out = ""
@ -25,10 +25,6 @@ def colorize(text):
return out
def rainbow(phenny, input):
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
arg = input.group(2)
if not arg:
return phenny.say(colorize("Rainbow") + "\x03 What?")

View File

@ -10,33 +10,33 @@ http://inamidst.com/phenny/
import sys, os.path, time, imp
import irc
def f_reload(phenny, input):
"""Reloads a module, for use by admins only."""
def f_reload(phenny, input):
"""Reloads a module, for use by admins only."""
if not input.admin: return
name = input.group(2)
if name == phenny.config.owner:
if name == phenny.config.owner:
return phenny.reply('What?')
if (not name) or (name == '*'):
if (not name) or (name == '*'):
phenny.variables = None
phenny.commands = None
phenny.setup()
return phenny.reply('done')
if not sys.modules.has_key(name):
if not sys.modules.has_key(name):
return phenny.reply('%s: no such module!' % name)
# Thanks to moot for prodding me on this
path = sys.modules[name].__file__
if path.endswith('.pyc') or path.endswith('.pyo'):
if path.endswith('.pyc') or path.endswith('.pyo'):
path = path[:-1]
if not os.path.isfile(path):
if not os.path.isfile(path):
return phenny.reply('Found %s, but not the source file' % name)
module = imp.load_source(name, path)
sys.modules[name] = module
if hasattr(module, 'setup'):
if hasattr(module, 'setup'):
module.setup(phenny)
mtime = os.path.getmtime(module.__file__)
@ -46,10 +46,11 @@ def f_reload(phenny, input):
phenny.bind_commands()
phenny.reply('%r (version: %s)' % (module, modified))
f_reload.name = 'reload'
f_reload.rule = ('$nick', ['reload'], r'(\S+)?')
f_reload.priority = 'low'
f_reload.thread = False
if __name__ == '__main__':
if __name__ == '__main__':
print __doc__.strip()

View File

@ -122,10 +122,9 @@ def rsscheck(phenny, input):
rssnotify["dont_print_first_message"] = False
print("[RssNotify]: Checked " + str(len(feeds)) + " RSS Feeds in %0.3f seconds" % (end-start))
rsscheck.priority = 'high'
rsscheck.priority = 'medium'
rsscheck.rule = r'.*'
rsscheck.event = '*'
rsscheck.thread = True
if __name__ == '__main__':
print __doc__.strip()

View File

@ -1,19 +1,15 @@
#!/usr/bin/env python
"""
rutils.py - Phenny Utility Module
Copyright 2012, Sfan5
Copyright 2012, sfan5
"""
import base64, binascii, re, random, time, multiprocessing, hashlib
def rs(s):
return repr(s)[1:-1]
def rev(phenny, input):
def rev(phenny, input):
"""reverse string"""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
if not input.group(2):
return phenny.reply("Nothing to reverse.")
q = input.group(2).encode('utf-8')
@ -26,12 +22,8 @@ def rev(phenny, input):
rev.commands = ['rev','reverse']
rev.priority = 'low'
def b64e(phenny, input):
def b64e(phenny, input):
"""base64 encode"""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
if not input.group(2):
return phenny.reply("Nothing to encode.")
q = input.group(2).encode('utf-8')
@ -39,16 +31,12 @@ def b64e(phenny, input):
return phenny.say(rs(base64.b64encode(q)))
except BaseException as e:
return phenny.reply("Failed to handle data")
b64e.commands = ['b64e','base64encode']
b64e.priority = 'low'
def b64d(phenny, input):
def b64d(phenny, input):
"""base64 decode"""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
if not input.group(2):
return phenny.reply("Nothing to decode.")
q = input.group(2).encode('utf-8')
@ -56,16 +44,12 @@ def b64d(phenny, input):
return phenny.say(rs(base64.b64decode(q)))
except BaseException as e:
return phenny.reply("Failed to handle data")
b64d.commands = ['b64d','base64decode']
b64d.priority = 'low'
def b32e(phenny, input):
def b32e(phenny, input):
"""base32 encode"""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
if not input.group(2):
return phenny.reply("Nothing to encode.")
q = input.group(2).encode('utf-8')
@ -73,16 +57,12 @@ def b32e(phenny, input):
return phenny.say(rs(base64.b32encode(q)))
except BaseException as e:
return phenny.reply("Failed to handle data")
b32e.commands = ['b32e','base32encode']
b32e.priority = 'low'
def b32d(phenny, input):
def b32d(phenny, input):
"""base32 decode"""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
if not input.group(2):
return phenny.reply("Nothing to decode.")
q = input.group(2).encode('utf-8')
@ -90,16 +70,12 @@ def b32d(phenny, input):
return phenny.say(rs(base64.b32decode(q)))
except BaseException as e:
return phenny.reply("Failed to handle data")
b32d.commands = ['b32d','base32decode']
b32d.priority = 'low'
def b16e(phenny, input):
def b16e(phenny, input):
"""base16 encode"""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
if not input.group(2):
return phenny.reply("Nothing to encode.")
q = input.group(2).encode('utf-8')
@ -107,11 +83,11 @@ def b16e(phenny, input):
return phenny.say(rs(base64.b16encode(q)))
except BaseException as e:
return phenny.reply("Failed to handle data")
b16e.commands = ['b16e','base16encode']
b16e.priority = 'low'
def b16d(phenny, input):
def b16d(phenny, input):
"""base16 decode"""
if not input.group(2):
return phenny.reply("Nothing to decode.")
@ -120,30 +96,22 @@ def b16d(phenny, input):
return phenny.say(rs(base64.b16decode(q)))
except BaseException as e:
return phenny.reply("Failed to handle data")
b16d.commands = ['b16d','base16decode']
b16d.priority = 'low'
def crc32(phenny, input):
def crc32(phenny, input):
"""crc32 hash"""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
if not input.group(2):
return phenny.reply("Nothing to hash.")
q = input.group(2).encode('utf-8')
h = binascii.crc32(q)
return phenny.say(rs(str(h) + "(" + hex(h) + ")"))
crc32.commands = ['crc32']
crc32.priority = 'low'
def hash_(phenny, input):
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
if not input.group(2):
return phenny.reply("Usage: hash <hash function> <text> | Get available hash funcs with ?")
hashfuncs = {
@ -165,12 +133,8 @@ def hash_(phenny, input):
hash_.commands = ['hash']
hash_.priority = 'low'
def regex(phenny, input):
def regex(phenny, input):
"""regex"""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
if not input.group(2):
return phenny.reply("Give me a regex and a message seperated by `")
q = input.group(2).encode('utf-8')
@ -202,12 +166,8 @@ regex.commands = ['re','regex']
regex.priority = 'low'
regex.thread = True
def rand(phenny, input):
def rand(phenny, input):
"""Returns a random number"""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
if not input.group(2):
return
arg = input.group(2)
@ -236,5 +196,5 @@ def rand(phenny, input):
rand.commands = ['rand', 'random']
rand.priority = 'low'
if __name__ == '__main__':
if __name__ == '__main__':
print __doc__.strip()

View File

@ -2,7 +2,7 @@
"""
search.py - Phenny Web Search Module
Copyright 2008-9, Sean B. Palmer, inamidst.com
Modified by Sfan5 2012
Modified by sfan5 2012
Licensed under the Eiffel Forum License 2.
http://inamidst.com/phenny/
@ -10,7 +10,7 @@ http://inamidst.com/phenny/
import web, re
search_badwords = ["porn","p0rn","pr0n","pron","redtube","sex","pussy","hot","weed","smoking","drug","penis","vagina"] #Thank KikaRz, LandMine and RagnarLaud for this
search_badwords = ["porn","p0rn","pr0n","pron","redtube","sex","pussy","weed","smoking","drug","penis","vagina"] # Thank KikaRz, LandMine and RagnarLaud for this
class Grab(web.urllib.URLopener):
def __init__(self, *args):
@ -20,9 +20,9 @@ class Grab(web.urllib.URLopener):
def http_error_default(self, url, fp, errcode, errmsg, headers):
return web.urllib.addinfourl(fp, [headers, errcode], "http:" + url)
def google_ajax(query):
def google_ajax(query):
"""Search using AjaxSearch, and return its JSON."""
if isinstance(query, unicode):
if isinstance(query, unicode):
query = query.encode('utf-8')
uri = 'http://ajax.googleapis.com/ajax/services/search/web'
args = '?v=1.0&safe=off&q=' + web.urllib.quote(query)
@ -32,23 +32,23 @@ def google_ajax(query):
web.urllib._urlopener = handler
return web.json(bytes)
def google_search(query):
def google_search(query):
results = google_ajax(query)
try: return results['responseData']['results'][0]['unescapedUrl']
except IndexError: return None
except TypeError:
except TypeError:
print results
return False
def google_count(query):
def google_count(query):
results = google_ajax(query)
if not results.has_key('responseData'): return '0'
if not results['responseData'].has_key('cursor'): return '0'
if not results['responseData']['cursor'].has_key('estimatedResultCount'):
if not results['responseData']['cursor'].has_key('estimatedResultCount'):
return '0'
return results['responseData']['cursor']['estimatedResultCount']
def formatnumber(n):
def formatnumber(n):
"""Format a number with beautiful commas."""
parts = list(str(n))
for i in range((len(parts) - 3), 0, -3):
@ -56,14 +56,10 @@ def formatnumber(n):
return ''.join(parts)
def g(phenny, input):
def g(phenny, input):
"""Queries Google for the specified input."""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
query = input.group(2)
if not query:
if not query:
return phenny.reply('.g what?')
for bw in search_badwords:
if bw in query:
@ -72,7 +68,7 @@ def g(phenny, input):
query = query.encode('utf-8')
print("[LOG]: %s queried Google Result for '%s'" % (input.nick,query))
uri = google_search(query)
if uri:
if uri:
phenny.reply(uri)
phenny.bot.last_seen_uri = uri
elif uri is False: phenny.reply("Problem getting data from Google.")
@ -82,10 +78,6 @@ g.priority = 'high'
g.example = '.g minetest'
def gc(phenny, input):
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
if not input.group(2):
return phenny.reply("No query term.")
query = input.group(2).encode('utf-8')
@ -98,7 +90,7 @@ def gc(phenny, input):
if result:
phenny.say(query + ": " + result)
else: phenny.reply("Sorry, couldn't get a result.")
def new_gc(query):
uri = 'https://www.google.com/search?hl=en&q='
uri = uri + web.urllib.quote(query).replace('+', '%2B')
@ -114,5 +106,5 @@ gc.commands = ['gc']
gc.priority = 'high'
gc.example = '.gc minetest'
if __name__ == '__main__':
if __name__ == '__main__':
print __doc__.strip()

View File

@ -51,11 +51,7 @@ def pushupdate(sender, time, nick):
update_l.release()
def seen(phenny, input):
""".seen <nick> - Reports when <nick> was last seen."""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
"""seen <nick> - Reports when <nick> was last seen."""
nick = input.group(2)
if not nick:
return phenny.reply("Need a nickname to search for...")

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
"""
server.py - Phenny Minetest Server Module
Copyright 2013, Sfan5
Copyright 2013, sfan5
"""
import web, json, random
@ -174,11 +174,6 @@ def by_port(tbl, arg):
return results
def server(phenny, input):
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
arg = input.group(2)
if not arg:
cfuncs = [by_random]

View File

@ -7,10 +7,6 @@ Copyright 2012, sfan5
import socket, time
def serverup(phenny, input):
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
arg = input.group(2)
if not arg:
return phenny.reply("Give me a Server Address")
@ -78,7 +74,7 @@ def serverup(phenny, input):
except:
phenny.say("%s seems to be down " % repres)
serverup.commands = ['up']
serverup.thread = True

View File

@ -6,10 +6,6 @@ Copyright 2013, sfan5
import urllib
def shorten(phenny, input):
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
arg = input.group(2)
if not arg:
arg = "" # Function continues and prints Help Message
@ -33,7 +29,7 @@ def shorten(phenny, input):
except:
return phenny.reply("Problems accessing v.gd, please try a different Service")
return phenny.reply("Unknown Service")
shorten.commands = ['shorten','sh']
shorten.thread = True

View File

@ -15,10 +15,6 @@ import json
def rtfm(phenny, input):
"""Manual reference command"""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return
if input.group(2):
u = input.group(2).strip() + ", "
else:
@ -29,10 +25,6 @@ rtfm.commands = ['rtfm']
def questions(phenny, input):
"""Ask smart questions"""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return
if input.group(2):
u = input.group(2).strip() + ", "
else:
@ -43,10 +35,6 @@ questions.commands = ['questions']
def next(phenny, input):
"""Next one please"""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return
phenny.say("Another satisfied customer. Next!")
next.commands = ['next']
@ -67,10 +55,6 @@ pil.commands = ['pil']
def git(phenny, input):
"""Git Manual link"""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return
if input.group(2):
u = input.group(2).strip() + ", "
else:
@ -81,10 +65,6 @@ git.commands = ['git']
def stfu(phenny, input):
"""usage: !stfu [nick]"""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return
if input.group(2):
u = input.group(2).strip() + ", "
else:
@ -95,10 +75,6 @@ stfu.commands = ['stfu']
def proc(phenny, input):
"""usage: !proc [nick]"""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return
if input.group(2):
u = input.group(2).strip() + ", "
else:
@ -109,10 +85,6 @@ proc.commands = ['proc']
def doge(phenny, input):
"""much wow, very function, such programming"""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return
if random.randint(0, 1) == 0:
f = urllib2.urlopen('http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=132')
data = f.read()
@ -143,5 +115,3 @@ def btc(phenny, input):
phenny.say('1 BTC = %.4f %s' % (data[currency]['15m'], data[currency]['symbol']))
btc.commands = ['btc']

View File

@ -31,10 +31,6 @@ def tell_diskwr():
tell_pending = []
def tell(phenny, input):
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
arg = input.group(2)
if not arg:
return phenny.reply("Need a nickname...")

View File

@ -13,26 +13,22 @@ import re, urllib2, urlparse
r_title = re.compile(r'(?ims)<title[^>]*>(.*?)</title\s*>')
def f_title(phenny, input):
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
uri = input.group(2)
uri = (uri or '').encode('utf-8')
if not uri and hasattr(phenny.bot, 'last_seen_uri'):
if not uri and hasattr(phenny.bot, 'last_seen_uri'):
uri = phenny.bot.last_seen_uri
if not uri:
if not uri:
return phenny.reply('I need a URI to give the title of...')
if not ':' in uri:
if not ':' in uri:
uri = 'http://' + uri
try:
try:
redirects = 0
while True:
headers = {
'Accept': 'text/html',
'Accept': 'text/html',
'User-Agent': 'Mozilla/5.0 (MinetestBot)'
}
req = urllib2.Request(uri, headers=headers)
@ -77,9 +73,9 @@ def f_title(phenny, input):
if len(title) > 100:
title = title[:100] + '[...]'
if title:
if title:
try: title.decode('utf-8')
except:
except:
try: title = title.decode('iso-8859-1').encode('utf-8')
except: title = title.decode('cp1252').encode('utf-8')
else: pass
@ -92,12 +88,12 @@ def f_title(phenny, input):
f_title.commands = ['title']
def noteuri(phenny, input):
def noteuri(phenny, input):
uri = input.group(1).encode('utf-8')
phenny.bot.last_seen_uri = uri
noteuri.rule = r'.*(https?://[^<> "\x01]+).*'
noteuri.priority = 'low'
if __name__ == '__main__':
if __name__ == '__main__':
print __doc__.strip()

View File

@ -2,7 +2,7 @@
"""
twitter.py - Phenny Twitter Module
Copyright 2012, Sean B. Palmer, inamidst.com
Modified by Sfan5 2012
Modified by sfan5 2012
Licensed under the Eiffel Forum License 2.
http://inamidst.com/phenny/
@ -23,7 +23,7 @@ r_breaks = re.compile(r'(?ims)[\r\n]+')
def entity(*args, **kargs):
return web.entity(*args, **kargs).encode('utf-8')
def decode(html):
def decode(html):
return web.r_entity.sub(entity, html)
def expand(tweet):
@ -69,10 +69,6 @@ def id_tweet(tid):
return "Sorry, couldn't get a tweet from %s" % link
def twitter(phenny, input):
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
arg = input.group(2)
if not arg:
return phenny.reply("Give me a link, a @username, or a tweet id")

74
wiki.py
View File

@ -2,7 +2,7 @@
"""
wiki.py - Phenny Wiki Module
Copyright 2008-9, Sean B. Palmer, inamidst.com
Modified by Sfan5 2013
Modified by sfan5 2013
Licensed under the Eiffel Forum License 2.
http://inamidst.com/phenny/
@ -21,30 +21,30 @@ r_redirect = re.compile(
r'(?ims)class=.redirectText.>\s*<a\s*href=./wiki/([^"/]+)'
)
abbrs = ['etc', 'ca', 'cf', 'Co', 'Ltd', 'Inc', 'Mt', 'Mr', 'Mrs',
'Dr', 'Ms', 'Rev', 'Fr', 'St', 'Sgt', 'pron', 'approx', 'lit',
abbrs = ['etc', 'ca', 'cf', 'Co', 'Ltd', 'Inc', 'Mt', 'Mr', 'Mrs',
'Dr', 'Ms', 'Rev', 'Fr', 'St', 'Sgt', 'pron', 'approx', 'lit',
'syn', 'transl', 'sess', 'fl', 'Op', 'Dec', 'Brig', 'Gen'] \
+ list('ABCDEFGHIJKLMNOPQRSTUVWXYZ') \
+ list('abcdefghijklmnopqrstuvwxyz')
t_sentence = r'^.{5,}?(?<!\b%s)(?:\.(?=[\[ ][A-Z0-9]|\Z)|\Z)'
r_sentence = re.compile(t_sentence % r')(?<!\b'.join(abbrs))
def unescape(s):
def unescape(s):
s = s.replace('&gt;', '>')
s = s.replace('&lt;', '<')
s = s.replace('&amp;', '&')
s = s.replace('&#160;', ' ')
return s
def text(html):
def text(html):
html = r_tag.sub('', html)
html = r_whitespace.sub(' ', html)
return unescape(html).strip()
def wikipedia(term, language='en', last=False):
def wikipedia(term, language='en', last=False):
global wikiuri
if not '%' in term:
if isinstance(term, unicode):
if not '%' in term:
if isinstance(term, unicode):
t = term.encode('utf-8')
else: t = term
q = urllib.quote(t)
@ -52,7 +52,7 @@ def wikipedia(term, language='en', last=False):
bytes = web.get(u)
else: bytes = web.get(wikiuri % (term))
if bytes.startswith('\x1f\x8b\x08\x00\x00\x00\x00\x00'):
if bytes.startswith('\x1f\x8b\x08\x00\x00\x00\x00\x00'):
f = StringIO.StringIO(bytes)
f.seek(0)
gzip_file = gzip.GzipFile(fileobj=f)
@ -62,56 +62,56 @@ def wikipedia(term, language='en', last=False):
bytes = r_tr.sub('', bytes)
if not last:
if not last:
r = r_redirect.search(bytes[:4096])
if r:
if r:
term = urllib.unquote(r.group(1))
return wikipedia(term, language=language, last=True)
paragraphs = r_paragraph.findall(bytes)
if not paragraphs:
if not last:
if not paragraphs:
if not last:
term = search(term)
return wikipedia(term, language=language, last=True)
return None
# Pre-process
paragraphs = [para for para in paragraphs
if (para and 'technical limitations' not in para
and 'window.showTocToggle' not in para
and 'Deletion_policy' not in para
and 'Template:AfD_footer' not in para
and not (para.startswith('<p><i>') and
paragraphs = [para for para in paragraphs
if (para and 'technical limitations' not in para
and 'window.showTocToggle' not in para
and 'Deletion_policy' not in para
and 'Template:AfD_footer' not in para
and not (para.startswith('<p><i>') and
para.endswith('</i></p>'))
and not 'disambiguation)"' in para)
and not 'disambiguation)"' in para)
and not '(images and media)' in para
and not 'This article contains a' in para
and not 'This article contains a' in para
and not 'id="coordinates"' in para
and not 'class="thumb' in para]
# and not 'style="display:none"' in para]
for i, para in enumerate(paragraphs):
for i, para in enumerate(paragraphs):
para = para.replace('<sup>', '|')
para = para.replace('</sup>', '|')
paragraphs[i] = text(para).strip()
# Post-process
paragraphs = [para for para in paragraphs if
paragraphs = [para for para in paragraphs if
(para and not (para.endswith(':') and len(para) < 150))]
para = text(paragraphs[0])
m = r_sentence.match(para)
if not m:
if not last:
if not m:
if not last:
term = search(term)
return wikipedia(term, language=language, last=True)
return None
sentence = m.group(0)
maxlength = 275
if len(sentence) > maxlength:
if len(sentence) > maxlength:
sentence = sentence[:maxlength]
words = sentence[:-5].split(' ')
words.pop()
@ -119,8 +119,8 @@ def wikipedia(term, language='en', last=False):
if (('using the Article Wizard if you wish' in sentence)
or ('or add a request for it' in sentence)
or ('in existing articles' in sentence)):
if not last:
or ('in existing articles' in sentence)):
if not last:
term = search(term)
return wikipedia(term, language=language, last=True)
return None
@ -131,39 +131,35 @@ def wikipedia(term, language='en', last=False):
term = term.decode('utf-8').encode('utf-8')
return sentence + ' - ' + (wikiuri % (term))
def wik(phenny, input):
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
def wik(phenny, input):
origterm = input.groups()[1]
if not origterm:
if not origterm:
return phenny.say('Perhaps you meant "!wik Zen"?')
origterm = origterm.encode('utf-8')
print("[LOG]: %s queried Minetest Wiki for '%s'" % (input.nick,origterm))
term = urllib.unquote(origterm)
language = 'en'
if term.startswith(':') and (' ' in term):
if term.startswith(':') and (' ' in term):
a, b = term.split(' ', 1)
a = a.lstrip(':')
if a.isalpha():
if a.isalpha():
language, term = a, b
term = term[0].upper() + term[1:]
term = term.replace(' ', '_')
try: result = wikipedia(term, language)
except IOError:
except IOError:
args = (language, wikiuri % (term))
error = "Can't connect to wiki.minetest.com (%s)" % args
return phenny.say(error)
if result is not None:
if result is not None:
phenny.say(result)
else: phenny.say('Can\'t find anything in Wiki for "%s".' % origterm)
wik.commands = ['wik', 'wiki']
wik.priority = 'high'
if __name__ == '__main__':
if __name__ == '__main__':
print __doc__.strip()