Merge branch 'develop' into refresh
Conflicts: plugins/factoids.py plugins/geoip.py
This commit is contained in:
commit
014c4bdc4b
26 changed files with 72 additions and 63 deletions
|
@ -3,7 +3,6 @@ import time
|
||||||
from util import hook
|
from util import hook
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# CTCP responses
|
# CTCP responses
|
||||||
@hook.regex(r'^\x01VERSION\x01$')
|
@hook.regex(r'^\x01VERSION\x01$')
|
||||||
def ctcp_version(inp, notice=None):
|
def ctcp_version(inp, notice=None):
|
||||||
|
|
|
@ -108,7 +108,7 @@ def info(inp, notice=None, db=None):
|
||||||
|
|
||||||
@hook.regex(r'^\? ?(.+)')
|
@hook.regex(r'^\? ?(.+)')
|
||||||
def factoid(inp, message=None, db=None, bot=None, action=None, conn=None, input=None):
|
def factoid(inp, message=None, db=None, bot=None, action=None, conn=None, input=None):
|
||||||
"?<word> -- Shows what data is associated with <word>."
|
"""?<word> -- Shows what data is associated with <word>."""
|
||||||
|
|
||||||
db_init(db)
|
db_init(db)
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ with open("./data/geoip_regions.json", "rb") as f:
|
||||||
regions = json.loads(f.read())
|
regions = json.loads(f.read())
|
||||||
|
|
||||||
if os.path.isfile(os.path.abspath("./data/GeoLiteCity.dat")):
|
if os.path.isfile(os.path.abspath("./data/GeoLiteCity.dat")):
|
||||||
# initalise geolocation database
|
# initialise geolocation database
|
||||||
geo = pygeoip.GeoIP(os.path.abspath("./data/GeoLiteCity.dat"))
|
geo = pygeoip.GeoIP(os.path.abspath("./data/GeoLiteCity.dat"))
|
||||||
else:
|
else:
|
||||||
download = http.get("http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz")
|
download = http.get("http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz")
|
||||||
|
|
|
@ -3,8 +3,8 @@ import re
|
||||||
from util import hook
|
from util import hook
|
||||||
|
|
||||||
|
|
||||||
@hook.command(autohelp=False)
|
@hook.command("help", autohelp=False)
|
||||||
def help(inp, notice=None, conn=None, bot=None):
|
def help_command(inp, notice=None, conn=None, bot=None):
|
||||||
"""help -- Gives a list of commands/help for a command."""
|
"""help -- Gives a list of commands/help for a command."""
|
||||||
|
|
||||||
funcs = {}
|
funcs = {}
|
||||||
|
|
|
@ -39,10 +39,10 @@ def imdb(inp):
|
||||||
|
|
||||||
@hook.regex(*imdb_re)
|
@hook.regex(*imdb_re)
|
||||||
def imdb_url(match):
|
def imdb_url(match):
|
||||||
id = match.group(4).split('/')[-1]
|
imdb_id = match.group(4).split('/')[-1]
|
||||||
if id == "":
|
if imdb_id == "":
|
||||||
id = match.group(4).split('/')[-2]
|
imdb_id = match.group(4).split('/')[-2]
|
||||||
content = http.get_json("http://www.omdbapi.com/", i=id)
|
content = http.get_json("http://www.omdbapi.com/", i=imdb_id)
|
||||||
if content.get('Error', None) == 'Movie not found!':
|
if content.get('Error', None) == 'Movie not found!':
|
||||||
return 'Movie not found!'
|
return 'Movie not found!'
|
||||||
elif content['Response'] == 'True':
|
elif content['Response'] == 'True':
|
||||||
|
|
|
@ -19,7 +19,8 @@ def is_valid(data):
|
||||||
|
|
||||||
@hook.command(autohelp=False)
|
@hook.command(autohelp=False)
|
||||||
def imgur(inp):
|
def imgur(inp):
|
||||||
"""imgur [subreddit] -- Gets the first page of imgur images from [subreddit] and returns a link to them. If [subreddit] is undefined, return any imgur images"""
|
"""imgur [subreddit] -- Gets the first page of imgur images from [subreddit] and returns a link to them.
|
||||||
|
If [subreddit] is undefined, return any imgur images"""
|
||||||
if inp:
|
if inp:
|
||||||
# see if the input ends with "nsfw"
|
# see if the input ends with "nsfw"
|
||||||
show_nsfw = inp.endswith(" nsfw")
|
show_nsfw = inp.endswith(" nsfw")
|
||||||
|
|
|
@ -132,7 +132,6 @@ def bukget(inp, reply=None, message=None):
|
||||||
message(line_b)
|
message(line_b)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@hook.command(autohelp=None)
|
@hook.command(autohelp=None)
|
||||||
def randomplugin(inp, reply=None, message=None):
|
def randomplugin(inp, reply=None, message=None):
|
||||||
"""randomplugin - Gets a random plugin from dev.bukkit.org"""
|
"""randomplugin - Gets a random plugin from dev.bukkit.org"""
|
||||||
|
|
|
@ -8,7 +8,7 @@ from util import hook
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import DNS
|
import DNS
|
||||||
# Please remember to install the dependancy 'pydns'
|
# Please remember to install the dependency 'pydns'
|
||||||
pydns_installed = True
|
pydns_installed = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pydns_installed = False
|
pydns_installed = False
|
||||||
|
@ -77,11 +77,12 @@ def mcping_modern(host, port):
|
||||||
try:
|
try:
|
||||||
version = data["version"]["name"]
|
version = data["version"]["name"]
|
||||||
desc = data["description"]
|
desc = data["description"]
|
||||||
max = data["players"]["max"]
|
max_players = data["players"]["max"]
|
||||||
online = data["players"]["online"]
|
online = data["players"]["online"]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return "Invalid data: {}; error: {}".format(data, e)
|
return "Invalid data: {}; error: {}".format(data, e)
|
||||||
return mc_color_format(u"{}\x0f - {}\x0f - {}/{} players *".format(desc, version, online, max)).replace("\n", u"\x0f - ")
|
return mc_color_format(u"{}\x0f - {}\x0f - {}/{} players *".format(desc, version, online,
|
||||||
|
max_players)).replace("\n", u"\x0f - ")
|
||||||
|
|
||||||
|
|
||||||
def mcping_legacy(host, port):
|
def mcping_legacy(host, port):
|
||||||
|
@ -102,7 +103,8 @@ def mcping_legacy(host, port):
|
||||||
message = u"{} - {}/{} players".format(mc_color_format(data[0]), data[1], data[2])
|
message = u"{} - {}/{} players".format(mc_color_format(data[0]), data[1], data[2])
|
||||||
else:
|
else:
|
||||||
# decoded data, server is using new format
|
# decoded data, server is using new format
|
||||||
message = u"{} \x0f- {} - {}/{} players".format(mc_color_format(data[3]), mc_color_format(data[2]), data[4], data[5])
|
message = u"{} \x0f- {} - {}/{} players".format(mc_color_format(data[3]),
|
||||||
|
mc_color_format(data[2]), data[4], data[5])
|
||||||
sock.close()
|
sock.close()
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
@ -174,7 +176,6 @@ def mcping(inp):
|
||||||
# return e.args[0]
|
# return e.args[0]
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return mcping_modern(host, port)
|
return mcping_modern(host, port)
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -46,14 +46,14 @@ def db_getall(db, nick, limit=-1):
|
||||||
""", (nick, limit))
|
""", (nick, limit))
|
||||||
|
|
||||||
|
|
||||||
def db_get(db, nick, id):
|
def db_get(db, nick, note_id):
|
||||||
return db.execute("""
|
return db.execute("""
|
||||||
select added, text from todos
|
select added, text from todos
|
||||||
where lower(user) = lower(?)
|
where lower(user) = lower(?)
|
||||||
order by added desc
|
order by added desc
|
||||||
limit 1
|
limit 1
|
||||||
offset ?
|
offset ?
|
||||||
""", (nick, id)).fetchone()
|
""", (nick, note_id)).fetchone()
|
||||||
|
|
||||||
|
|
||||||
def db_del(db, nick, limit='all'):
|
def db_del(db, nick, limit='all'):
|
||||||
|
|
|
@ -20,7 +20,7 @@ def ping(inp, reply=None):
|
||||||
args = inp.split(' ')
|
args = inp.split(' ')
|
||||||
host = args[0]
|
host = args[0]
|
||||||
|
|
||||||
# check for a seccond argument and set the ping count
|
# check for a second argument and set the ping count
|
||||||
if len(args) > 1:
|
if len(args) > 1:
|
||||||
count = int(args[1])
|
count = int(args[1])
|
||||||
if count > 20:
|
if count > 20:
|
||||||
|
|
|
@ -39,7 +39,7 @@ potatoes = ['AC Belmont', 'AC Blue Pride', 'AC Brador', 'AC Chaleur', 'AC Domino
|
||||||
|
|
||||||
|
|
||||||
@hook.command
|
@hook.command
|
||||||
def potato(inp, action=None, input=None):
|
def potato(inp, action=None):
|
||||||
"""potato <user> - Makes <user> a tasty little potato."""
|
"""potato <user> - Makes <user> a tasty little potato."""
|
||||||
inp = inp.strip()
|
inp = inp.strip()
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ def rottentomatoes(inp, bot=None):
|
||||||
|
|
||||||
movie = results['movies'][0]
|
movie = results['movies'][0]
|
||||||
title = movie['title']
|
title = movie['title']
|
||||||
id = movie['id']
|
movie_id = movie['id']
|
||||||
critics_score = movie['ratings']['critics_score']
|
critics_score = movie['ratings']['critics_score']
|
||||||
audience_score = movie['ratings']['audience_score']
|
audience_score = movie['ratings']['audience_score']
|
||||||
url = movie['links']['alternate']
|
url = movie['links']['alternate']
|
||||||
|
@ -29,7 +29,7 @@ def rottentomatoes(inp, bot=None):
|
||||||
if critics_score == -1:
|
if critics_score == -1:
|
||||||
return
|
return
|
||||||
|
|
||||||
reviews = http.get_json(movie_reviews_url % id, apikey=api_key, review_type='all')
|
reviews = http.get_json(movie_reviews_url % movie_id, apikey=api_key, review_type='all')
|
||||||
review_count = reviews['total']
|
review_count = reviews['total']
|
||||||
|
|
||||||
fresh = critics_score * review_count / 100
|
fresh = critics_score * review_count / 100
|
||||||
|
|
|
@ -30,11 +30,11 @@ def get_steam_info(url):
|
||||||
break
|
break
|
||||||
|
|
||||||
# find the next element directly after the <b></b> tag
|
# find the next element directly after the <b></b> tag
|
||||||
next = b.nextSibling
|
next_element = b.nextSibling
|
||||||
if next:
|
if next_element:
|
||||||
# if the element is some text
|
# if the element is some text
|
||||||
if isinstance(next, NavigableString):
|
if isinstance(next_element, NavigableString):
|
||||||
text = next.string.strip()
|
text = next_element.string.strip()
|
||||||
if text:
|
if text:
|
||||||
# we found valid text, save it and continue the loop
|
# we found valid text, save it and continue the loop
|
||||||
data[title] = text
|
data[title] = text
|
||||||
|
@ -44,11 +44,11 @@ def get_steam_info(url):
|
||||||
# useless spaces or tabs between the <b> and <a> tags.
|
# useless spaces or tabs between the <b> and <a> tags.
|
||||||
# so we find the next <a> tag and carry on to the next
|
# so we find the next <a> tag and carry on to the next
|
||||||
# bit of code below
|
# bit of code below
|
||||||
next = next.find_next('a', href=True)
|
next_element = next_element.find_next('a', href=True)
|
||||||
|
|
||||||
# if the element is an <a></a> tag
|
# if the element is an <a></a> tag
|
||||||
if isinstance(next, Tag) and next.name == 'a':
|
if isinstance(next_element, Tag) and next_element.name == 'a':
|
||||||
text = next.string.strip()
|
text = next_element.string.strip()
|
||||||
if text:
|
if text:
|
||||||
# we found valid text (in the <a></a> tag),
|
# we found valid text (in the <a></a> tag),
|
||||||
# save it and continue the loop
|
# save it and continue the loop
|
||||||
|
|
|
@ -91,7 +91,7 @@ def tell(inp, nick='', chan='', db=None, input=None, notice=None):
|
||||||
return
|
return
|
||||||
|
|
||||||
if user_to.lower() == input.conn.nick.lower():
|
if user_to.lower() == input.conn.nick.lower():
|
||||||
# user is looking for us, being a smartass
|
# user is looking for us, being a smart-ass
|
||||||
notice("Thanks for the message, {}!".format(user_from))
|
notice("Thanks for the message, {}!".format(user_from))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ strip_re = re.compile("(\x03|\x02|\x1f)(?:,?\d{1,2}(?:,\d{1,2})?)?", re.UNICODE)
|
||||||
def strip(string):
|
def strip(string):
|
||||||
return strip_re.sub('', string)
|
return strip_re.sub('', string)
|
||||||
|
|
||||||
|
|
||||||
# basic text tools
|
# basic text tools
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,6 +64,7 @@ def swapcase(inp):
|
||||||
"""swapcase <string> -- Swaps the capitalization of <string>."""
|
"""swapcase <string> -- Swaps the capitalization of <string>."""
|
||||||
return inp.swapcase()
|
return inp.swapcase()
|
||||||
|
|
||||||
|
|
||||||
# encoding
|
# encoding
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,6 +118,7 @@ def escape(inp):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return "Error: {}".format(e)
|
return "Error: {}".format(e)
|
||||||
|
|
||||||
|
|
||||||
# length
|
# length
|
||||||
|
|
||||||
|
|
||||||
|
@ -124,6 +127,7 @@ def length(inp):
|
||||||
"""length <string> -- gets the length of <string>"""
|
"""length <string> -- gets the length of <string>"""
|
||||||
return "The length of that string is {} characters.".format(len(inp))
|
return "The length of that string is {} characters.".format(len(inp))
|
||||||
|
|
||||||
|
|
||||||
# reverse
|
# reverse
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,15 +136,17 @@ def reverse(inp):
|
||||||
"""reverse <string> -- reverses <string>."""
|
"""reverse <string> -- reverses <string>."""
|
||||||
return inp[::-1]
|
return inp[::-1]
|
||||||
|
|
||||||
|
|
||||||
# hashing
|
# hashing
|
||||||
|
|
||||||
|
|
||||||
@hook.command
|
@hook.command("hash")
|
||||||
def hash(inp):
|
def hash_command(inp):
|
||||||
"""hash <string> -- Returns hashes of <string>."""
|
"""hash <string> -- Returns hashes of <string>."""
|
||||||
return ', '.join(x + ": " + getattr(hashlib, x)(inp).hexdigest()
|
return ', '.join(x + ": " + getattr(hashlib, x)(inp).hexdigest()
|
||||||
for x in ['md5', 'sha1', 'sha256'])
|
for x in ['md5', 'sha1', 'sha256'])
|
||||||
|
|
||||||
|
|
||||||
# novelty
|
# novelty
|
||||||
|
|
||||||
|
|
||||||
|
@ -149,6 +155,7 @@ def munge(inp):
|
||||||
"""munge <text> -- Munges up <text>."""
|
"""munge <text> -- Munges up <text>."""
|
||||||
return text.munge(inp)
|
return text.munge(inp)
|
||||||
|
|
||||||
|
|
||||||
# colors - based on code by Reece Selwood - <https://github.com/hitzler/homero>
|
# colors - based on code by Reece Selwood - <https://github.com/hitzler/homero>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
Crypto
|
oauth2
|
||||||
|
pygeoip
|
||||||
|
tweepy
|
||||||
BeautifulSoup==3.2.1
|
BeautifulSoup==3.2.1
|
||||||
lxml==3.1beta1
|
lxml==3.1beta1
|
||||||
pyenchant==1.6.5
|
pyenchant==1.6.5
|
||||||
|
|
Reference in a new issue