This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/disabled_stuff/minecraft_items.py

101 lines
2.4 KiB
Python
Raw Permalink Normal View History

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