add offshore in bank cmd
This commit is contained in:
1 parent
a4150cf9a5
commit
ae8d1708c4
2 files changed
+85
-49
No files matched your search
@@ -7,3 +7,4 @@ store
|
|||||||
*.pyd
|
*.pyd
|
||||||
.venv
|
.venv
|
||||||
krampus_calc.java
|
krampus_calc.java
|
||||||
|
pyrightconfig.json
|
||||||
+84
-49
@@ -1,30 +1,29 @@
|
|||||||
from ast import alias
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import datetime
|
import datetime
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import pprint
|
import pprint
|
||||||
import random
|
|
||||||
import traceback
|
from typing import List, Optional
|
||||||
from typing import List, Literal, Optional
|
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import discord
|
import discord
|
||||||
import asyncpg
|
|
||||||
import pnwkit
|
import pnwkit
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord import app_commands
|
|
||||||
from discord.utils import format_dt
|
from discord.utils import format_dt
|
||||||
from numerize_denumerize import denumerize, numerize
|
from numerize_denumerize import denumerize
|
||||||
import math
|
import math
|
||||||
|
|
||||||
|
from pnwkit.data import Alliance
|
||||||
|
|
||||||
from botclass import Brahmos, CustomCtx
|
from botclass import Brahmos, CustomCtx
|
||||||
from utils.base import BasicView
|
from utils.base import BasicView
|
||||||
from utils.emojis import Emojis
|
from utils.emojis import Emojis
|
||||||
from utils.paginator import Paginator
|
from utils.paginator import Paginator
|
||||||
|
|
||||||
OFFSHORE_ID = 10198
|
DILF_ID = 10198
|
||||||
|
MILF_ID = 10177
|
||||||
|
|
||||||
|
|
||||||
class BaseMul:
|
class BaseMul:
|
||||||
@@ -102,7 +101,13 @@ class Banking(commands.Cog):
|
|||||||
bot_key_api_key=os.getenv("pnwACCKEY"),
|
bot_key_api_key=os.getenv("pnwACCKEY"),
|
||||||
aiohttp_session=aiohttp.ClientSession(loop=self.bot.loop),
|
aiohttp_session=aiohttp.ClientSession(loop=self.bot.loop),
|
||||||
)
|
)
|
||||||
self.WARCHEST_IDS = None
|
self.WARCHEST_IDS = []
|
||||||
|
|
||||||
|
async def get_kit_alliance(self, kit: pnwkit.QueryKit) -> pnwkit.data.Alliance:
|
||||||
|
res = await kit.query(
|
||||||
|
"me", dict(), "nation {nation_name, id, flag, alliance {name, id, flag}}"
|
||||||
|
)
|
||||||
|
return res.me.nation.alliance
|
||||||
|
|
||||||
async def cog_load(self):
|
async def cog_load(self):
|
||||||
"""Called when the cog is loaded."""
|
"""Called when the cog is loaded."""
|
||||||
@@ -129,13 +134,13 @@ class Banking(commands.Cog):
|
|||||||
# fetch resources
|
# fetch resources
|
||||||
resources = await self.kit.query(
|
resources = await self.kit.query(
|
||||||
"alliances",
|
"alliances",
|
||||||
{"id": 10177, "first": 1},
|
{"id": MILF_ID, "first": 1},
|
||||||
"money, food, uranium, coal, iron, oil, bauxite, iron, lead, munitions, gasoline, aluminum, steel",
|
"money, food, uranium, coal, iron, oil, bauxite, iron, lead, munitions, gasoline, aluminum, steel",
|
||||||
)
|
)
|
||||||
resources = resources.alliances[0]
|
resources = resources.alliances[0]
|
||||||
e = discord.Embed(
|
e = discord.Embed(
|
||||||
color=discord.Color.yellow(),
|
color=discord.Color.yellow(),
|
||||||
timestamp=datetime.datetime.utcnow(),
|
timestamp=datetime.datetime.now(),
|
||||||
title="Approve Transaction",
|
title="Approve Transaction",
|
||||||
)
|
)
|
||||||
e.description = (
|
e.description = (
|
||||||
@@ -179,7 +184,7 @@ class Banking(commands.Cog):
|
|||||||
await self.kit.mutation(
|
await self.kit.mutation(
|
||||||
"bankWithdraw",
|
"bankWithdraw",
|
||||||
{
|
{
|
||||||
"receiver": OFFSHORE_ID,
|
"receiver": DILF_ID,
|
||||||
"receiver_type": 2,
|
"receiver_type": 2,
|
||||||
"money": resources.money,
|
"money": resources.money,
|
||||||
"food": resources.food,
|
"food": resources.food,
|
||||||
@@ -212,7 +217,7 @@ class Banking(commands.Cog):
|
|||||||
"""
|
"""
|
||||||
data = await self.kit.query(
|
data = await self.kit.query(
|
||||||
"alliances",
|
"alliances",
|
||||||
{"id": 10177, "first": 1},
|
{"id": MILF_ID, "first": 1},
|
||||||
"nations {id, nation_name, discord, money, food, steel, gasoline, munitions, aluminum, uranium, cities {name}}",
|
"nations {id, nation_name, discord, money, food, steel, gasoline, munitions, aluminum, uranium, cities {name}}",
|
||||||
)
|
)
|
||||||
alliance = data.alliances[0]
|
alliance = data.alliances[0]
|
||||||
@@ -222,7 +227,7 @@ class Banking(commands.Cog):
|
|||||||
kit = self.dkit
|
kit = self.dkit
|
||||||
dilf = await kit.query(
|
dilf = await kit.query(
|
||||||
"nations",
|
"nations",
|
||||||
{"alliance_id": 10198},
|
{"alliance_id": DILF_ID},
|
||||||
"id, nation_name, discord, money, food, steel, gasoline, munitions, aluminum, uranium, cities {name}",
|
"id, nation_name, discord, money, food, steel, gasoline, munitions, aluminum, uranium, cities {name}",
|
||||||
)
|
)
|
||||||
nations.extend(dilf.nations)
|
nations.extend(dilf.nations)
|
||||||
@@ -346,7 +351,7 @@ class Banking(commands.Cog):
|
|||||||
|
|
||||||
async def callback(self, interaction: discord.Interaction):
|
async def callback(self, interaction: discord.Interaction):
|
||||||
kit = pnwkit.QueryKit(
|
kit = pnwkit.QueryKit(
|
||||||
api_key=os.getenv("pnwOFFKEY"),
|
api_key=os.getenv("pnwDILFKEY"),
|
||||||
bot_key=os.getenv("pnwBOTKEY"),
|
bot_key=os.getenv("pnwBOTKEY"),
|
||||||
bot_key_api_key=os.getenv("pnwACCKEY"),
|
bot_key_api_key=os.getenv("pnwACCKEY"),
|
||||||
aiohttp_session=aiohttp.ClientSession(loop=self.bot.loop),
|
aiohttp_session=aiohttp.ClientSession(loop=self.bot.loop),
|
||||||
@@ -361,7 +366,7 @@ class Banking(commands.Cog):
|
|||||||
self.v.add_item(self)
|
self.v.add_item(self)
|
||||||
e = discord.Embed(
|
e = discord.Embed(
|
||||||
color=discord.Color.blurple(),
|
color=discord.Color.blurple(),
|
||||||
timestamp=datetime.datetime.utcnow(),
|
timestamp=datetime.datetime.now(),
|
||||||
title="Transferring resources",
|
title="Transferring resources",
|
||||||
)
|
)
|
||||||
await interaction.message.edit(embed=e, view=self.v)
|
await interaction.message.edit(embed=e, view=self.v)
|
||||||
@@ -457,22 +462,20 @@ class Banking(commands.Cog):
|
|||||||
embeds = []
|
embeds = []
|
||||||
nations = []
|
nations = []
|
||||||
if nation_names:
|
if nation_names:
|
||||||
nation_names = nation_names.split(",")
|
nation_list = nation_names.split(",")
|
||||||
result = await self.kit.query(
|
result = await self.kit.query("nations", {"nation_name": nation_list}, "id")
|
||||||
"nations", {"nation_name": nation_names}, "id"
|
|
||||||
)
|
|
||||||
for nation in result.nations:
|
for nation in result.nations:
|
||||||
ids.append(nation.id)
|
ids.append(nation.id)
|
||||||
if not ids:
|
if not ids:
|
||||||
result = await self.dkit.query(
|
result = await self.dkit.query(
|
||||||
"nations",
|
"nations",
|
||||||
{"alliance_id": 10198},
|
{"alliance_id": DILF_ID},
|
||||||
"id, nation_name,leader_name, discord,money, flag, food, uranium, coal, iron, oil, bauxite, iron, lead, munitions, gasoline, aluminum, steel, num_cities, credits",
|
"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)
|
nations.extend(result.nations)
|
||||||
result = await self.kit.query(
|
result = await self.kit.query(
|
||||||
"nations",
|
"nations",
|
||||||
{"alliance_id": 10177},
|
{"alliance_id": MILF_ID},
|
||||||
"id, nation_name,leader_name, discord,money, flag, food, uranium, coal, iron, oil, bauxite, iron, lead, munitions, gasoline, aluminum, steel, num_cities, credits",
|
"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)
|
nations.extend(result.nations)
|
||||||
@@ -517,22 +520,32 @@ class Banking(commands.Cog):
|
|||||||
"""sends bank resources"""
|
"""sends bank resources"""
|
||||||
m_resources = await self.kit.query(
|
m_resources = await self.kit.query(
|
||||||
"alliances",
|
"alliances",
|
||||||
{"id": 10177, "first": 1},
|
{"id": MILF_ID, "first": 1},
|
||||||
"id, name, flag, money, food, uranium, coal, iron, oil, bauxite, iron, lead, munitions, gasoline, aluminum, steel",
|
"id, name, flag, money, food, uranium, coal, iron, oil, bauxite, iron, lead, munitions, gasoline, aluminum, steel",
|
||||||
)
|
)
|
||||||
m_resources = m_resources.alliances[0]
|
m_resources = m_resources.alliances[0]
|
||||||
d_resources = await self.dkit.query(
|
d_resources = await self.dkit.query(
|
||||||
"alliances",
|
"alliances",
|
||||||
{"id": 10198, "first": 1},
|
{"id": DILF_ID, "first": 1},
|
||||||
"id, name,flag, money, food, uranium, coal, iron, oil, bauxite, iron, lead, munitions, gasoline, aluminum, steel",
|
"id, name,flag, money, food, uranium, coal, iron, oil, bauxite, iron, lead, munitions, gasoline, aluminum, steel",
|
||||||
)
|
)
|
||||||
d_resources = d_resources.alliances[0]
|
d_resources = d_resources.alliances[0]
|
||||||
|
|
||||||
|
resources_list = [d_resources, m_resources]
|
||||||
|
if self.okit:
|
||||||
|
o_id = (await self.get_kit_alliance(self.okit)).id
|
||||||
|
o_resources = await self.okit.query(
|
||||||
|
"alliances",
|
||||||
|
{"id": o_id, "first": 1},
|
||||||
|
"id, name,flag, money, food, uranium, coal, iron, oil, bauxite, iron, lead, munitions, gasoline, aluminum, steel",
|
||||||
|
)
|
||||||
|
resources_list.append(o_resources.alliances[0])
|
||||||
|
|
||||||
embeds = []
|
embeds = []
|
||||||
for resources in [d_resources, m_resources]:
|
for resources in resources_list:
|
||||||
e = discord.Embed(
|
e = discord.Embed(
|
||||||
title=f"Resources for {resources.name}",
|
title=f"Resources for {resources.name}",
|
||||||
timestamp=datetime.datetime.utcnow(),
|
timestamp=datetime.datetime.now(),
|
||||||
color=ctx.author.color,
|
color=ctx.author.color,
|
||||||
url=f"https://politicsandwar.com/alliance/id={resources.id}",
|
url=f"https://politicsandwar.com/alliance/id={resources.id}",
|
||||||
)
|
)
|
||||||
@@ -566,24 +579,21 @@ class Banking(commands.Cog):
|
|||||||
444896160105103361,
|
444896160105103361,
|
||||||
]:
|
]:
|
||||||
return await ctx.send("-# You are not in list of authorized users")
|
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 = (
|
milf = await self.get_kit_alliance(self.kit)
|
||||||
(await self.kit.query("alliances", {"id": 10177, "first": 1}, "flag"))
|
|
||||||
.alliances[0]
|
alliances = {MILF_ID: "Man I Love Frogs", DILF_ID: "Damn I Love Frogs"}
|
||||||
.flag
|
if hasattr(self, "okit"):
|
||||||
)
|
offshore = await self.get_kit_alliance(self.okit)
|
||||||
d_flag = (
|
alliances.update({offshore.id: offshore.name})
|
||||||
(await self.dkit.query("alliances", {"id": 10198, "first": 1}, "flag"))
|
|
||||||
.alliances[0]
|
|
||||||
.flag
|
|
||||||
)
|
|
||||||
e = discord.Embed(
|
e = discord.Embed(
|
||||||
timestamp=datetime.datetime.now(),
|
timestamp=datetime.datetime.now(),
|
||||||
title=f"Transfer Resources (`EXPIRES IN` {format_dt(datetime.datetime.now() + datetime.timedelta(seconds=200), 'R')})",
|
title=f"Transfer Resources (`EXPIRES IN` {format_dt(datetime.datetime.now() + datetime.timedelta(seconds=200), 'R')})",
|
||||||
color=ctx.author.color,
|
color=ctx.author.color,
|
||||||
)
|
)
|
||||||
e.add_field(name="Transferring From", value=alliances.get(10177))
|
e.add_field(name="Transferring From", value=alliances.get(MILF_ID))
|
||||||
e.set_thumbnail(url=m_flag)
|
e.set_thumbnail(url=milf.flag)
|
||||||
|
|
||||||
class TransferView(BasicView):
|
class TransferView(BasicView):
|
||||||
def __init__(
|
def __init__(
|
||||||
@@ -592,6 +602,8 @@ class Banking(commands.Cog):
|
|||||||
clear: bool | None = False,
|
clear: bool | None = False,
|
||||||
kit: pnwkit.QueryKit = None,
|
kit: pnwkit.QueryKit = None,
|
||||||
dkit: pnwkit.QueryKit = None,
|
dkit: pnwkit.QueryKit = None,
|
||||||
|
okit: pnwkit.QueryKit = None,
|
||||||
|
offshore: Alliance = None,
|
||||||
):
|
):
|
||||||
super().__init__(timeout=timeout, clear=clear)
|
super().__init__(timeout=timeout, clear=clear)
|
||||||
self.alliance_id = None
|
self.alliance_id = None
|
||||||
@@ -599,14 +611,29 @@ class Banking(commands.Cog):
|
|||||||
self.resources = None
|
self.resources = None
|
||||||
self.kit = kit
|
self.kit = kit
|
||||||
self.dkit = dkit
|
self.dkit = dkit
|
||||||
self.sel_alliance = 10177
|
self.okit = okit
|
||||||
|
self.offshore = offshore
|
||||||
|
self.sel_alliance = MILF_ID
|
||||||
|
self.alliances = [MILF_ID, DILF_ID]
|
||||||
|
if offshore:
|
||||||
|
self.alliances.append(offshore.id)
|
||||||
|
self.index = 0
|
||||||
|
|
||||||
@discord.ui.button(
|
@discord.ui.button(
|
||||||
label="change selected alliance", style=discord.ButtonStyle.gray
|
label="change selected alliance", style=discord.ButtonStyle.gray
|
||||||
)
|
)
|
||||||
async def change_alliance(self, i: discord.Interaction, _):
|
async def change_alliance(self, i: discord.Interaction, _):
|
||||||
self.sel_alliance = 10198 if self.sel_alliance == 10177 else 10177
|
self.index += 1
|
||||||
flag = d_flag if self.sel_alliance == 10198 else m_flag
|
self.sel_alliance = self.alliances[self.index % 3]
|
||||||
|
flag = (
|
||||||
|
(
|
||||||
|
await self.dkit.query(
|
||||||
|
"alliances", {"id": self.sel_alliance, "first": 1}, "flag"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.alliances[0]
|
||||||
|
.flag
|
||||||
|
)
|
||||||
e = i.message.embeds[0]
|
e = i.message.embeds[0]
|
||||||
e.set_thumbnail(url=flag)
|
e.set_thumbnail(url=flag)
|
||||||
e.set_field_at(
|
e.set_field_at(
|
||||||
@@ -819,7 +846,11 @@ class Banking(commands.Cog):
|
|||||||
label="confirm", style=discord.ButtonStyle.blurple, disabled=True, row=2
|
label="confirm", style=discord.ButtonStyle.blurple, disabled=True, row=2
|
||||||
)
|
)
|
||||||
async def confirm(self, i: discord.Interaction, _):
|
async def confirm(self, i: discord.Interaction, _):
|
||||||
kit = self.kit if self.sel_alliance == 10177 else self.dkit
|
kit_dict = {MILF_ID: self.kit, DILF_ID: self.okit}
|
||||||
|
if offshore:
|
||||||
|
kit_dict.update({offshore.id: self.okit})
|
||||||
|
|
||||||
|
kit = kit_dict.get(self.sel_alliance)
|
||||||
if self.nation_id:
|
if self.nation_id:
|
||||||
await kit.mutation(
|
await kit.mutation(
|
||||||
"bankWithdraw",
|
"bankWithdraw",
|
||||||
@@ -872,6 +903,10 @@ class Banking(commands.Cog):
|
|||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
v = TransferView(kit=self.kit, dkit=self.okit)
|
v = TransferView(kit=self.kit, dkit=self.okit)
|
||||||
|
if self.okit:
|
||||||
|
v = TransferView(
|
||||||
|
kit=self.kit, dkit=self.okit, okit=self.okit, offshore=offshore
|
||||||
|
)
|
||||||
v.author = ctx.message.author
|
v.author = ctx.message.author
|
||||||
m = await ctx.send(embed=e, view=v)
|
m = await ctx.send(embed=e, view=v)
|
||||||
v.message = m
|
v.message = m
|
||||||
@@ -924,7 +959,7 @@ class Banking(commands.Cog):
|
|||||||
async def not_on_wclist(self, ctx: CustomCtx):
|
async def not_on_wclist(self, ctx: CustomCtx):
|
||||||
res = await self.kit.query(
|
res = await self.kit.query(
|
||||||
"nations",
|
"nations",
|
||||||
{"alliance_id": [10177, 10198], "alliance_position": [2, 3, 4, 5]},
|
{"alliance_id": [MILF_ID, DILF_ID], "alliance_position": [2, 3, 4, 5]},
|
||||||
"id, leader_name, nation_name",
|
"id, leader_name, nation_name",
|
||||||
)
|
)
|
||||||
i = 0
|
i = 0
|
||||||
@@ -981,7 +1016,7 @@ class Banking(commands.Cog):
|
|||||||
"""
|
"""
|
||||||
Revenue calculation from nations by fetching cities and projects.
|
Revenue calculation from nations by fetching cities and projects.
|
||||||
"""
|
"""
|
||||||
message = await ctx.send("Calculating revenue for nations...")
|
await ctx.send("Calculating revenue for nations...")
|
||||||
try:
|
try:
|
||||||
revenue_data = await self.get_alliance_rev(ids)
|
revenue_data = await self.get_alliance_rev(ids)
|
||||||
|
|
||||||
@@ -1004,8 +1039,8 @@ class Banking(commands.Cog):
|
|||||||
"bank, shopping_mall, stadium, barracks, factory, hangar, drydock}}"
|
"bank, shopping_mall, stadium, barracks, factory, hangar, drydock}}"
|
||||||
)
|
)
|
||||||
|
|
||||||
data = await self.kit.query("alliances", {"id": [10177]}, query_text)
|
data = await self.kit.query("alliances", {"id": [MILF_ID]}, query_text)
|
||||||
data2 = await self.dkit.query("alliances", {"id": [10198]}, query_text)
|
data2 = await self.dkit.query("alliances", {"id": [DILF_ID]}, query_text)
|
||||||
|
|
||||||
nations = []
|
nations = []
|
||||||
for alliance in data.alliances:
|
for alliance in data.alliances:
|
||||||
@@ -1384,7 +1419,7 @@ class Banking(commands.Cog):
|
|||||||
# treasures = {"name": [], "bonus": []}
|
# treasures = {"name": [], "bonus": []}
|
||||||
# treasures_data = treasures_query.treasures
|
# treasures_data = treasures_query.treasures
|
||||||
# for treasure in treasures_data:
|
# for treasure in treasures_data:
|
||||||
# if treasure.nation.alliance_id == 10177:
|
# if treasure.nation.alliance_id == MILF_ID:
|
||||||
# treasures["name"].append(treasure.name)
|
# treasures["name"].append(treasure.name)
|
||||||
# treasures["bonus"].append(treasure.bonus)
|
# treasures["bonus"].append(treasure.bonus)
|
||||||
|
|
||||||
@@ -1544,7 +1579,7 @@ class Banking(commands.Cog):
|
|||||||
|
|
||||||
async def callback(self, interaction: discord.Interaction):
|
async def callback(self, interaction: discord.Interaction):
|
||||||
kit = pnwkit.QueryKit(
|
kit = pnwkit.QueryKit(
|
||||||
api_key=os.getenv("pnwOFFKEY"),
|
api_key=os.getenv("pnwDILFKEY"),
|
||||||
bot_key=os.getenv("pnwBOTKEY"),
|
bot_key=os.getenv("pnwBOTKEY"),
|
||||||
bot_key_api_key=os.getenv("pnwACCKEY"),
|
bot_key_api_key=os.getenv("pnwACCKEY"),
|
||||||
aiohttp_session=aiohttp.ClientSession(loop=self.bot.loop),
|
aiohttp_session=aiohttp.ClientSession(loop=self.bot.loop),
|
||||||
|
|||||||
Reference in new issue
Block a user