Uploaded the old launcher to the disabled_stuff folder, because some people still want it
This commit is contained in:
parent
fa630eb285
commit
1be43d9e51
9 changed files with 126 additions and 0 deletions
33
disabled_stuff/antiflood.py
Executable file
33
disabled_stuff/antiflood.py
Executable file
|
@ -0,0 +1,33 @@
|
|||
def yaml_load(filename):
|
||||
import yaml
|
||||
fileHandle = open(filename, 'r')
|
||||
stuff = yaml.load(fileHandle.read())
|
||||
fileHandle.close()
|
||||
return stuff
|
||||
|
||||
def yaml_save(stuff, filename):
|
||||
import yaml
|
||||
fileHandle = open (filename, 'w' )
|
||||
fileHandle.write (yaml.dump(stuff))
|
||||
fileHandle.close()
|
||||
|
||||
from util import hook
|
||||
|
||||
@hook.event('*')
|
||||
def tellinput(paraml, input=None, say=None):
|
||||
# import time
|
||||
# now = time.time()
|
||||
# spam = yaml_load('spam')
|
||||
# if spam[input.nick]:
|
||||
# spam[input.nick].append(time.time())
|
||||
# else:
|
||||
# spam[input.nick] = [time.time()]
|
||||
# for x in spam[input.nick]:
|
||||
# if now - x > 5:
|
||||
# spam[input.nick].pop(x)
|
||||
# if len(spam[input.nick]) > 8:
|
||||
# say(":O")
|
||||
# say("HOW COULD YOU "+input.nick)
|
||||
# say("lol!")
|
||||
# yaml_save(spam,'spam')
|
||||
return
|
126
disabled_stuff/cloudbot.sh
Normal file
126
disabled_stuff/cloudbot.sh
Normal file
|
@ -0,0 +1,126 @@
|
|||
#!/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
|
183
disabled_stuff/mtg.py
Executable file
183
disabled_stuff/mtg.py
Executable file
|
@ -0,0 +1,183 @@
|
|||
import re
|
||||
|
||||
from util import hook, http
|
||||
|
||||
|
||||
@hook.command
|
||||
def mtg(inp):
|
||||
".mtg <name> -- Gets information about Magic the Gathering card <name>."
|
||||
|
||||
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('<br>', '$')
|
||||
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'}
|
115
disabled_stuff/mygengo_translate.py
Executable file
115
disabled_stuff/mygengo_translate.py
Executable file
|
@ -0,0 +1,115 @@
|
|||
# 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 <source language> <target language> <sentence> -- Translates <sentence> from <source language> to <target language> 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")
|
||||
]
|
180
disabled_stuff/repaste.py
Executable file
180
disabled_stuff/repaste.py
Executable file
|
@ -0,0 +1,180 @@
|
|||
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)(?<=<body>\n).+(?=<hr>)', pagesource).group(0)
|
||||
filterbr = rawpaste.replace("<br />", "")
|
||||
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] <pastebinurl> -- 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
|
33
disabled_stuff/suggest.py
Executable file
33
disabled_stuff/suggest.py
Executable file
|
@ -0,0 +1,33 @@
|
|||
import json
|
||||
import random
|
||||
import re
|
||||
|
||||
from util import hook, http
|
||||
|
||||
|
||||
@hook.command
|
||||
def suggest(inp, inp_unstripped=''):
|
||||
".suggest [#n] <phrase> -- 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('<b>', '').replace('</b>', ''))
|
80
disabled_stuff/urlhistory.py
Executable file
80
disabled_stuff/urlhistory.py
Executable file
|
@ -0,0 +1,80 @@
|
|||
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)
|
20
disabled_stuff/wordoftheday.py
Executable file
20
disabled_stuff/wordoftheday.py
Executable file
|
@ -0,0 +1,20 @@
|
|||
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'<span class="ssens"><strong>:</strong>'
|
||||
# r' *([^<]+)</span>', content)
|
||||
|
||||
say("(%s) The word of the day is:"\
|
||||
" \x02%s\x02 (%s)" % (nick, word, function))
|
196
disabled_stuff/wrapper.old
Executable file
196
disabled_stuff/wrapper.old
Executable file
|
@ -0,0 +1,196 @@
|
|||
#!/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
|
Reference in a new issue