822 lines
35 KiB
Python
822 lines
35 KiB
Python
import asyncio
|
|
import datetime
|
|
import io
|
|
import json
|
|
import os
|
|
import pprint
|
|
import random
|
|
from typing import List, Literal, Optional
|
|
|
|
import aiohttp
|
|
import discord
|
|
import pnwkit
|
|
from discord.ext import commands
|
|
from discord.utils import format_dt
|
|
from numerize_denumerize import denumerize, numerize
|
|
|
|
from botclass import Brahmos, CustomCtx
|
|
from utils.base import BasicView
|
|
from utils.emojis import Emojis
|
|
from utils.paginator import Paginator
|
|
|
|
|
|
FILL: list = json.load(open("refill.json"))
|
|
|
|
|
|
class BaseMul:
|
|
money = 1000000
|
|
food = 5000
|
|
uranium = 75
|
|
gasoline = 1000
|
|
munitions = 1200
|
|
steel40 = 1575
|
|
steel100 = 1100
|
|
aluminum = 600
|
|
|
|
@classmethod
|
|
def values(cls):
|
|
return {
|
|
"money": cls.money,
|
|
"food": cls.food,
|
|
"uranium": cls.uranium,
|
|
"gasoline": cls.gasoline,
|
|
"munitions": cls.munitions,
|
|
"steel40": cls.steel40,
|
|
"steel100": cls.steel100,
|
|
"aluminum": cls.aluminum,
|
|
}
|
|
|
|
@classmethod
|
|
def calc(cls, cities: int, nation: pnwkit.Nation):
|
|
return {
|
|
"money": cls.money * cities - nation.money,
|
|
"food": cls.food * cities - nation.food,
|
|
"uranium": cls.uranium * cities - nation.uranium,
|
|
"gasoline": cls.gasoline * cities - nation.gasoline,
|
|
"munitions": cls.munitions * cities - nation.munitions,
|
|
"steel40": cls.steel40 * cities - nation.steel,
|
|
"steel100": cls.steel100 * cities - nation.steel,
|
|
"aluminum": cls.aluminum * cities - nation.aluminum,
|
|
}
|
|
|
|
|
|
class Banking(commands.Cog):
|
|
def __init__(self, bot: Brahmos):
|
|
self.bot = bot
|
|
self.kit = pnwkit.QueryKit(
|
|
api_key=os.getenv("pnwAPIKEY"),
|
|
bot_key=os.getenv("pnwBOTKEY"),
|
|
bot_key_api_key=os.getenv("pnwACCKEY"),
|
|
aiohttp_session=aiohttp.ClientSession(loop=self.bot.loop),
|
|
)
|
|
self.dkit = 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),
|
|
)
|
|
|
|
@commands.has_role(987770837627187250)
|
|
@commands.command()
|
|
async def tmilf(self, ctx: CustomCtx):
|
|
"""
|
|
transfer resources from MILF to DILF
|
|
"""
|
|
# fetch resources
|
|
resources = await self.kit.query(
|
|
"alliances",
|
|
{"id": 10177, "first": 1},
|
|
"money, food, uranium, coal, iron, oil, bauxite, iron, lead, munitions, gasoline, aluminum, steel",
|
|
)
|
|
resources = resources.alliances[0]
|
|
e = discord.Embed(
|
|
color=discord.Color.yellow(),
|
|
timestamp=datetime.datetime.utcnow(),
|
|
title="Approve Transaction",
|
|
)
|
|
e.description = (
|
|
"Transferring resources to **Damn I Love Frogs**\n"
|
|
f"{Emojis.money} {resources.money:,}\n"
|
|
f"{Emojis.food} {resources.food:,}\n"
|
|
f"{Emojis.uranium} {resources.uranium:,}\n"
|
|
f"{Emojis.coal} {resources.coal:,}\n"
|
|
f"{Emojis.iron} {resources.iron:,}\n"
|
|
f"{Emojis.oil} {resources.oil:,}\n"
|
|
f"{Emojis.bauxite} {resources.bauxite:,}\n"
|
|
f"{Emojis.lead} {resources.lead:,}\n"
|
|
f"{Emojis.munitions} {resources.munitions:,}\n"
|
|
f"{Emojis.gasoline} {resources.gasoline:,}\n"
|
|
f"{Emojis.aluminum} {resources.aluminum:,}\n"
|
|
f"{Emojis.steel} {resources.steel:,}"
|
|
)
|
|
|
|
class View(BasicView):
|
|
def __init__(
|
|
self,
|
|
timeout: float | None = 60,
|
|
clear: bool | None = False,
|
|
kit: pnwkit.QueryKit = None,
|
|
):
|
|
super().__init__(timeout, clear)
|
|
self.kit = kit
|
|
|
|
@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()
|
|
|
|
@discord.ui.button(label="confirm", style=discord.ButtonStyle.green)
|
|
async def confirm(self, i: discord.Interaction, _):
|
|
e.title = "Transaction Approved"
|
|
e.description = e.description.replace("Transferring", "Transferred")
|
|
e.color = discord.Color.green()
|
|
await self.kit.mutation(
|
|
"bankWithdraw",
|
|
{
|
|
"receiver": 10198,
|
|
"receiver_type": 2,
|
|
"money": resources.money,
|
|
"food": resources.food,
|
|
"uranium": resources.uranium,
|
|
"coal": resources.coal,
|
|
"iron": resources.iron,
|
|
"oil": resources.oil,
|
|
"bauxite": resources.bauxite,
|
|
"lead": resources.lead,
|
|
"munitions": resources.munitions,
|
|
"gasoline": resources.gasoline,
|
|
"aluminum": resources.aluminum,
|
|
"steel": resources.steel,
|
|
},
|
|
"id",
|
|
)
|
|
await i.message.edit(embed=e, view=None)
|
|
self.stop()
|
|
v = View(kit=self.kit)
|
|
v.author = ctx.message.author
|
|
m = await ctx.send(embed=e, view=v)
|
|
v.message = m
|
|
|
|
@commands.has_role(987770837627187250)
|
|
@commands.command(aliases=["wc"])
|
|
async def warchest(self, ctx: CustomCtx):
|
|
"""
|
|
refill warchest of all members
|
|
"""
|
|
data = await self.kit.query(
|
|
"alliances",
|
|
{"id": 10177, "first": 1},
|
|
"nations {id, nation_name, discord, money, food, steel, gasoline, munitions, aluminum, uranium, cities {name}}",
|
|
)
|
|
alliance = data.alliances[0]
|
|
nations = alliance.nations
|
|
|
|
resource_delta = []
|
|
kit = self.dkit
|
|
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(
|
|
{
|
|
"id": nation.id,
|
|
"discord": nation.discord or "N/A",
|
|
"cities": cities,
|
|
"name": nation.nation_name,
|
|
}
|
|
)
|
|
for key in delta:
|
|
if isinstance(delta[key], float):
|
|
delta[key] = int(delta[key])
|
|
resource_delta.append(delta)
|
|
|
|
embeds = []
|
|
e = discord.Embed(
|
|
title="Warchest Resources",
|
|
timestamp=datetime.datetime.now(),
|
|
color=ctx.author.color,
|
|
)
|
|
count = 0
|
|
|
|
for rd in resource_delta:
|
|
e.add_field(
|
|
name=rd.get("name"),
|
|
value=(
|
|
f"[{rd.get('discord')}](https://politicsandwar.com/nation/id={rd.get('id')}) (c{rd.get('cities')})\n\n"
|
|
f"{Emojis.money} {rd.get('money'):,}\n"
|
|
f"{Emojis.food} {rd.get('food'):,}\n"
|
|
f"{Emojis.uranium} {rd.get('uranium'):,}\n"
|
|
f"{Emojis.munitions} {rd.get('munitions'):,}\n"
|
|
f"{Emojis.gasoline} {rd.get('gasoline'):,}\n"
|
|
f"{Emojis.aluminum} {rd.get('aluminum'):,}\n"
|
|
f"{Emojis.steel} {rd.get('steel100'):,}"
|
|
),
|
|
)
|
|
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 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"] += max(0, rd.get("money"))
|
|
total["steel100"] += max(0, rd.get("steel100"))
|
|
total["steel40"] += max(0, rd.get("steel40"))
|
|
total["aluminum"] += max(0, rd.get("aluminum"))
|
|
total["food"] += max(0, rd.get("food"))
|
|
total["munitions"] += max(0, rd.get("munitions"))
|
|
total["uranium"] += max(0, rd.get("uranium"))
|
|
total["gasoline"] += max(0, rd.get("gasoline"))
|
|
|
|
e.description += (
|
|
"\n **Total warchest to transfer**\n"
|
|
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,
|
|
):
|
|
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:1275827052909432887>"
|
|
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 rd in resource_delta:
|
|
for k in rd: # remove negatives
|
|
if isinstance(rd[k], int) and (rd[k] < 0):
|
|
rd[k] = 0
|
|
try:
|
|
sum = (
|
|
rd.get("money")
|
|
+ rd.get("food")
|
|
+ rd.get("uranium")
|
|
+ rd.get("gasoline")
|
|
+ rd.get("munitions")
|
|
+ rd.get("aluminum")
|
|
+ rd.get("steel100")
|
|
)
|
|
if sum !=0:
|
|
await kit.mutation(
|
|
"bankWithdraw",
|
|
{
|
|
"receiver": rd.get("id"),
|
|
"receiver_type": 1,
|
|
"money": rd.get("money"),
|
|
"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)
|
|
except Exception as err:
|
|
pprint.pprint(
|
|
f"{rd.get('name')} -> {err}", stream=logstream, indent=3
|
|
)
|
|
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)]
|
|
)
|
|
|
|
@commands.has_role(987770837627187250)
|
|
@commands.command()
|
|
async def rss(
|
|
self,
|
|
ctx: CustomCtx,
|
|
ids: commands.Greedy[int] = None,
|
|
*,
|
|
nation_names: str | None = None,
|
|
):
|
|
"""get resources of a nation in alliance
|
|
|
|
Args:
|
|
ids (commands.Greedy[int]): ids of nations
|
|
"""
|
|
if ids is None:
|
|
ids = []
|
|
|
|
embeds = []
|
|
if nation_names:
|
|
nation_names = nation_names.split(",")
|
|
result = await self.kit.query(
|
|
"nations",
|
|
{"nation_name": nation_names},
|
|
"id"
|
|
)
|
|
for nation in result.nations:
|
|
ids.append(nation.id)
|
|
if not ids:
|
|
ids = FILL
|
|
nations = []
|
|
if 103764 in ids:
|
|
ids.remove(103764)
|
|
kit = self.dkit
|
|
result = await kit.query(
|
|
"nations",
|
|
{"id": 103764, "first": 1},
|
|
"id, nation_name,leader_name, discord,money, flag, food, uranium, coal, iron, oil, bauxite, iron, lead, munitions, gasoline, aluminum, steel, num_cities, credits",
|
|
)
|
|
nations.extend(result.nations)
|
|
kit = self.kit
|
|
result = await kit.query(
|
|
"nations",
|
|
{"id": ids},
|
|
"id, nation_name,leader_name, discord,money, flag, food, uranium, coal, iron, oil, bauxite, iron, lead, munitions, gasoline, aluminum, steel, num_cities, credits",
|
|
)
|
|
nations.extend(result.nations)
|
|
for nation in nations:
|
|
e = discord.Embed(
|
|
title=f"Resources for {nation.nation_name} c({nation.num_cities})",
|
|
color=ctx.author.color,
|
|
timestamp=datetime.datetime.utcnow(),
|
|
url=f"https://politicsandwar.com/nation/id={nation.id}",
|
|
)
|
|
e.set_thumbnail(url=nation.flag)
|
|
e.description = (
|
|
f"{Emojis.money} {nation.money:,}\n"
|
|
f"{Emojis.food} {nation.food:,}\n"
|
|
f"{Emojis.uranium} {nation.uranium:,}\n"
|
|
f"{Emojis.coal} {nation.coal:,}\n"
|
|
f"{Emojis.iron} {nation.iron:,}\n"
|
|
f"{Emojis.oil} {nation.oil:,}\n"
|
|
f"{Emojis.bauxite} {nation.bauxite:,}\n"
|
|
f"{Emojis.lead} {nation.lead:,}\n"
|
|
f"{Emojis.munitions} {nation.munitions:,}\n"
|
|
f"{Emojis.gasoline} {nation.gasoline:,}\n"
|
|
f"{Emojis.aluminum} {nation.aluminum:,}\n"
|
|
f"{Emojis.steel} {nation.steel:,}\n"
|
|
f"{Emojis.credits} {nation.credits}\n"
|
|
)
|
|
e.set_footer(text=nation.leader_name, icon_url=self.bot.user.avatar)
|
|
embeds.append(e)
|
|
|
|
await ctx.paginate(pages=embeds)
|
|
|
|
@commands.has_role(987770837627187250)
|
|
@commands.command()
|
|
async def bank(self, ctx: CustomCtx):
|
|
"""sends bank resources"""
|
|
m_resources = await self.kit.query(
|
|
"alliances",
|
|
{"id": 10177, "first": 1},
|
|
"id, name, flag, money, food, uranium, coal, iron, oil, bauxite, iron, lead, munitions, gasoline, aluminum, steel",
|
|
)
|
|
m_resources = m_resources.alliances[0]
|
|
d_resources = await self.dkit.query(
|
|
"alliances",
|
|
{"id": 10198, "first": 1},
|
|
"id, name,flag, money, food, uranium, coal, iron, oil, bauxite, iron, lead, munitions, gasoline, aluminum, steel",
|
|
)
|
|
d_resources = d_resources.alliances[0]
|
|
|
|
embeds = []
|
|
for resources in [d_resources, m_resources]:
|
|
e = discord.Embed(
|
|
title=f"Resources for {resources.name}",
|
|
timestamp=datetime.datetime.utcnow(),
|
|
color=ctx.author.color,
|
|
url=f"https://politicsandwar.com/alliance/id={resources.id}",
|
|
)
|
|
e.description = (
|
|
f"{Emojis.money} {resources.money:,}\n"
|
|
f"{Emojis.food} {resources.food:,}\n"
|
|
f"{Emojis.uranium} {resources.uranium:,}\n"
|
|
f"{Emojis.coal} {resources.coal:,}\n"
|
|
f"{Emojis.iron} {resources.iron:,}\n"
|
|
f"{Emojis.oil} {resources.oil:,}\n"
|
|
f"{Emojis.bauxite} {resources.bauxite:,}\n"
|
|
f"{Emojis.lead} {resources.lead:,}\n"
|
|
f"{Emojis.munitions} {resources.munitions:,}\n"
|
|
f"{Emojis.gasoline} {resources.gasoline:,}\n"
|
|
f"{Emojis.aluminum} {resources.aluminum:,}\n"
|
|
f"{Emojis.steel} {resources.steel:,}"
|
|
)
|
|
e.set_thumbnail(url=resources.flag)
|
|
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"}
|
|
m_flag = (await self.kit.query(
|
|
"alliances", {"id": 10177, "first": 1}, "flag"
|
|
)).alliances[0].flag
|
|
d_flag = (await self.dkit.query(
|
|
"alliances", {"id": 10198, "first": 1}, "flag"
|
|
)).alliances[0].flag
|
|
e = discord.Embed(
|
|
timestamp=datetime.datetime.now(),
|
|
title=f"Transfer Resources (`EXPIRES IN` {format_dt(datetime.datetime.now() + datetime.timedelta(seconds=200), 'R')})",
|
|
color=ctx.author.color,
|
|
)
|
|
e.add_field(name="Transferring From", value=alliances.get(10177))
|
|
e.set_thumbnail(url=m_flag)
|
|
|
|
class TransferView(BasicView):
|
|
def __init__(self, timeout: float | None = 200, clear: bool | None = False, kit: pnwkit.QueryKit = None, dkit: pnwkit.QueryKit = None):
|
|
super().__init__(timeout=timeout, clear=clear)
|
|
self.alliance_id = None
|
|
self.nation_id = None
|
|
self.resources = None
|
|
self.kit = kit
|
|
self.dkit = dkit
|
|
self.sel_alliance = 10177
|
|
|
|
@discord.ui.button(
|
|
label="change selected alliance", style=discord.ButtonStyle.gray
|
|
)
|
|
async def change_alliance(self, i: discord.Interaction, _):
|
|
self.sel_alliance = 10198 if self.sel_alliance == 10177 else 10177
|
|
flag = d_flag if self.sel_alliance == 10198 else m_flag
|
|
e = i.message.embeds[0]
|
|
e.set_thumbnail(url=flag)
|
|
e.set_field_at(
|
|
0, name="Transferring From", value=alliances.get(self.sel_alliance)
|
|
)
|
|
e.remove_field(1)
|
|
await i.message.edit(embed=e)
|
|
await i.response.defer()
|
|
|
|
@discord.ui.button(
|
|
label="transfer to nation", style=discord.ButtonStyle.blurple, row=1
|
|
)
|
|
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,
|
|
)
|
|
rss = discord.ui.TextInput(
|
|
label="Resources",
|
|
style=discord.TextStyle.long,
|
|
max_length=1024,
|
|
placeholder=(
|
|
"money: 1000\n"
|
|
"food: 1000\n"
|
|
"... and so on"
|
|
),
|
|
required=True,
|
|
)
|
|
|
|
|
|
def __init__(self, view: TransferView, kit: pnwkit.QueryKit):
|
|
super().__init__(timeout=200)
|
|
self.view = view
|
|
self.kit = kit
|
|
|
|
async def on_submit(self, i: discord.Interaction):
|
|
await i.response.defer()
|
|
e = i.message.embeds[0]
|
|
inp = self.nation.value
|
|
if inp.isdigit():
|
|
nation = await self.kit.query(
|
|
"nations",
|
|
{"id": int(inp), "first": 1},
|
|
"id, nation_name, leader_name, flag"
|
|
)
|
|
else:
|
|
nation = await self.kit.query(
|
|
"nations",
|
|
{"nation_name": inp, "first": 1},
|
|
"id, nation_name, leader_name, flag"
|
|
)
|
|
nation = nation.nations[0]
|
|
rss = self.rss.value.split("\n")
|
|
resources = dict()
|
|
for r in rss:
|
|
if ":" in r:
|
|
key, value = r.split(":")
|
|
else:
|
|
key, value = r.split(" ")
|
|
key = key.strip().lower()
|
|
value = value.replace(',', '')
|
|
value = int(denumerize.denumerize(value.upper()))
|
|
resources[key] = value
|
|
|
|
|
|
e.description = (
|
|
"**Resources** \n"
|
|
f"{Emojis.money} {resources.get('money', 0):,}\n"
|
|
f"{Emojis.food} {resources.get('food', 0):,}\n"
|
|
f"{Emojis.uranium} {resources.get('uranium', 0):,}\n"
|
|
f"{Emojis.coal} {resources.get('coal', 0):,}\n"
|
|
f"{Emojis.iron} {resources.get('iron', 0):,}\n"
|
|
f"{Emojis.oil} {resources.get('oil', 0):,}\n"
|
|
f"{Emojis.bauxite} {resources.get('bauxite', 0):,}\n"
|
|
f"{Emojis.lead} {resources.get('lead', 0):,}\n"
|
|
f"{Emojis.munitions} {resources.get('munitions', 0):,}\n"
|
|
f"{Emojis.gasoline} {resources.get('gasoline', 0):,}\n"
|
|
f"{Emojis.aluminum} {resources.get('aluminum', 0):,}\n"
|
|
f"{Emojis.steel} {resources.get('steel', 0):,}\n"
|
|
)
|
|
|
|
e.set_image(url=nation.flag)
|
|
e.add_field(
|
|
name="Transferring To",
|
|
value=f"[**{nation.nation_name}**](https://politicsandwar.com/nation/id={nation.id})",
|
|
inline=False,
|
|
)
|
|
e.add_field(
|
|
name="Leader",
|
|
value=nation.leader_name,
|
|
inline=True,
|
|
)
|
|
self.view.nation_id = nation.id
|
|
self.view.resources = {
|
|
"money" : resources.get('money', 0),
|
|
"food" : resources.get('food', 0),
|
|
"uranium" : resources.get('uranium', 0),
|
|
"coal" : resources.get('coal', 0),
|
|
"iron" : resources.get('iron', 0),
|
|
"oil" : resources.get('oil', 0),
|
|
"bauxite" : resources.get('bauxite', 0),
|
|
"lead" : resources.get('lead', 0),
|
|
"munitions" : resources.get('munitions', 0),
|
|
"gasoline" : resources.get('gasoline', 0),
|
|
"aluminum" : resources.get('aluminum', 0),
|
|
"steel" : resources.get('steel', 0),
|
|
}
|
|
self.view.confirm.disabled = False
|
|
self.view.transfer_to_nation.disabled = True
|
|
self.view.transfer_to_alliance.disabled = True
|
|
self.view.change_alliance.disabled = True
|
|
await i.message.edit(embed=e, view=self.view)
|
|
await i.response.send_modal(NationModal(self, self.kit))
|
|
|
|
@discord.ui.button(label="transfer to alliance", style=discord.ButtonStyle.blurple, row=1)
|
|
async def transfer_to_alliance(self, i: discord.Interaction, _):
|
|
class AllianceModal(discord.ui.Modal, title="Alliance Details"):
|
|
def __init__(self, view: TransferView, kit: pnwkit.QueryKit):
|
|
super().__init__(timeout=200)
|
|
self.view = view
|
|
self.kit = kit
|
|
|
|
alliance = discord.ui.TextInput(
|
|
label="Alliance ID/name",
|
|
style=discord.TextStyle.short,
|
|
placeholder="alliance id or name",
|
|
max_length=32,
|
|
required=True,
|
|
)
|
|
rss = discord.ui.TextInput(
|
|
label="Resources",
|
|
style=discord.TextStyle.long,
|
|
max_length=1024,
|
|
placeholder=(
|
|
"money: 1000\n"
|
|
"food: 1000\n"
|
|
"... and so on"
|
|
),
|
|
required=True,
|
|
)
|
|
|
|
async def on_submit(self, i: discord.Interaction):
|
|
await i.response.defer()
|
|
e = i.message.embeds[0]
|
|
inp = self.alliance.value
|
|
if inp.isdigit():
|
|
alliance = await self.kit.query(
|
|
"alliances",
|
|
{"id": int(inp), "first": 1},
|
|
"id, name, flag"
|
|
)
|
|
else:
|
|
alliance = await self.kit.query(
|
|
"alliances",
|
|
{"name": inp, "first": 1},
|
|
"id, name, flag"
|
|
)
|
|
alliance = alliance.alliances[0]
|
|
rss = self.rss.value.split("\n")
|
|
resources = dict()
|
|
for r in rss:
|
|
if ":" in r:
|
|
key, value = r.split(":")
|
|
else:
|
|
key, value = r.split(" ")
|
|
key = key.strip().lower()
|
|
value = value.replace(',', '')
|
|
value = int(denumerize.denumerize(value.upper()))
|
|
resources[key] = value
|
|
|
|
e.description = (
|
|
"**Resources** \n"
|
|
f"{Emojis.money} {resources.get('money', 0):,}\n"
|
|
f"{Emojis.food} {resources.get('food', 0):,}\n"
|
|
f"{Emojis.uranium} {resources.get('uranium', 0):,}\n"
|
|
f"{Emojis.coal} {resources.get('coal', 0):,}\n"
|
|
f"{Emojis.iron} {resources.get('iron', 0):,}\n"
|
|
f"{Emojis.oil} {resources.get('oil', 0):,}\n"
|
|
f"{Emojis.bauxite} {resources.get('bauxite', 0):,}\n"
|
|
f"{Emojis.lead} {resources.get('lead', 0):,}\n"
|
|
f"{Emojis.munitions} {resources.get('munitions', 0):,}\n"
|
|
f"{Emojis.gasoline} {resources.get('gasoline', 0):,}\n"
|
|
f"{Emojis.aluminum} {resources.get('aluminum', 0):,}\n"
|
|
f"{Emojis.steel} {resources.get('steel', 0):,}\n"
|
|
|
|
)
|
|
e.set_image(url=alliance.flag)
|
|
e.add_field(
|
|
name="Transferring To",
|
|
value=f"[**{alliance.name}**](https://politicsandwar.com/alliance/id={alliance.id})",
|
|
)
|
|
self.view.alliance_id = alliance.id
|
|
self.view.resources = {
|
|
"money" : resources.get('money', 0),
|
|
"food" : resources.get('food', 0),
|
|
"uranium" : resources.get('uranium', 0),
|
|
"coal" : resources.get('coal', 0),
|
|
"iron" : resources.get('iron', 0),
|
|
"oil" : resources.get('oil', 0),
|
|
"bauxite" : resources.get('bauxite', 0),
|
|
"lead" : resources.get('lead', 0),
|
|
"munitions" : resources.get('munitions', 0),
|
|
"gasoline" : resources.get('gasoline', 0),
|
|
"aluminum" : resources.get('aluminum', 0),
|
|
"steel" : resources.get('steel', 0),
|
|
}
|
|
self.view.confirm.disabled = False
|
|
self.view.transfer_to_nation.disabled = True
|
|
self.view.transfer_to_alliance.disabled = True
|
|
self.view.change_alliance.disabled = True
|
|
await i.message.edit(embed=e, view=self.view)
|
|
await i.response.send_modal(AllianceModal(self, self.kit))
|
|
|
|
|
|
@discord.ui.button(label="confirm", style=discord.ButtonStyle.blurple, disabled=True, row=2)
|
|
async def confirm(self, i: discord.Interaction, _):
|
|
kit = self.kit if self.sel_alliance == 10177 else self.dkit
|
|
if self.nation_id:
|
|
await kit.mutation(
|
|
"bankWithdraw",
|
|
{
|
|
"receiver": self.nation_id,
|
|
"receiver_type": 1,
|
|
**self.resources,
|
|
},
|
|
"id",
|
|
)
|
|
url = f"https://politicsandwar.com/nation/id={self.nation_id}"
|
|
elif self.alliance_id:
|
|
await kit.mutation(
|
|
"bankWithdraw",
|
|
{
|
|
"receiver": self.alliance_id,
|
|
"receiver_type": 2,
|
|
**self.resources,
|
|
},
|
|
"id",
|
|
)
|
|
url = f"https://politicsandwar.com/alliance/id={self.alliance_id}"
|
|
e = i.message.embeds[0]
|
|
e.title = "Transaction Completed"
|
|
e.color = discord.Color.green()
|
|
e.description = (
|
|
"Resources have been transferred successfully\n"
|
|
f"Target => {url}\n\n"
|
|
f"{Emojis.money} {self.resources.get('money'):,}\n"
|
|
f"{Emojis.food} {self.resources.get('food'):,}\n"
|
|
f"{Emojis.uranium} {self.resources.get('uranium'):,}\n"
|
|
f"{Emojis.coal} {self.resources.get('coal'):,}\n"
|
|
f"{Emojis.iron} {self.resources.get('iron'):,}\n"
|
|
f"{Emojis.oil} {self.resources.get('oil'):,}\n"
|
|
f"{Emojis.bauxite} {self.resources.get('bauxite'):,}\n"
|
|
f"{Emojis.lead} {self.resources.get('lead'):,}\n"
|
|
f"{Emojis.munitions} {self.resources.get('munitions'):,}\n"
|
|
f"{Emojis.gasoline} {self.resources.get('gasoline'):,}\n"
|
|
f"{Emojis.aluminum} {self.resources.get('aluminum'):,}\n"
|
|
f"{Emojis.steel} {self.resources.get('steel'):,}\n"
|
|
)
|
|
await i.message.edit(embed=e, view=None)
|
|
await i.response.defer()
|
|
|
|
@discord.ui.button(label="cancel", style=discord.ButtonStyle.red, row=2)
|
|
async def cancel(self, i: discord.Interaction, _):
|
|
await i.message.edit(
|
|
content="> transaction cancelled", embed=None, view=None
|
|
)
|
|
self.stop()
|
|
|
|
v = TransferView(kit=self.kit, dkit=self.dkit)
|
|
v.author = ctx.message.author
|
|
m = await ctx.send(embed=e, view=v)
|
|
v.message = m
|
|
|
|
# @commands.has_role(987770837627187250)
|
|
# @commands.command()
|
|
# async def refill(self, ctx: CustomCtx, option: str, commands.Greedy[Int] = None, *, names: str = None):
|
|
|
|
|
|
|
|
async def setup(bot: Brahmos):
|
|
await bot.add_cog(Banking(bot))
|