add cmd tp update offshore key

This commit is contained in:
un1xx committed 2025-11-04 23:54:49 +05:30
1 parent 75dee03687
commit 84fce7f885
1 file changed
+19 -19
+19 -19
View File
@@ -5,7 +5,6 @@ import json
import os
import pprint
from sqlite3 import Date
from typing import List, Optional
import aiohttp
@@ -82,7 +81,7 @@ class TransferFlags(commands.FlagConverter, delimiter=" ", prefix="--"):
class Banking(commands.Cog):
async def __init__(self, bot: Brahmos):
def __init__(self, bot: Brahmos):
self.bot = bot
self.kit = pnwkit.QueryKit(
api_key=os.getenv("pnwAPIKEY"),
@@ -96,12 +95,7 @@ class Banking(commands.Cog):
bot_key_api_key=os.getenv("pnwACCKEY"),
aiohttp_session=aiohttp.ClientSession(loop=self.bot.loop),
)
self.okit = pnwkit.QueryKit(
api_key=await self.get_offshore_key(),
bot_key=os.getenv("pnwBOTKEY"),
bot_key_api_key=os.getenv("pnwACCKEY"),
aiohttp_session=aiohttp.ClientSession(loop=self.bot.loop),
)
self.WARCHEST_IDS = []
async def get_kit_alliance(
@@ -117,6 +111,12 @@ class Banking(commands.Cog):
async def cog_load(self):
"""Called when the cog is loaded."""
await self.fetch_warchest_ids()
self.okit = pnwkit.QueryKit(
api_key=await self.get_offshore_key(),
bot_key=os.getenv("pnwBOTKEY"),
bot_key_api_key=os.getenv("pnwACCKEY"),
aiohttp_session=aiohttp.ClientSession(loop=self.bot.loop),
)
async def fetch_warchest_ids(self):
"""Fetch nation IDs from the warchest table."""
@@ -134,7 +134,7 @@ class Banking(commands.Cog):
"""Set offshore key"""
try:
async with self.bot.db_pool.acquire() as conn:
await conn.execute("UPDATE offshore SET key = ($1)", key)
await conn.execute("UPDATE offshorekey SET key = ($1)", key)
except Exception as e:
raise e
@@ -171,18 +171,11 @@ class Banking(commands.Cog):
super().__init__(timeout, clear)
self.bank = bank
@discord.ui.button(label="cancel", style=discord.ButtonStyle.red)
async def cancel(self, i: discord.Interaction, _):
await i.message.edit(
content="> action cancelled", embed=None, view=None
)
self.stop()
@discord.ui.button(label="set key", style=discord.ButtonStyle.green)
async def confirm(self, i: discord.Interaction, _):
class TextInput(discord.ui.Modal, title="Enter API Key"):
key = discord.ui.TextInput(
label="Nation ID/name",
label="API KEY",
style=discord.TextStyle.short,
placeholder="api key",
max_length=32,
@@ -222,13 +215,20 @@ class Banking(commands.Cog):
await self.bank.set_offshore(key=key)
await i.message.edit(embed=embed, view=None)
except Exception:
except Exception as e:
embed.color = discord.Color.red()
embed.description = "invalid key entered."
embed.description = f"invalid key entered.\n```py\n{e}\n```"
await i.message.edit(embed=embed, view=None)
await i.response.send_modal(TextInput(bank=self.bank))
@discord.ui.button(label="cancel", style=discord.ButtonStyle.red)
async def cancel(self, i: discord.Interaction, _):
await i.message.edit(
content="> action cancelled", embed=None, view=None
)
self.stop()
embed = discord.Embed(
description="Key updation menu",
color=0x2D3236,