update refill cmd
This commit is contained in:
1 parent
2fd8d32335
commit
843e32067a
1 file changed
+184
-4
+184
-4
@@ -988,7 +988,8 @@ class Banking(commands.Cog):
|
|||||||
"nation_iron": nation.iron,
|
"nation_iron": nation.iron,
|
||||||
"nation_bauxite": nation.bauxite,
|
"nation_bauxite": nation.bauxite,
|
||||||
"nation_lead": nation.lead,
|
"nation_lead": nation.lead,
|
||||||
"nation_flag": nation.flag
|
"nation_flag": nation.flag,
|
||||||
|
"num_cities": nation.num_cities
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1230,6 +1231,11 @@ class Banking(commands.Cog):
|
|||||||
rev_obj["net_rev_txt"] = (
|
rev_obj["net_rev_txt"] = (
|
||||||
f"Coal: {round(coal):,}\nOil: {round(oil):,}\nLead: {round(lead):,}\nIron: {round(iron):,}\nBauxite: {round(bauxite):,}{starve_money_text}"
|
f"Coal: {round(coal):,}\nOil: {round(oil):,}\nLead: {round(lead):,}\nIron: {round(iron):,}\nBauxite: {round(bauxite):,}{starve_money_text}"
|
||||||
)
|
)
|
||||||
|
rev_obj["bauxite"] = bauxite
|
||||||
|
rev_obj["coal"] = coal
|
||||||
|
rev_obj["iron"] = iron
|
||||||
|
rev_obj["lead"] = lead
|
||||||
|
rev_obj["oil"] = oil
|
||||||
return rev_obj
|
return rev_obj
|
||||||
|
|
||||||
async def calculate_revenue(
|
async def calculate_revenue(
|
||||||
@@ -1370,9 +1376,183 @@ class Banking(commands.Cog):
|
|||||||
# Paginate the results
|
# Paginate the results
|
||||||
await ctx.paginate(pages=embeds)
|
await ctx.paginate(pages=embeds)
|
||||||
|
|
||||||
# @commands.has_any_role("The Croak Council", "Government")
|
@commands.has_any_role("The Croak Council", "Government")
|
||||||
# @commands.command()
|
@commands.command()
|
||||||
# async def refill(): ...
|
async def refill(self, ctx: CustomCtx, ids: commands.Greedy[int]):
|
||||||
|
revenue_data = await self.get_alliance_rev(ids)
|
||||||
|
await ctx.cbsend(revenue_data[0])
|
||||||
|
|
||||||
|
def calc_tosend(raw: float, on_nation: float):
|
||||||
|
return int(7 * abs(raw) - on_nation)
|
||||||
|
|
||||||
|
embeds = []
|
||||||
|
e = discord.Embed(
|
||||||
|
title="Raws to Refill",
|
||||||
|
timestamp=datetime.datetime.now(),
|
||||||
|
color=ctx.author.color,
|
||||||
|
)
|
||||||
|
total = {
|
||||||
|
"oil": 0,
|
||||||
|
"coal": 0,
|
||||||
|
"lead": 0,
|
||||||
|
"iron": 0,
|
||||||
|
"bauxite": 0
|
||||||
|
}
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
for data in revenue_data:
|
||||||
|
oil = data.get("oil")
|
||||||
|
coal = data.get("coal")
|
||||||
|
lead = data.get("lead")
|
||||||
|
iron = data.get("iron")
|
||||||
|
bauxite = data.get("bauxite")
|
||||||
|
data["refill"] = dict()
|
||||||
|
text = ""
|
||||||
|
if oil < 0:
|
||||||
|
tosend = calc_tosend(oil, data.get("nation_oil"))
|
||||||
|
data["refill"].update(oil=tosend)
|
||||||
|
text += f"{Emojis.oil} {tosend:,}\n"
|
||||||
|
total["oil"] += tosend
|
||||||
|
if coal < 0:
|
||||||
|
tosend = calc_tosend(coal, data.get("nation_coal"))
|
||||||
|
data["refill"].update(coal=tosend)
|
||||||
|
text += f"{Emojis.coal} {tosend:,}"
|
||||||
|
total["coal"] += tosend
|
||||||
|
if lead < 0:
|
||||||
|
tosend = calc_tosend(lead, data.get("nation_lead"))
|
||||||
|
data["refill"].update(lead=tosend)
|
||||||
|
text += f"{Emojis.lead} {tosend:,}"
|
||||||
|
total["lead"] += tosend
|
||||||
|
if iron < 0:
|
||||||
|
tosend = calc_tosend(iron, data.get("nation_iron"))
|
||||||
|
data["refill"].update(iron=tosend)
|
||||||
|
text += f"{Emojis.iron} {tosend:,}"
|
||||||
|
total["iron"] += tosend
|
||||||
|
if bauxite < 0:
|
||||||
|
tosend = calc_tosend(bauxite, data.get("nation_bauxite"))
|
||||||
|
data["refill"].update(bauxite=tosend)
|
||||||
|
text += f"{Emojis.bauxite} {tosend:,}"
|
||||||
|
total["bauxite"] += tosend
|
||||||
|
|
||||||
|
e.add_field(
|
||||||
|
name=f"{data.get('nation_name')} (c{data.get('num_cities')})",
|
||||||
|
value=(
|
||||||
|
f"[go to nation](https://politicsandwar.com/nation/id={rd.get('id')}) \n\n"
|
||||||
|
f"{text}"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
count += 1
|
||||||
|
if count == 9:
|
||||||
|
embeds.append(e)
|
||||||
|
e = discord.Embed(
|
||||||
|
title="Warchest Resources",
|
||||||
|
timestamp=datetime.datetime.now(),
|
||||||
|
color=ctx.author.color,
|
||||||
|
)
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
if count > 0:
|
||||||
|
embeds.append(e)
|
||||||
|
e = discord.Embed(
|
||||||
|
title="Nation List",
|
||||||
|
timestamp=datetime.datetime.now(),
|
||||||
|
color=ctx.author.color,
|
||||||
|
description="\u200b",
|
||||||
|
)
|
||||||
|
i = 0
|
||||||
|
for data in revenue_data:
|
||||||
|
i += 1
|
||||||
|
e.description += f"{i}. [{data.get('nation_name')}](https://politicsandwar.com/nation/id={data.get('nation_id')})\n"
|
||||||
|
|
||||||
|
e.description += (
|
||||||
|
"\n **Total raws to transfer**\n"
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
embeds.insert(0, e)
|
||||||
|
|
||||||
|
class ConfirmButton(discord.ui.Button):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
style=discord.ButtonStyle.green,
|
||||||
|
label="confirm",
|
||||||
|
bot: Brahmos,
|
||||||
|
p: Paginator,
|
||||||
|
):
|
||||||
|
super().__init__(style=style, label=label)
|
||||||
|
self.bot = bot
|
||||||
|
self.v = p
|
||||||
|
|
||||||
|
async def interaction_check(self, interaction: discord.Interaction) -> bool:
|
||||||
|
return interaction.user == ctx.author
|
||||||
|
|
||||||
|
async def callback(self, interaction: discord.Interaction):
|
||||||
|
|
||||||
|
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),
|
||||||
|
)
|
||||||
|
logmsg = ""
|
||||||
|
logstream = io.StringIO()
|
||||||
|
await interaction.response.defer()
|
||||||
|
self.label = "processing"
|
||||||
|
self.emoji = "<a:load:1275839759192686654>"
|
||||||
|
self.style = discord.ButtonStyle.blurple
|
||||||
|
self.v.clear_items()
|
||||||
|
self.v.add_item(self)
|
||||||
|
e = discord.Embed(
|
||||||
|
color=discord.Color.blurple(),
|
||||||
|
timestamp=datetime.datetime.utcnow(),
|
||||||
|
title="Transferring resources",
|
||||||
|
)
|
||||||
|
await interaction.message.edit(embed=e, view=self.v)
|
||||||
|
for data in revenue_data:
|
||||||
|
try:
|
||||||
|
if data["refill"]:
|
||||||
|
await kit.mutation(
|
||||||
|
"bankWithdraw",
|
||||||
|
{
|
||||||
|
"receiver": rd.get("id"),
|
||||||
|
"receiver_type": 1,
|
||||||
|
"note": "raws refill",
|
||||||
|
**data["refill"]
|
||||||
|
},
|
||||||
|
"id",
|
||||||
|
)
|
||||||
|
pprint.pprint(data, stream=logstream, indent=3)
|
||||||
|
logmsg += f"{data.get('nation_name')} <:tick:1275839665819353148>\n"
|
||||||
|
else:
|
||||||
|
pprint.pprint(
|
||||||
|
f"{data.get('nation_name')} (already filled)",
|
||||||
|
stream=logstream,
|
||||||
|
indent=3,
|
||||||
|
)
|
||||||
|
logmsg += f"{data.get('nation_name')} (already filled)\n"
|
||||||
|
e.description = logmsg
|
||||||
|
await interaction.message.edit(embed=e)
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
except Exception as err:
|
||||||
|
pprint.pprint(
|
||||||
|
f"{data.get('nation_name')} -> {err}", stream=logstream, indent=3
|
||||||
|
)
|
||||||
|
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"))
|
||||||
|
|
||||||
|
paginator = ctx.Paginator(pages=embeds)
|
||||||
|
await paginator.start(
|
||||||
|
ctx=ctx, custom_items=[ConfirmButton(bot=self.bot, p=paginator)]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def setup(bot: Brahmos):
|
async def setup(bot: Brahmos):
|
||||||
|
|||||||
Reference in new issue
Block a user