diff --git a/exts/banking.py b/exts/banking.py index cf4d04e..964a810 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -5,6 +5,7 @@ import json import os import pprint import random +import traceback from typing import List, Literal, Optional import aiohttp @@ -22,8 +23,6 @@ from utils.base import BasicView from utils.emojis import Emojis from utils.paginator import Paginator - - class BaseMul: money = 1000000 food = 5000 @@ -78,17 +77,15 @@ class Banking(commands.Cog): ) self.WARCHEST_IDS = None - async def cog_load(self): """Called when the cog is loaded.""" await self.fetch_warchest_ids() - async def fetch_warchest_ids(self): """Fetch nation IDs from the warchest table.""" try: async with self.bot.db_pool.acquire() as conn: - query = "SELECT id FROM warchest" + query = "SELECT id FROM warchest" rows = await conn.fetch(query) self.WARCHEST_IDS = [row[0] for row in rows] return self.WARCHEST_IDS @@ -174,6 +171,7 @@ class Banking(commands.Cog): ) 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) @@ -181,7 +179,7 @@ class Banking(commands.Cog): @commands.has_any_role("Government", "The Croak Council") @commands.command(aliases=["wc"]) - async def warchest(self, ctx: CustomCtx, ids: commands.Greedy[int]=None): + async def warchest(self, ctx: CustomCtx, ids: commands.Greedy[int] = None): """ refill warchest of all members """ @@ -282,7 +280,6 @@ class Banking(commands.Cog): i += 1 e.description += f"{i}. [{rd.get('name')}](https://politicsandwar.com/nation/id={rd.get('id')})\n" - total["money"] += max(0, rd.get("money")) total["steel100"] += max(0, rd.get("steel100")) total["steel40"] += max(0, rd.get("steel40")) @@ -356,7 +353,7 @@ class Banking(commands.Cog): + rd.get("aluminum") + rd.get("steel100") ) - if sum !=0: + if sum != 0: await kit.mutation( "bankWithdraw", { @@ -377,7 +374,9 @@ class Banking(commands.Cog): logmsg += f"{rd.get('name')} <:tick:1275839665819353148>\n" else: pprint.pprint( - f"{rd.get('name')} (already filled)", stream=logstream, indent=3 + f"{rd.get('name')} (already filled)", + stream=logstream, + indent=3, ) logmsg += f"{rd.get('name')} (already filled)\n" e.description = logmsg @@ -422,9 +421,7 @@ class Banking(commands.Cog): if nation_names: nation_names = nation_names.split(",") result = await self.kit.query( - "nations", - {"nation_name": nation_names}, - "id" + "nations", {"nation_name": nation_names}, "id" ) for nation in result.nations: ids.append(nation.id) @@ -436,10 +433,10 @@ class Banking(commands.Cog): ) nations.extend(result.nations) result = await self.kit.query( - "nations", - {"alliance_id": 10177}, - "id, nation_name,leader_name, discord,money, flag, food, uranium, coal, iron, oil, bauxite, iron, lead, munitions, gasoline, aluminum, steel, num_cities, credits", - ) + "nations", + {"alliance_id": 10177}, + "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) else: result = await self.kit.query( @@ -532,12 +529,16 @@ class Banking(commands.Cog): ]: 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 + 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')})", @@ -547,7 +548,13 @@ class Banking(commands.Cog): 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): + 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 @@ -563,7 +570,7 @@ class Banking(commands.Cog): 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_thumbnail(url=flag) e.set_field_at( 0, name="Transferring From", value=alliances.get(self.sel_alliance) ) @@ -587,14 +594,9 @@ class Banking(commands.Cog): label="Resources", style=discord.TextStyle.long, max_length=1024, - placeholder=( - "money: 1000\n" - "food: 1000\n" - "... and so on" - ), + placeholder=("money: 1000\n" "food: 1000\n" "... and so on"), required=True, ) - def __init__(self, view: TransferView, kit: pnwkit.QueryKit): super().__init__(timeout=200) @@ -609,13 +611,13 @@ class Banking(commands.Cog): nation = await self.kit.query( "nations", {"id": int(inp), "first": 1}, - "id, nation_name, leader_name, flag" + "id, nation_name, leader_name, flag", ) else: nation = await self.kit.query( "nations", {"nation_name": inp, "first": 1}, - "id, nation_name, leader_name, flag" + "id, nation_name, leader_name, flag", ) nation = nation.nations[0] rss = self.rss.value.split("\n") @@ -626,10 +628,9 @@ class Banking(commands.Cog): else: key, value = r.split(" ") key = key.strip().lower() - value = value.replace(',', '') + value = value.replace(",", "") value = int(denumerize.denumerize(value.upper())) resources[key] = value - e.description = ( "**Resources** \n" @@ -646,7 +647,7 @@ class Banking(commands.Cog): 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", @@ -660,34 +661,37 @@ class Banking(commands.Cog): ) 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), + "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) + + @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, @@ -699,11 +703,7 @@ class Banking(commands.Cog): label="Resources", style=discord.TextStyle.long, max_length=1024, - placeholder=( - "money: 1000\n" - "food: 1000\n" - "... and so on" - ), + placeholder=("money: 1000\n" "food: 1000\n" "... and so on"), required=True, ) @@ -715,13 +715,11 @@ class Banking(commands.Cog): alliance = await self.kit.query( "alliances", {"id": int(inp), "first": 1}, - "id, name, flag" + "id, name, flag", ) else: alliance = await self.kit.query( - "alliances", - {"name": inp, "first": 1}, - "id, name, flag" + "alliances", {"name": inp, "first": 1}, "id, name, flag" ) alliance = alliance.alliances[0] rss = self.rss.value.split("\n") @@ -732,10 +730,10 @@ class Banking(commands.Cog): else: key, value = r.split(" ") key = key.strip().lower() - value = value.replace(',', '') + value = value.replace(",", "") value = int(denumerize.denumerize(value.upper())) resources[key] = value - + e.description = ( "**Resources** \n" f"{Emojis.money} {resources.get('money', 0):,}\n" @@ -750,7 +748,6 @@ class Banking(commands.Cog): 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( @@ -759,28 +756,30 @@ class Banking(commands.Cog): ) 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), + "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) + + @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: @@ -826,20 +825,19 @@ class Banking(commands.Cog): ) 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_any_role("The Croak Council", "Government") @commands.command(aliases=["wca"]) async def wcadd(self, ctx: CustomCtx, ids: commands.Greedy[int]): @@ -864,33 +862,25 @@ class Banking(commands.Cog): async with self.bot.db_pool.acquire() as conn: async with conn.transaction(): for nation in notin_list: - await conn.execute( - "INSERT INTO warchest (id) VALUES ($1)", - nation - ) - + await conn.execute("INSERT INTO warchest (id) VALUES ($1)", nation) + await ctx.send(f"> inserted nations in war refill list: {notin_list}") - await ctx.invoke(discord.utils.get(self.bot.commands, name='wclist')) - - + await ctx.invoke(discord.utils.get(self.bot.commands, name="wclist")) @commands.has_any_role("The Croak Council", "Government") @commands.command(aliases=["wcl"]) async def wclist(self, ctx: CustomCtx): await self.fetch_warchest_ids() result = await self.kit.query( - "nations", - {"id": self.WARCHEST_IDS}, - "id, nation_name" + "nations", {"id": self.WARCHEST_IDS}, "id, nation_name" ) i = 0 content = "Nations in warchest refill list\n" for nation in result.nations: - i+=1 + i += 1 content += f"{i:>3}. {nation.id} {nation.nation_name}\n" await ctx.cbsend(content=content) - @commands.has_any_role("The Croak Council", "Government") @commands.command(aliases=["wcr"]) async def wcremove(self, ctx: commands.Context, ids: commands.Greedy[int]): @@ -899,7 +889,7 @@ class Banking(commands.Cog): """ if not ids: return await ctx.send("No ids provided.") - await self.fetch_warchest_ids() + await self.fetch_warchest_ids() removed_list = [] not_in_list = [] @@ -910,41 +900,46 @@ class Banking(commands.Cog): not_in_list.append(nation) if not_in_list: - await ctx.send(f"> Nations not found in warchest refill list: `{not_in_list}`") + await ctx.send( + f"> Nations not found in warchest refill list: `{not_in_list}`" + ) - if removed_list: + if removed_list: async with self.bot.db_pool.acquire() as conn: async with conn.transaction(): for nation in removed_list: await conn.execute( - "DELETE FROM warchest WHERE id = ($1)", - nation + "DELETE FROM warchest WHERE id = ($1)", nation ) - await ctx.send(f"> Removed nations from warchest refill list: `{removed_list}`") - await ctx.invoke(discord.utils.get(self.bot.commands, name='wclist')) + await ctx.send( + f"> Removed nations from warchest refill list: `{removed_list}`" + ) + await ctx.invoke(discord.utils.get(self.bot.commands, name="wclist")) else: - await ctx.send("> None of the provided nations were in the warchest refill list.") + await ctx.send( + "> None of the provided nations were in the warchest refill list." + ) @commands.has_any_role("The Croak Council", "Government") @commands.command(aliases=["refill"]) - async def resource_refill(self, ctx: commands.Context, ids: commands.Greedy[int]): + async def resource_refill(self, ctx: CustomCtx, ids: commands.Greedy[int]): """ Revenue calculation from nations by fetching cities and projects. """ data = await self.kit.query( "alliances", {"id": [10198]}, - "id, nations {id, nation_name, continent, color, war_policy, domestic_policy, beige_turns, num_cities, soldiers, tanks" \ - ", aircraft, ships, missiles, nukes, spies, wars { date, turnsleft, attid, winner }, coal, oil, uranium, iron, bauxite, lead, " \ - "money, food, steel, gasoline, munitions, aluminum, iron_works, bauxite_works, arms_stockpile, emergency_gasoline_reserve, " \ - "mass_irrigation, international_trade_center, telecommunications_satellite, recycling_initiative, green_technologies, " \ - "clinical_research_center, specialized_police_training_program, uranium_enrichment_program, cities {infrastructure, " \ - "land, powered, date, name, coal_power, oil_power," \ - "wind_power, nuclear_power, coal_mine, oil_well, uranium_mine, lead_mine, iron_mine, bauxite_mine, farm, oil_refinery," \ - "aluminum_refinery, munitions_factory, steel_mill, police_station, hospital, recycling_center, subway, supermarket," \ - "bank, shopping_mall, stadium, barracks, factory, hangar, drydock}}" + "id, nations {id, nation_name, continent, color, war_policy, domestic_policy, beige_turns, num_cities, soldiers, tanks" + ", aircraft, ships, missiles, nukes, spies, wars { date, turnsleft, attid, winner }, coal, oil, uranium, iron, bauxite, lead, " + "money, food, steel, gasoline, munitions, aluminum, iron_works, bauxite_works, arms_stockpile, emergency_gasoline_reserve, " + "mass_irrigation, international_trade_center, telecommunications_satellite, recycling_initiative, green_technologies, " + "clinical_research_center, specialized_police_training_program, uranium_enrichment_program, cities {infrastructure, " + "land, powered, date, name, coal_power, oil_power," + "wind_power, nuclear_power, coal_mine, oil_well, uranium_mine, lead_mine, iron_mine, bauxite_mine, farm, oil_refinery," + "aluminum_refinery, munitions_factory, steel_mill, police_station, hospital, recycling_center, subway, supermarket," + "bank, shopping_mall, stadium, barracks, factory, hangar, drydock}}", ) - + nations = [] for alliance in data.alliances: nations.extend(alliance.nations) @@ -962,31 +957,43 @@ class Banking(commands.Cog): try: game_data = await self.get_game_data() - + for nation in nations: try: if (nation.id not in self.WARCHEST_IDS) and (not ids): continue revenue = await self.calculate_revenue(message, nation, game_data) - - revenue_data.append({ - 'nation_id': nation.id, - 'nation_name': nation.nation_name, - 'revenue': revenue - }) - + + revenue_data.append( + { + "nation_id": nation.id, + "nation_name": nation.nation_name, + "revenue": revenue, + } + ) + except Exception as e: - raise e + await ctx.cbsend(f"{traceback.format_exc()}") # Format and send the results await self.send_revenue_results(ctx, revenue_data) - + except Exception as e: await ctx.send(f"> Error getting game data: {str(e)}") - - async def revenue_calc(message: discord.Message, nation: dict, radiation: dict, treasures: dict, prices: dict, colors: dict, seasonal_mod: dict, build: str = None, single_city: bool = False, include_spies: bool = False) -> dict: + async def revenue_calc( + message: discord.Message, + nation: dict, + radiation: dict, + treasures: dict, + prices: dict, + colors: dict, + seasonal_mod: dict, + build: str = None, + single_city: bool = False, + include_spies: bool = False, + ) -> dict: max_commerce = 100 base_com = 0 hos_dis_red = 2.5 @@ -1007,7 +1014,7 @@ class Banking(commands.Cog): military_upkeep = 0 money_income = 0 power_upkeep = 0 - nationpop = 0 + nationpop = 0 color_bonus = 0 policy_bonus = 1 new_player_bonus = 1 @@ -1022,7 +1029,6 @@ class Banking(commands.Cog): treasure_text = "" footer = "" - if nation.iron_works == True: ste_mod = 1.36 if nation.bauxite_works == True: @@ -1068,7 +1074,9 @@ class Banking(commands.Cog): try: build = json.loads(build) except json.JSONDecodeError: - await message.edit(content="Something is wrong with the build you sent!") + await message.edit( + content="Something is wrong with the build you sent!" + ) return land = 0 for city in nation.cities: @@ -1076,37 +1084,39 @@ class Banking(commands.Cog): city = {} for key, value in build.items(): city[key[4:]] = int(value) - city.infrastructure = city.pop('a_needed') - city.land = round(land/nation.num_cities) + city.infrastructure = city.pop("a_needed") + city.land = round(land / nation.num_cities) city.powered = True - city.date = nation.cities[math.ceil(nation.num_cities/2)]['date'] + city.date = nation.cities[math.ceil(nation.num_cities / 2)]["date"] nation.cities = [city] - #print(city) + # print(city) for city in nation.cities: total_infra += city.infrastructure base_pop = city.infrastructure * 100 pollution = 0 unpowered_infra = city.infrastructure - for wind_plant in range(city.wind_power): #can add something about wasted slots + for wind_plant in range( + city.wind_power + ): # can add something about wasted slots if unpowered_infra > 0: unpowered_infra -= 250 power_upkeep += 42 - for nucl_plant in range(city.nuclear_power): + for nucl_plant in range(city.nuclear_power): power_upkeep += 10500 for level in range(2): if unpowered_infra > 0: unpowered_infra -= 1000 uranium -= 1.2 - for oil_plant in range(city.oil_power): - power_upkeep += 1800 + for oil_plant in range(city.oil_power): + power_upkeep += 1800 pollution += 6 for level in range(5): if unpowered_infra > 0: unpowered_infra -= 100 oil -= 1.2 - for coal_plant in range(city.coal_power): - power_upkeep += 1200 + for coal_plant in range(city.coal_power): + power_upkeep += 1200 pollution += 8 for level in range(5): if unpowered_infra > 0: @@ -1123,7 +1133,12 @@ class Banking(commands.Cog): rss_upkeep += 5000 * city.uranium_mine * rss_upkeep_mod pollution += 20 * city.uranium_mine - uranium += 3 * city.uranium_mine * (1 + ((0.5 * (city.uranium_mine - 1)) / (5 - 1))) * uranium_mod + uranium += ( + 3 + * city.uranium_mine + * (1 + ((0.5 * (city.uranium_mine - 1)) / (5 - 1))) + * uranium_mod + ) rss_upkeep += 1500 * city.lead_mine * rss_upkeep_mod pollution += 12 * city.lead_mine @@ -1135,47 +1150,106 @@ class Banking(commands.Cog): rss_upkeep += 1600 * city.bauxite_mine * rss_upkeep_mod pollution += 12 * city.bauxite_mine - bauxite += 3 * city.bauxite_mine * (1 + ((0.5 * (city.bauxite_mine - 1)) / (10 - 1))) + bauxite += ( + 3 + * city.bauxite_mine + * (1 + ((0.5 * (city.bauxite_mine - 1)) / (10 - 1))) + ) - rss_upkeep += 300 * city.farm * rss_upkeep_mod ## seasonal modifiers and radiation + rss_upkeep += ( + 300 * city.farm * rss_upkeep_mod + ) ## seasonal modifiers and radiation pollution += 2 * city.farm * farm_poll_mod - food_prod = city.land/food_land_mod * city.farm * (1 + ((0.5 * (city.farm - 1)) / (20 - 1))) * seasonal_mod[nation.continent] * radiation[nation.continent] * 12 + food_prod = ( + city.land + / food_land_mod + * city.farm + * (1 + ((0.5 * (city.farm - 1)) / (20 - 1))) + * seasonal_mod[nation.continent] + * radiation[nation.continent] + * 12 + ) if food_prod < 0: food += 0 else: food += food_prod - + commerce = base_com if city.powered: rss_upkeep += 4000 * city.oil_refinery * rss_upkeep_mod pollution += 32 * city.oil_refinery * manu_poll_mod - oil -= 3 * city.oil_refinery * (1 + ((0.5 * (city.oil_refinery - 1)) / (5 - 1))) * gas_mod - gasoline += 6 * city.oil_refinery * (1 + ((0.5 * (city.oil_refinery - 1)) / (5 - 1))) * gas_mod + oil -= ( + 3 + * city.oil_refinery + * (1 + ((0.5 * (city.oil_refinery - 1)) / (5 - 1))) + * gas_mod + ) + gasoline += ( + 6 + * city.oil_refinery + * (1 + ((0.5 * (city.oil_refinery - 1)) / (5 - 1))) + * gas_mod + ) rss_upkeep += 4000 * city.steel_mill * rss_upkeep_mod pollution += 40 * city.steel_mill * manu_poll_mod - iron -= 3 * city.steel_mill * (1 + ((0.5 * (city.steel_mill - 1)) / (5 - 1))) * ste_mod - coal -= 3 * city.steel_mill * (1 + ((0.5 * (city.steel_mill - 1)) / (5 - 1))) * ste_mod - steel += 9 * city.steel_mill * (1 + ((0.5 * (city.steel_mill - 1)) / (5 - 1))) * ste_mod + iron -= ( + 3 + * city.steel_mill + * (1 + ((0.5 * (city.steel_mill - 1)) / (5 - 1))) + * ste_mod + ) + coal -= ( + 3 + * city.steel_mill + * (1 + ((0.5 * (city.steel_mill - 1)) / (5 - 1))) + * ste_mod + ) + steel += ( + 9 + * city.steel_mill + * (1 + ((0.5 * (city.steel_mill - 1)) / (5 - 1))) + * ste_mod + ) rss_upkeep += 2500 * city.aluminum_refinery * rss_upkeep_mod pollution += 40 * city.aluminum_refinery * manu_poll_mod - bauxite -= 3 * city.aluminum_refinery * (1 + ((0.5 * (city.aluminum_refinery - 1)) / (5 - 1))) * alu_mod - aluminum += 9 * city.aluminum_refinery * (1 + ((0.5 * (city.aluminum_refinery - 1)) / (5 - 1))) * alu_mod + bauxite -= ( + 3 + * city.aluminum_refinery + * (1 + ((0.5 * (city.aluminum_refinery - 1)) / (5 - 1))) + * alu_mod + ) + aluminum += ( + 9 + * city.aluminum_refinery + * (1 + ((0.5 * (city.aluminum_refinery - 1)) / (5 - 1))) + * alu_mod + ) rss_upkeep += 3500 * city.munitions_factory * rss_upkeep_mod pollution += 32 * city.munitions_factory * manu_poll_mod - lead -= 6 * city.munitions_factory * (1 + ((0.5 * (city.munitions_factory - 1)) / (5 - 1))) * mun_mod - munitions += 18 * city.munitions_factory * (1 + ((0.5 * (city.munitions_factory - 1)) / (5 - 1))) * mun_mod - - civil_upkeep += city.police_station * 750 - civil_upkeep += city.hospital * 1000 - civil_upkeep += city.recycling_center * 2500 - civil_upkeep += city.subway * 3250 - civil_upkeep += city.supermarket * 600 - civil_upkeep += city.bank * 1800 + lead -= ( + 6 + * city.munitions_factory + * (1 + ((0.5 * (city.munitions_factory - 1)) / (5 - 1))) + * mun_mod + ) + munitions += ( + 18 + * city.munitions_factory + * (1 + ((0.5 * (city.munitions_factory - 1)) / (5 - 1))) + * mun_mod + ) + + civil_upkeep += city.police_station * 750 + civil_upkeep += city.hospital * 1000 + civil_upkeep += city.recycling_center * 2500 + civil_upkeep += city.subway * 3250 + civil_upkeep += city.supermarket * 600 + civil_upkeep += city.bank * 1800 civil_upkeep += city.shopping_mall * 5400 - civil_upkeep += city.stadium * 12150 + civil_upkeep += city.stadium * 12150 police_stations = city.police_station hospitals = city.hospital @@ -1193,10 +1267,10 @@ class Banking(commands.Cog): city.pollution = pollution commerce += city.subway * 8 - commerce += city.supermarket * 3 - commerce += city.bank * 5 + commerce += city.supermarket * 3 + commerce += city.bank * 5 commerce += city.shopping_mall * 9 - commerce += city.stadium * 12 + commerce += city.stadium * 12 city.real_commerce = commerce if commerce > max_commerce: @@ -1207,20 +1281,27 @@ class Banking(commands.Cog): police_stations = 0 hospitals = 0 - crime_rate = ((103 - commerce)**2 + (city.infrastructure * 100))/(111111) - police_stations * pol_cri_red + crime_rate = ((103 - commerce) ** 2 + (city.infrastructure * 100)) / ( + 111111 + ) - police_stations * pol_cri_red city.real_crime_rate = crime_rate if crime_rate < 0: crime_rate = 0 city.crime_rate = crime_rate crime_deaths = ((crime_rate) / 10) * (100 * city.infrastructure) - 25 - disease_rate = (((((base_pop / city.land)**2) * 0.01) - 25)/100) + (base_pop/100000) + pollution * 0.05 - hospitals * hos_dis_red + disease_rate = ( + (((((base_pop / city.land) ** 2) * 0.01) - 25) / 100) + + (base_pop / 100000) + + pollution * 0.05 + - hospitals * hos_dis_red + ) city.real_disease_rate = disease_rate if disease_rate > 100: disease_rate = 100 elif disease_rate < 0: disease_rate = 0 city.disease_rate = disease_rate - disease_deaths = base_pop * (disease_rate/100) + disease_deaths = base_pop * (disease_rate / 100) if disease_deaths < 0: disease_deaths = 0 if isinstance(city.date, str): @@ -1230,25 +1311,27 @@ class Banking(commands.Cog): city_age = (datetime.datetime.utcnow() - city_date).days if city_age == 0: city_age = 1 - population = ((base_pop - disease_deaths - crime_deaths) * (1 + math.log(city_age)/15)) + population = (base_pop - disease_deaths - crime_deaths) * ( + 1 + math.log(city_age) / 15 + ) nationpop += population money_income += (((commerce / 50) * 0.725) + 0.725) * population - + alliance_treasures = 0 nation_treasure_bonus = 1 for treasure in treasures: - if treasure['nation'] == None: + if treasure["nation"] == None: continue - if treasure['nation']['id'] == nation.id: - nation_treasure_bonus += treasure['bonus'] / 100 + if treasure["nation"]["id"] == nation.id: + nation_treasure_bonus += treasure["bonus"] / 100 if nation.alliance: - if treasure['nation']['alliance_id'] == nation.alliance_id: + if treasure["nation"]["alliance_id"] == nation.alliance_id: alliance_treasures += 1 if alliance_treasures > 0: nation_treasure_bonus += math.sqrt(alliance_treasures * 4) / 100 if nation_treasure_bonus > 1: treasure_text = f"\n\nTreasure Bonus: ${round(money_income * (nation_treasure_bonus - 1)):,}" - + if not single_city: color_bonus = colors[nation.color] color_text = f"\n\nColor Trade Bloc Bonus: ${round(color_bonus):,}" @@ -1259,14 +1342,16 @@ class Banking(commands.Cog): new_player_text = f"\n\nNew Player Bonus: ${round((new_player_bonus - 1) * money_income):,}" if nation.dompolicy == "Open Markets": policy_bonus = 1.01 - policy_bonus_text = f"\n\nOpen Markets Bonus: ${round(money_income * 0.01):,}" - + policy_bonus_text = ( + f"\n\nOpen Markets Bonus: ${round(money_income * 0.01):,}" + ) + at_war = False if not single_city: for war in nation.wars: - if war['turnsleft'] > 0: + if war["turnsleft"] > 0: at_war = True - if include_spies: + if include_spies: military_upkeep += nation.spies * 2400 if not at_war: military_upkeep += nation.soldiers * 1.25 @@ -1275,14 +1360,14 @@ class Banking(commands.Cog): military_upkeep += nation.aircraft * 500 military_upkeep += nation.ships * 3750 military_upkeep += nation.missiles * 21000 - military_upkeep += nation.nukes * 31500 + military_upkeep += nation.nukes * 31500 else: military_upkeep += nation.soldiers * 1.88 food -= nation.soldiers / 500 military_upkeep += nation.tanks * 75 military_upkeep += nation.aircraft * 750 military_upkeep += nation.ships * 5625 - military_upkeep += nation.missiles * 35000 + military_upkeep += nation.missiles * 35000 military_upkeep += nation.nukes * 52500 else: military_upkeep += int(city.barracks) * 3000 * 1.25 @@ -1292,78 +1377,130 @@ class Banking(commands.Cog): if nation.dompolicy == "Imperialism": mil_cost = 0.95 - policy_bonus_text = f"\n\nImperialism Bonus: ${round(military_upkeep * 0.05):,}" + policy_bonus_text = ( + f"\n\nImperialism Bonus: ${round(military_upkeep * 0.05):,}" + ) if food < 0: starve_exp_text = f"\n\nPossible Starvation Penalty: ${round(money_income * policy_bonus * new_player_bonus * 0.33):,}*" starve_money_text = f" (${round(money_income * policy_bonus * new_player_bonus * 0.67 + color_bonus - power_upkeep - rss_upkeep - military_upkeep * mil_cost - civil_upkeep):,}*)" starve_net_text = f" (${round(money_income * policy_bonus * new_player_bonus * 0.67 + color_bonus - power_upkeep - rss_upkeep - military_upkeep * mil_cost - civil_upkeep + coal * prices['coal'] + oil * prices['oil'] + uranium * prices['uranium'] + lead * prices['lead'] + iron * prices['iron'] + bauxite * prices['bauxite'] + gasoline * prices['gasoline'] + munitions * prices['munitions'] + steel * prices['steel'] + aluminum * prices['aluminum'] + food * prices['food']):,}*)" footer = "* The income if the nation is suffering from a starvation penalty" - - max_infra = sorted(nation.cities, key=lambda k: k['infrastructure'], reverse=True)[0]['infrastructure'] + + max_infra = sorted( + nation.cities, key=lambda k: k["infrastructure"], reverse=True + )[0]["infrastructure"] if single_city: rev_obj = nation.cities[0] else: rev_obj = {} - rev_obj['monetary_net_num'] = round(money_income * policy_bonus * new_player_bonus * nation_treasure_bonus + color_bonus - power_upkeep - rss_upkeep - military_upkeep * mil_cost - civil_upkeep + coal * prices['coal'] + oil * prices['oil'] + uranium * prices['uranium'] + lead * prices['lead'] + iron * prices['iron'] + bauxite * prices['bauxite'] + gasoline * prices['gasoline'] + munitions * prices['munitions'] + steel * prices['steel'] + aluminum * prices['aluminum'] + food * prices['food']) - rev_obj['net_cash_num'] = round(money_income * policy_bonus * new_player_bonus * nation_treasure_bonus + color_bonus - power_upkeep - rss_upkeep - military_upkeep * mil_cost - civil_upkeep) - rev_obj['food'] = food + rev_obj["monetary_net_num"] = round( + money_income * policy_bonus * new_player_bonus * nation_treasure_bonus + + color_bonus + - power_upkeep + - rss_upkeep + - military_upkeep * mil_cost + - civil_upkeep + + coal * prices["coal"] + + oil * prices["oil"] + + uranium * prices["uranium"] + + lead * prices["lead"] + + iron * prices["iron"] + + bauxite * prices["bauxite"] + + gasoline * prices["gasoline"] + + munitions * prices["munitions"] + + steel * prices["steel"] + + aluminum * prices["aluminum"] + + food * prices["food"] + ) + rev_obj["net_cash_num"] = round( + money_income * policy_bonus * new_player_bonus * nation_treasure_bonus + + color_bonus + - power_upkeep + - rss_upkeep + - military_upkeep * mil_cost + - civil_upkeep + ) + rev_obj["food"] = food if single_city and not build: - rev_obj['money'] = rev_obj['net_cash_num'] - rev_obj['net income'] = rev_obj['monetary_net_num'] - rev_obj['aluminum'] = aluminum - rev_obj['bauxite'] = bauxite - rev_obj['coal'] = coal - rev_obj['gasoline'] = gasoline - rev_obj['iron'] = iron - rev_obj['lead'] = lead - rev_obj['munitions'] = munitions - rev_obj['oil'] = oil - rev_obj['steel'] = steel - rev_obj['uranium'] = uranium - rev_obj['disease_rate'] = disease_rate - rev_obj['crime_rate'] = crime_rate - rev_obj['commerce'] = commerce - rev_obj['pollution'] = pollution + rev_obj["money"] = rev_obj["net_cash_num"] + rev_obj["net income"] = rev_obj["monetary_net_num"] + rev_obj["aluminum"] = aluminum + rev_obj["bauxite"] = bauxite + rev_obj["coal"] = coal + rev_obj["gasoline"] = gasoline + rev_obj["iron"] = iron + rev_obj["lead"] = lead + rev_obj["munitions"] = munitions + rev_obj["oil"] = oil + rev_obj["steel"] = steel + rev_obj["uranium"] = uranium + rev_obj["disease_rate"] = disease_rate + rev_obj["crime_rate"] = crime_rate + rev_obj["commerce"] = commerce + rev_obj["pollution"] = pollution return rev_obj else: - rev_obj['nation'] = nation - rev_obj['footer'] = footer - rev_obj['max_infra'] = max_infra - rev_obj['avg_infra'] = round(total_infra / nation.num_cities) - rev_obj['income_txt']=f"National Tax Revenue: ${round(money_income):,}{color_text}{new_player_text}{policy_bonus_text}{treasure_text}" - rev_obj['expenses_txt']=f"Power Plant Upkeep: ${round(power_upkeep):,}\n\nResource Prod. Upkeep: ${round(rss_upkeep):,}\n\nMilitary Upkeep: ${round(military_upkeep * mil_cost):,}\n\nCity Improvement Upkeep: ${round(civil_upkeep):,}{starve_exp_text}" - rev_obj['net_rev_txt']=f"Coal: {round(coal):,}\nOil: {round(oil):,}\nUranium: {round(uranium):,}\nLead: {round(lead):,}\nIron: {round(iron):,}\nBauxite: {round(bauxite):,}\nGasoline: {round(gasoline):,}\nMunitions: {round(munitions):,}\nSteel: {round(steel):,}\nAluminum: {round(aluminum):,}\nFood: {round(food):,}\nMoney: ${round(money_income * policy_bonus * new_player_bonus * nation_treasure_bonus + color_bonus - power_upkeep - rss_upkeep - military_upkeep * mil_cost - civil_upkeep):,}{starve_money_text}" - rev_obj['mon_net_txt']=f"${round(money_income * policy_bonus * new_player_bonus * nation_treasure_bonus + color_bonus - power_upkeep - rss_upkeep - military_upkeep * mil_cost - civil_upkeep + coal * prices['coal'] + oil * prices['oil'] + uranium * prices['uranium'] + lead * prices['lead'] + iron * prices['iron'] + bauxite * prices['bauxite'] + gasoline * prices['gasoline'] + munitions * prices['munitions'] + steel * prices['steel'] + aluminum * prices['aluminum'] + food * prices['food']):,}{starve_net_text}" - rev_obj['money_txt']=f"${round(money_income * policy_bonus * new_player_bonus * nation_treasure_bonus + color_bonus - power_upkeep - rss_upkeep - military_upkeep * mil_cost - civil_upkeep):,}{starve_money_text}" + rev_obj["nation"] = nation + rev_obj["footer"] = footer + rev_obj["max_infra"] = max_infra + rev_obj["avg_infra"] = round(total_infra / nation.num_cities) + rev_obj["income_txt"] = ( + f"National Tax Revenue: ${round(money_income):,}{color_text}{new_player_text}{policy_bonus_text}{treasure_text}" + ) + rev_obj["expenses_txt"] = ( + f"Power Plant Upkeep: ${round(power_upkeep):,}\n\nResource Prod. Upkeep: ${round(rss_upkeep):,}\n\nMilitary Upkeep: ${round(military_upkeep * mil_cost):,}\n\nCity Improvement Upkeep: ${round(civil_upkeep):,}{starve_exp_text}" + ) + rev_obj["net_rev_txt"] = ( + f"Coal: {round(coal):,}\nOil: {round(oil):,}\nUranium: {round(uranium):,}\nLead: {round(lead):,}\nIron: {round(iron):,}\nBauxite: {round(bauxite):,}\nGasoline: {round(gasoline):,}\nMunitions: {round(munitions):,}\nSteel: {round(steel):,}\nAluminum: {round(aluminum):,}\nFood: {round(food):,}\nMoney: ${round(money_income * policy_bonus * new_player_bonus * nation_treasure_bonus + color_bonus - power_upkeep - rss_upkeep - military_upkeep * mil_cost - civil_upkeep):,}{starve_money_text}" + ) + rev_obj["mon_net_txt"] = ( + f"${round(money_income * policy_bonus * new_player_bonus * nation_treasure_bonus + color_bonus - power_upkeep - rss_upkeep - military_upkeep * mil_cost - civil_upkeep + coal * prices['coal'] + oil * prices['oil'] + uranium * prices['uranium'] + lead * prices['lead'] + iron * prices['iron'] + bauxite * prices['bauxite'] + gasoline * prices['gasoline'] + munitions * prices['munitions'] + steel * prices['steel'] + aluminum * prices['aluminum'] + food * prices['food']):,}{starve_net_text}" + ) + rev_obj["money_txt"] = ( + f"${round(money_income * policy_bonus * new_player_bonus * nation_treasure_bonus + color_bonus - power_upkeep - rss_upkeep - military_upkeep * mil_cost - civil_upkeep):,}{starve_money_text}" + ) return rev_obj - - async def calculate_revenue(self, message: discord.Message, nation: dict, game_data: dict) -> dict: + async def calculate_revenue( + self, message: discord.Message, nation: dict, game_data: dict + ) -> dict: """Calculate revenue for a nation.""" revenue = await self.revenue_calc( nation=nation, - radiation=game_data['radiation'], - treasures=game_data['treasures'], - prices=game_data['prices'], - colors=game_data['colors'], - seasonal_mod=game_data['seasonal_mod'], - build = None, - single_city = False, - include_spies = True + radiation=game_data["radiation"], + treasures=game_data["treasures"], + prices=game_data["prices"], + colors=game_data["colors"], + seasonal_mod=game_data["seasonal_mod"], + build=None, + single_city=False, + include_spies=True, ) - + return revenue async def get_game_data(self) -> dict: """ Fetch game-wide data needed for revenue calculations. """ - trade_prices_query = await self.kit.query("tradeprices", {"page":1, "first":1}, "coal, oil, uranium, iron, bauxite, lead, gasoline, munitions, steel, aluminum, food") + trade_prices_query = await self.kit.query( + "tradeprices", + {"page": 1, "first": 1}, + "coal, oil, uranium, iron, bauxite, lead, gasoline, munitions, steel, aluminum, food", + ) colors_query = await self.kit.query("colors", {}, "color, turn_bonus") - game_info_query = await self.kit.query("game_info", {}, "game_date, radiation {global, north_america, south_america, africa, europe, asia, australia, antarctica}") - treasures_query = await self.kit.query("treasures", {}, "name, bonus, spawn_date, nation_id, nation { alliance_id }") - + game_info_query = await self.kit.query( + "game_info", + {}, + "game_date, radiation {global, north_america, south_america, africa, europe, asia, australia, antarctica}", + ) + treasures_query = await self.kit.query( + "treasures", + {}, + "name, bonus, spawn_date, nation_id, nation { alliance_id }", + ) + # color bloc bonus colors = {} for color in colors_query.colors: @@ -1372,93 +1509,92 @@ class Banking(commands.Cog): # radiation rad = game_info_query.game_info.radiation radiation = { - "na": 1 - (rad.north_america + rad.global_)/1000, - "sa": 1 - (rad.south_america + rad.global_)/1000, - "eu": 1 - (rad.europe + rad.global_)/1000, - "as": 1 - (rad.asia + rad.global_)/1000, - "af": 1 - (rad.africa + rad.global_)/1000, - "au": 1 - (rad.australia + rad.global_)/1000, - "an": 1 - (rad.antarctica + rad.global_)/1000 + "na": 1 - (rad.north_america + rad.global_) / 1000, + "sa": 1 - (rad.south_america + rad.global_) / 1000, + "eu": 1 - (rad.europe + rad.global_) / 1000, + "as": 1 - (rad.asia + rad.global_) / 1000, + "af": 1 - (rad.africa + rad.global_) / 1000, + "au": 1 - (rad.australia + rad.global_) / 1000, + "an": 1 - (rad.antarctica + rad.global_) / 1000, } - + # seasons month = int(game_info_query.game_info.game_date.month) seasonal_mod = {"na": 1, "sa": 1, "eu": 1, "as": 1, "af": 1, "au": 1, "an": 0.5} - if month in [6,7,8]: - seasonal_mod['na'] = 1.2 - seasonal_mod['as'] = 1.2 - seasonal_mod['eu'] = 1.2 - seasonal_mod['sa'] = 0.8 - seasonal_mod['af'] = 0.8 - seasonal_mod['au'] = 0.8 - elif month in [12,1,2]: - seasonal_mod['na'] = 0.8 - seasonal_mod['as'] = 0.8 - seasonal_mod['eu'] = 0.8 - seasonal_mod['sa'] = 1.2 - seasonal_mod['af'] = 1.2 - seasonal_mod['au'] = 1.2 + if month in [6, 7, 8]: + seasonal_mod["na"] = 1.2 + seasonal_mod["as"] = 1.2 + seasonal_mod["eu"] = 1.2 + seasonal_mod["sa"] = 0.8 + seasonal_mod["af"] = 0.8 + seasonal_mod["au"] = 0.8 + elif month in [12, 1, 2]: + seasonal_mod["na"] = 0.8 + seasonal_mod["as"] = 0.8 + seasonal_mod["eu"] = 0.8 + seasonal_mod["sa"] = 1.2 + seasonal_mod["af"] = 1.2 + seasonal_mod["au"] = 1.2 # market price prices_data = trade_prices_query.tradeprices[0] prices = { - 'coal': prices_data.coal, - 'oil' : prices_data.oil, - 'uranium' : prices_data.uranium, - 'iron' : prices_data.iron, - 'bauxite' : prices_data.bauxite, - 'lead' : prices_data.lead, - 'gasoline' : prices_data.gasoline, - 'munitions' : prices_data.munitions, - 'steel' : prices_data.steel, - 'aluminum' : prices_data.aluminum, - 'food' : prices_data.food + "coal": prices_data.coal, + "oil": prices_data.oil, + "uranium": prices_data.uranium, + "iron": prices_data.iron, + "bauxite": prices_data.bauxite, + "lead": prices_data.lead, + "gasoline": prices_data.gasoline, + "munitions": prices_data.munitions, + "steel": prices_data.steel, + "aluminum": prices_data.aluminum, + "food": prices_data.food, } - treasures = { - 'name': [], 'bonus':[] - } + treasures = {"name": [], "bonus": []} treasures_data = treasures_query.treasures for treasure in treasures_data: if treasure.nation.alliance_id == 10177: - treasures['name'].append(treasure.name) - treasures['bonus'].append(treasure.bonus) + treasures["name"].append(treasure.name) + treasures["bonus"].append(treasure.bonus) return { - 'prices': prices, - 'treasures': treasures, - 'radiation': radiation, - 'seasonal_mod': seasonal_mod, - 'colors': colors + "prices": prices, + "treasures": treasures, + "radiation": radiation, + "seasonal_mod": seasonal_mod, + "colors": colors, } async def send_revenue_results(self, ctx: commands.Context, revenue_data: list): """Format and send the revenue calculation results.""" if not revenue_data: return await ctx.send("> No revenue data to display.") - + # Create embeds for each nation's revenue embeds = [] for data in revenue_data: - revenue = data['revenue'] + revenue = data["revenue"] e = discord.Embed( title=f"Revenue for {data['nation_name']}", color=ctx.author.color, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.datetime.utcnow(), ) - - e.add_field(name="Income", value=revenue['income_txt'], inline=False) - e.add_field(name="Expenses", value=revenue['expenses_txt'], inline=False) - e.add_field(name="Net Revenue", value=revenue['net_rev_txt'], inline=False) - e.add_field(name="Monetary Net", value=revenue['mon_net_txt'], inline=False) - - if revenue['footer']: - e.set_footer(text=revenue['footer']) - + + e.add_field(name="Income", value=revenue["income_txt"], inline=False) + e.add_field(name="Expenses", value=revenue["expenses_txt"], inline=False) + e.add_field(name="Net Revenue", value=revenue["net_rev_txt"], inline=False) + e.add_field(name="Monetary Net", value=revenue["mon_net_txt"], inline=False) + + if revenue["footer"]: + e.set_footer(text=revenue["footer"]) + embeds.append(e) - + # Paginate the results await ctx.paginate(pages=embeds) + async def setup(bot: Brahmos): await bot.add_cog(Banking(bot))