<commit_before>part of recipes;

@app.Group("/recipes")
class RecipeBook extends Object with MetabolicsChange {
	static List<Recipe> recipes = [];

	// Client Communication

	@app.Route("/list")
	Future<String> listRecipes(@app.QueryParam("email") String email, @app.QueryParam("tool") String tool, @app.QueryParam("token") String token) async {
		if (token != redstoneToken) {
			return "Invalid token";
		}

		List<Map> toolRecipes = [];
		await Future.forEach(recipes, (Recipe recipe) async {

			// If the recipe is made with the requested tool (if requested)
			if ((tool == "" || tool == null) || tool == items[recipe.tool].itemType) {

				// Define a returned recipe
				Map toolRecipe = new Map()
					..["id"] = recipe.id
					..["tool"] = recipe.tool
					..["input"] = []
					..["output_map"] = items[recipe.output].getMap()
					..["output_amt"] = recipe.output_amt
					..["time"] = recipe.time
					..["energy"] = recipe.energy
					..["img"] = recipe.img;

				// Provide user-specific data if an email is provided
				if (email != null && email != "") {

					// For every item it requires...
					await Future.forEach(recipe.input.keys, (String itemType) async {
						int qty = recipe.input[itemType];

						// Get the item data to send
						Map itemMap = items[itemType].getMap();
						itemMap['qtyReq'] = qty;

						// Add item data to the recipe input data
						(toolRecipe["input"] as List<Map>).add(itemMap);

					});
					// End input items loop

				}
				// End user-specific data

				toolRecipes.add(toolRecipe);

			}
			// End tool recipe filter

		}); // End recipes loop

		return JSON.encode(toolRecipes);
	}

	@app.Route("/make")
	Future makeRecipe(@app.QueryParam("token") String token,
		@app.QueryParam("id") String id,
		@app.QueryParam("email") String email,
		@app.QueryParam("username") String username) async {

		if (token != redstoneToken) {
			return false;
		}

		// Get the recipe info
		Recipe recipe;
		List<Recipe> rList = recipes.where((Recipe recipe) => recipe.id == id).toList();
		if (rList.length != 1) {
			return false;
		} else {
			recipe = rList.first;
		}

		if(items[recipe.tool].durability != null) {
			//take away tool durability
			bool durabilitySuccess = await InventoryV2.decreaseDurability(email, recipe.tool);
			if(!durabilitySuccess) {
				return false;
			}
		}

		// Take away energy
		bool takeEnergySuccess = await trySetMetabolics(email, energy: recipe.energy);
		if (!takeEnergySuccess) {
			// If they don't have enough energy, they're not frying an egg
			return false;
		}

		// Take all of the items
		Future.forEach(recipe.input.keys, (String itemType) async {
			int qty = recipe.input[itemType];
			int got = (await InventoryV2.takeAnyItemsFromUser(email, itemType, qty));
			if (got != qty) {
				// If they didn't have a required item, they're not making a smoothie
				throw "Not enough $itemType. Took $got but wanted $qty";
			}
		});

		// Wait for it to make it, then give the item
		new Timer(new Duration(seconds: recipe.time), () async {
			// Add the item after we finish "making" one
			await InventoryV2.addItemToUser(email, items[recipe.output].getMap(), 1);
			// Award iMG
			await trySetMetabolics(email, imgMin: recipe.img);

			//send possible quest event
			messageBus.publish(new RequirementProgress('makeRecipe_${recipe.output}',email));

			// Count stat for achievements
			StatAchvManager.update(email, recipe.tool);
		});

		return true;
	}
}<commit_msg>(untested) stop making a recipe if the tool breaks<commit_after>part of recipes;

@app.Group("/recipes")
class RecipeBook extends Object with MetabolicsChange {
	static List<Recipe> recipes = [];

	static Recipe findRecipe(String id) {
		return recipes.singleWhere((Recipe recipe) {
			recipe.id == id;
		});
	}

	// Client Communication

	@app.Route("/list")
	Future<String> listRecipes(@app.QueryParam("email") String email, @app.QueryParam("tool") String tool, @app.QueryParam("token") String token) async {
		if (token != redstoneToken) {
			return "Invalid token";
		}

		List<Map> toolRecipes = [];
		await Future.forEach(recipes, (Recipe recipe) async {

			// If the recipe is made with the requested tool (if requested)
			if ((tool == "" || tool == null) || tool == items[recipe.tool].itemType) {

				// Define a returned recipe
				Map toolRecipe = new Map()
					..["id"] = recipe.id
					..["tool"] = recipe.tool
					..["input"] = []
					..["output_map"] = items[recipe.output].getMap()
					..["output_amt"] = recipe.output_amt
					..["time"] = recipe.time
					..["energy"] = recipe.energy
					..["img"] = recipe.img;

				// Provide user-specific data if an email is provided
				if (email != null && email != "") {

					// For every item it requires...
					await Future.forEach(recipe.input.keys, (String itemType) async {
						int qty = recipe.input[itemType];

						// Get the item data to send
						Map itemMap = items[itemType].getMap();
						itemMap['qtyReq'] = qty;

						// Add item data to the recipe input data
						(toolRecipe["input"] as List<Map>).add(itemMap);

					});
					// End input items loop

				}
				// End user-specific data

				toolRecipes.add(toolRecipe);

			}
			// End tool recipe filter

		}); // End recipes loop

		return JSON.encode(toolRecipes);
	}

	@app.Route("/make")
	Future makeRecipe(@app.QueryParam("token") String token,
		@app.QueryParam("id") String id,
		@app.QueryParam("email") String email,
		@app.QueryParam("username") String username) async {

		if (token != redstoneToken) {
			return false;
		}

		// Stop if the tool breaks
		if (!(await InventoryV2.hasItem(email, findRecipe(id).tool, 1))) {
			return false;
		}

		// Get the recipe info
		Recipe recipe;
		List<Recipe> rList = recipes.where((Recipe recipe) => recipe.id == id).toList();
		if (rList.length != 1) {
			return false;
		} else {
			recipe = rList.first;
		}

		if(items[recipe.tool].durability != null) {
			//take away tool durability
			bool durabilitySuccess = await InventoryV2.decreaseDurability(email, recipe.tool);
			if(!durabilitySuccess) {
				return false;
			}
		}

		// Take away energy
		bool takeEnergySuccess = await trySetMetabolics(email, energy: recipe.energy);
		if (!takeEnergySuccess) {
			// If they don't have enough energy, they're not frying an egg
			return false;
		}

		// Take all of the items
		Future.forEach(recipe.input.keys, (String itemType) async {
			int qty = recipe.input[itemType];
			int got = (await InventoryV2.takeAnyItemsFromUser(email, itemType, qty));
			if (got != qty) {
				// If they didn't have a required item, they're not making a smoothie
				throw "Not enough $itemType. Took $got but wanted $qty";
			}
		});

		// Wait for it to make it, then give the item
		new Timer(new Duration(seconds: recipe.time), () async {
			// Add the item after we finish "making" one
			await InventoryV2.addItemToUser(email, items[recipe.output].getMap(), 1);
			// Award iMG
			await trySetMetabolics(email, imgMin: recipe.img);

			//send possible quest event
			messageBus.publish(new RequirementProgress('makeRecipe_${recipe.output}',email));

			// Count stat for achievements
			StatAchvManager.update(email, recipe.tool);
		});

		return true;
	}
}
{'fraction_non_alphanumeric': 0.1415316438166459, 'fraction_numerical': 0.0016618196925633569, 'mean_word_length': 3.1649365628604382, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2007085', 'n_tokens_mistral': 2731, 'n_tokens_neox': 2266, 'n_words': 651}