diff --git a/exts/banking.py b/exts/banking.py index 828c22a..d0c379a 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -61,6 +61,23 @@ class BaseMul: } +class TransferFlags(commands.FlagConverter, delimiter=" ", prefix="--"): + money: int = commands.flag(default=0) + food: int = commands.flag(default=0) + uranium: int = commands.flag(default=0) + gasoline: int = commands.flag(default=0) + munitions: int = commands.flag(default=0) + steel: int = commands.flag(default=0) + aluminum: int = commands.flag(default=0) + coal: int = commands.flag(default=0) + iron: int = commands.flag(default=0) + lead: int = commands.flag(default=0) + bauxite: int = commands.flag(default=0) + oil: int = commands.flag(default=0) + nation: List[int] = commands.flag(default=[]) + alliance: Optional[int] = commands.flag(default=None) + + class Banking(commands.Cog): def __init__(self, bot: Brahmos): self.bot = bot @@ -394,6 +411,17 @@ class Banking(commands.Cog): await interaction.message.edit(view=None) logstream.seek(0) await ctx.send(file=discord.File(logstream, filename="log.txt")) + e.title = "Resources Transferred" + e.color = discord.Color.green() + e.description = ( + 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'):,}" + ) paginator = ctx.Paginator(pages=embeds) await paginator.start( @@ -989,7 +1017,7 @@ class Banking(commands.Cog): "nation_bauxite": nation.bauxite, "nation_lead": nation.lead, "nation_flag": nation.flag, - "num_cities": nation.num_cities + "num_cities": nation.num_cities, } ) @@ -1355,7 +1383,7 @@ class Banking(commands.Cog): title=f"Raws consumption for {data['nation_name']}", color=ctx.author.color, timestamp=datetime.datetime.utcnow(), - url=f"https://politicsandwar.com/nation/id={data.get('nation_id')}" + url=f"https://politicsandwar.com/nation/id={data.get('nation_id')}", ) e.set_thumbnail(url=data.get("nation_flag")) @@ -1381,8 +1409,9 @@ class Banking(commands.Cog): async def refill(self, ctx: CustomCtx, ids: commands.Greedy[int]): await ctx.send(f"> calculating raws") revenue_data = await self.get_alliance_rev(ids) + def calc_tosend(raw: float, on_nation: float): - net = int(7 * abs(raw) - on_nation) + net = int(7 * abs(raw) - on_nation) if net < 0: return 0 return net @@ -1393,13 +1422,7 @@ class Banking(commands.Cog): timestamp=datetime.datetime.now(), color=ctx.author.color, ) - total = { - "oil": 0, - "coal": 0, - "lead": 0, - "iron": 0, - "bauxite": 0 - } + total = {"oil": 0, "coal": 0, "lead": 0, "iron": 0, "bauxite": 0} count = 0 for data in revenue_data: @@ -1415,7 +1438,7 @@ class Banking(commands.Cog): tosend = calc_tosend(oil, data.get("nation_oil")) data["refill"].update(oil=tosend) text += f"{Emojis.oil} {tosend:,}\n" - total["oil"] += tosend + total["oil"] += tosend if coal < 0: tosend = calc_tosend(coal, data.get("nation_coal")) data["refill"].update(coal=tosend) @@ -1436,13 +1459,13 @@ class Banking(commands.Cog): data["refill"].update(bauxite=tosend) text += f"{Emojis.bauxite} {tosend:,}" total["bauxite"] += tosend - + if not text: text = "already satisfied" e.add_field( name=f"{data.get('nation_name')} (c{data.get('num_cities')})", - value=text + value=text, ) count += 1 if count == 9: @@ -1524,7 +1547,7 @@ class Banking(commands.Cog): "receiver": data.get("nation_id"), "receiver_type": 1, "note": "raws refill", - **data["refill"] + **data["refill"], }, "id", ) @@ -1542,15 +1565,28 @@ class Banking(commands.Cog): await asyncio.sleep(1) except Exception as err: pprint.pprint( - f"{data.get('nation_name')} -> {err}", stream=logstream, indent=3 + f"{data.get('nation_name')} -> {err}", + stream=logstream, + indent=3, + ) + logmsg += ( + f"{data.get('nation_name')} <:cross:1275839683984621568>\n" ) - logmsg += f"{data.get('nation_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")) + e.title = "raws transferred" + e.description = ( + f"{Emojis.oil} {total.get('oil'):,}\n" + f"{Emojis.coal} {total.get('coal'):,}\n" + f"{Emojis.lead} {total.get('lead'):,}\n" + f"{Emojis.iron} {total.get('iron'):,}\n" + f"{Emojis.bauxite} {total.get('bauxite'):,}\n" + ) + await ctx.send(embed=e) paginator = ctx.Paginator(pages=embeds) await paginator.start( @@ -1558,5 +1594,28 @@ class Banking(commands.Cog): ) + @commands.command() + async def tf(self, ctx: CustomCtx, flags: TransferFlags): + """ + Transfer resources to a nation or alliance. + """ + nation_ids = flags.nation + alliance_id = flags.alliance + resources = { + "money": flags.money, + "food": flags.food, + "uranium": flags.uranium, + "gasoline": flags.gasoline, + "munitions": flags.munitions, + "steel": flags.steel, + "aluminum": flags.aluminum, + "coal": flags.coal, + "iron": flags.iron, + "lead": flags.lead, + "bauxite": flags.bauxite, + "oil": flags.oil, + } + + async def setup(bot: Brahmos): await bot.add_cog(Banking(bot))