diff --git a/exts/banking.py b/exts/banking.py index 8c1f98c..0282f91 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1,6 +1,7 @@ import asyncio import datetime import io +import json import os import pprint import random @@ -16,6 +17,7 @@ from utils.base import BasicView from utils.emojis import Emojis from utils.paginator import Paginator +FILL = json.load(open('refill.json')) class BaseMul: money = 1000000 food = 5000 @@ -155,9 +157,25 @@ class Banking(commands.Cog): ) alliance = data.alliances[0] nations = alliance.nations + resource_delta = [] + kit = pnwkit.QueryKit( + api_key=os.getenv("pnwDILFKEY"), + bot_key=os.getenv("pnwBOTKEY"), + bot_key_api_key=os.getenv("pnwACCKEY"), + aiohttp_session= aiohttp.ClientSession(loop=self.bot.loop) + ) + gator = await kit.query( + "nations", + {"id" : 103764, "first": 1}, + "id, nation_name, discord, money, food, steel, gasoline, munitions, aluminum, uranium, cities {name}" + ) + gator = gator.nations[0] + nations.append(gator) for nation in nations: + if nation.id not in FILL: + continue cities = len(nation.cities) delta = BaseMul.calc(cities, nation) delta.update({ @@ -173,7 +191,7 @@ class Banking(commands.Cog): embeds = [] - e = discord.Embed(title="Warchest Resources") + e = discord.Embed(title="Warchest Resources", timestamp=datetime.datetime.utcnow(), color=ctx.author.color) count = 0 for rd in resource_delta: @@ -193,11 +211,47 @@ class Banking(commands.Cog): count += 1 if count == 9: embeds.append(e) - e = discord.Embed(title="Warchest Resources") + e = discord.Embed(title="Warchest Resources", timestamp=datetime.datetime.utcnow(), color=ctx.author.color) count = 0 if count > 0: embeds.append(e) + e = discord.Embed(title="Nation List", timestamp=datetime.datetime.utcnow(), color=ctx.author.color, description="\u200b") + i = 0 + for rd in resource_delta: + i+=1 + e.description += f"**{i}. [{rd.get('name')}](https://politicsandwar.com/nation/id={rd.get('id')})**\n" + total= { + "money": 0, + "gasoline": 0, + "munitions": 0, + "aluminum": 0, + "steel100": 0, + "uranium": 0, + "food": 0, + "steel40": 0 + } + for rd in resource_delta: + total["money"] += rd.get("money") + total["steel100"] += rd.get("steel100") + total["steel40"] += rd.get("steel40") + total["aluminum"] += rd.get("aluminum") + total["food"] += rd.get("food") + total["munitions"] += rd.get("munitions") + total["uranium"] += rd.get("uranium") + total["gasoline"] += rd.get("gasoline") + + e.description += ( + "\n# Total warchest to transfer" + f"{Emojis.money} {total.get('money'):,}\n" + f"{Emojis.food} {total.get('food'):,}\n" + f"{Emojis.uranium} {total.get('uranium'):,}\n" + f"{Emojis.munitions} {total.get('munitions'):,}\n" + f"{Emojis.gasoline} {total.get('gasoline'):,}\n" + f"{Emojis.aluminum} {total.get('aluminum'):,}\n" + f"{Emojis.steel} {total.get('steel100'):,}" + ) + embeds.append(e) class ConfirmButton(discord.ui.Button): def __init__(self, *, style = discord.ButtonStyle.green, label= "confirm", bot: Brahmos, p: Paginator): @@ -218,7 +272,7 @@ class Banking(commands.Cog): aiohttp_session= aiohttp.ClientSession(loop=self.bot.loop) ) logmsg = "" - logstream = io.StringIO + logstream = io.StringIO() await interaction.response.defer() self.label = "processing" self.emoji = "" @@ -237,11 +291,11 @@ class Banking(commands.Cog): { "receiver" : rd.get("id"), "receiver_type": 1, - "money": rd.get("money"), + "money": rd.get("money") + 1, "food": rd.get("food"), "uranium": rd.get("uranium"), "gasoline": rd.get("gasoline"), - "steel": rd.get("steel00"), + "steel": rd.get("steel100"), "munitions": rd.get("munitions"), "aluminum": rd.get("aluminum"), "note": "warchest" @@ -249,17 +303,18 @@ class Banking(commands.Cog): "id" ) pprint.pprint(rd, stream=logstream, indent=3) - logmsg += f"{rd.get('name')} <:tick:1275824967522717707>\n" + logmsg += f"{rd.get('name')} <:tick:1275839665819353148>\n" e.description = logmsg await interaction.message.edit(embed=e) await asyncio.sleep(1) except Exception as e: pprint.pprint(f"{rd.get('name')} -> {e}", stream=logstream, indent=3) - logmsg += f"{rd.get('name')} <:cross:1275824989131505779>\n" + logmsg += f"{rd.get('name')} <:cross:1275839683984621568>\n" e.description = logmsg await interaction.message.edit(embed=e) await asyncio.sleep(1) await interaction.message.edit(view=None) + logstream.seek(0) await ctx.send(file=discord.File(logstream, filename="log.txt")) paginator = ctx.Paginator(pages=embeds) await paginator.start(ctx=ctx, custom_items=[ConfirmButton(bot=self.bot, p=paginator)]) diff --git a/refill.json b/refill.json new file mode 100644 index 0000000..bba4700 --- /dev/null +++ b/refill.json @@ -0,0 +1,20 @@ +[ + 178717, + 199964, + 216570, + 245457, + 255045, + 259121, + 425933, + 436008, + 443556, + 446076, + 406376, + 455761, + 500221, + 544445, + 565984, + 604712, + 574264, + 103764 +] \ No newline at end of file