Navigation Menu

Skip to content

Commit

Permalink
My hands are typing words
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Jul 19, 2014
1 parent 5cfa4bc commit 606d7e1
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 68 deletions.
26 changes: 13 additions & 13 deletions admin.py
Expand Up @@ -2,31 +2,31 @@
"""
admin.py - Phenny Admin 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/
"""

def join(phenny, input):
def join(phenny, input):
"""Join the specified channel. This is an admin-only command."""
# Can only be done in privmsg by an admin
if input.sender.startswith('#'): return
if input.admin:
if input.admin:
channel, key = input.group(1), input.group(2)
if not key:
if not key:
phenny.write(['JOIN'], channel)
else: phenny.write(['JOIN', channel, key])
join.rule = r'\!join (#\S+)(?: *(\S+))?'
#join.commands = ['join']
join.priority = 'low'
join.example = '.join #example or .join #example key'

def part(phenny, input):
def part(phenny, input):
"""Part the specified channel. This is an admin-only command."""
# Can only be done in privmsg by an admin
if input.sender.startswith('#'): return
if input.admin:
if input.admin:
if ' ' in input.group(2):
arg = input.group(2).split(" ")
arg2 = ' '.join(arg[1:])
Expand All @@ -38,11 +38,11 @@ def part(phenny, input):
part.priority = 'low'
part.example = '.part #example'

def quit(phenny, input):
def quit(phenny, input):
"""Quit from the server. This is an owner-only command."""
# Can only be done in privmsg by the owner
if input.sender.startswith('#'): return
if input.owner:
if input.owner:
phenny.write(['QUIT'])
__import__('os')._exit(0)
quit.commands = ['quit']
Expand All @@ -54,20 +54,20 @@ def quit2(phenny, input):
quit2.rule = ('$nick', 'quit')
quit2.priority = 'low'

def msg(phenny, input):
def msg(phenny, input):
# Can only be done in privmsg by an admin
if input.sender.startswith('#'): return
a, b = input.group(2), input.group(3)
if (not a) or (not b): return
if input.admin:
if input.admin:
phenny.msg(a, b)
msg.rule = (['msg'], r'(#?\S+) (.+)')
msg.priority = 'low'

def me(phenny, input):
def me(phenny, input):
# Can only be done in privmsg by an admin
if input.sender.startswith('#'): return
if input.admin:
if input.admin:
msg = '\x01ACTION %s\x01' % input.group(3)
phenny.msg(input.group(2) or input.sender, msg)
me.rule = (['me'], r'(#?\S+) (.+)')
Expand All @@ -79,5 +79,5 @@ def py(phenny, input):
py.commands = ['py']
py.priority = 'high'

if __name__ == '__main__':
if __name__ == '__main__':
print __doc__.strip()
66 changes: 45 additions & 21 deletions antiabuse.py
Expand Up @@ -10,14 +10,49 @@
antiabuse["cooldown_l"] = {}
antiabuse["cooldown"] = 3 # seconds

def api_ignore(mask):
antiabuse["ignorelist"].append(mask)
db = sqlite3.connect("antiabuse.sqlite")
c = db.cursor()
c.execute("INSERT INTO ignore (nick) VALUES (?)", (mask,))
c.close()
db.commit()
db.close()

def api_unignore(mask):
if not mask in antiabuse["ignorelist"]:
return
antiabuse['ignorelist'].remove(mask)
db = sqlite3.connect("antiabuse.sqlite")
c = db.cursor()
c.execute("DELETE FROM ignore WHERE nick = ?", (mask,))
c.close()
db.commit()
db.close()

def api_get_ignorelist():
return antiabuse["ignorelist"]

class SomeObject(object):
pass

antiabuse_api = SomeObject()
antiabuse_api.ignore = api_ignore
antiabuse_api.unignore = api_unignore
antiabuse_api.get_ignorelsit = api_get_ignorelist

_export = {
'antiabuse': antiabuse_api,
}

def aa_hook(phenny, input, func):
if input.admin or input.owner:
return False
return True

# Ignore list
for entry in antiabuse["ignorelist"]:
if phenny.match_hostmask(entry, input.hostmask):
return True # abort command
return False # abort command

# Cooldown
if input.nick in antiabuse["cooldown_l"]:
Expand All @@ -26,10 +61,10 @@ def aa_hook(phenny, input, func):
ot = 0
antiabuse["cooldown_l"][input.nick] = time.time()
if antiabuse["cooldown_l"][input.nick] - antiabuse["cooldown"] < ot:
return True # abort command
return False # abort command
pass

return False
return True

aa_hook.hook = True

Expand All @@ -49,13 +84,7 @@ def ignore(phenny, input):
if not input.admin:
return
arg = hmasktrans(input.group(2).strip())
antiabuse["ignorelist"].append(arg)
db = sqlite3.connect("antiabuse.sqlite")
c = db.cursor()
c.execute("INSERT INTO ignore (nick) VALUES (?)", (arg,))
c.close()
db.commit()
db.close()
api_ignore(arg)
phenny.reply("'%s' added to ignore list." % arg)

ignore.commands = ['ignore']
Expand All @@ -65,15 +94,7 @@ def unignore(phenny, input):
if not input.admin:
return
arg = hmasktrans(input.group(2).strip())
if not arg in antiabuse["ignorelist"]:
return
antiabuse['ignorelist'].remove(arg)
db = sqlite3.connect("antiabuse.sqlite")
c = db.cursor()
c.execute("DELETE FROM ignore WHERE nick = ?", (arg,))
c.close()
db.commit()
db.close()
api_unignore(arg)
phenny.reply("'%s' removed from ignore list." % arg)

unignore.commands = ['unignore']
Expand All @@ -82,7 +103,10 @@ def unignore(phenny, input):
def listignore(phenny, input):
if not input.admin:
return
phenny.reply(', '.join(antiabuse['ignorelist']))
s = ', '.join(antiabuse['ignorelist'])
if s == "":
s = "Ignore list empty."
phenny.reply(s)

listignore.commands = ['listignore']
listignore.priority = 'high'
Expand Down
28 changes: 23 additions & 5 deletions calc.py
Expand Up @@ -8,6 +8,7 @@
import math
import random
import struct
import multiprocessing

class SomeObject(object):
pass
Expand Down Expand Up @@ -39,11 +40,28 @@ def c(phenny, input):
q = input.group(2).encode('ascii', 'ignore')
if '__' in q:
return phenny.reply("Sorry, but no double underscores.")
print("[LOG]: %s calculated '%s'" % (input.nick, q))
try:
phenny.say(repr(eval(q, {'__builtins__': env}, {})))
except Exception as e:
phenny.say(type(e).__name__ + ": " + str(e))
log.log("event", "%s calculated '%s'" % (log.fmt_user(input), q), phenny)
o = multiprocessing.Queue()
def get_result(o, q):
try:
o.put(repr(eval(q, {'__builtins__': env}, {})))
except Exception as e:
o.put(type(e).__name__ + ": " + str(e))
proc = multiprocessing.Process(target=get_result, args=(o,q))
proc.start()
proc.join(2.0)
if proc.is_alive():
proc.terminate()
if 'math.pow' in q or '**' in q:
phenny.reply("Kindly go fuck yourself!")
antiabuse.ignore("*!*" + input.hostmask[input.hostmask.find("@"):])
log.log("action", "Auto-ignored %s for !c crash attempt" % log.fmt_user(input), phenny)
else:
phenny.reply("Took to long to calculate")
return
else:
phenny.say(o.get())


c.commands = ['c']
c.example = '.c 5 + 3'
Expand Down
4 changes: 2 additions & 2 deletions devwiki.py
Expand Up @@ -131,12 +131,12 @@ def devwikipedia(term, language='en', last=False):
term = term.decode('utf-8').encode('utf-8')
return sentence + ' - ' + (devwikiuri % (term))

def devwik(phenny, input):
def devwik(phenny, input):
origterm = input.groups()[1]
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))
log.log("event", "%s queried Devwiki for '%s'" % (log.fmt_user(input), origterm), phenny)

term = urllib.unquote(origterm)
language = 'en'
Expand Down
14 changes: 2 additions & 12 deletions search.py
Expand Up @@ -10,8 +10,6 @@

import web, re

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):
self.version = 'Mozilla/5.0 (MinetestBot)'
Expand Down Expand Up @@ -61,12 +59,8 @@ def g(phenny, input):
query = input.group(2)
if not query:
return phenny.reply('.g what?')
for bw in search_badwords:
if bw in query:
print("[LOG]: %s queried Google Result for '%s' | DENIED: Badword" % (input.nick,query))
return phenny.reply("Gross!")
query = query.encode('utf-8')
print("[LOG]: %s queried Google Result for '%s'" % (input.nick,query))
log.log("%s searched Google for '%s'" % (log.fmt_user(input), query))
uri = google_search(query)
if uri:
phenny.reply(uri)
Expand All @@ -81,12 +75,8 @@ def gc(phenny, input):
if not input.group(2):
return phenny.reply("No query term.")
query = input.group(2).encode('utf-8')
log.log("%s searched Google for '%s'" % (log.fmt_user(input), query))
result = new_gc(query)
for bw in search_badwords:
if bw in query:
print("[LOG]: %s queried Google Result Number for '%s' | DENIED: Badword" % (input.nick,query))
return phenny.reply("Gross!")
print("[LOG]: %s queried Google Result Number for '%s'" % (input.nick,query))
if result:
phenny.say(query + ": " + result)
else: phenny.reply("Sorry, couldn't get a result.")
Expand Down
32 changes: 23 additions & 9 deletions seen.py
Expand Up @@ -52,23 +52,37 @@ def pushupdate(sender, nick):
updates.append((sender, ts, nick))
update_l.release()

def api_seen(nick):
dblock.acquire()
db = opendb()
c = db.cursor()
c.execute("SELECT channel, time FROM seen WHERE nick = ?", (nick,))
r = c.fetchone()
c.close()
db.close()
dblock.release()
return r

class SomeObject(object):
pass

seen_api = SomeObject()
seen_api.seen = api_seen

_export = {
'seen': seen_api,
}

def seen(phenny, input):
"""seen <nick> - Reports when <nick> was last seen."""
nick = input.group(2)
if not nick:
return phenny.reply("Need a nickname to search for...")
nick = nick.lower()

print("[LOG]: %s queried Seen Result for %s" % (input.nick,nick))
log.log("event", "%s queried Seen database for '%s'" % (log.fmt_user(input), nick), phenny)

dblock.acquire()
db = opendb()
c = db.cursor()
c.execute("SELECT channel, time FROM seen WHERE nick = ?", (nick,))
r = c.fetchone()
c.close()
db.close()
dblock.release()
r = api_seen(nick)

if r:
channel, t = r[0], r[1]
Expand Down
21 changes: 17 additions & 4 deletions tell.py
Expand Up @@ -30,6 +30,22 @@ def tell_diskwr():
db.close()
tell_pending = []

def api_tell(teller, tellee, text):
d = (teller, tellee, text, int(time.mktime(time.gmtime())))
tell_pending.append(("add", d))
# We do not insert the entry into tell_list yet because we don't know the id it will have
tell_diskwr() # Write the change to disk

class SomeObject(object):
pass

tell_api = SomeObject()
tell_api.tell = api_tell

_export = {
'tell': tell_api,
}

def tell(phenny, input):
arg = input.group(2)
if not arg:
Expand All @@ -46,10 +62,7 @@ def tell(phenny, input):
elif target[-1] == ":":
return phenny.reply("Do not put an : at the end of nickname")

d = (teller, target, text, int(time.mktime(time.gmtime())))
tell_pending.append(("add", d))
# We do not insert the entry into tell_list yet because we don't know the id it will have
tell_diskwr() # Write the change to disk
api_tell(teller, target, text)

response = "I'll pass that on when %s is around" % target
rand = random.random()
Expand Down
2 changes: 1 addition & 1 deletion twitter.py
Expand Up @@ -76,7 +76,7 @@ def twitter(phenny, input):
arg = arg.strip()
if isinstance(arg, unicode):
arg = arg.encode('utf-8')
print("[LOG]: %s queried Twitter for '%s'" % (input.nick,arg))
log.log("%s queried Twitter for '%s'" % (log.fmt_user(input), arg))
if arg.isdigit():
phenny.say(id_tweet(arg))
elif r_username.match(arg):
Expand Down
3 changes: 2 additions & 1 deletion wiki.py
Expand Up @@ -136,7 +136,8 @@ def wik(phenny, input):
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))

log.log("event", "%s queried Wiki for '%s'" % (log.fmt_user(input), origterm), phenny)

term = urllib.unquote(origterm)
language = 'en'
Expand Down

0 comments on commit 606d7e1

Please sign in to comment.