This commit is contained in:
Luke Rogers 2012-03-23 13:32:48 +13:00
parent e7d69e63c0
commit 549bb70690
5 changed files with 21 additions and 27 deletions

View file

@ -24,7 +24,8 @@ def db_init(db):
def get_memory(db, word):
row = db.execute("select data from mem where word=lower(?)", [word]).fetchone()
row = db.execute("select data from mem where word=lower(?)",
[word]).fetchone()
if row:
return row[0]
else:
@ -46,7 +47,8 @@ def multiwordReplace(text, wordDic):
@hook.command("r", adminonly=True)
@hook.command(adminonly=True)
def remember(inp, nick='', db=None, say=None, input=None, notice=None):
".remember <word> [+]<data> -- Remembers <data> with <word>. Add + to <data> to append."
".remember <word> [+]<data> -- Remembers <data> with <word>. Add +"
" to <data> to append."
db_init(db)
append = False
@ -78,8 +80,8 @@ def remember(inp, nick='', db=None, say=None, input=None, notice=None):
if append:
notice("Appending %s to %s" % (new, data.replace('"', "''")))
else:
notice('Forgetting existing data (%s), remembering this instead!' % \
data.replace('"', "''"))
notice('Forgetting existing data (%s), remembering this instead!'
% data.replace('"', "''"))
return
else:
notice('Remembered!')

View file

@ -5,7 +5,8 @@ import urllib2
@hook.command
def gitio(inp):
".gitio <url> [code] -- Shorten Github URLs with git.io. [code] is a optional custom short code."
".gitio <url> [code] -- Shorten Github URLs with git.io. [code] is"
" a optional custom short code."
split = inp.split(" ")
url = split[0]

View file

@ -6,6 +6,7 @@ from re import match
from urllib2 import urlopen, Request, HTTPError
from urllib import urlencode
class ShortenError(Exception):
def __init__(self, value):
self.value = value
@ -13,13 +14,15 @@ class ShortenError(Exception):
def __str__(self):
return repr(self.value)
def bitly(url, user, apikey):
try:
if url[:8] == "https://":
pass
elif url[:7] != "http://":
url = "http://" + url
params = urlencode({'longUrl': url, 'login': user, 'apiKey': apikey, 'format': 'json'})
params = urlencode({'longUrl': url, 'login': user, 'apiKey': apikey,
'format': 'json'})
j = http.get_json("http://api.bit.ly/v3/shorten?%s" % params)
if j['status_code'] == 200:
return j['data']['url']
@ -27,20 +30,12 @@ def bitly(url, user, apikey):
except (HTTPError, ShortenError):
return "Could not shorten %s!" % url
@hook.command
def shorten(inp, bot = None):
def shorten(inp, bot=None):
".shorten <url> - Makes an j.mp/bit.ly shortlink to the url provided."
api_user = bot.config.get("api_keys", {}).get("bitly_user", None)
api_key = bot.config.get("api_keys", {}).get("bitly_api", None)
if api_key is None:
return "error: no api key set"
return bitly(inp, api_user, api_key)
@hook.command
def expand(inp, bot = None):
".expand <url> - Gets the original URL from a shortened link."
try:
url = http.get_url(inp)
except HTTPError, e:
return "Failed to expand URL."
return url

View file

@ -2,10 +2,12 @@ from util import hook, http, misc
import re
import string
def sloganize(word):
bytes = http.get('http://www.sloganizer.net/en/outbound.php', slogan=word)
return bytes
@hook.command("slogan")
def sloganizr(inp, nick=None, say=None, input=None):
".slogan <word> -- Makes a slogan for <word>."

View file

@ -12,19 +12,13 @@ from util import hook, http, timesince
def unescape_xml(string):
# unescape the 5 chars that might be escaped in xml
# gratuitously functional
# return reduce(lambda x, y: x.replace(*y), (string,
# zip('&gt; &lt; &apos; &quote; &amp'.split(), '> < \' " &'.split()))
# boring, normal
return string.replace('&gt;', '>').replace('&lt;', '<').replace('&apos;',
"'").replace('&quote;', '"').replace('&amp;', '&')
history = []
history_max_size = 250
def parseDateTime(s):
if s is None:
return None
@ -154,9 +148,9 @@ def twitter(inp):
strptime(time.text,
'%a %b %d %H:%M:%S +0000 %Y'))
time_pretty = timesince.timesince(parseDateTime(time_raw), datetime.utcnow())
time_nice = timesince.timesince(parseDateTime(time_raw), datetime.utcnow())
text = unescape_xml(tweet.find(text).text.replace('\n', ''))
screen_name = tweet.find(screen_name).text
return "\x02@%s\x02: %s (%s ago)" % (screen_name, text, time_pretty)
return "\x02@%s\x02: %s (%s ago)" % (screen_name, text, time_nice)