reformatting
This commit is contained in:
1 parent
165922abbf
commit
a7f3a3bee2
2 files changed
+94
-61
No files matched your search
+93
-61
@@ -15,9 +15,11 @@ from discord.ext import commands
|
|||||||
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
|
||||||
|
|
||||||
|
FILL = json.load(open("refill.json"))
|
||||||
|
|
||||||
|
|
||||||
FILL = json.load(open('refill.json'))
|
|
||||||
class BaseMul:
|
class BaseMul:
|
||||||
money = 1000000
|
money = 1000000
|
||||||
food = 5000
|
food = 5000
|
||||||
@@ -31,28 +33,30 @@ class BaseMul:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def values(cls):
|
def values(cls):
|
||||||
return {
|
return {
|
||||||
'money': cls.money,
|
"money": cls.money,
|
||||||
'food': cls.food,
|
"food": cls.food,
|
||||||
'uranium': cls.uranium,
|
"uranium": cls.uranium,
|
||||||
'gasoline': cls.gasoline,
|
"gasoline": cls.gasoline,
|
||||||
'munitions': cls.munitions,
|
"munitions": cls.munitions,
|
||||||
'steel40': cls.steel40,
|
"steel40": cls.steel40,
|
||||||
'steel100': cls.steel100,
|
"steel100": cls.steel100,
|
||||||
'aluminum': cls.aluminum
|
"aluminum": cls.aluminum,
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def calc(cls, cities: int, nation: pnwkit.Nation):
|
def calc(cls, cities: int, nation: pnwkit.Nation):
|
||||||
return {
|
return {
|
||||||
'money': cls.money * cities - nation.money,
|
"money": cls.money * cities - nation.money,
|
||||||
'food': cls.food * cities - nation.food,
|
"food": cls.food * cities - nation.food,
|
||||||
'uranium': cls.uranium * cities - nation.uranium,
|
"uranium": cls.uranium * cities - nation.uranium,
|
||||||
'gasoline': cls.gasoline * cities - nation.gasoline,
|
"gasoline": cls.gasoline * cities - nation.gasoline,
|
||||||
'munitions': cls.munitions * cities - nation.munitions,
|
"munitions": cls.munitions * cities - nation.munitions,
|
||||||
'steel40': cls.steel40 * cities - nation.steel,
|
"steel40": cls.steel40 * cities - nation.steel,
|
||||||
'steel100': cls.steel100 * cities - nation.steel,
|
"steel100": cls.steel100 * cities - nation.steel,
|
||||||
'aluminum': cls.aluminum * cities - nation.aluminum
|
"aluminum": cls.aluminum * cities - nation.aluminum,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Banking(commands.Cog):
|
class Banking(commands.Cog):
|
||||||
def __init__(self, bot: Brahmos):
|
def __init__(self, bot: Brahmos):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
@@ -143,7 +147,7 @@ class Banking(commands.Cog):
|
|||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
await ctx.send(embed=e, view=View(kit=self.kit))
|
await ctx.send(embed=e, view=View(kit=self.kit))
|
||||||
|
|
||||||
@commands.has_role(987770837627187250)
|
@commands.has_role(987770837627187250)
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def warchest(self, ctx: CustomCtx):
|
async def warchest(self, ctx: CustomCtx):
|
||||||
@@ -153,22 +157,22 @@ class Banking(commands.Cog):
|
|||||||
data = await self.kit.query(
|
data = await self.kit.query(
|
||||||
"alliances",
|
"alliances",
|
||||||
{"id": 10177, "first": 1},
|
{"id": 10177, "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]
|
||||||
nations = alliance.nations
|
nations = alliance.nations
|
||||||
|
|
||||||
resource_delta = []
|
resource_delta = []
|
||||||
kit = pnwkit.QueryKit(
|
kit = pnwkit.QueryKit(
|
||||||
api_key=os.getenv("pnwDILFKEY"),
|
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),
|
||||||
)
|
)
|
||||||
gator = await kit.query(
|
gator = await kit.query(
|
||||||
"nations",
|
"nations",
|
||||||
{"id" : 103764, "first": 1},
|
{"id": 103764, "first": 1},
|
||||||
"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}",
|
||||||
)
|
)
|
||||||
gator = gator.nations[0]
|
gator = gator.nations[0]
|
||||||
nations.append(gator)
|
nations.append(gator)
|
||||||
@@ -178,26 +182,31 @@ class Banking(commands.Cog):
|
|||||||
continue
|
continue
|
||||||
cities = len(nation.cities)
|
cities = len(nation.cities)
|
||||||
delta = BaseMul.calc(cities, nation)
|
delta = BaseMul.calc(cities, nation)
|
||||||
delta.update({
|
delta.update(
|
||||||
'id': nation.id,
|
{
|
||||||
'discord': nation.discord or "N/A",
|
"id": nation.id,
|
||||||
'cities': cities,
|
"discord": nation.discord or "N/A",
|
||||||
'name': nation.nation_name
|
"cities": cities,
|
||||||
})
|
"name": nation.nation_name,
|
||||||
|
}
|
||||||
|
)
|
||||||
for key in delta:
|
for key in delta:
|
||||||
if isinstance(delta[key], float):
|
if isinstance(delta[key], float):
|
||||||
delta[key] = int(delta[key])
|
delta[key] = int(delta[key])
|
||||||
resource_delta.append(delta)
|
resource_delta.append(delta)
|
||||||
|
|
||||||
|
|
||||||
embeds = []
|
embeds = []
|
||||||
e = discord.Embed(title="Warchest Resources", timestamp=datetime.datetime.utcnow(), color=ctx.author.color)
|
e = discord.Embed(
|
||||||
|
title="Warchest Resources",
|
||||||
|
timestamp=datetime.datetime.utcnow(),
|
||||||
|
color=ctx.author.color,
|
||||||
|
)
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
for rd in resource_delta:
|
for rd in resource_delta:
|
||||||
e.add_field(
|
e.add_field(
|
||||||
name=rd.get('name'),
|
name=rd.get("name"),
|
||||||
value= (
|
value=(
|
||||||
f"[{rd.get('discord')}](https://politicsandwar.com/nation/id={rd.get('id')}) (c{rd.get('cities')})\n\n"
|
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.money} {rd.get('money'):,}\n"
|
||||||
f"{Emojis.food} {rd.get('food'):,}\n"
|
f"{Emojis.food} {rd.get('food'):,}\n"
|
||||||
@@ -206,22 +215,31 @@ class Banking(commands.Cog):
|
|||||||
f"{Emojis.gasoline} {rd.get('gasoline'):,}\n"
|
f"{Emojis.gasoline} {rd.get('gasoline'):,}\n"
|
||||||
f"{Emojis.aluminum} {rd.get('aluminum'):,}\n"
|
f"{Emojis.aluminum} {rd.get('aluminum'):,}\n"
|
||||||
f"{Emojis.steel} {rd.get('steel100'):,}"
|
f"{Emojis.steel} {rd.get('steel100'):,}"
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
count += 1
|
count += 1
|
||||||
if count == 9:
|
if count == 9:
|
||||||
embeds.append(e)
|
embeds.append(e)
|
||||||
e = discord.Embed(title="Warchest Resources", timestamp=datetime.datetime.utcnow(), color=ctx.author.color)
|
e = discord.Embed(
|
||||||
|
title="Warchest Resources",
|
||||||
|
timestamp=datetime.datetime.utcnow(),
|
||||||
|
color=ctx.author.color,
|
||||||
|
)
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
if count > 0:
|
if count > 0:
|
||||||
embeds.append(e)
|
embeds.append(e)
|
||||||
e = discord.Embed(title="Nation List", timestamp=datetime.datetime.utcnow(), color=ctx.author.color, description="\u200b")
|
e = discord.Embed(
|
||||||
|
title="Nation List",
|
||||||
|
timestamp=datetime.datetime.utcnow(),
|
||||||
|
color=ctx.author.color,
|
||||||
|
description="\u200b",
|
||||||
|
)
|
||||||
i = 0
|
i = 0
|
||||||
for rd in resource_delta:
|
for rd in resource_delta:
|
||||||
i+=1
|
i += 1
|
||||||
e.description += f"{i}. [{rd.get('name')}](https://politicsandwar.com/nation/id={rd.get('id')})\n"
|
e.description += f"{i}. [{rd.get('name')}](https://politicsandwar.com/nation/id={rd.get('id')})\n"
|
||||||
total= {
|
total = {
|
||||||
"money": 0,
|
"money": 0,
|
||||||
"gasoline": 0,
|
"gasoline": 0,
|
||||||
"munitions": 0,
|
"munitions": 0,
|
||||||
@@ -229,18 +247,18 @@ class Banking(commands.Cog):
|
|||||||
"steel100": 0,
|
"steel100": 0,
|
||||||
"uranium": 0,
|
"uranium": 0,
|
||||||
"food": 0,
|
"food": 0,
|
||||||
"steel40": 0
|
"steel40": 0,
|
||||||
}
|
}
|
||||||
for rd in resource_delta:
|
for rd in resource_delta:
|
||||||
total["money"] += max(0, rd.get("money"))
|
total["money"] += max(0, rd.get("money"))
|
||||||
total["steel100"] += max(0, rd.get("steel100"))
|
total["steel100"] += max(0, rd.get("steel100"))
|
||||||
total["steel40"] += max(0, rd.get("steel40"))
|
total["steel40"] += max(0, rd.get("steel40"))
|
||||||
total["aluminum"] += max(0, rd.get("aluminum"))
|
total["aluminum"] += max(0, rd.get("aluminum"))
|
||||||
total["food"] +=max(0, rd.get("food"))
|
total["food"] += max(0, rd.get("food"))
|
||||||
total["munitions"] += max(0, rd.get("munitions"))
|
total["munitions"] += max(0, rd.get("munitions"))
|
||||||
total["uranium"] += max(0, rd.get("uranium"))
|
total["uranium"] += max(0, rd.get("uranium"))
|
||||||
total["gasoline"] += max(0, rd.get("gasoline"))
|
total["gasoline"] += max(0, rd.get("gasoline"))
|
||||||
|
|
||||||
e.description += (
|
e.description += (
|
||||||
"\n **Total warchest to transfer**\n"
|
"\n **Total warchest to transfer**\n"
|
||||||
f"{Emojis.money} {total.get('money'):,}\n"
|
f"{Emojis.money} {total.get('money'):,}\n"
|
||||||
@@ -254,42 +272,52 @@ class Banking(commands.Cog):
|
|||||||
embeds.append(e)
|
embeds.append(e)
|
||||||
|
|
||||||
class ConfirmButton(discord.ui.Button):
|
class ConfirmButton(discord.ui.Button):
|
||||||
def __init__(self, *, style = discord.ButtonStyle.green, label= "confirm", bot: Brahmos, p: Paginator):
|
def __init__(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
style=discord.ButtonStyle.green,
|
||||||
|
label="confirm",
|
||||||
|
bot: Brahmos,
|
||||||
|
p: Paginator,
|
||||||
|
):
|
||||||
super().__init__(style=style, label=label)
|
super().__init__(style=style, label=label)
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.v = p
|
self.v = p
|
||||||
|
|
||||||
|
|
||||||
async def interaction_check(self, interaction: discord.Interaction) -> bool:
|
async def interaction_check(self, interaction: discord.Interaction) -> bool:
|
||||||
return interaction.user == ctx.author
|
return interaction.user == ctx.author
|
||||||
|
|
||||||
async def callback(self, interaction: discord.Interaction):
|
async def callback(self, interaction: discord.Interaction):
|
||||||
|
|
||||||
kit = pnwkit.QueryKit(
|
kit = pnwkit.QueryKit(
|
||||||
api_key=os.getenv("pnwDILFKEY"),
|
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),
|
||||||
)
|
)
|
||||||
logmsg = ""
|
logmsg = ""
|
||||||
logstream = io.StringIO()
|
logstream = io.StringIO()
|
||||||
await interaction.response.defer()
|
await interaction.response.defer()
|
||||||
self.label = "processing"
|
self.label = "processing"
|
||||||
self.emoji = "<a:load:1275827052909432887>"
|
self.emoji = "<a:load:1275827052909432887>"
|
||||||
self.style= discord.ButtonStyle.blurple
|
self.style = discord.ButtonStyle.blurple
|
||||||
self.v.clear_items()
|
self.v.clear_items()
|
||||||
self.v.add_item(self)
|
self.v.add_item(self)
|
||||||
e = discord.Embed(color=discord.Color.blurple(), timestamp=datetime.datetime.utcnow(), title="Transferring resources")
|
e = discord.Embed(
|
||||||
|
color=discord.Color.blurple(),
|
||||||
|
timestamp=datetime.datetime.utcnow(),
|
||||||
|
title="Transferring resources",
|
||||||
|
)
|
||||||
await interaction.message.edit(embed=e, view=self.v)
|
await interaction.message.edit(embed=e, view=self.v)
|
||||||
for rd in resource_delta:
|
for rd in resource_delta:
|
||||||
for k in rd: # remove negatives
|
for k in rd: # remove negatives
|
||||||
if isinstance(rd[k], int) and (rd[k] < 0):
|
if isinstance(rd[k], int) and (rd[k] < 0):
|
||||||
rd[k] = 0
|
rd[k] = 0
|
||||||
try:
|
try:
|
||||||
await kit.mutation(
|
await kit.mutation(
|
||||||
"bankWithdraw",
|
"bankWithdraw",
|
||||||
{
|
{
|
||||||
"receiver" : rd.get("id"),
|
"receiver": rd.get("id"),
|
||||||
"receiver_type": 1,
|
"receiver_type": 1,
|
||||||
"money": rd.get("money") + 1,
|
"money": rd.get("money") + 1,
|
||||||
"food": rd.get("food"),
|
"food": rd.get("food"),
|
||||||
@@ -298,9 +326,9 @@ class Banking(commands.Cog):
|
|||||||
"steel": rd.get("steel100"),
|
"steel": rd.get("steel100"),
|
||||||
"munitions": rd.get("munitions"),
|
"munitions": rd.get("munitions"),
|
||||||
"aluminum": rd.get("aluminum"),
|
"aluminum": rd.get("aluminum"),
|
||||||
"note": "warchest"
|
"note": "warchest",
|
||||||
},
|
},
|
||||||
"id"
|
"id",
|
||||||
)
|
)
|
||||||
pprint.pprint(rd, stream=logstream, indent=3)
|
pprint.pprint(rd, stream=logstream, indent=3)
|
||||||
logmsg += f"{rd.get('name')} <:tick:1275839665819353148>\n"
|
logmsg += f"{rd.get('name')} <:tick:1275839665819353148>\n"
|
||||||
@@ -308,7 +336,9 @@ class Banking(commands.Cog):
|
|||||||
await interaction.message.edit(embed=e)
|
await interaction.message.edit(embed=e)
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pprint.pprint(f"{rd.get('name')} -> {e}", stream=logstream, indent=3)
|
pprint.pprint(
|
||||||
|
f"{rd.get('name')} -> {e}", stream=logstream, indent=3
|
||||||
|
)
|
||||||
logmsg += f"{rd.get('name')} <:cross:1275839683984621568>\n"
|
logmsg += f"{rd.get('name')} <:cross:1275839683984621568>\n"
|
||||||
e.description = logmsg
|
e.description = logmsg
|
||||||
await interaction.message.edit(embed=e)
|
await interaction.message.edit(embed=e)
|
||||||
@@ -316,9 +346,11 @@ class Banking(commands.Cog):
|
|||||||
await interaction.message.edit(view=None)
|
await interaction.message.edit(view=None)
|
||||||
logstream.seek(0)
|
logstream.seek(0)
|
||||||
await ctx.send(file=discord.File(logstream, filename="log.txt"))
|
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)])
|
|
||||||
|
|
||||||
|
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):
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from typing import List, Union
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
|
|
||||||
async def get_webhook(
|
async def get_webhook(
|
||||||
channel: Union[discord.TextChannel, discord.ForumChannel, discord.VoiceChannel]
|
channel: Union[discord.TextChannel, discord.ForumChannel, discord.VoiceChannel]
|
||||||
) -> discord.Webhook:
|
) -> discord.Webhook:
|
||||||
|
|||||||
Reference in new issue
Block a user