Cleaning up.
This commit is contained in:
parent
25ffcd44be
commit
4ebaba1746
3 changed files with 0 additions and 218 deletions
|
@ -1,24 +0,0 @@
|
||||||
import re
|
|
||||||
|
|
||||||
from util import hook, http, misc
|
|
||||||
from urlparse import urljoin
|
|
||||||
from BeautifulSoup import BeautifulSoup
|
|
||||||
|
|
||||||
|
|
||||||
base_url = 'http://www.fmylife.com/'
|
|
||||||
rand_url = urljoin(base_url, 'random')
|
|
||||||
spec_url = urljoin(base_url, '%d')
|
|
||||||
error = 'Today I couldn\'t seem to access fmylife.com.. FML'
|
|
||||||
|
|
||||||
@hook.command(autohelp=False)
|
|
||||||
@hook.command("fml")
|
|
||||||
def fmylife(inp):
|
|
||||||
|
|
||||||
page = http.get(rand_url)
|
|
||||||
soup = BeautifulSoup(page)
|
|
||||||
|
|
||||||
soup.find('div', id='submit').extract()
|
|
||||||
post = soup.body.find('div', 'post')
|
|
||||||
id = int(post.find('a', 'fmllink')['href'].split('/')[-1])
|
|
||||||
body = strip_html(decode(' '.join(link.renderContents() for link in post('a', 'fmllink')), 'utf-8'))
|
|
||||||
return u'%s: (%d) %s' % (nick, id, body)
|
|
|
@ -1,77 +0,0 @@
|
||||||
#-*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Copyright (C) 2011 by Guilherme Pinto Gonçalves, Ivan Sichmman Freitas
|
|
||||||
|
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
# of this software and associated documentation files (the "Software"), to deal
|
|
||||||
# in the Software without restriction, including without limitation the rights
|
|
||||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
# copies of the Software, and to permit persons to whom the Software is
|
|
||||||
# furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
# The above copyright notice and this permission notice shall be included in
|
|
||||||
# all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
# THE SOFTWARE.
|
|
||||||
|
|
||||||
from util import hook
|
|
||||||
import sys
|
|
||||||
import subprocess
|
|
||||||
from functools import partial
|
|
||||||
|
|
||||||
fortunes = {
|
|
||||||
'fortunes': 'fortunes',
|
|
||||||
'fortune': 'fortunes',
|
|
||||||
'quotes': 'literature',
|
|
||||||
'quote': 'literature',
|
|
||||||
'riddle': 'riddles',
|
|
||||||
'riddles': 'riddles',
|
|
||||||
'cookie': 'cookie',
|
|
||||||
'cookies': 'cookie',
|
|
||||||
'disclaimer': 'disclaimer',
|
|
||||||
'f': 'fortunes',
|
|
||||||
'q': 'literature',
|
|
||||||
'r': 'riddles'
|
|
||||||
}
|
|
||||||
|
|
||||||
# Use this later to replace the fortunes list workaaround
|
|
||||||
def get_installed_fortunes():
|
|
||||||
try:
|
|
||||||
proc = subprocess.Popen(("/usr/bin/fortune", "-f"),
|
|
||||||
stderr = subprocess.PIPE)
|
|
||||||
except OSError:
|
|
||||||
return set()
|
|
||||||
|
|
||||||
return set(proc.stderr)
|
|
||||||
|
|
||||||
# Use this later to replace the fortunes list workaaround
|
|
||||||
def get_fortune(inp):
|
|
||||||
try:
|
|
||||||
proc = subprocess.Popen(("fortune", "-a", inp),
|
|
||||||
stderr = subprocess.PIPE,
|
|
||||||
stdout = subprocess.PIPE)
|
|
||||||
except OSError:
|
|
||||||
return set()
|
|
||||||
|
|
||||||
return set(proc.stderr)
|
|
||||||
|
|
||||||
@hook.command()
|
|
||||||
def get(inp, say=None):
|
|
||||||
".get <what> -- uses fortune-mod to get something. <what> can be riddle, quote or fortune"
|
|
||||||
fortune = get_fortune(fortune[inp])
|
|
||||||
|
|
||||||
while fortune.length() =< 5:
|
|
||||||
fortune = get_fortune(fortune[inp])
|
|
||||||
|
|
||||||
if proc.wait() == 0:
|
|
||||||
|
|
||||||
for line in proc.stdout:
|
|
||||||
say(line.lstrip())
|
|
||||||
else:
|
|
||||||
return "Fortune failed: " + proc.stderr.read()
|
|
117
plugins/karma.py
117
plugins/karma.py
|
@ -1,117 +0,0 @@
|
||||||
# Karma plugin for Skybot
|
|
||||||
# Written by GhettoWizard(2011)
|
|
||||||
|
|
||||||
import time
|
|
||||||
import re
|
|
||||||
|
|
||||||
from util import hook, timesince
|
|
||||||
|
|
||||||
|
|
||||||
def up(db, nick_vote):
|
|
||||||
db.execute("""UPDATE karma SET
|
|
||||||
up_karma = up_karma+1,
|
|
||||||
total_karma = total_karma+1 WHERE nick_vote=?""", (nick_vote.lower(),))
|
|
||||||
db.commit()
|
|
||||||
|
|
||||||
|
|
||||||
def down(db, nick_vote):
|
|
||||||
db.execute("""UPDATE karma SET
|
|
||||||
down_karma = down_karma+1,
|
|
||||||
total_karma = total_karma+1 WHERE nick_vote=?""", (nick_vote.lower(),))
|
|
||||||
db.commit()
|
|
||||||
|
|
||||||
|
|
||||||
def allowed(db, nick, nick_vote):
|
|
||||||
time_restriction = 3600
|
|
||||||
db.execute("""DELETE FROM karma_voters WHERE ? - epoch >= 3600""",
|
|
||||||
(time.time(),))
|
|
||||||
db.commit()
|
|
||||||
check = db.execute("""SELECT epoch FROM karma_voters WHERE voter=? AND votee=?""",
|
|
||||||
(nick.lower(), nick_vote.lower())).fetchone()
|
|
||||||
|
|
||||||
if check:
|
|
||||||
check = check[0]
|
|
||||||
if time.time() - check >= time_restriction:
|
|
||||||
db.execute("""INSERT OR REPLACE INTO karma_voters(
|
|
||||||
voter,
|
|
||||||
votee,
|
|
||||||
epoch) values(?,?,?)""", (nick.lower(), nick_vote.lower(), time.time()))
|
|
||||||
db.commit()
|
|
||||||
return True#, 0
|
|
||||||
else:
|
|
||||||
return False#, timesince.timeuntil(check, now=time.time()-time_restriction)
|
|
||||||
else:
|
|
||||||
db.execute("""INSERT OR REPLACE INTO karma_voters(
|
|
||||||
voter,
|
|
||||||
votee,
|
|
||||||
epoch) values(?,?,?)""", (nick.lower(), nick_vote.lower(), time.time()))
|
|
||||||
db.commit()
|
|
||||||
return True#, 0
|
|
||||||
|
|
||||||
|
|
||||||
# TODO Make this work on multiple matches in a string, right now it'll only
|
|
||||||
# work on one match. Scaevolus might have to change the hook function to work
|
|
||||||
# with findall, as search seems limited.
|
|
||||||
# karma_re = ('((\S+)(\+\+|\-\-))+', re.I)
|
|
||||||
karma_re = ('(.+)(\+\+|\-\-)$', re.I)
|
|
||||||
|
|
||||||
@hook.regex(*karma_re)
|
|
||||||
def karma_add(match, nick='', chan='', db=None):
|
|
||||||
nick_vote = match.group(1).strip()
|
|
||||||
if nick.lower() == nick_vote.lower():
|
|
||||||
return
|
|
||||||
vote_allowed = allowed(db, nick, nick_vote)
|
|
||||||
if vote_allowed:
|
|
||||||
if match.group(2) == '++':
|
|
||||||
db.execute("""INSERT or IGNORE INTO karma(
|
|
||||||
nick_vote,
|
|
||||||
up_karma,
|
|
||||||
down_karma,
|
|
||||||
total_karma) values(?,?,?,?)""", (nick_vote.lower(),0,0,0))
|
|
||||||
up(db, nick_vote)
|
|
||||||
if match.group(2) == '--':
|
|
||||||
db.execute("""INSERT or IGNORE INTO karma(
|
|
||||||
nick_vote,
|
|
||||||
up_karma,
|
|
||||||
down_karma,
|
|
||||||
total_karma) values(?,?,?,?)""", (nick_vote.lower(),0,0,0))
|
|
||||||
down(db, nick_vote)
|
|
||||||
else:
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
return
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
@hook.command('k')
|
|
||||||
@hook.command
|
|
||||||
def karma(inp, nick='', chan='', db=None):
|
|
||||||
""".k/.karma <nick> -- returns karma stats for <nick>"""
|
|
||||||
|
|
||||||
db.execute("""CREATE TABLE if not exists karma(
|
|
||||||
nick_vote TEXT PRIMARY KEY,
|
|
||||||
up_karma INTEGER,
|
|
||||||
down_karma INTEGER,
|
|
||||||
total_karma INTEGER)""")
|
|
||||||
|
|
||||||
db.execute("""CREATE TABLE if not exists karma_voters(
|
|
||||||
voter TEXT,
|
|
||||||
votee TEXT,
|
|
||||||
epoch FLOAT,
|
|
||||||
PRIMARY KEY(voter, votee))""")
|
|
||||||
|
|
||||||
if not chan.startswith('#'):
|
|
||||||
return
|
|
||||||
|
|
||||||
nick_vote = inp
|
|
||||||
out = db.execute("""SELECT * FROM karma WHERE nick_vote=?""",
|
|
||||||
(nick_vote.lower(),)).fetchall()
|
|
||||||
|
|
||||||
if not out:
|
|
||||||
return "no karma"
|
|
||||||
else:
|
|
||||||
out = out[0]
|
|
||||||
return "'%s' has %s karma" % (nick_vote, out[1]-out[2])
|
|
||||||
|
|
||||||
return
|
|
Reference in a new issue