From 45cfd0fb2ecd6c624fd1653e736e68040fb28b19 Mon Sep 17 00:00:00 2001 From: Sfan5 Date: Thu, 14 Feb 2013 21:27:04 +0100 Subject: [PATCH] Add global AntiAbuse module, remove badnick list from search.py --- antiabuse.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ calc.py | 4 ++++ forumutils.py | 4 ++++ ping.py | 6 +++++- rutils.py | 44 ++++++++++++++++++++++++++++++++++++++++ search.py | 17 ++++++++-------- seen.py | 4 ++++ server.py | 4 ++++ serverup.py | 4 ++++ shorten.py | 4 ++++ twitter.py | 4 ++++ wikipedia.py | 4 ++++ 12 files changed, 145 insertions(+), 10 deletions(-) create mode 100644 antiabuse.py diff --git a/antiabuse.py b/antiabuse.py new file mode 100644 index 0000000..3bca3bb --- /dev/null +++ b/antiabuse.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +""" +antiabuse.py - Phenny AntiAbuse Module +Copyright 2012, Sfan5 +""" +import time + +antiabuse = {} +antiabuse["timeout"] = {} +antiabuse["ignorelist"] = ["KikaRz","LandMine","LandMineMT","markveidemanis"] +antiabuse["s_timeout"] = 3 # in Seconds +antiabuse["f_set"] = False + +def aa_hook(phenny, input): + if input.admin or input.owner: + return False + #Ignore-List check + if input.nick in antiabuse["ignorelist"]: + return True # abort command + #Timeout check + try: + ot = antiabuse["timeout"][input.nick] + except: + ot = 0 + antiabuse["timeout"][input.nick] = time.time() + if antiabuse["timeout"][input.nick] - antiabuse["s_timeout"] < ot: + return True # abort command + + return False +aa_hook.event = 'THISWONTHAPPEN' +aa_hook.priority = 'high' +aa_hook.rule = r'h^' +#Warning: Uses a very very dirty hack to achieve that other modules can access this function + + +def ignore(phenny, input): + if not input.admin or not input.owner: return + arg = input.group(2) + antiabuse["ignorelist"].append(arg) + phenny.reply("'%s' added to ignore list." % arg) + +ignore.commands = ['ignore'] +ignore.priority = 'high' + +def unignore(phenny, input): + if not input.admin or not input.owner: return + arg = input.group(2) + try: + antiabuse["ignorelist"].remove(arg) + except: + return + phenny.reply("'%s' removed from ignore list." % arg) + +unignore.commands = ['unignore'] +unignore.priority = 'high' + diff --git a/calc.py b/calc.py index cae7cfe..e262439 100755 --- a/calc.py +++ b/calc.py @@ -30,6 +30,10 @@ subs = [ def c(phenny, input): """Google calculator.""" + 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('utf-8') diff --git a/forumutils.py b/forumutils.py index 9c0bc9d..28be4ca 100755 --- a/forumutils.py +++ b/forumutils.py @@ -61,6 +61,10 @@ 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") diff --git a/ping.py b/ping.py index 23219ac..2e282ff 100755 --- a/ping.py +++ b/ping.py @@ -7,7 +7,11 @@ About: http://inamidst.com/phenny/ import random -def hello(phenny, input): +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')) punctuation = random.choice(('', '!')) phenny.say(greeting + ' ' + input.nick + punctuation) diff --git a/rutils.py b/rutils.py index c64c019..2b7ea9c 100755 --- a/rutils.py +++ b/rutils.py @@ -7,6 +7,10 @@ import base64, binascii 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') @@ -21,6 +25,10 @@ rev.priority = 'low' 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') @@ -34,6 +42,10 @@ b64e.priority = 'low' 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') @@ -47,6 +59,10 @@ b64d.priority = 'low' 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') @@ -60,6 +76,10 @@ b32e.priority = 'low' 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') @@ -73,6 +93,10 @@ b32d.priority = 'low' 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') @@ -99,6 +123,10 @@ b16d.priority = 'low' 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') @@ -110,6 +138,10 @@ crc32.priority = 'low' def hex_(phenny, input): """hexlify http://docs.python.org/2/library/binascii.html#binascii.hexlify""" + 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 hexlify.") q = input.group(2).encode('utf-8') @@ -123,6 +155,10 @@ hex_.priority = 'low' def unhex(phenny, input): """unhexlify http://docs.python.org/2/library/binascii.html#binascii.unhexlify""" + 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 unhexlify.") q = input.group(2).encode('utf-8') @@ -136,6 +172,10 @@ unhex.priority = 'low' def uuencode(phenny, input): """uuencode""" + 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') @@ -149,6 +189,10 @@ uuencode.priority = 'low' def uudecode(phenny, input): """uudecode""" + 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') diff --git a/search.py b/search.py index dcbeb6d..2ec2b2c 100755 --- a/search.py +++ b/search.py @@ -11,7 +11,6 @@ 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_badnicks = ["KikaRz","LandMine","LandMineMT"] class Grab(web.urllib.URLopener): def __init__(self, *args): @@ -59,6 +58,10 @@ def formatnumber(n): 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: return phenny.reply('.g what?') @@ -66,10 +69,6 @@ def g(phenny, input): if bw in query: print("[LOG]: %s queried Google Result for '%s' | DENIED: Badword" % (input.nick,query)) return phenny.reply("Gross!") - for bn in search_badnicks: - if bn in input.nick: - print("[LOG]: %s queried Google Result for '%s' | DENIED: Badnick" % (input.nick,query)) - return phenny.reply("Nope!") query = query.encode('utf-8') print("[LOG]: %s queried Google Result for '%s'" % (input.nick,query)) uri = google_search(query) @@ -85,6 +84,10 @@ 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') @@ -93,10 +96,6 @@ def gc(phenny, input): if bw in query: print("[LOG]: %s queried Google Result Number for '%s' | DENIED: Badword" % (input.nick,query)) return phenny.reply("Gross!") - for bn in search_badnicks: - if bn in input.nick: - print("[LOG]: %s queried Google Result Number for '%s' | DENIED: Badnick" % (input.nick,query)) - return phenny.reply("Nope!") print("[LOG]: %s queried Google Result Number for '%s'" % (input.nick,query)) if result: phenny.say(query + ": " + result) diff --git a/seen.py b/seen.py index 0c1834c..49c6377 100644 --- a/seen.py +++ b/seen.py @@ -13,6 +13,10 @@ from tools import deprecated def seen(phenny, input): """.seen - Reports when 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 nick = input.group(2) if not nick: return phenny.reply("Need a nickname to search for...") diff --git a/server.py b/server.py index db48092..f434772 100755 --- a/server.py +++ b/server.py @@ -8,6 +8,10 @@ import web, math, random from xml.dom import minidom def read_server(): + for x in phenny.bot.commands["high"].values(): + if x[0].__name__ == "aa_hook": + if x[0](phenny, input): + return # Abort function bytes = web.get("http://servers.minetest.ru/") shim = '' shim2 = '
' diff --git a/serverup.py b/serverup.py index be04a5a..dd00f67 100755 --- a/serverup.py +++ b/serverup.py @@ -7,6 +7,10 @@ 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") diff --git a/shorten.py b/shorten.py index b616cf2..0ceddf9 100644 --- a/shorten.py +++ b/shorten.py @@ -6,6 +6,10 @@ 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 diff --git a/twitter.py b/twitter.py index 82df3e1..c6f9f51 100755 --- a/twitter.py +++ b/twitter.py @@ -69,6 +69,10 @@ 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") diff --git a/wikipedia.py b/wikipedia.py index e9ee750..2bf6d16 100755 --- a/wikipedia.py +++ b/wikipedia.py @@ -132,6 +132,10 @@ def wikipedia(term, language='en', last=False): 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 origterm = input.groups()[1] if not origterm: return phenny.say('Perhaps you meant ".wik Zen"?')