PEP8, various other tweaks

This commit is contained in:
Luke Rogers 2012-09-05 07:52:03 +12:00
parent 6c022dac1c
commit e12e7721da
11 changed files with 29 additions and 34 deletions

View file

@ -1,8 +1,6 @@
# Plugin made by iloveportalz0r, TheNoodle, Lukeroge and neersighted
from util import hook from util import hook
import os import os
import re import re
import sys
import json import json
import time import time
import subprocess import subprocess

View file

@ -1,5 +1,4 @@
from util import hook from util import hook
import re
import random import random
with open("plugins/data/fortunes.txt") as f: with open("plugins/data/fortunes.txt") as f:

View file

@ -1,6 +1,4 @@
import re from util import hook, http
from util import hook, http, misc
from bs4 import BeautifulSoup from bs4 import BeautifulSoup

View file

@ -26,7 +26,6 @@ def help(inp, say=None, notice=None, input=None, conn=None, bot=None):
commands = dict((value, key) for key, value in funcs.iteritems()) commands = dict((value, key) for key, value in funcs.iteritems())
if not inp: if not inp:
length = 0
out = ["", ""] out = ["", ""]
well = [] well = []
for x in commands: for x in commands:
@ -41,8 +40,8 @@ def help(inp, say=None, notice=None, input=None, conn=None, bot=None):
notice("Commands I recognise: " + out[0][1:]) notice("Commands I recognise: " + out[0][1:])
if out[1]: if out[1]:
notice(out[1][1:]) notice(out[1][1:])
notice("For detailed help, do '.help <example>' where <example> "\ notice("For detailed help, do '%shelp <example>' where <example> "\
"is the name of the command you want help for.") "is the name of the command you want help for." % conn.conf["command_prefix"])
else: else:
if inp in commands: if inp in commands:

View file

@ -1,22 +1,24 @@
from util import hook, http, timesince from util import hook, http, timesince
from datetime import datetime from datetime import datetime
api_url = "http://ws.audioscrobbler.com/2.0/?format=json"
@hook.command('l', autohelp=False) @hook.command('l', autohelp=False)
@hook.command(autohelp=False) @hook.command(autohelp=False)
def lastfm(inp, nick='', say=None, db=None, bot=None): def lastfm(inp, nick='', say=None, db=None, bot=None, notice=None):
"lastfm [user] [dontsave] -- Displays the now playing (or last played)" \ "lastfm [user] [dontsave] -- Displays the now playing (or last played)" \
" track of LastFM user [user]." " track of LastFM user [user]."
api_key = bot.config.get("api_keys", {}).get("lastfm") api_key = bot.config.get("api_keys", {}).get("lastfm")
if not api_key: if not api_key:
return "error: no api key set" return "error: no api key set"
user = inp # check if the user asked us not to save his details
dontsave = inp.endswith(" dontsave")
api_url = "http://ws.audioscrobbler.com/2.0/?format=json"
dontsave = user.endswith(" dontsave")
if dontsave: if dontsave:
user = user[:-9].strip().lower() user = inp[:-9].strip().lower()
else:
user = inp
db.execute("create table if not exists lastfm(nick primary key, acc)") db.execute("create table if not exists lastfm(nick primary key, acc)")

View file

@ -1,7 +1,4 @@
from util import hook, web, http
from util import hook
from util.web import isgd
from urllib import quote_plus
@hook.command('gfy') @hook.command('gfy')
@ -9,5 +6,5 @@ from urllib import quote_plus
def lmgtfy(inp, bot=None): def lmgtfy(inp, bot=None):
"lmgtfy [phrase] - Posts a google link for the specified phrase" "lmgtfy [phrase] - Posts a google link for the specified phrase"
url = "http://lmgtfy.com/?q=%s" % quote_plus(inp) url = "http://lmgtfy.com/?q=%s" % http.quote_plus(inp)
return isgd(url, api_user, api_key) return web.isgd(url)

View file

@ -104,8 +104,10 @@ def get_text_list(list_, last_word='or'):
>>> get_text_list([]) >>> get_text_list([])
u'' u''
""" """
if len(list_) == 0: return '' if len(list_) == 0:
if len(list_) == 1: return list_[0] return ''
if len(list_) == 1:
return list_[0]
return '%s %s %s' % ( return '%s %s %s' % (
# Translators: This string is used as a separator between list elements # Translators: This string is used as a separator between list elements
(', ').join([i for i in list_][:-1]), (', ').join([i for i in list_][:-1]),