From 91188e48f1b8d4fc40c7ee1948090facd5983174 Mon Sep 17 00:00:00 2001 From: un1xx Date: Thu, 10 Oct 2024 17:29:34 +0530 Subject: [PATCH] minor fixes --- exts/banking.py | 210 ++++++++++++++++++++++++++++++++++++++++++------ refill.json | 3 +- 2 files changed, 189 insertions(+), 24 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index 624a11d..c1cba59 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -199,7 +199,7 @@ class Banking(commands.Cog): embeds = [] e = discord.Embed( title="Warchest Resources", - timestamp=datetime.datetime.utcnow(), + timestamp=datetime.datetime.now(), color=ctx.author.color, ) count = 0 @@ -223,7 +223,7 @@ class Banking(commands.Cog): embeds.append(e) e = discord.Embed( title="Warchest Resources", - timestamp=datetime.datetime.utcnow(), + timestamp=datetime.datetime.now(), color=ctx.author.color, ) count = 0 @@ -232,7 +232,7 @@ class Banking(commands.Cog): embeds.append(e) e = discord.Embed( title="Nation List", - timestamp=datetime.datetime.utcnow(), + timestamp=datetime.datetime.now(), color=ctx.author.color, description="\u200b", ) @@ -315,24 +315,39 @@ class Banking(commands.Cog): if isinstance(rd[k], int) and (rd[k] < 0): rd[k] = 0 try: - await kit.mutation( - "bankWithdraw", - { - "receiver": rd.get("id"), - "receiver_type": 1, - "money": rd.get("money") + 1, - "food": rd.get("food"), - "uranium": rd.get("uranium"), - "gasoline": rd.get("gasoline"), - "steel": rd.get("steel100"), - "munitions": rd.get("munitions"), - "aluminum": rd.get("aluminum"), - "note": "warchest", - }, - "id", + sum = ( + rd.get("money") + + rd.get("food") + + rd.get("uranium") + + rd.get("gasoline") + + rd.get("munitions") + + rd.get("aluminum") + + rd.get("steel100") ) - pprint.pprint(rd, stream=logstream, indent=3) - logmsg += f"{rd.get('name')} <:tick:1275839665819353148>\n" + if sum !=0: + await kit.mutation( + "bankWithdraw", + { + "receiver": rd.get("id"), + "receiver_type": 1, + "money": rd.get("money") + 1, + "food": rd.get("food"), + "uranium": rd.get("uranium"), + "gasoline": rd.get("gasoline"), + "steel": rd.get("steel100"), + "munitions": rd.get("munitions"), + "aluminum": rd.get("aluminum"), + "note": "warchest", + }, + "id", + ) + pprint.pprint(rd, stream=logstream, indent=3) + logmsg += f"{rd.get('name')} <:tick:1275839665819353148>\n" + else: + pprint.pprint( + f"{rd.get('name')} (already filled)", stream=logstream, indent=3 + ) + logmsg += f"{rd.get('name')} (already filled)\n" e.description = logmsg await interaction.message.edit(embed=e) await asyncio.sleep(1) @@ -438,7 +453,7 @@ class Banking(commands.Cog): title=f"Resources for {resources.name}", timestamp=datetime.datetime.utcnow(), color=ctx.author.color, - url= f"https://politicsandwar.com/alliance/id={resources.id}" + url=f"https://politicsandwar.com/alliance/id={resources.id}", ) e.description = ( f"{Emojis.money} {resources.money:,}\n" @@ -455,11 +470,160 @@ class Banking(commands.Cog): f"{Emojis.steel} {resources.steel:,}" ) e.set_thumbnail(url=resources.flag) - e.set_footer(text='Bank', icon_url=ctx.author.avatar) + e.set_footer(text="Bank", icon_url=ctx.author.avatar) embeds.append(e) - + await ctx.paginate(pages=embeds) + @commands.has_role(987770837627187250) + @commands.command() + async def transfer(self, ctx: CustomCtx): + """transfer resources""" + if ctx.author.id not in [ + 367740727624466433, + 322156710590676993, + 407135783678640128, + 444896160105103361, + ]: + return await ctx.send("-# You are not in list of authorized users") + alliances = {10177: "Man I Love Frogs", 10198: "Damn I Love Frogs"} + e = discord.Embed( + timestamp=datetime.datetime.now(), + title="Transfer Resources", + color=ctx.author.color, + ) + e.add_field(name="Transferring From", value=alliances.get(10177)) + + sel_alliance = 10177 + + class TransferView(BasicView): + def __init__(self, timeout: float | None = 60, clear: bool | None = False): + super().__init__(timeout=timeout, clear=clear) + + @discord.ui.button( + label="change alliance", style=discord.ButtonStyle.blurple + ) + async def change_alliance(self, i: discord.Interaction, _): + nonlocal sel_alliance + sel_alliance = 10198 if sel_alliance == 10177 else 10177 + e.set_field_at( + 0, name="Transferring From", value=alliances.get(sel_alliance) + ) + e.remove_field(1) + await i.message.edit(embed=e) + + @discord.ui.button( + label="transfer to nation", style=discord.ButtonStyle.blurple + ) + async def transfer_to_nation(self, i: discord.Interaction, _): + class NationModal(discord.ui.Modal, title="Nation Details"): + nation = discord.ui.TextInput( + label="Nation ID/name", + style=discord.TextStyle.short, + placeholder="nation id or name", + max_length=32, + required=True, + ) + money = discord.ui.TextInput( + label="Money", + style=discord.TextStyle.short, + max_length=15, + placeholder="money", + required=False, + ) + food = discord.ui.TextInput( + label="Food", + style=discord.TextStyle.short, + max_length=15, + placeholder="food", + required=False, + ) + uranium = discord.ui.TextInput( + label="Uranium", + style=discord.TextStyle.short, + max_length=15, + placeholder="uranium", + required=False, + ) + coal = discord.ui.TextInput( + label="Coal", + style=discord.TextStyle.short, + max_length=15, + placeholder="coal", + required=False, + ) + iron = discord.ui.TextInput( + label="Iron", + style=discord.TextStyle.short, + max_length=15, + placeholder="iron", + required=False, + ) + oil = discord.ui.TextInput( + label="Oil", + style=discord.TextStyle.short, + max_length=15, + placeholder="oil", + required=False, + ) + bauxite = discord.ui.TextInput( + label="Bauxite", + style=discord.TextStyle.short, + max_length=15, + placeholder="bauxite", + required=False, + ) + lead = discord.ui.TextInput( + label="Lead", + style=discord.TextStyle.short, + max_length=15, + placeholder="lead", + required=False, + ) + munitions = discord.ui.TextInput( + label="Munitions", + style=discord.TextStyle.short, + max_length=15, + placeholder="munitions", + required=False, + ) + gasoline = discord.ui.TextInput( + label="Gasoline", + style=discord.TextStyle.short, + max_length=15, + placeholder="gasoline", + required=False, + ) + aluminum = discord.ui.TextInput( + label="Aluminum", + style=discord.TextStyle.short, + max_length=15, + placeholder="aluminum", + required=False, + ) + steel = discord.ui.TextInput( + label="Steel", + style=discord.TextStyle.short, + max_length=15, + placeholder="steel", + required=False, + ) + + def __init__(self, view: TransferView): + super().__init__(timeout=60) + self.view = view + + async def on_submit(self, interaction: discord.Interaction): + e = i.message.embeds[0] + e.description = ... + + @discord.ui.button(label="cancel", style=discord.ButtonStyle.red) + async def cancel(self, i: discord.Interaction, _): + await i.message.edit( + content="> transaction cancelled", embed=None, view=None + ) + self.stop() + async def setup(bot: Brahmos): await bot.add_cog(Banking(bot)) diff --git a/refill.json b/refill.json index bba4700..414dd20 100644 --- a/refill.json +++ b/refill.json @@ -16,5 +16,6 @@ 565984, 604712, 574264, - 103764 + 103764, + 608467 ] \ No newline at end of file