more little things

This commit is contained in:
Luke Rogers 2014-02-14 16:30:38 +13:00
parent b4d7e200a3
commit 4447e6cd1f
9 changed files with 25 additions and 22 deletions

View file

@ -13,7 +13,7 @@ details_url = base_url + "plugins/bukkit/{}"
categories = http.get_json("http://api.bukget.org/3/categories") categories = http.get_json("http://api.bukget.org/3/categories")
count_total = sum([cat["count"] for cat in categories]) count_total = sum([cat["count"] for cat in categories])
count_categories = {cat["name"].lower() : int(cat["count"]) for cat in categories} # dict comps! count_categories = {cat["name"].lower(): int(cat["count"]) for cat in categories} # dict comps!
class BukgetError(Exception): class BukgetError(Exception):

View file

@ -42,29 +42,29 @@ with open("plugins/data/itemids.txt") as f:
if line.startswith("//"): if line.startswith("//"):
continue continue
parts = line.strip().split() parts = line.strip().split()
id = parts[0] itemid = parts[0]
name = " ".join(parts[1:]) name = " ".join(parts[1:])
ids.append((id, name)) ids.append((itemid, name))
@hook.command("mcid") @hook.command("mcid")
@hook.command @hook.command
def mcitem(input, reply=None): def mcitem(inp, reply=None):
"""mcitem <item/id> -- gets the id from an item or vice versa""" """mcitem <item/id> -- gets the id from an item or vice versa"""
input = input.lower().strip() inp = inp.lower().strip()
if input == "": if inp == "":
reply("error: no input.") reply("error: no input.")
return return
results = [] results = []
for id, name in ids: for item_id, item_name in ids:
if input == id: if inp == item_id:
results = ["\x02[{}]\x02 {}".format(id, name)] results = ["\x02[{}]\x02 {}".format(item_id, item_name)]
break break
elif input in name.lower(): elif inp in item_name.lower():
results.append("\x02[{}]\x02 {}".format(id, name)) results.append("\x02[{}]\x02 {}".format(item_id, item_name))
if not results: if not results:
return "No matches found." return "No matches found."
@ -80,12 +80,12 @@ def mcitem(input, reply=None):
@hook.command("mccraft") @hook.command("mccraft")
@hook.command @hook.command
def mcrecipe(input, reply=None): def mcrecipe(inp, reply=None):
"""mcrecipe <item> -- gets the crafting recipe for an item""" """mcrecipe <item> -- gets the crafting recipe for an item"""
input = input.lower().strip() inp = inp.lower().strip()
results = [recipe.line for recipe in recipelist results = [recipe.line for recipe in recipelist
if input in recipe.output] if inp in recipe.output]
if not results: if not results:
return "No matches found." return "No matches found."

View file

@ -1,3 +1,4 @@
# TODO: Rewrite this whole mess
from util import hook from util import hook
import socket import socket
import struct import struct

View file

@ -25,9 +25,9 @@ refresh_cache()
def mlia(inp, reply=None): def mlia(inp, reply=None):
"""mlia -- Gets a random quote from MyLifeIsAverage.com.""" """mlia -- Gets a random quote from MyLifeIsAverage.com."""
# grab the last item in the mlia cache and remove it # grab the last item in the mlia cache and remove it
id, text = mlia_cache.pop() mlia_id, text = mlia_cache.pop()
# reply with the mlia we grabbed # reply with the mlia we grabbed
reply('({}) {}'.format(id, text)) reply('({}) {}'.format(mlia_id, text))
# refresh mlia cache if its getting empty # refresh mlia cache if its getting empty
if len(mlia_cache) < 3: if len(mlia_cache) < 3:
refresh_cache() refresh_cache()

View file

@ -1,4 +1,5 @@
# based on password generation code by TheNoodle # TODO: Add some kind of pronounceable password generation
# TODO: Improve randomness
from util import hook from util import hook
import string import string
import random import random

View file

@ -13,6 +13,7 @@ def ping(inp, reply=None):
if os.name == "nt": if os.name == "nt":
return "Sorry, this command is not supported on Windows systems." return "Sorry, this command is not supported on Windows systems."
# TODO: Rewrite this entire command to work on Windows, somehow
args = inp.split(' ') args = inp.split(' ')
host = args[0] host = args[0]

View file

@ -8,9 +8,9 @@ def qrcode(inp):
"""qrcode [link] returns a link for a QR code.""" """qrcode [link] returns a link for a QR code."""
args = { args = {
"cht": "qr", # chart type "cht": "qr", # chart type (QR)
"chs": "200x200", # dimensions "chs": "200x200", # dimensions
"chl": inp "chl": inp # data
} }
link = http.prepare_url("http://chart.googleapis.com/chart", args) link = http.prepare_url("http://chart.googleapis.com/chart", args)