This repository has been archived on 2023-04-13. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
CloudBot/disabled_stuff/minecraft_items.py

101 lines
2.4 KiB
Python
Raw Normal View History

2012-03-16 16:20:13 +13:00
""" plugin by _303 (?)
"""
import re
2014-02-14 16:36:57 +13:00
from util import hook
2012-03-16 16:20:13 +13:00
pattern = re.compile(r'^(?P<count>\d+)x (?P<name>.+?): (?P<ingredients>.*)$')
recipelist = []
2012-03-23 13:00:22 +13:00
2012-03-16 16:20:13 +13:00
class Recipe(object):
__slots__ = 'output', 'count', 'ingredients', 'line'
def __init__(self, output, count, ingredients, line):
self.output = output
self.count = count
self.ingredients = ingredients
self.line = line
def __str__(self):
return self.line
2012-03-23 13:00:22 +13:00
2012-03-26 17:17:19 +13:00
with open("plugins/data/recipes.txt") as f:
2012-03-16 16:20:13 +13:00
for line in f.readlines():
2012-03-20 15:53:33 +13:00
if line.startswith("//"):
continue
2012-03-16 16:20:13 +13:00
line = line.strip()
match = pattern.match(line)
if not match:
continue
recipelist.append(Recipe(line=line,
output=match.group("name").lower(),
ingredients=match.group("ingredients"),
count=match.group("count")))
2012-03-16 16:20:13 +13:00
ids = []
2012-03-26 17:17:19 +13:00
with open("plugins/data/itemids.txt") as f:
2012-03-16 16:20:13 +13:00
for line in f.readlines():
2012-03-20 15:53:33 +13:00
if line.startswith("//"):
continue
2012-03-16 16:20:13 +13:00
parts = line.strip().split()
2014-02-14 16:30:38 +13:00
itemid = parts[0]
2012-03-16 16:20:13 +13:00
name = " ".join(parts[1:])
2014-02-14 16:30:38 +13:00
ids.append((itemid, name))
2012-03-23 13:00:22 +13:00
2012-03-16 16:20:13 +13:00
2012-05-15 20:08:26 -07:00
@hook.command("mcid")
2012-03-16 16:20:13 +13:00
@hook.command
2014-02-14 16:30:38 +13:00
def mcitem(inp, reply=None):
"""mcitem <item/id> -- gets the id from an item or vice versa"""
2014-02-14 16:30:38 +13:00
inp = inp.lower().strip()
2012-03-16 16:20:13 +13:00
2014-02-14 16:30:38 +13:00
if inp == "":
2012-03-18 20:07:10 -07:00
reply("error: no input.")
2012-03-16 16:20:13 +13:00
return
results = []
2014-02-14 16:30:38 +13:00
for item_id, item_name in ids:
if inp == item_id:
results = ["\x02[{}]\x02 {}".format(item_id, item_name)]
2012-03-20 16:10:25 +13:00
break
2014-02-14 16:30:38 +13:00
elif inp in item_name.lower():
results.append("\x02[{}]\x02 {}".format(item_id, item_name))
2012-03-16 16:20:13 +13:00
2012-05-17 07:47:49 +12:00
if not results:
return "No matches found."
2012-03-23 13:00:22 +13:00
2012-03-20 16:10:25 +13:00
if len(results) > 12:
2013-09-05 10:11:18 +08:00
reply("There are too many options, please narrow your search. ({})".format(str(len(results))))
2012-03-16 16:20:13 +13:00
return
2012-03-23 13:00:22 +13:00
2012-03-19 15:57:43 +13:00
out = ", ".join(results)
2012-03-23 13:00:22 +13:00
2012-03-19 15:57:43 +13:00
return out
2012-03-16 16:20:13 +13:00
2012-05-15 20:08:26 -07:00
@hook.command("mccraft")
2012-03-16 16:20:13 +13:00
@hook.command
2014-02-14 16:30:38 +13:00
def mcrecipe(inp, reply=None):
"""mcrecipe <item> -- gets the crafting recipe for an item"""
2014-02-14 16:30:38 +13:00
inp = inp.lower().strip()
2012-03-16 16:20:13 +13:00
2012-05-17 07:47:49 +12:00
results = [recipe.line for recipe in recipelist
2014-02-14 16:30:38 +13:00
if inp in recipe.output]
2012-03-16 16:20:13 +13:00
2012-05-17 07:47:49 +12:00
if not results:
return "No matches found."
2012-03-19 15:57:43 +13:00
if len(results) > 3:
2013-09-05 10:11:18 +08:00
reply("There are too many options, please narrow your search. ({})".format(len(results)))
2012-03-16 16:20:13 +13:00
return
for result in results:
reply(result)