Jan-11-2019, 07:44 PM
The code feeds back into a discord command. I know this works, as my previous version of the bot works fine, but the json file was a mess and needed to be completely rewritten.
https://pastebin.com/eNztKujJ
async def calc(ctx, quantity: float, itemA: str, itemB: str): itemAPrice = get_value(itemA) itemBPrice = get_value(itemB) if itemAPrice and itemBPrice: itemQuotient = itemAPrice/itemBPrice itemBEquivalent = round(quantity * itemQuotient, 2) quantity = quantity itemA = itemA itemBEquivalent = itemBEquivalent itemB = itemB author = ctx.message.author.name embed=discord.Embed(title="\N{CONVENIENCE STORE} Recommended Exchange Rate \N{CONVENIENCE STORE}", description=f'{quantity} {itemA} is equal to {itemBEquivalent} {itemB}', color=0xDA70D6) embed.set_footer(text=f"Requested by {author}") await ctx.send(embed=embed) await ctx.message.delete() elif not itemAPrice: await ctx.send('No match found for ' + itemA) elif not itemBPrice: await ctx.send('No match found for ' + itemB)Previous version of it looked like this.
CONFIG = 'config.json' with open(CONFIG) as json_data_file: config = json.load(json_data_file) TOKEN = config['token'] items = config['items'] BOT_PREFIX = config['prefix'] aliases = config['aliases'] def get_value(item: str): if item: item = item.replace(" ", "").lower() try: return items[aliases[item]] except KeyError: return else: return Nonewith the json looking like this
https://pastebin.com/eNztKujJ