Skip to content
This repository was archived by the owner on Oct 25, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
92c31cd
Fixed problems with 405: method not allowed for links
mattr555 Nov 28, 2013
60cb026
Added apertium translate plugin
mattr555 Nov 28, 2013
14d11c0
Get title 405 fix take 2
mattr555 Nov 28, 2013
fd1f70e
Get title 404 fix
mattr555 Nov 29, 2013
490ad82
fixed apertium_translate's spacing
mattr555 Nov 29, 2013
7424f42
added .botslap
mattr555 Nov 29, 2013
59cad85
Added .py
mattr555 Nov 29, 2013
00e1a1a
Updated .time to the newer version of phenny
mattr555 Nov 29, 2013
9501389
Added .ethnologue, language lookup
mattr555 Nov 29, 2013
787ffa3
Added eldea, a translation follower
mattr555 Nov 29, 2013
061ee51
Get title 404 fix take 2
mattr555 Nov 29, 2013
373cae0
Added github.py: new commit notifier
mattr555 Nov 29, 2013
f8354a4
get title non-string fix
mattr555 Nov 29, 2013
a123d4c
Added .iso639- language code lookup
mattr555 Nov 29, 2013
96763ad
Added .lgmtfy
mattr555 Nov 29, 2013
e710e63
Updated .seen, added time since to response
mattr555 Nov 29, 2013
88b2e39
Added pm functionality to tell command
mattr555 Nov 29, 2013
ba3494f
Added .fight, .hug
mattr555 Nov 29, 2013
11379ee
Added .wikicount
mattr555 Nov 29, 2013
40ed3de
Added language functionality to .wik
mattr555 Nov 29, 2013
e37d6e2
Added .ety- etymology lookup on wiktionary
mattr555 Nov 29, 2013
e26e877
Added .whereis
mattr555 Nov 29, 2013
e4a41c3
Added minor documentation
mattr555 Nov 29, 2013
390c939
Updated apertium-related tests
mattr555 Nov 29, 2013
2d4332f
Not sure what this is for, probably best if committed ;)
mattr555 Nov 29, 2013
c1032c2
Added svnpoller.py
mattr555 Nov 29, 2013
e0fc389
Fix botslap rule to only apply if bot mentioned
sushain97 Feb 1, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*~
*.swp
__pycache__
desktop.ini
3 changes: 2 additions & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def __new__(cls, text, origin, bytes, match, event, args):
s.args = args
s.admin = s.nick in self.config.admins
s.owner = s.nick == self.config.owner
s.chans = self.config.channels
return s

return CommandInput(text, origin, bytes, match, event, args)
Expand Down Expand Up @@ -231,7 +232,7 @@ def dispatch(self, origin, args):

if func.thread:
targs = (func, origin, phenny, input)
t = threading.Thread(target=self.call, args=targs)
t = threading.Thread(target=self.call, args=targs, name=func.name)
t.start()
else: self.call(func, origin, phenny, input)

Expand Down
2 changes: 2 additions & 0 deletions modules/8ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def eightball(phenny, input):
quote = random.choice(quotes)
phenny.reply(quote)
eightball.commands = ['8ball']
eightball.name = '8ball'
eightball.example = '.8ball is pie amazing?'

if __name__ == '__main__':
print(__doc__.strip())
190 changes: 190 additions & 0 deletions modules/apertium_translate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
#!/usr/bin/env python
# coding=utf-8
"""
apertium_translate.py - Phenny Translation Module
"""

import re, urllib.request, json
import web
from tools import GrumbleError

headers = [(
'User-Agent', 'Mozilla/5.0' +
'(X11; U; Linux i686)' +
'Gecko/20071127 Firefox/2.0.0.11'
)]

APIerrorData = 'Sorry, the apertium API did not return any data ☹'
APIerrorHttp = 'Sorry, the apertium API gave HTTP error %s: %s ☹'

def translate(translate_me, input_lang, output_lang='en'):
opener = urllib.request.build_opener()
opener.addheaders = headers

input_lang, output_lang = web.quote(input_lang), web.quote(output_lang)
translate_me = web.quote(translate_me)

response = opener.open('http://api.apertium.org/json/translate?q='+translate_me+'&langpair='+input_lang+"|"+output_lang).read()

responseArray = json.loads(response.decode('utf-8'))
if int(responseArray['responseStatus']) != 200:
raise GrumbleError(APIerrorHttp % (responseArray['responseStatus'], responseArray['responseDetails']))
if responseArray['responseData']['translatedText'] == []:
raise GrumbleError(APIerrorData)

translated_text = responseArray['responseData']['translatedText']
return translated_text


def apertium_translate(phenny, input):
"""Translates a phrase using the apertium API"""
line = input.group(2)
if not line:
raise GrumbleError("Need something to translate!")
#line = line.encode('utf-8')

pairs = []
guidelines = line.split('|')
if len(guidelines) > 1:
for guideline in guidelines[1:]:
#phenny.say(guideline)
pairs.append(guideline.strip().split('-'))
guidelines = guidelines[0]
#phenny.say(str(guidelines))
stuff = re.search('(.*) ([a-z]+-[a-z]+)', guidelines)
#phenny.say(str(stuff.groups()))
pairs.insert(0, stuff.group(2).split('-'))
translate_me = stuff.group(1)
#phenny.say(str(pairs))

#output_lang = line.split(' ')[-1]
#input_lang = line.split(' ')[-2]
#translate_me = ' '.join(line.split(' ')[:-2])

if (len(translate_me) > 350) and (not input.admin):
raise GrumbleError('Phrase must be under 350 characters.')

msg = translate_me
finalmsg = False
translated = ""
for (input_lang, output_lang) in pairs:
if input_lang == output_lang:
raise GrumbleError('Stop trying to confuse me! Pick different languages ;)')
msg = translate(msg, input_lang, output_lang)
if not msg:
raise GrumbleError('The %s to %s translation failed, sorry!' % (input_lang, output_lang))
msg = web.decode(msg) # msg.replace(''', "'")
this_translated = "(%s-%s) %s" % (input_lang, output_lang, msg)
translated = msg

#if not finalmsg:
# finalmsg = translated
#phenny.reply(finalmsg)
phenny.reply(translated)

def apertium_listlangs(phenny, input):
"""Lists languages available for translation from/to"""

opener = urllib.request.build_opener()
opener.addheaders = headers

response = opener.open('http://api.apertium.org/json/listPairs').read()

langs = json.loads(response.decode('utf-8'))
if int(langs['responseStatus']) != 200:
raise GrumbleError(APIerrorHttp % (langs['responseStatus'], langs['responseDetails']))
if langs['responseData'] == []:
raise GrumbleError(APIerrorData)

outlangs = []
#phenny.say(str(langs))
for pair in langs['responseData']:
if pair['sourceLanguage'] not in outlangs:
outlangs.append(pair['sourceLanguage'])
if pair['targetLanguage'] not in outlangs:
outlangs.append(pair['targetLanguage'])
#phenny.say(str(outlangs))

extra = "; more info: .listpairs lg"

first=True
allLangs = ""
for lang in outlangs:
if not first:
allLangs+=", "
else:
first=False
allLangs += lang
phenny.say(allLangs + extra)


def apertium_listpairs(phenny, input):
"""Lists translation pairs available to apertium translation"""
lang = input.group(2)

opener = urllib.request.build_opener()
opener.addheaders = headers

response = opener.open('http://api.apertium.org/json/listPairs').read()

langs = json.loads(response.decode('utf-8'))

langs = json.loads(response.decode('utf-8'))
if langs['responseData'] is []:
raise GrumbleError(APIerrorData)
if int(langs['responseStatus']) != 200:
raise GrumbleError(APIerrorHttp % (langs['responseStatus'], langs['responseDetails']))

if not lang:
allpairs=""
first=True
for pair in langs['responseData']:
if not first:
allpairs+=","
else:
first=False
allpairs+="%s→%s" % (pair['sourceLanguage'], pair['targetLanguage'])
phenny.say(allpairs)
else:
toLang = []
fromLang = []
for pair in langs['responseData']:
if pair['sourceLanguage'] == lang:
fromLang.append(pair['targetLanguage'])
if pair['targetLanguage'] == lang:
toLang.append(pair['sourceLanguage'])
first=True
froms = ""
for lg in fromLang:
if not first:
froms += ", "
else:
first = False
froms += lg
first = True
tos = ""
for lg in toLang:
if not first:
tos += ", "
else:
first = False
tos += lg
#finals = froms + (" → %s → " % lang) + tos
finals = tos + (" → %s → " % lang) + froms

phenny.say(finals)

apertium_listpairs.name = 'listpairs'
apertium_listpairs.commands = ['listpairs']
apertium_listpairs.example = '.listpairs ca'
apertium_listpairs.priority = 'low'

apertium_listlangs.name = 'listlangs'
apertium_listlangs.commands = ['listlangs']
apertium_listlangs.example = '.listlangs'
apertium_listlangs.priority = 'low'

apertium_translate.name = 't'
apertium_translate.commands = ['t']
apertium_translate.example = '.t I like pie en-es'
apertium_translate.priority = 'high'
52 changes: 52 additions & 0 deletions modules/away.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python
"""
away.py - Phenny's record or who's away/present module
"""

import os, re, time, random
import web

statuses = {"alan": "boom bitchezzzz"}

def whereis(phenny, input):
"""Tells you nick's current status."""
whereis_nick = input.split(" ")[1]
print(input + " --> " + whereis_nick)
if (whereis_nick in list(statuses.keys())):
phenny.reply(whereis_nick + " said: " + statuses[whereis_nick])
else:
phenny.reply("Sorry, " + whereis_nick + " seems to be AWOL...")
whereis.commands = ["whereis"]
whereis.priority = 'low'
whereis.example = '.whereis sushain'
whereis.thread = False

def away(phenny, input):
"""Set your status to being away."""
nick = input.nick
if input.count(" ") == 0:
statuses[nick] = "I'm away right now"
else:
message = str(" ".join(input.split(" ")[1:]))
statuses[nick] = message
away.commands = ['away']
away.example = '.away eating pie'
away.priority = 'low'
away.thread = False

def back(phenny, input):
"""Set your status to being available."""
nick = input.nick
if input.count(" ") == 0:
statuses[nick] = "I'm around at the minute"
else:
message = str(" ".join(input.split(" ")[1:]))
statuses[nick] = message
back.commands = ['back']
back.example = '.back'
back.priority = 'low'
back.thread = False


if __name__ == '__main__':
print(__doc__.strip())
2 changes: 2 additions & 0 deletions modules/botfun.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ def botfight(phenny, input):
phenny.do(response % otherbot)
botfight.commands = ['botfight']
botfight.priority = 'low'
botfight.example = '.botfight'

def bothug(phenny, input):
""".bothug - Hug the other bot in the channel."""

phenny.do("hugs %s" % otherbot)
bothug.commands = ['bothug']
bothug.priority = 'low'
bothug.example = '.bothug'

if __name__ == '__main__':
print(__doc__.strip())
9 changes: 9 additions & 0 deletions modules/botsnack.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,14 @@ def botsnack(phenny, input):
botsnack.last_tick = time.time()
botsnack.coolingdown = False

def botslap(phenny, input):
"""tell me I'm being a bad bot"""
messages = ["hides in corner", "eats own hat", "apologises", "stares at feet", "points at zfe", "didn't do anything", "doesn't deserve this", "hates you guys", "did it on purpose", "is an inconsistent sketchy little bot", "scurries off"]
phenny.do(random.choice(messages))

botslap.commands = ['botslap', 'botsmack']
botslap.rule = r'''^(?:(?:$nickname[ ,:]?)\s+(you suck|I hate you|you ruin everything|you spoil all [themyour]*fun|bad|wtf|lame| [youare']*?stupid|silly)\s*$)|(?:.*?(you suck|I hate you|you ruin everything|you spoil all [themyour]*fun|bad|wtf|lame|[youare']*?stupid|silly)(?:[, ]? $nickname))'''
botsnack.priority = 'low'

if __name__ == '__main__':
print(__doc__.strip())
12 changes: 11 additions & 1 deletion modules/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ def c(phenny, input):
c.commands = ['c']
c.example = '.c 5 + 3'

def py(phenny, input):
"""evaluates a python2 expression via a remote sandbox"""
query = input.group(2).encode('utf-8')
uri = 'http://tumbolia.appspot.com/py/'
answer = web.get(uri + web.quote(query))
if answer:
phenny.say(answer)
else: phenny.reply('Sorry, no result.')
py.commands = ['py']
py.example = '.py if not False: print "hello world!"'

def wa(phenny, input):
if not input.group(2):
Expand All @@ -68,7 +78,7 @@ def wa(phenny, input):

phenny.say(answer)
wa.commands = ['wa']

wa.example = '.wa answer to life'

if __name__ == '__main__':
print(__doc__.strip())
Loading