diff --git a/disabled_stuff/cleverbot.py b/disabled_stuff/cleverbot.py deleted file mode 100644 index 6604d8b..0000000 --- a/disabled_stuff/cleverbot.py +++ /dev/null @@ -1,121 +0,0 @@ -# from jessi bot -import urllib2 -import hashlib -import re -import unicodedata -from util import hook - -# these are just parts required -# TODO: Merge them. - -arglist = ['', 'y', '', '', '', '', '', '', '', '', 'wsf', '', - '', '', '', '', '', '', '', '0', 'Say', '1', 'false'] - -always_safe = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ' - 'abcdefghijklmnopqrstuvwxyz' - '0123456789' '_.-') - -headers = {'X-Moz': 'prefetch', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', - 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1)Gecko/20100101 Firefox/7.0', - 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'Referer': 'http://www.cleverbot.com', - 'Pragma': 'no-cache', 'Cache-Control': 'no-cache, no-cache', 'Accept-Language': 'en-us;q=0.8,en;q=0.5'} - -keylist = ['stimulus', 'start', 'sessionid', 'vText8', 'vText7', 'vText6', - 'vText5', 'vText4', 'vText3', 'vText2', 'icognoid', - 'icognocheck', 'prevref', 'emotionaloutput', 'emotionalhistory', - 'asbotname', 'ttsvoice', 'typing', 'lineref', 'fno', 'sub', - 'islearning', 'cleanslate'] - -MsgList = list() - - -def quote(s, safe='/'): # quote('abc def') -> 'abc%20def' - s = s.encode('utf-8') - s = s.decode('utf-8') - print "s= " + s - print "safe= " + safe - safe += always_safe - safe_map = dict() - for i in range(256): - c = chr(i) - safe_map[c] = (c in safe) and c or ('%%%02X' % i) - try: - res = map(safe_map.__getitem__, s) - except: - print "blank" - return '' - print "res= " + ''.join(res) - return ''.join(res) - - -def encode(keylist, arglist): - text = str() - for i in range(len(keylist)): - k = keylist[i] - v = quote(arglist[i]) - text += '&' + k + '=' + v - text = text[1:] - return text - - -def Send(): - data = encode(keylist, arglist) - digest_txt = data[9:29] - new_hash = hashlib.md5(digest_txt).hexdigest() - arglist[keylist.index('icognocheck')] = new_hash - data = encode(keylist, arglist) - req = urllib2.Request('http://www.cleverbot.com/webservicemin', - data, headers) - f = urllib2.urlopen(req) - reply = f.read() - return reply - - -def parseAnswers(text): - d = dict() - keys = ['text', 'sessionid', 'logurl', 'vText8', 'vText7', 'vText6', - 'vText5', 'vText4', 'vText3', 'vText2', 'prevref', 'foo', - 'emotionalhistory', 'ttsLocMP3', 'ttsLocTXT', 'ttsLocTXT3', - 'ttsText', 'lineRef', 'lineURL', 'linePOST', 'lineChoices', - 'lineChoicesAbbrev', 'typingData', 'divert'] - values = text.split('\r') - i = 0 - for key in keys: - d[key] = values[i] - i += 1 - return d - - -def ask(inp): - arglist[keylist.index('stimulus')] = inp - if MsgList: - arglist[keylist.index('lineref')] = '!0' + str(len( - MsgList) / 2) - asw = Send() - MsgList.append(inp) - answer = parseAnswers(asw) - for k, v in answer.iteritems(): - try: - arglist[keylist.index(k)] = v - except ValueError: - pass - arglist[keylist.index('emotionaloutput')] = str() - text = answer['ttsText'] - MsgList.append(text) - return text - - -@hook.command("cb") -def cleverbot(inp, reply=None): - reply(ask(inp)) - - -''' # TODO: add in command to control extra verbose per channel -@hook.event('PRIVMSG') -def cbevent(inp, reply=None): - reply(ask(inp)) - -@hook.command("cbver", permissions=['cleverbot']) -def cleverbotverbose(inp, notice=None): - if on in input -''' diff --git a/disabled_stuff/cloudbot.sh b/disabled_stuff/cloudbot.sh deleted file mode 100644 index 877c4ea..0000000 --- a/disabled_stuff/cloudbot.sh +++ /dev/null @@ -1,126 +0,0 @@ -#!/bin/bash -echo "" -echo " ________ ______ __ " -echo " / ____/ /___ __ ______/ / __ )____ / /_" -echo " / / / / __ \/ / / / __ / __ / __ \/ __/" -echo "/ /___/ / /_/ / /_/ / /_/ / /_/ / /_/ / /_ " -echo "\____/_/\____/\__,_/\__,_/_____/\____/\__/ " -echo " http://git.io/cloudbotirc by ClouDev " -echo "" -locatefiles() { - botfile="/bot.py" - botfile=$(pwd)$botfile - logfile="/bot.log" - logfile=$(pwd)$logfile -} - -running() { - if [[ $(ps aux|grep bot.py|grep -v grep|grep -v daemon|grep -v SCREEN) != "" ]]; then - true - else - false - fi -} - -checkbackend() { - if dpkg -l| grep ^ii|grep daemon|grep 'turns other' > /dev/null; then - backend="daemon" - elif dpkg -l| grep ^ii|grep screen|grep 'terminal multi' > /dev/null; then - backend="screen" - else - backend="manual" - fi - return 0 -} - -setcommands() { - status() { - if running; then - echo "CloudBot is running!" - else - echo "CloudBot is not running!" - fi - } - clear() { - : > $logfile - } - if [ "$backend" == "daemon" ]; then - start() { - daemon -r -n cloudbot -O $logfile python $botfile - } - stop() { - daemon -n cloudbot --stop - } - elif [ "$backend" == "screen" ]; then - start() { - screen -d -m -S cloudbot -t cloudbot python $botfile > $logfile 2>&1 - } - stop() { - pid=`ps ax|grep -v grep|grep python|grep -v SCREEN|grep $botfile|awk '{print $1}'` - kill $pid - } - elif [ "$backend" == "manual" ]; then - start() { - $botfile - } - stop() { - pid=`ps ax|grep -v grep|grep python|grep $botfile|awk '{print $1}'` - kill $pid - } - fi -} - -processargs() { - case $1 in - start|-start|--start) - if running; then - echo "Cannot start! Bot is already running!" - exit 1 - else - echo "Starting CloudBot... ($backend)" - start - fi - ;; - stop|-stop|--stop) - if running; then - echo "Stopping CloudBot... ($backend)" - stop - else - echo "Cannot stop! Bot is not already running!" - exit 1 - fi - ;; - restart|-restart|--restart) - if running; then - echo "Restarting CloudBot... ($backend)" - stop - sleep 3 - start - else - echo "Cannot restart! Bot is not already running!" - exit 1 - fi - ;; - clear|-clear|--clear) - echo "Clearing logs..." - clear - ;; - status|-status|--status) - status - ;; - *) - usage="usage: ./cloudbot {start|stop|restart|clear|status}" - echo $usage - ;; - esac -} - -main() { - locatefiles - checkbackend - setcommands - processargs $1 -} - -main $* -exit 0 \ No newline at end of file diff --git a/disabled_stuff/mtg.py b/disabled_stuff/mtg.py deleted file mode 100755 index 3db8306..0000000 --- a/disabled_stuff/mtg.py +++ /dev/null @@ -1,183 +0,0 @@ -import re - -from util import hook, http - - -@hook.command -def mtg(inp): - ".mtg -- Gets information about Magic the Gathering card ." - - url = 'http://magiccards.info/query?v=card&s=cname' - h = http.get_html(url, q=inp) - - name = h.find('body/table/tr/td/span/a') - if name is None: - return "No cards found :(" - card = name.getparent().getparent().getparent() - - type = card.find('td/p').text.replace('\n', '') - - # this is ugly - text = http.html.tostring(card.xpath("//p[@class='ctext']/b")[0]) - text = text.replace('
', '$') - text = http.html.fromstring(text).text_content() - text = re.sub(r'(\w+\s*)\$+(\s*\w+)', r'\1. \2', text) - text = text.replace('$', ' ') - text = re.sub(r'\(.*?\)', '', text) # strip parenthetical explanations - text = re.sub(r'\.(\S)', r'. \1', text) # fix spacing - - printings = card.find('td/small').text_content() - printings = re.search(r'Editions:(.*)Languages:', printings).group(1) - printings = re.findall(r'\s*(.+?(?: \([^)]+\))*) \((.*?)\)', - ' '.join(printings.split())) - - printing_out = ', '.join('%s (%s)' % (set_abbrevs.get(x[0], x[0]), - rarity_abbrevs.get(x[1], x[1])) - for x in printings) - - name.make_links_absolute(base_url=url) - link = name.attrib['href'] - name = name.text_content().strip() - type = type.strip() - text = ' '.join(text.split()) - - return ' | '.join((name, type, text, printing_out, link)) - - -set_abbrevs = { - '15th Anniversary': '15ANN', - 'APAC Junior Series': 'AJS', - 'Alara Reborn': 'ARB', - 'Alliances': 'AI', - 'Anthologies': 'AT', - 'Antiquities': 'AQ', - 'Apocalypse': 'AP', - 'Arabian Nights': 'AN', - 'Arena League': 'ARENA', - 'Asia Pacific Land Program': 'APAC', - 'Battle Royale': 'BR', - 'Battle Royale Box Set': 'BRB', - 'Beatdown': 'BTD', - 'Beatdown Box Set': 'BTD', - 'Betrayers of Kamigawa': 'BOK', - 'Celebration Cards': 'UQC', - 'Champions of Kamigawa': 'CHK', - 'Champs': 'CP', - 'Chronicles': 'CH', - 'Classic Sixth Edition': '6E', - 'Coldsnap': 'CS', - 'Coldsnap Theme Decks': 'CSTD', - 'Conflux': 'CFX', - 'Core Set - Eighth Edition': '8E', - 'Core Set - Ninth Edition': '9E', - 'Darksteel': 'DS', - 'Deckmasters': 'DM', - 'Dissension': 'DI', - 'Dragon Con': 'DRC', - 'Duel Decks: Divine vs. Demonic': 'DVD', - 'Duel Decks: Elves vs. Goblins': 'EVG', - 'Duel Decks: Garruk vs. Liliana': 'GVL', - 'Duel Decks: Jace vs. Chandra': 'JVC', - 'Eighth Edition': '8ED', - 'Eighth Edition Box Set': '8EB', - 'European Land Program': 'EURO', - 'Eventide': 'EVE', - 'Exodus': 'EX', - 'Fallen Empires': 'FE', - 'Fifth Dawn': '5DN', - 'Fifth Edition': '5E', - 'Fourth Edition': '4E', - 'Friday Night Magic': 'FNMP', - 'From the Vault: Dragons': 'FVD', - 'From the Vault: Exiled': 'FVE', - 'Future Sight': 'FUT', - 'Gateway': 'GRC', - 'Grand Prix': 'GPX', - 'Guildpact': 'GP', - 'Guru': 'GURU', - 'Happy Holidays': 'HHO', - 'Homelands': 'HL', - 'Ice Age': 'IA', - 'Introductory Two-Player Set': 'ITP', - 'Invasion': 'IN', - 'Judge Gift Program': 'JR', - 'Judgment': 'JU', - 'Junior Series': 'JSR', - 'Legend Membership': 'DCILM', - 'Legends': 'LG', - 'Legions': 'LE', - 'Limited Edition (Alpha)': 'LEA', - 'Limited Edition (Beta)': 'LEB', - 'Limited Edition Alpha': 'LEA', - 'Limited Edition Beta': 'LEB', - 'Lorwyn': 'LW', - 'MTGO Masters Edition': 'MED', - 'MTGO Masters Edition II': 'ME2', - 'MTGO Masters Edition III': 'ME3', - 'Magic 2010': 'M10', - 'Magic Game Day Cards': 'MGDC', - 'Magic Player Rewards': 'MPRP', - 'Magic Scholarship Series': 'MSS', - 'Magic: The Gathering Launch Parties': 'MLP', - 'Media Inserts': 'MBP', - 'Mercadian Masques': 'MM', - 'Mirage': 'MR', - 'Mirrodin': 'MI', - 'Morningtide': 'MT', - 'Multiverse Gift Box Cards': 'MGBC', - 'Nemesis': 'NE', - 'Ninth Edition Box Set': '9EB', - 'Odyssey': 'OD', - 'Onslaught': 'ON', - 'Planar Chaos': 'PC', - 'Planechase': 'PCH', - 'Planeshift': 'PS', - 'Portal': 'PO', - 'Portal Demogame': 'POT', - 'Portal Second Age': 'PO2', - 'Portal Three Kingdoms': 'P3K', - 'Premium Deck Series: Slivers': 'PDS', - 'Prerelease Events': 'PTC', - 'Pro Tour': 'PRO', - 'Prophecy': 'PR', - 'Ravnica: City of Guilds': 'RAV', - 'Release Events': 'REP', - 'Revised Edition': 'RV', - 'Saviors of Kamigawa': 'SOK', - 'Scourge': 'SC', - 'Seventh Edition': '7E', - 'Shadowmoor': 'SHM', - 'Shards of Alara': 'ALA', - 'Starter': 'ST', - 'Starter 1999': 'S99', - 'Starter 2000 Box Set': 'ST2K', - 'Stronghold': 'SH', - 'Summer of Magic': 'SOM', - 'Super Series': 'SUS', - 'Tempest': 'TP', - 'Tenth Edition': '10E', - 'The Dark': 'DK', - 'Time Spiral': 'TS', - 'Time Spiral Timeshifted': 'TSTS', - 'Torment': 'TR', - 'Two-Headed Giant Tournament': 'THGT', - 'Unglued': 'UG', - 'Unhinged': 'UH', - 'Unhinged Alternate Foils': 'UHAA', - 'Unlimited Edition': 'UN', - "Urza's Destiny": 'UD', - "Urza's Legacy": 'UL', - "Urza's Saga": 'US', - 'Visions': 'VI', - 'Weatherlight': 'WL', - 'Worlds': 'WRL', - 'WotC Online Store': 'WOTC', - 'Zendikar': 'ZEN'} - -rarity_abbrevs = { - 'Land': 'L', - 'Common': 'C', - 'Uncommon': 'UC', - 'Rare': 'R', - 'Special': 'S', - 'Mythic Rare': 'MR'} diff --git a/disabled_stuff/mygengo_translate.py b/disabled_stuff/mygengo_translate.py deleted file mode 100755 index d61ab14..0000000 --- a/disabled_stuff/mygengo_translate.py +++ /dev/null @@ -1,115 +0,0 @@ -# BING translation plugin by Lukeroge and neersighted -from util import hook -from util import http -import re -import htmlentitydefs -import mygengo - -gengo = mygengo.MyGengo( - public_key='PlwtF1CZ2tu27IdX_SXNxTFmfN0j|_-pJ^Rf({O-oLl--r^QM4FygRdt^jusSSDE', - private_key='wlXpL=SU[#JpPu[dQaf$v{S3@rg[=95$$TA(k$sb3_6~B_zDKkTbd4#hXxaorIae', - sandbox=False, -) - -def gengo_translate(text, source, target): - try: - translation = gengo.postTranslationJob(job={ - 'type': 'text', - 'slug': 'Translating '+source+' to '+target+' with the myGengo API', - 'body_src': text, - 'lc_src': source, - 'lc_tgt': target, - 'tier': 'machine', - }) - translated = translation['response']['job']['body_tgt'] - return u"(%s > %s) %s" % (source, target, translated) - except mygengo.MyGengoError: - return "error: could not translate" - -def match_language(fragment): - fragment = fragment.lower() - for short, _ in lang_pairs: - if fragment in short.lower().split(): - return short.split()[0] - - for short, full in lang_pairs: - if fragment in full.lower(): - return short.split()[0] - return None - -@hook.command -def translate(inp): - ".translate -- Translates from to using MyGengo." - args = inp.split(' ') - sl = match_language(args[0]) - tl = match_language(args[1]) - txt = unicode(" ".join(args[2:])) - if sl and tl: - return unicode(gengo_translate(txt, sl, tl)) - else: - return "error: translate could not reliably determine one or both languages" - -languages = 'ja fr de ko ru zh'.split() -language_pairs = zip(languages[:-1], languages[1:]) -lang_pairs = [ - ("no", "Norwegian"), - ("it", "Italian"), - ("ht", "Haitian Creole"), - ("af", "Afrikaans"), - ("sq", "Albanian"), - ("ar", "Arabic"), - ("hy", "Armenian"), - ("az", "Azerbaijani"), - ("eu", "Basque"), - ("be", "Belarusian"), - ("bg", "Bulgarian"), - ("ca", "Catalan"), - ("zh-CN zh", "Chinese"), - ("hr", "Croatian"), - ("cs cz", "Czech"), - ("da dk", "Danish"), - ("nl", "Dutch"), - ("en", "English"), - ("et", "Estonian"), - ("tl", "Filipino"), - ("fi", "Finnish"), - ("fr", "French"), - ("gl", "Galician"), - ("ka", "Georgian"), - ("de", "German"), - ("el", "Greek"), - ("ht", "Haitian Creole"), - ("iw", "Hebrew"), - ("hi", "Hindi"), - ("hu", "Hungarian"), - ("is", "Icelandic"), - ("id", "Indonesian"), - ("ga", "Irish"), - ("it", "Italian"), - ("ja jp jpn", "Japanese"), - ("ko", "Korean"), - ("lv", "Latvian"), - ("lt", "Lithuanian"), - ("mk", "Macedonian"), - ("ms", "Malay"), - ("mt", "Maltese"), - ("no", "Norwegian"), - ("fa", "Persian"), - ("pl", "Polish"), - ("pt", "Portuguese"), - ("ro", "Romanian"), - ("ru", "Russian"), - ("sr", "Serbian"), - ("sk", "Slovak"), - ("sl", "Slovenian"), - ("es", "Spanish"), - ("sw", "Swahili"), - ("sv", "Swedish"), - ("th", "Thai"), - ("tr", "Turkish"), - ("uk", "Ukrainian"), - ("ur", "Urdu"), - ("vi", "Vietnamese"), - ("cy", "Welsh"), - ("yi", "Yiddish") -] diff --git a/disabled_stuff/repaste.py b/disabled_stuff/repaste.py deleted file mode 100755 index 1443345..0000000 --- a/disabled_stuff/repaste.py +++ /dev/null @@ -1,180 +0,0 @@ -from util import hook, http - -import urllib -import random -import urllib2 -import htmlentitydefs -import re - -re_htmlent = re.compile("&(" + "|".join(htmlentitydefs.name2codepoint.keys()) + ");") -re_numeric = re.compile(r'&#(x?)([a-fA-F0-9]+);') - - -def db_init(db): - db.execute("create table if not exists repaste(chan, manual, primary key(chan))") - db.commit() - - -def decode_html(text): - text = re.sub(re_htmlent, - lambda m: unichr(htmlentitydefs.name2codepoint[m.group(1)]), - text) - - text = re.sub(re_numeric, - lambda m: unichr(int(m.group(2), 16 if m.group(1) else 10)), - text) - return text - - -def scrape_mibpaste(url): - if not url.startswith("http"): - url = "http://" + url - pagesource = http.get(url) - rawpaste = re.search(r'(?s)(?<=\n).+(?=
)', pagesource).group(0) - filterbr = rawpaste.replace("
", "") - unescaped = decode_html(filterbr) - stripped = unescaped.strip() - - return stripped - - -def scrape_pastebin(url): - id = re.search(r'(?:www\.)?pastebin.com/([a-zA-Z0-9]+)$', url).group(1) - rawurl = "http://pastebin.com/raw.php?i=" + id - text = http.get(rawurl) - - return text - - -autorepastes = {} - - -#@hook.regex('(pastebin\.com)(/[^ ]+)') -@hook.regex('(mibpaste\.com)(/[^ ]+)') -def autorepaste(inp, input=None, notice=None, db=None, chan=None, nick=None): - db_init(db) - manual = db.execute("select manual from repaste where chan=?", (chan, )).fetchone() - if manual and len(manual) and manual[0]: - return - url = inp.group(1) + inp.group(2) - urllib.unquote(url) - if url in autorepastes: - out = autorepastes[url] - notice("In the future, please use a less awful pastebin (e.g. pastebin.com)") - else: - out = repaste("http://" + url, input, db, False) - autorepastes[url] = out - notice("In the future, please use a less awful pastebin (e.g. pastebin.com) instead of %s." % inp.group(1)) - input.say("%s (repasted for %s)" % (out, nick)) - - -scrapers = { - r'mibpaste\.com': scrape_mibpaste, - r'pastebin\.com': scrape_pastebin -} - - -def scrape(url): - for pat, scraper in scrapers.iteritems(): - print "matching " + repr(pat) + " " + url - if re.search(pat, url): - break - else: - return None - - return scraper(url) - - -def paste_sprunge(text, syntax=None, user=None): - data = urllib.urlencode({"sprunge": text}) - url = urllib2.urlopen("http://sprunge.us/", data).read().strip() - - if syntax: - url += "?" + syntax - - return url - - -def paste_ubuntu(text, user=None, syntax='text'): - data = urllib.urlencode({"poster": user, - "syntax": syntax, - "content": text}) - - return urllib2.urlopen("http://paste.ubuntu.com/", data).url - - -def paste_gist(text, user=None, syntax=None, description=None): - data = { - 'file_contents[gistfile1]': text, - 'action_button': "private" - } - - if description: - data['description'] = description - - if syntax: - data['file_ext[gistfile1]'] = "." + syntax - - req = urllib2.urlopen('https://gist.github.com/gists', urllib.urlencode(data).encode('utf8')) - return req.url - - -def paste_strictfp(text, user=None, syntax="plain"): - data = urllib.urlencode(dict( - language=syntax, - paste=text, - private="private", - submit="Paste")) - req = urllib2.urlopen("http://paste.strictfp.com/", data) - return req.url - - -pasters = dict( - ubuntu=paste_ubuntu, - sprunge=paste_sprunge, - gist=paste_gist, - strictfp=paste_strictfp -) - - -@hook.command -def repaste(inp, input=None, db=None, isManual=True): - ".repaste mode|list|[provider] [syntax] -- Reuploads mibpaste to [provider]." - - parts = inp.split() - db_init(db) - if parts[0] == 'list': - return " ".join(pasters.keys()) - - paster = paste_gist - args = {} - - if not parts[0].startswith("http"): - p = parts[0].lower() - - if p in pasters: - paster = pasters[p] - parts = parts[1:] - - if not parts[0].startswith("http"): - p = parts[0].lower() - parts = parts[1:] - - args["syntax"] = p - - if len(parts) > 1: - return "PEBKAC" - - args["user"] = input.user - - url = parts[0] - - scraped = scrape(url) - - if not scraped: - return "No scraper for given url" - - args["text"] = scraped - pasted = paster(**args) - - return pasted diff --git a/disabled_stuff/suggest.py b/disabled_stuff/suggest.py deleted file mode 100755 index 92f9405..0000000 --- a/disabled_stuff/suggest.py +++ /dev/null @@ -1,33 +0,0 @@ -import json -import random -import re - -from util import hook, http - - -@hook.command -def suggest(inp, inp_unstripped=''): - ".suggest [#n] -- gets a random/the nth suggested google search" - - inp = inp_unstripped - m = re.match('^#(\d+) (.+)$', inp) - if m: - num, inp = m.groups() - num = int(num) - if num > 10: - return 'I can only get the first ten suggestions.' - else: - num = 0 - - page = http.get('http://google.com/complete/search', output='json', client='hp', q=inp) - page_json = page.split('(', 1)[1][:-1] - suggestions = json.loads(page_json)[1] - if not suggestions: - return 'No suggestions found.' - if num: - if len(suggestions) + 1 <= num: - return 'I only got %d suggestions.' % len(suggestions) - out = suggestions[num - 1] - else: - out = random.choice(suggestions) - return '#%d: %s' % (int(out[2][0]) + 1, out[0].replace('', '').replace('', '')) \ No newline at end of file diff --git a/disabled_stuff/urlhistory.py b/disabled_stuff/urlhistory.py deleted file mode 100755 index c5e344e..0000000 --- a/disabled_stuff/urlhistory.py +++ /dev/null @@ -1,80 +0,0 @@ -import math -import re -import time - -from util import hook, urlnorm, timesince - - -expiration_period = 60 * 60 * 24 # 1 day - -ignored_urls = [urlnorm.normalize("http://google.com"),] - - -def db_init(db): - db.execute("create table if not exists urlhistory" - "(chan, url, nick, time)") - db.commit() - - -def insert_history(db, chan, url, nick): - now = time.time() - db.execute("insert into urlhistory(chan, url, nick, time) " - "values(?,?,?,?)", (chan, url, nick, time.time())) - db.commit() - - -def get_history(db, chan, url): - db.execute("delete from urlhistory where time < ?", - (time.time() - expiration_period,)) - return db.execute("select nick, time from urlhistory where " - "chan=? and url=? order by time desc", (chan, url)).fetchall() - - -def nicklist(nicks): - nicks = sorted(dict(nicks), key=unicode.lower) - if len(nicks) <= 2: - return ' and '.join(nicks) - else: - return ', and '.join((', '.join(nicks[:-1]), nicks[-1])) - - -def format_reply(history): - if not history: - return - - last_nick, recent_time = history[0] - last_time = timesince.timesince(recent_time) - - if len(history) == 1: - return #"%s linked that %s ago." % (last_nick, last_time) - - hour_span = math.ceil((time.time() - history[-1][1]) / 3600) - hour_span = '%.0f hours' % hour_span if hour_span > 1 else 'hour' - - hlen = len(history) - ordinal = ["once", "twice", "%d times" % hlen][min(hlen, 3) - 1] - - if len(dict(history)) == 1: - last = "last linked %s ago" % last_time - else: - last = "last linked by %s %s ago" % (last_nick, last_time) - - return #"that url has been posted %s in the past %s by %s (%s)." % (ordinal, - -@hook.command -def url(inp, nick='', chan='', db=None, bot=None): - db_init(db) - url = urlnorm.normalize(inp.group().encode('utf-8')) - if url not in ignored_urls: - url = url.decode('utf-8') - history = get_history(db, chan, url) - insert_history(db, chan, url, nick) - - inp = match.string.lower() - - for name in dict(history): - if name.lower() in inp: # person was probably quoting a line - return # that had a link. don't remind them. - - if nick not in dict(history): - return format_reply(history) diff --git a/disabled_stuff/wordoftheday.py b/disabled_stuff/wordoftheday.py deleted file mode 100755 index 7b7a19b..0000000 --- a/disabled_stuff/wordoftheday.py +++ /dev/null @@ -1,20 +0,0 @@ -import re -from util import hook, http, misc -from BeautifulSoup import BeautifulSoup - - -@hook.command(autohelp=False) -def word(inp, say=False, nick=False): - "word -- Gets the word of the day." - page = http.get('http://merriam-webster.com/word-of-the-day') - - soup = BeautifulSoup(page) - - word = soup.find('strong', {'class': 'main_entry_word'}).renderContents() - function = soup.find('p', {'class': 'word_function'}).renderContents() - - #definitions = re.findall(r':' - # r' *([^<]+)', content) - - say("(%s) The word of the day is:"\ - " \x02%s\x02 (%s)" % (nick, word, function)) diff --git a/disabled_stuff/wrapper.old b/disabled_stuff/wrapper.old deleted file mode 100755 index d2f2cda..0000000 --- a/disabled_stuff/wrapper.old +++ /dev/null @@ -1,196 +0,0 @@ -#!/usr/bin/env python -# Bot Wrapper by neersighted - -# Import required modules -import os -import sys -import subprocess -import json -import re - -# Files -configfile = os.path.isfile("./config") -botfile = os.path.isfile("./bot.py") - -# Colors -nocol = "\033[1;m" -red = "\033[1;31m" -green = "\033[1;32m" - -# Messages -firstrun = "Welclome to your first run of: " -usage = "usage: ./cloudbot {start|stop|restart|status}" -iusage = "{1|start} {2|stop} {3|restart} {4|status} {5|exit}" -quit = "Thanks for using CloudBot!" - -error1 = red + "Neither screen nor daemon is installed! "\ - "This program cannot run! {ERROR 1}" + nocol -error2 = red + "Could not find bot.py! Are you in the wrong folder? "\ - "{ERROR 2}" + nocol -error3 = red + "Invalid choice, exiting! {ERROR 3}" + nocol -error4 = red + "Program killed by user! {ERROR 4}" + nocol -error5 = red + "Invalid backend in config! (Or, backend not installed)"\ - " {ERROR 5}" + nocol -error6 = red + "Author error! We be derpin'! {ERROR 6}" + nocol - - -# Commands -pwd = os.getcwd() -clearlog = ": > ./bot.log" - -start = "echo " + "'" + error1 + "'" -stop = "echo " + "'" + error1 + "'" -restart = "echo " + "'" + error1 + "'" -pid = "echo 'Cannot get pid'" - -daemonstart = "daemon -r -n cloudbot -O " + pwd + \ - "/bot.log python " + pwd + "/bot.py" -daemonstop = "daemon -n cloudbot --stop" -daemonrestart = "./cloudbot stop > /dev/null 2>&1 && ./cloudbot start > /dev/null 2>&1" -daemonpid = "pidof /usr/bin/daemon" - -screenstart = "screen -d -m -S cloudbot -t cloudbot python " + pwd +\ - "/bot.py > " + pwd + "/bot.log 2>&1" -screenstop = "kill `pidof /usr/bin/screen`" -screenrestart = "./cloudbot stop > /dev/null 2>&1 && ./cloudbot start > /dev/null 2>&1" -screenpid = "pidof /usr/bin/screen" - -# Checks -if configfile: - try: - config = json.load(open('config')) - command = ":" - except ValueError, e: - print 'error: malformed config', e -else: - config = False - command = "python bot.py" - -daemoncheck = subprocess.check_output("locate /usr/bin/daemon", shell=True) -daemon = re.match(r'^/usr/bin/daemon$', daemoncheck) - -screencheck = subprocess.check_output("locate /usr/bin/screen", shell=True) -screen = re.match(r'^/usr/bin/screen$', screencheck) - -if configfile: - backend = config.get("wrapper", {}).get("backend", "daemon") - daemonloc = config.get("wrapper", {}).get("daemonloc", "/usr/bin/daemon") - screenloc = config.get("wrapper", {}).get("screenloc", "/usr/bin/screen") -else: - backend = False - daemonloc = "/usr/bin/daemon" - screenloc = "/usr/bin/screen" - -try: - runningcheck = subprocess.check_output("ps ax|grep cloudbot|"\ - "grep -v grep|grep -v ./cloudbot", shell=True) - running = re.match(r'^[1-9]+', runningcheck) -except (subprocess.CalledProcessError): - running = False - -# Set commands -if (backend == "daemon"): - if daemon: - start = daemonstart - stop = daemonstop - restart = daemonrestart - pid = daemonpid - else: - print error5 - exit -elif (backend == "screen"): - if screen: - start = screenstart - stop = screenstop - restart = screenrestart - pid = screenpid - else: - print error5 - exit -elif (backend == False): - print firstrun -else: - print error5 - exit - -# Fancy banner -print " ______ __ ______ __ __ "\ -" _______ .______ ______ .___________." -print " / || | / __ \ | | | | "\ -"| \ | _ \ / __ \ | |" -print "| ,----'| | | | | | | | | | "\ -"| .--. || |_) | | | | | `---| |----`" -print "| | | | | | | | | | | | "\ -"| | | || _ < | | | | | | " -print "| `----.| `----.| `--' | | `--' | "\ -"| '--' || |_) | | `--' | | | " -print " \______||_______| \______/ \______/ "\ -"|_______/ |______/ \______/ |__| " -print "http://git.io/cloudbot "\ -" by lukeroge" - -# Read arguments/turn interactive -try: - if (len(sys.argv) > 1): - read = 0 - else: - sys.argv = "interactive" - print iusage - read = int(raw_input("Please choose a option: ")) - - if (sys.argv[1] == "start") or (read == 1): - if running: - print "Bot is already running, cannot start!" - else: - command = start - print "Starting... (" + backend + ")" - elif (sys.argv[1] == "stop") or (read == 2): - if running: - command = stop - print "Stopping... (" + backend + ")" - else: - print "Bot is not running, cannot stop!" - elif (sys.argv[1] == "restart") or (read == 3): - if running: - command = restart - print "Restarting... (" + backend + ")" - else: - print "Bot is not running, cannot restart!" - elif (sys.argv[1] == "status") or (read == 4): - if running: - command = pid - print green + "Bot is running! " + nocol - else: - print red + "Bot is not running! " + nocol - elif (sys.argv[1] == "clear"): - command = clearlog - elif (sys.argv[1] == "exit") or (read == 5): - exit - elif (sys.argv[1] == "interactive"): - pass - else: - print usage - exit - -# Pretify errors -except (TypeError, ValueError), e: - print error3 - exit -except (KeyboardInterrupt), e: - print error4 - exit -except (NameError, SyntaxError), e: - print error6 - exit - -# Check for bot files -if botfile: - pass -else: - print error2 - exit - -# Call command -subprocess.call(command, shell=True) -print quit -exit