From 7ab4f756fe645d3bb1d7abad3c1b3500eada0999 Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Thu, 5 Sep 2013 09:46:49 +0800 Subject: [PATCH] .format --- plugins/admin.py | 44 +++++++++++++++++++++---------------------- plugins/attacks.py | 4 ++-- plugins/bitcoin.py | 4 ++-- plugins/brainfuck.py | 2 +- plugins/coin.py | 5 ++--- plugins/core_ctcp.py | 2 +- plugins/core_misc.py | 8 ++------ plugins/correction.py | 6 +++--- plugins/dice.py | 4 ++-- plugins/dictionary.py | 8 ++++---- plugins/down.py | 4 ++-- plugins/drama.py | 2 +- plugins/eightball.py | 2 +- plugins/fact.py | 2 +- plugins/factoids.py | 14 ++++++-------- plugins/fmylife.py | 2 +- plugins/gcalc.py | 4 ++-- plugins/github.py | 8 ++++---- plugins/google.py | 8 +++----- plugins/horoscope.py | 2 +- plugins/ignore.py | 10 +++++----- plugins/imdb.py | 2 +- 22 files changed, 69 insertions(+), 78 deletions(-) diff --git a/plugins/admin.py b/plugins/admin.py index 851e642..11b7a2e 100755 --- a/plugins/admin.py +++ b/plugins/admin.py @@ -19,7 +19,7 @@ def permissions(inp, bot=None, notice=None): for k in permissions: groups.append(k) if not groups: - notice("%s is not a group with permissions" % inp) + notice("{} is not a group with permissions".format(inp)) return None for v in groups: @@ -27,10 +27,10 @@ def permissions(inp, bot=None, notice=None): for value in permissions[v]["users"]: members = members + value + ", " if members: - notice("the members in the %s group are.." % v) + notice("the members in the {} group are..".format(v)) notice(members[:-2]) else: - notice("there are no members in the %s group" % v) + notice("there are no members in the {} group".format(v)) @hook.command(permissions=["permissions_users"]) @@ -51,7 +51,7 @@ def deluser(inp, bot=None, notice=None): if specgroup == k: groups.append(k) if not groups: - notice("%s is not a group with permissions" % inp[1]) + notice("{} is not a group with permissions".format(inp[1])) return None removed = 0 @@ -61,14 +61,14 @@ def deluser(inp, bot=None, notice=None): if inp[0] == value: users.remove(inp[0]) removed = 1 - notice("%s has been removed from the group %s" % (inp[0], v)) + notice("{} has been removed from the group {}".format(inp[0], v)) json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2) if specgroup: if removed == 0: - notice("%s is not in the group %s" % (inp[0], specgroup)) + notice("{} is not in the group {}".format(inp[0], specgroup)) else: if removed == 0: - notice("%s is not in any groups" % inp[0]) + notice("{} is not in any groups".format(inp[0])) @hook.command(permissions=["permissions_users"]) @@ -89,14 +89,14 @@ def adduser(inp, bot=None, notice=None): try: users = permissions[targetgroup]["users"] except KeyError: - notice("no such group as %s" % targetgroup) + notice("no such group as {}".format(targetgroup)) return None if user in users: - notice("%s is already in %s" % (user, targetgroup)) + notice("{} is already in {}".format(user, targetgroup)) return None users.append(user) - notice("%s has been added to the group %s" % (user, targetgroup)) + notice("{} has been added to the group {}".format(user, targetgroup)) users.sort() json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2) @@ -106,9 +106,9 @@ def adduser(inp, bot=None, notice=None): def stop(inp, nick=None, conn=None): """stop [reason] -- Kills the bot with [reason] as its quit message.""" if inp: - conn.cmd("QUIT", ["Killed by %s (%s)" % (nick, inp)]) + conn.cmd("QUIT", ["Killed by {} ({})".format(nick, inp)]) else: - conn.cmd("QUIT", ["Killed by %s." % nick]) + conn.cmd("QUIT", ["Killed by {}.".format(nick)]) time.sleep(5) os.execl("./cloudbot", "cloudbot", "stop") @@ -117,9 +117,9 @@ def stop(inp, nick=None, conn=None): def restart(inp, nick=None, conn=None): """restart [reason] -- Restarts the bot with [reason] as its quit message.""" if inp: - conn.cmd("QUIT", ["Restarted by %s (%s)" % (nick, inp)]) + conn.cmd("QUIT", ["Restarted by {} ({})".format(nick, inp)]) else: - conn.cmd("QUIT", ["Restarted by %s." % nick]) + conn.cmd("QUIT", ["Restarted by {}.".format(nick)]) time.sleep(5) os.execl("./cloudbot", "cloudbot", "restart") @@ -133,7 +133,7 @@ def clearlogs(inp, input=None): @hook.command(permissions=["botcontrol"]) def join(inp, conn=None, notice=None): """join -- Joins .""" - notice("Attempting to join %s..." % inp) + notice("Attempting to join {}...".format(inp)) conn.join(inp) @@ -146,7 +146,7 @@ def part(inp, conn=None, chan=None, notice=None): target = inp else: target = chan - notice("Attempting to leave %s..." % target) + notice("Attempting to leave {}...".format(target)) conn.part(target) @@ -159,7 +159,7 @@ def cycle(inp, conn=None, chan=None, notice=None): target = inp else: target = chan - notice("Attempting to cycle %s..." % target) + notice("Attempting to cycle {}...".format(target}) conn.part(target) conn.join(target) @@ -170,7 +170,7 @@ def nick(inp, notice=None, conn=None): if not re.match("^[A-Za-z0-9_|.-\]\[]*$", inp.lower()): notice("Invalid username!") return - notice("Attempting to change nick to \"%s\"..." % inp) + notice("Attempting to change nick to \"{}\"...".format(inp)) conn.set_nick(inp) @@ -189,10 +189,10 @@ def say(inp, conn=None, chan=None): inp = inp.split(" ") if inp[0][0] == "#": message = " ".join(inp[1:]) - out = "PRIVMSG %s :%s" % (inp[0], message) + out = "PRIVMSG {} :{}".format(inp[0], message) else: message = " ".join(inp[0:]) - out = "PRIVMSG %s :%s" % (chan, message) + out = "PRIVMSG {} :{}".format(chan, message) conn.send(out) @@ -208,11 +208,11 @@ def me(inp, conn=None, chan=None): for x in inp[1:]: message = message + x + " " message = message[:-1] - out = "PRIVMSG %s :\x01ACTION %s\x01" % (inp[0], message) + out = "PRIVMSG {} :\x01ACTION {}\x01".format(inp[0], message) else: message = "" for x in inp[0:]: message = message + x + " " message = message[:-1] - out = "PRIVMSG %s :\x01ACTION %s\x01" % (chan, message) + out = "PRIVMSG {} :\x01ACTION {}\x01".format(chan, message) conn.send(out) diff --git a/plugins/attacks.py b/plugins/attacks.py index 14fa7ac..2a24102 100644 --- a/plugins/attacks.py +++ b/plugins/attacks.py @@ -100,7 +100,7 @@ def insult(inp, nick=None, me=None, conn=None, notice=None): else: target = inp - out = 'insults %s... "%s"' % (target, random.choice(insults)) + out = 'insults {}... "{}"'.format(target, random.choice(insults)) me(out) @@ -118,5 +118,5 @@ def flirt(inp, me=None, conn=None, notice=None): else: target = inp - out = 'flirts with %s... "%s"' % (target, random.choice(flirts)) + out = 'flirts with {}... "{}"'.format(target, random.choice(flirts)) me(out) diff --git a/plugins/bitcoin.py b/plugins/bitcoin.py index ea7967d..adf985b 100755 --- a/plugins/bitcoin.py +++ b/plugins/bitcoin.py @@ -12,5 +12,5 @@ def bitcoin(inp, say=None): 'low': data['low']['display_short'], 'vol': data['vol']['display_short'], } - say("Current: \x0307%(buy)s\x0f - High: \x0307%(high)s\x0f" - " - Low: \x0307%(low)s\x0f - Volume: %(vol)s" % ticker) + say("Current: \x0307{}\x0f - High: \x0307{}\x0f" + " - Low: \x0307{}\x0f - Volume: {}".format(data['buy'],data['high'],data['low'],data['vol'])) diff --git a/plugins/brainfuck.py b/plugins/brainfuck.py index a2fb126..1c68b57 100755 --- a/plugins/brainfuck.py +++ b/plugins/brainfuck.py @@ -76,7 +76,7 @@ def bf(inp): if steps > MAX_STEPS: if output == '': output = '(no output)' - output += '[exceeded %d iterations]' % MAX_STEPS + output += '[exceeded {} iterations]'.format(MAX_STEPS) break stripped_output = re.sub(r'[\x00-\x1F]', '', output) diff --git a/plugins/coin.py b/plugins/coin.py index ef984fe..78668bb 100755 --- a/plugins/coin.py +++ b/plugins/coin.py @@ -15,11 +15,10 @@ def coin(inp, me=None): amount = 1 if amount == 1: - me("flips a coin and gets %s." % random.choice(["heads", "tails"])) + me("flips a coin and gets {}.".format(random.choice(["heads", "tails"]))) elif amount == 0: me("makes a coin flipping motion with its hands.") else: heads = int(random.normalvariate(.5 * amount, (.75 * amount) ** .5)) tails = amount - heads - me("flips %i coins and gets " - "%i heads and %i tails." % (amount, heads, tails)) + me("flips {} coins and gets {} heads and {} tails.".format(amount, heads, tails)) diff --git a/plugins/core_ctcp.py b/plugins/core_ctcp.py index 523a4e4..4f399f6 100755 --- a/plugins/core_ctcp.py +++ b/plugins/core_ctcp.py @@ -15,4 +15,4 @@ def ctcp_ping(inp, notice=None): @hook.regex(r'^\x01TIME\x01$') def ctcp_time(inp, notice=None): - notice('\x01TIME: The time is: %s' % time.strftime("%r", time.localtime())) + notice('\x01TIME: The time is: {}'.format(time.strftime("%r", time.localtime()))) diff --git a/plugins/core_misc.py b/plugins/core_misc.py index 5e075a9..0b43542 100755 --- a/plugins/core_misc.py +++ b/plugins/core_misc.py @@ -25,16 +25,12 @@ def onjoin(paraml, conn=None, bot=None): nickserv_account_name = conn.conf.get('nickserv_user', '') nickserv_command = conn.conf.get('nickserv_command', 'IDENTIFY') if nickserv_password: - print "Found a password..." if nickserv_password in bot.config['censored_strings']: bot.config['censored_strings'].remove(nickserv_password) if nickserv_account_name: - print "Found an account name..." - print "Sending"," ".join([nickserv_command, nickserv_account_name, nickserv_password]),"to",nickserv_name - conn.msg(nickserv_name, " ".join([nickserv_command, nickserv_account_name, nickserv_password])) + conn.msg(nickserv_name, "{} {} {}".format([nickserv_command, nickserv_account_name, nickserv_password])) else: - print "Sending"," ".join([nickserv_command, nickserv_password]),"to",nickserv_name - conn.msg(nickserv_name, " ".join([nickserv_command, nickserv_password])) + conn.msg(nickserv_name, "{} {}".format([nickserv_command, nickserv_password])) bot.config['censored_strings'].append(nickserv_password) time.sleep(1) diff --git a/plugins/correction.py b/plugins/correction.py index c7d248d..5f2e2f6 100644 --- a/plugins/correction.py +++ b/plugins/correction.py @@ -20,11 +20,11 @@ def correction(inp, say=None, notice=None, db=None): message = last_message[1].replace("\x01ACTION ", "/me ").replace("\x01", "") else: message = last_message[1] - say("%s meant to say: %s" % (nick, message.replace(find, "\x02" + replace + "\x02"))) + say("{} meant to say: {}".format(nick, message.replace(find, "\x02" + replace + "\x02"))) else: - notice("%s can't be found in your last message" % find) + notice("{} can't be found in your last message".format(find)) else: if nick == input.nick: notice("I haven't seen you say anything here yet") else: - notice("I haven't seen %s say anything here yet" % nick) + notice("I haven't seen {} say anything here yet".format(nick)) diff --git a/plugins/dice.py b/plugins/dice.py index f2173d1..94e0f46 100755 --- a/plugins/dice.py +++ b/plugins/dice.py @@ -84,6 +84,6 @@ def dice(inp): return "Thanks for overflowing a float, jerk >:[" if desc: - return "%s: %d (%s)" % (desc.strip(), total, ", ".join(rolls)) + return "{}: {} ({})".format(desc.strip(), total, ", ".join(rolls)) else: - return "%d (%s)" % (total, ", ".join(rolls)) + return "{} ({})".format(total, ", ".join(rolls)) diff --git a/plugins/dictionary.py b/plugins/dictionary.py index dac19b6..478f77f 100755 --- a/plugins/dictionary.py +++ b/plugins/dictionary.py @@ -21,11 +21,11 @@ def define(inp): return 'No results for ' + inp + ' :(' def format_output(show_examples): - result = '%s: ' % h.xpath('//dt[@class="title-word"]/a/text()')[0] + result = '{}: '.format(h.xpath('//dt[@class="title-word"]/a/text()')[0]) correction = h.xpath('//span[@class="correct-word"]/text()') if correction: - result = 'Definition for "%s": ' % correction[0] + result = 'Definition for "{}": '.format(correction[0]) sections = [] for section in definition: @@ -40,7 +40,7 @@ def define(inp): for article in sections: result += article[0] if len(article) > 2: - result += ' '.join('%d. %s' % (n + 1, section) + result += ' '.join('{}. {}'.format(n + 1, section) for n, section in enumerate(article[1:])) else: result += article[1] + ' ' @@ -76,7 +76,7 @@ def etymology(inp): etym = h.xpath('//dl') if not etym: - return 'No etymology found for ' + inp + ' :(' + return 'No etymology found for {} :('.format(inp) etym = etym[0].text_content() diff --git a/plugins/down.py b/plugins/down.py index ec6dc0d..f03c078 100755 --- a/plugins/down.py +++ b/plugins/down.py @@ -15,6 +15,6 @@ def down(inp): # http://mail.python.org/pipermail/python-list/2006-December/589854.html try: http.get(inp, get_method='HEAD') - return inp + ' seems to be up' + return '{} seems to be up'.format(inp) except http.URLError: - return inp + ' seems to be down' + return '{} seems to be down'.format(inp) diff --git a/plugins/drama.py b/plugins/drama.py index b6bf77d..351c5c8 100755 --- a/plugins/drama.py +++ b/plugins/drama.py @@ -24,6 +24,6 @@ def drama(inp): summary = " ".join(p.text_content().splitlines()) summary = re.sub("\[\d+\]", "", summary) summary = text.truncate_str(summary, 220) - return "%s :: %s" % (summary, url) + return "{} :: {}".format(summary, url) return "Unknown Error." diff --git a/plugins/eightball.py b/plugins/eightball.py index e7ef418..141c464 100755 --- a/plugins/eightball.py +++ b/plugins/eightball.py @@ -18,4 +18,4 @@ def eightball(input, me=None): in electronic form. Ask and it shall be answered!""" magic = text.multiword_replace(random.choice(responses), color_codes) - me("shakes the magic 8 ball... %s" % magic) + me("shakes the magic 8 ball... {}".format(magic)) diff --git a/plugins/fact.py b/plugins/fact.py index 062be77..ab05f17 100755 --- a/plugins/fact.py +++ b/plugins/fact.py @@ -34,4 +34,4 @@ def fact(inp, say=False, nick=False): url = web.try_isgd(link) - return "%s - %s" % (fact, url) + return "{} - {}".format(fact, url) diff --git a/plugins/factoids.py b/plugins/factoids.py index 8440fc1..a42ed56 100755 --- a/plugins/factoids.py +++ b/plugins/factoids.py @@ -62,14 +62,12 @@ def remember(inp, nick='', db=None, notice=None): if old_data: if append: - notice("Appending \x02%s\x02 to \x02%s\x02" % (new_data, old_data)) + notice("Appending \x02{}\x02 to \x02{}\x02".format(new_data, old_data)) else: - notice('Remembering \x02%s\x02 for \x02%s\x02. Type ?%s to see it.' - % (data, word, word)) - notice('Previous data was \x02%s\x02' % old_data) + notice('Remembering \x02{}\x02 for \x02{}\x02. Type ?{} to see it.'.format(data, word, word)) + notice('Previous data was \x02{}\x02'.format(old_data)) else: - notice('Remembering \x02%s\x02 for \x02%s\x02. Type ?%s to see it.' - % (data, word, word)) + notice('Remembering \x02{}\x02 for \x02{}\x02. Type ?{} to see it.'.format(data, word, word)) @hook.command("f", permissions=["delfactoid"]) @@ -131,7 +129,7 @@ def factoid(inp, say=None, db=None, bot=None, me=None, conn=None, input=None): # factoid preprocessors if data.startswith(""): code = data[4:].strip() - variables = 'input="""%s"""; nick="%s"; chan="%s"; bot_nick="%s";' % (arguments.replace('"', '\\"'), + variables = 'input="""{}"""; nick="{}"; chan="{}"; bot_nick="{}";'.format(arguments.replace('"', '\\"'), input.nick, input.chan, input.conn.nick) result = execute.eval_py(variables + code) @@ -152,6 +150,6 @@ def factoid(inp, say=None, db=None, bot=None, me=None, conn=None, input=None): say("Could not fetch URL.") else: if prefix_on: - say("\x02[%s]:\x02 %s" % (factoid_id, result)) + say("\x02[{}]:\x02 {}".format(factoid_id, result)) else: say(result) diff --git a/plugins/fmylife.py b/plugins/fmylife.py index c213d44..a25b1a4 100755 --- a/plugins/fmylife.py +++ b/plugins/fmylife.py @@ -23,7 +23,7 @@ def fml(inp, reply=None): # grab the last item in the fml cache and remove it id, text = fml_cache.pop() # reply with the fml we grabbed - reply('(#%d) %s' % (id, text)) + reply('(#{}) {}'.format(id, text)) # refresh fml cache if its getting empty if len(fml_cache) < 3: refresh_cache() diff --git a/plugins/gcalc.py b/plugins/gcalc.py index fd4b136..9a2dbb5 100755 --- a/plugins/gcalc.py +++ b/plugins/gcalc.py @@ -11,9 +11,9 @@ def calc(inp): result = soup.find('h2', {'class': 'r'}) exponent = result.find('sup') if not result: - return "Could not calculate '%s'" % inp + return "Could not calculate '{}'".format(inp) if not exponent: return result.contents[0] if exponent: - return result.contents[0] + "^" + exponent.contents[0] + return "{}^{}".format(result.contents[0]*2) diff --git a/plugins/github.py b/plugins/github.py index dd1aeb9..00ee88d 100644 --- a/plugins/github.py +++ b/plugins/github.py @@ -31,7 +31,7 @@ def ghissues(inp): repo = shortcuts[args[0]] else: repo = args[0] - url = "https://api.github.com/repos/%s/issues" % repo + url = "https://api.github.com/repos/{}/issues".format(repo) except IndexError: return "Invalid syntax. .github issues username/repo [number]" try: @@ -50,13 +50,13 @@ def ghissues(inp): return "Repo has no open issues" except ValueError: return "Invalid data returned. Check arguments (.github issues username/repo [number]" - fmt = "Issue: #%s (%s) by %s: %s | %s %s" # (number, state, user.login, title, truncate(body), gitio.gitio(data.url)) - fmt1 = "Issue: #%s (%s) by %s: %s %s" # (number, state, user.login, title, gitio.gitio(data.url)) + fmt = "Issue: #{} ({}) by {}: {} | {} {}".format(number, state, user.login, title, truncate(body), gitio.gitio(data.url)) + fmt1 = "Issue: #{} ({}) by {}: {} {}".format(number, state, user.login, title, gitio.gitio(data.url)) number = data["number"] if data["state"] == "open": state = u"\x033\x02OPEN\x02\x0f" else: - state = u"\x034\x02CLOSED\x02\x0f by %s" % data["closed_by"]["login"] + state = u"\x034\x02CLOSED\x02\x0f by {}".format(data["closed_by"]["login"]) user = data["user"]["login"] title = data["title"] summary = truncate(data["body"]) diff --git a/plugins/google.py b/plugins/google.py index 1e1dad4..74b0c18 100755 --- a/plugins/google.py +++ b/plugins/google.py @@ -17,8 +17,7 @@ def googleimage(inp): parsed = api_get('images', inp) if not 200 <= parsed['responseStatus'] < 300: - raise IOError('error searching for images: %d: %s' % ( - parsed['responseStatus'], '')) + raise IOError('error searching for images: {}: {}'.format(parsed['responseStatus'], '')) if not parsed['responseData']['results']: return 'no images found' return random.choice(parsed['responseData']['results'][:10]) \ @@ -33,8 +32,7 @@ def google(inp): parsed = api_get('web', inp) if not 200 <= parsed['responseStatus'] < 300: - raise IOError('error searching for pages: %d: %s' % ( - parsed['responseStatus'], '')) + raise IOError('error searching for pages: {}: {}'.format(parsed['responseStatus'], '')) if not parsed['responseData']['results']: return 'No results found.' @@ -50,6 +48,6 @@ def google(inp): content = http.html.fromstring(content).text_content() content = text.truncate_str(content, 150) - out = '%s -- \x02%s\x02: "%s"' % (result['unescapedUrl'], title, content) + out = '{} -- \x02{}\x02: "{}"'.format(result['unescapedUrl'], title, content) return out diff --git a/plugins/horoscope.py b/plugins/horoscope.py index 7bd6221..ef3ed84 100644 --- a/plugins/horoscope.py +++ b/plugins/horoscope.py @@ -46,7 +46,7 @@ def horoscope(inp, db=None, notice=None, nick=None): #result = unicode(result, "utf8").replace('flight ','') if not title: - return "Could not get the horoscope for %s." % inp + return "Could not get the horoscope for {}.".format(inp) if inp and not dontsave: db.execute("insert or replace into horoscope(nick, sign) values (?,?)", diff --git a/plugins/ignore.py b/plugins/ignore.py index 00ce9e1..dc3f382 100755 --- a/plugins/ignore.py +++ b/plugins/ignore.py @@ -34,7 +34,7 @@ def ignored(inp, notice=None, bot=None): """ignored -- Lists ignored channels/users.""" ignorelist = bot.config["plugins"]["ignore"]["ignored"] if ignorelist: - notice("Ignored channels/users are: %s" % ", ".join(ignorelist)) + notice("Ignored channels/users are: {}".format(", ".join(ignorelist))) else: notice("No masks are currently ignored.") return @@ -46,9 +46,9 @@ def ignore(inp, notice=None, bot=None, config=None): target = inp.lower() ignorelist = bot.config["plugins"]["ignore"]["ignored"] if target in ignorelist: - notice("%s is already ignored." % target) + notice("{} is already ignored.".format(target)) else: - notice("%s has been ignored." % target) + notice("{} has been ignored.".format(target)) ignorelist.append(target) ignorelist.sort() json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2) @@ -62,10 +62,10 @@ def unignore(inp, notice=None, bot=None, config=None): target = inp.lower() ignorelist = bot.config["plugins"]["ignore"]["ignored"] if target in ignorelist: - notice("%s has been unignored." % target) + notice("{} has been unignored.".format(target)) ignorelist.remove(target) ignorelist.sort() json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2) else: - notice("%s is not ignored." % target) + notice("{} is not ignored.".format(target)) return diff --git a/plugins/imdb.py b/plugins/imdb.py index e44bd2c..f7a0223 100755 --- a/plugins/imdb.py +++ b/plugins/imdb.py @@ -21,7 +21,7 @@ def imdb(inp): if content.get('Error', None) == 'Movie not found!': return 'Movie not found!' elif content['Response'] == 'True': - content['URL'] = 'http://www.imdb.com/title/%(imdbID)s' % content + content['URL'] = 'http://www.imdb.com/title/{}'.format(content['imdbID']) out = '\x02%(Title)s\x02 (%(Year)s) (%(Genre)s): %(Plot)s' if content['Runtime'] != 'N/A':