From 00b2ce7d49f556525637f4755a23a57fc058ddbf Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 25 May 2025 20:49:22 +0530 Subject: [PATCH 01/45] initial_resource_calculation --- exts/banking.py | 530 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 529 insertions(+), 1 deletion(-) diff --git a/exts/banking.py b/exts/banking.py index b67b434..0653f9c 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -15,6 +15,7 @@ from discord.ext import commands from discord import app_commands from discord.utils import format_dt from numerize_denumerize import denumerize, numerize +import math from botclass import Brahmos, CustomCtx from utils.base import BasicView @@ -922,9 +923,536 @@ class Banking(commands.Cog): 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 refill(self, ctx: commands.Context, ids: commands.Greedy[int]): + """ + Revenue calculation from nations by fetching cities and projects. + """ + data = await self.kit.query( + "alliances", + {"id": [10177, 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}}" + ) + + nations = [] + for alliance in data.alliances: + nations.extend(alliance.nations) + + if ids: + notinalliance = [n for n in ids if n not in [n.id for n in nations]] + nations = [n for n in nations if n.id in ids] + if not nations: + return await ctx.send(f"> {ids} not in MILF or DILF") + if notinalliance: + await ctx.send(f"> {notinalliance} not in MILF or DILF") + + revenue_data = [] + message = await ctx.send("Calculating revenue for nations...") + + 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 + }) + + except Exception as e: + await ctx.send(f"> Error calculating revenue for {nation.nation_name}: {str(e)}") + continue + + # 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: + max_commerce = 100 + base_com = 0 + hos_dis_red = 2.5 + alu_mod = 1 + mun_mod = 1 + gas_mod = 1 + manu_poll_mod = 1 + farm_poll_mod = 0.5 + subw_poll_red = 45 + rss_upkeep_mod = 1 + ste_mod = 1 + rec_poll = 70 + pol_cri_red = 2.5 + food_land_mod = 500 + uranium_mod = 1 + rss_upkeep = 0 + civil_upkeep = 0 + military_upkeep = 0 + money_income = 0 + power_upkeep = 0 + nationpop = 0 + color_bonus = 0 + policy_bonus = 1 + new_player_bonus = 1 + mil_cost = 1 + total_infra = 0 + starve_net_text = "" + starve_money_text = "" + starve_exp_text = "" + color_text = "" + new_player_text = "" + policy_bonus_text = "" + treasure_text = "" + footer = "" + + if nation['iron_works'] == True: + ste_mod = 1.36 + if nation['bauxite_works'] == True: + alu_mod = 1.36 + if nation['arms_stockpile'] == True: + mun_mod = 1.34 + if nation['emergency_gasoline_reserve'] == True: + gas_mod = 2 + if nation['mass_irrigation'] == True: + food_land_mod = 400 + if nation['international_trade_center'] == True: + max_commerce = 115 + if nation['telecommunications_satellite'] == True: + max_commerce = 125 + base_com = 2 + if nation['recycling_initiative'] == True: + rec_poll = 75 + if nation['green_technologues'] == True: + manu_poll_mod = 0.75 + farm_poll_mod = 0.5 + subw_poll_red = 70 + rss_upkeep_mod = 0.9 + if nation['clinical_research_center'] == True: + hos_dis_red = 3.5 + if nation['specialized_police_training'] == True: + hos_dis_red = 3.5 + if nation['uranium_enrichment_program'] == True: + uranium_mod = 2 + + coal = 0 + oil = 0 + uranium = 0 + lead = 0 + iron = 0 + bauxite = 0 + gasoline = 0 + munitions = 0 + steel = 0 + aluminum = 0 + food = 0 + + if build != None: + try: + build = json.loads(build) + except json.JSONDecodeError: + await message.edit(content="Something is wrong with the build you sent!") + return + land = 0 + for city in nation['cities']: + land += city['land'] + 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['powered'] = True + city['date'] = nation['cities'][math.ceil(nation['num_cities']/2)]['date'] + nation['cities'] = [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 + if unpowered_infra > 0: + unpowered_infra -= 250 + power_upkeep += 42 + 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 + 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 + pollution += 8 + for level in range(5): + if unpowered_infra > 0: + unpowered_infra -= 100 + coal -= 1.2 + + rss_upkeep += 400 * city['coal_mine'] * rss_upkeep_mod + pollution += 12 * city['coal_mine'] + coal += 3 * city['coal_mine'] * (1 + ((0.5 * (city['coal_mine'] - 1)) / (10 - 1))) + + rss_upkeep += 600 * city['oil_well'] * rss_upkeep_mod + pollution += 12 * city['oil_well'] + oil += 3 * city['oil_well'] * (1 + ((0.5 * (city['oil_well'] - 1)) / (10 - 1))) + + 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 + + rss_upkeep += 1500 * city['lead_mine'] * rss_upkeep_mod + pollution += 12 * city['lead_mine'] + lead += 3 * city['lead_mine'] * (1 + ((0.5 * (city['lead_mine'] - 1)) / (10 - 1))) + + rss_upkeep += 1600 * city['iron_mine'] * rss_upkeep_mod + pollution += 12 * city['iron_mine'] + iron += 3 * city['iron_mine'] * (1 + ((0.5 * (city['iron_mine'] - 1)) / (10 - 1))) + + 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))) + + 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 + 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 + + 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 + + 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 + + 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 + civil_upkeep += city['mall'] * 5400 + civil_upkeep += city['stadium'] * 12150 + + police_stations = city['police_station'] + hospitals = city['hospital'] + + pollution += city['police_station'] + pollution += city['hospital'] * 4 + pollution -= city['recycling_center'] * rec_poll + pollution -= city['subway'] * subw_poll_red + pollution += city['mall'] * 2 + pollution += city['stadium'] * 5 + + city['real_pollution'] = pollution + if pollution < 0: + pollution = 0 + city['pollution'] = pollution + + commerce += city['subway'] * 8 + commerce += city['supermarket'] * 3 + commerce += city['bank'] * 5 + commerce += city['mall'] * 9 + commerce += city['stadium'] * 12 + + city['real_commerce'] = commerce + if commerce > max_commerce: + commerce = max_commerce + city['commerce'] = commerce + + else: + police_stations = 0 + hospitals = 0 + + 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 + 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) + if disease_deaths < 0: + disease_deaths = 0 + city_age = (datetime.datetime.utcnow() - datetime.datetime.strptime(city['date'], "%Y-%m-%d")).days + if city_age == 0: + city_age = 1 + 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: + continue + if treasure['nation']['id'] == nation['id']: + nation_treasure_bonus += treasure['bonus'] / 100 + if nation['alliance']: + 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):,}" + food -= nationpop / 1000 + + if nation['num_cities'] < 11: + new_player_bonus = 2.1 - 0.1 * nation['num_cities'] + 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):,}" + + at_war = False + if not single_city: + for war in nation['wars']: + if war['turnsleft'] > 0: + at_war = True + if include_spies: + military_upkeep += nation['spies'] * 2400 + if not at_war: + military_upkeep += nation['soldiers'] * 1.25 + food -= nation['soldiers'] / 750 + military_upkeep += nation['tanks'] * 50 + military_upkeep += nation['aircraft'] * 500 + military_upkeep += nation['ships'] * 3750 + military_upkeep += nation['missiles'] * 21000 + 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['nukes'] * 52500 + else: + military_upkeep += int(city['barracks']) * 3000 * 1.25 + military_upkeep += int(city['factory']) * 250 * 50 + military_upkeep += int(city['hangar']) * 15 * 500 + military_upkeep += int(city['drydock']) * 5 * 3750 + + if nation['dompolicy'] == "Imperialism": + mil_cost = 0.95 + 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'] + + 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 + 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 + 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}" + return rev_obj + + +async def calculate_revenue(self, message: discord.Message, nation: dict, game_data: dict) -> dict: + """Calculate revenue for a nation.""" + revenue = await revenue_calc( + message=message, + nation=nation, + radiation=game_data['radiation'], + treasures=game_data['treasures'], + prices=game_data['prices'], + colors=game_data['colors'], + seasonal_mod=game_data['seasonal_mod'] + ) + + 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") + 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 }") + + # color bloc bonus + colors = {} + for color in colors_query.colors: + colors[color.color] = color.turn_bonus * 12 + + # 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 + } + + # 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 + + # 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 + } + + 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) + + return { + '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'] + e = discord.Embed( + title=f"Revenue for {data['nation_name']}", + color=ctx.author.color, + 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']) + + embeds.append(e) + + # Paginate the results + await ctx.paginate(pages=embeds) async def setup(bot: Brahmos): await bot.add_cog(Banking(bot)) From 232c4178aaedec01ca32e9218c5ee5ed7dcc22dc Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 25 May 2025 20:58:29 +0530 Subject: [PATCH 02/45] changes --- exts/banking.py | 1050 +++++++++++++++++++++++------------------------ 1 file changed, 525 insertions(+), 525 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index 0653f9c..03f5845 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -925,534 +925,534 @@ class Banking(commands.Cog): else: 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 refill(self, ctx: commands.Context, ids: commands.Greedy[int]): - """ - Revenue calculation from nations by fetching cities and projects. - """ - data = await self.kit.query( - "alliances", - {"id": [10177, 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}}" - ) - - nations = [] - for alliance in data.alliances: - nations.extend(alliance.nations) - - if ids: - notinalliance = [n for n in ids if n not in [n.id for n in nations]] - nations = [n for n in nations if n.id in ids] - if not nations: - return await ctx.send(f"> {ids} not in MILF or DILF") - if notinalliance: - await ctx.send(f"> {notinalliance} not in MILF or DILF") - - revenue_data = [] - message = await ctx.send("Calculating revenue for nations...") - - 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 - }) - - except Exception as e: - await ctx.send(f"> Error calculating revenue for {nation.nation_name}: {str(e)}") - continue - - # 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: - max_commerce = 100 - base_com = 0 - hos_dis_red = 2.5 - alu_mod = 1 - mun_mod = 1 - gas_mod = 1 - manu_poll_mod = 1 - farm_poll_mod = 0.5 - subw_poll_red = 45 - rss_upkeep_mod = 1 - ste_mod = 1 - rec_poll = 70 - pol_cri_red = 2.5 - food_land_mod = 500 - uranium_mod = 1 - rss_upkeep = 0 - civil_upkeep = 0 - military_upkeep = 0 - money_income = 0 - power_upkeep = 0 - nationpop = 0 - color_bonus = 0 - policy_bonus = 1 - new_player_bonus = 1 - mil_cost = 1 - total_infra = 0 - starve_net_text = "" - starve_money_text = "" - starve_exp_text = "" - color_text = "" - new_player_text = "" - policy_bonus_text = "" - treasure_text = "" - footer = "" - - if nation['iron_works'] == True: - ste_mod = 1.36 - if nation['bauxite_works'] == True: - alu_mod = 1.36 - if nation['arms_stockpile'] == True: - mun_mod = 1.34 - if nation['emergency_gasoline_reserve'] == True: - gas_mod = 2 - if nation['mass_irrigation'] == True: - food_land_mod = 400 - if nation['international_trade_center'] == True: - max_commerce = 115 - if nation['telecommunications_satellite'] == True: - max_commerce = 125 - base_com = 2 - if nation['recycling_initiative'] == True: - rec_poll = 75 - if nation['green_technologues'] == True: - manu_poll_mod = 0.75 - farm_poll_mod = 0.5 - subw_poll_red = 70 - rss_upkeep_mod = 0.9 - if nation['clinical_research_center'] == True: - hos_dis_red = 3.5 - if nation['specialized_police_training'] == True: - hos_dis_red = 3.5 - if nation['uranium_enrichment_program'] == True: - uranium_mod = 2 - - coal = 0 - oil = 0 - uranium = 0 - lead = 0 - iron = 0 - bauxite = 0 - gasoline = 0 - munitions = 0 - steel = 0 - aluminum = 0 - food = 0 - - if build != None: - try: - build = json.loads(build) - except json.JSONDecodeError: - await message.edit(content="Something is wrong with the build you sent!") - return - land = 0 - for city in nation['cities']: - land += city['land'] - 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['powered'] = True - city['date'] = nation['cities'][math.ceil(nation['num_cities']/2)]['date'] - nation['cities'] = [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 - if unpowered_infra > 0: - unpowered_infra -= 250 - power_upkeep += 42 - 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 - 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 - pollution += 8 - for level in range(5): - if unpowered_infra > 0: - unpowered_infra -= 100 - coal -= 1.2 - - rss_upkeep += 400 * city['coal_mine'] * rss_upkeep_mod - pollution += 12 * city['coal_mine'] - coal += 3 * city['coal_mine'] * (1 + ((0.5 * (city['coal_mine'] - 1)) / (10 - 1))) - - rss_upkeep += 600 * city['oil_well'] * rss_upkeep_mod - pollution += 12 * city['oil_well'] - oil += 3 * city['oil_well'] * (1 + ((0.5 * (city['oil_well'] - 1)) / (10 - 1))) - - 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 - - rss_upkeep += 1500 * city['lead_mine'] * rss_upkeep_mod - pollution += 12 * city['lead_mine'] - lead += 3 * city['lead_mine'] * (1 + ((0.5 * (city['lead_mine'] - 1)) / (10 - 1))) - - rss_upkeep += 1600 * city['iron_mine'] * rss_upkeep_mod - pollution += 12 * city['iron_mine'] - iron += 3 * city['iron_mine'] * (1 + ((0.5 * (city['iron_mine'] - 1)) / (10 - 1))) - - 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))) - - 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 - 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 - - 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 - - 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 - - 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 - civil_upkeep += city['mall'] * 5400 - civil_upkeep += city['stadium'] * 12150 - - police_stations = city['police_station'] - hospitals = city['hospital'] - - pollution += city['police_station'] - pollution += city['hospital'] * 4 - pollution -= city['recycling_center'] * rec_poll - pollution -= city['subway'] * subw_poll_red - pollution += city['mall'] * 2 - pollution += city['stadium'] * 5 - - city['real_pollution'] = pollution - if pollution < 0: - pollution = 0 - city['pollution'] = pollution - - commerce += city['subway'] * 8 - commerce += city['supermarket'] * 3 - commerce += city['bank'] * 5 - commerce += city['mall'] * 9 - commerce += city['stadium'] * 12 - - city['real_commerce'] = commerce - if commerce > max_commerce: - commerce = max_commerce - city['commerce'] = commerce - - else: - police_stations = 0 - hospitals = 0 - - 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 - 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) - if disease_deaths < 0: - disease_deaths = 0 - city_age = (datetime.datetime.utcnow() - datetime.datetime.strptime(city['date'], "%Y-%m-%d")).days - if city_age == 0: - city_age = 1 - 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: - continue - if treasure['nation']['id'] == nation['id']: - nation_treasure_bonus += treasure['bonus'] / 100 - if nation['alliance']: - 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):,}" - food -= nationpop / 1000 - - if nation['num_cities'] < 11: - new_player_bonus = 2.1 - 0.1 * nation['num_cities'] - 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):,}" - - at_war = False - if not single_city: - for war in nation['wars']: - if war['turnsleft'] > 0: - at_war = True - if include_spies: - military_upkeep += nation['spies'] * 2400 - if not at_war: - military_upkeep += nation['soldiers'] * 1.25 - food -= nation['soldiers'] / 750 - military_upkeep += nation['tanks'] * 50 - military_upkeep += nation['aircraft'] * 500 - military_upkeep += nation['ships'] * 3750 - military_upkeep += nation['missiles'] * 21000 - 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['nukes'] * 52500 - else: - military_upkeep += int(city['barracks']) * 3000 * 1.25 - military_upkeep += int(city['factory']) * 250 * 50 - military_upkeep += int(city['hangar']) * 15 * 500 - military_upkeep += int(city['drydock']) * 5 * 3750 - - if nation['dompolicy'] == "Imperialism": - mil_cost = 0.95 - 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'] - - 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 - 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 - 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}" - return rev_obj - - -async def calculate_revenue(self, message: discord.Message, nation: dict, game_data: dict) -> dict: - """Calculate revenue for a nation.""" - revenue = await revenue_calc( - message=message, - nation=nation, - radiation=game_data['radiation'], - treasures=game_data['treasures'], - prices=game_data['prices'], - colors=game_data['colors'], - seasonal_mod=game_data['seasonal_mod'] - ) - - 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") - 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 }") - - # color bloc bonus - colors = {} - for color in colors_query.colors: - colors[color.color] = color.turn_bonus * 12 - - # 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 - } - - # 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 - - # 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 - } - - 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) - - return { - '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'] - e = discord.Embed( - title=f"Revenue for {data['nation_name']}", - color=ctx.author.color, - timestamp=datetime.datetime.utcnow() + @commands.has_any_role("The Croak Council", "Government") + @commands.command(aliases=["refill"]) + async def refill(self, ctx: commands.Context, ids: commands.Greedy[int]): + """ + Revenue calculation from nations by fetching cities and projects. + """ + data = await self.kit.query( + "alliances", + {"id": [10177, 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}}" ) - 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']) + nations = [] + for alliance in data.alliances: + nations.extend(alliance.nations) + + if ids: + notinalliance = [n for n in ids if n not in [n.id for n in nations]] + nations = [n for n in nations if n.id in ids] + if not nations: + return await ctx.send(f"> {ids} not in MILF or DILF") + if notinalliance: + await ctx.send(f"> {notinalliance} not in MILF or DILF") + + revenue_data = [] + message = await ctx.send("Calculating revenue for nations...") + + try: + game_data = await self.get_game_data() - embeds.append(e) - - # Paginate the results - await ctx.paginate(pages=embeds) + 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 + }) + + except Exception as e: + await ctx.send(f"> Error calculating revenue for {nation.nation_name}: {str(e)}") + continue + + # 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: + max_commerce = 100 + base_com = 0 + hos_dis_red = 2.5 + alu_mod = 1 + mun_mod = 1 + gas_mod = 1 + manu_poll_mod = 1 + farm_poll_mod = 0.5 + subw_poll_red = 45 + rss_upkeep_mod = 1 + ste_mod = 1 + rec_poll = 70 + pol_cri_red = 2.5 + food_land_mod = 500 + uranium_mod = 1 + rss_upkeep = 0 + civil_upkeep = 0 + military_upkeep = 0 + money_income = 0 + power_upkeep = 0 + nationpop = 0 + color_bonus = 0 + policy_bonus = 1 + new_player_bonus = 1 + mil_cost = 1 + total_infra = 0 + starve_net_text = "" + starve_money_text = "" + starve_exp_text = "" + color_text = "" + new_player_text = "" + policy_bonus_text = "" + treasure_text = "" + footer = "" + + if nation['iron_works'] == True: + ste_mod = 1.36 + if nation['bauxite_works'] == True: + alu_mod = 1.36 + if nation['arms_stockpile'] == True: + mun_mod = 1.34 + if nation['emergency_gasoline_reserve'] == True: + gas_mod = 2 + if nation['mass_irrigation'] == True: + food_land_mod = 400 + if nation['international_trade_center'] == True: + max_commerce = 115 + if nation['telecommunications_satellite'] == True: + max_commerce = 125 + base_com = 2 + if nation['recycling_initiative'] == True: + rec_poll = 75 + if nation['green_technologues'] == True: + manu_poll_mod = 0.75 + farm_poll_mod = 0.5 + subw_poll_red = 70 + rss_upkeep_mod = 0.9 + if nation['clinical_research_center'] == True: + hos_dis_red = 3.5 + if nation['specialized_police_training'] == True: + hos_dis_red = 3.5 + if nation['uranium_enrichment_program'] == True: + uranium_mod = 2 + + coal = 0 + oil = 0 + uranium = 0 + lead = 0 + iron = 0 + bauxite = 0 + gasoline = 0 + munitions = 0 + steel = 0 + aluminum = 0 + food = 0 + + if build != None: + try: + build = json.loads(build) + except json.JSONDecodeError: + await message.edit(content="Something is wrong with the build you sent!") + return + land = 0 + for city in nation['cities']: + land += city['land'] + 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['powered'] = True + city['date'] = nation['cities'][math.ceil(nation['num_cities']/2)]['date'] + nation['cities'] = [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 + if unpowered_infra > 0: + unpowered_infra -= 250 + power_upkeep += 42 + 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 + 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 + pollution += 8 + for level in range(5): + if unpowered_infra > 0: + unpowered_infra -= 100 + coal -= 1.2 + + rss_upkeep += 400 * city['coal_mine'] * rss_upkeep_mod + pollution += 12 * city['coal_mine'] + coal += 3 * city['coal_mine'] * (1 + ((0.5 * (city['coal_mine'] - 1)) / (10 - 1))) + + rss_upkeep += 600 * city['oil_well'] * rss_upkeep_mod + pollution += 12 * city['oil_well'] + oil += 3 * city['oil_well'] * (1 + ((0.5 * (city['oil_well'] - 1)) / (10 - 1))) + + 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 + + rss_upkeep += 1500 * city['lead_mine'] * rss_upkeep_mod + pollution += 12 * city['lead_mine'] + lead += 3 * city['lead_mine'] * (1 + ((0.5 * (city['lead_mine'] - 1)) / (10 - 1))) + + rss_upkeep += 1600 * city['iron_mine'] * rss_upkeep_mod + pollution += 12 * city['iron_mine'] + iron += 3 * city['iron_mine'] * (1 + ((0.5 * (city['iron_mine'] - 1)) / (10 - 1))) + + 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))) + + 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 + 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 + + 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 + + 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 + + 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 + civil_upkeep += city['mall'] * 5400 + civil_upkeep += city['stadium'] * 12150 + + police_stations = city['police_station'] + hospitals = city['hospital'] + + pollution += city['police_station'] + pollution += city['hospital'] * 4 + pollution -= city['recycling_center'] * rec_poll + pollution -= city['subway'] * subw_poll_red + pollution += city['mall'] * 2 + pollution += city['stadium'] * 5 + + city['real_pollution'] = pollution + if pollution < 0: + pollution = 0 + city['pollution'] = pollution + + commerce += city['subway'] * 8 + commerce += city['supermarket'] * 3 + commerce += city['bank'] * 5 + commerce += city['mall'] * 9 + commerce += city['stadium'] * 12 + + city['real_commerce'] = commerce + if commerce > max_commerce: + commerce = max_commerce + city['commerce'] = commerce + + else: + police_stations = 0 + hospitals = 0 + + 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 + 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) + if disease_deaths < 0: + disease_deaths = 0 + city_age = (datetime.datetime.utcnow() - datetime.datetime.strptime(city['date'], "%Y-%m-%d")).days + if city_age == 0: + city_age = 1 + 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: + continue + if treasure['nation']['id'] == nation['id']: + nation_treasure_bonus += treasure['bonus'] / 100 + if nation['alliance']: + 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):,}" + food -= nationpop / 1000 + + if nation['num_cities'] < 11: + new_player_bonus = 2.1 - 0.1 * nation['num_cities'] + 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):,}" + + at_war = False + if not single_city: + for war in nation['wars']: + if war['turnsleft'] > 0: + at_war = True + if include_spies: + military_upkeep += nation['spies'] * 2400 + if not at_war: + military_upkeep += nation['soldiers'] * 1.25 + food -= nation['soldiers'] / 750 + military_upkeep += nation['tanks'] * 50 + military_upkeep += nation['aircraft'] * 500 + military_upkeep += nation['ships'] * 3750 + military_upkeep += nation['missiles'] * 21000 + 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['nukes'] * 52500 + else: + military_upkeep += int(city['barracks']) * 3000 * 1.25 + military_upkeep += int(city['factory']) * 250 * 50 + military_upkeep += int(city['hangar']) * 15 * 500 + military_upkeep += int(city['drydock']) * 5 * 3750 + + if nation['dompolicy'] == "Imperialism": + mil_cost = 0.95 + 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'] + + 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 + 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 + 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}" + return rev_obj + + + async def calculate_revenue(self, message: discord.Message, nation: dict, game_data: dict) -> dict: + """Calculate revenue for a nation.""" + revenue = await revenue_calc( + message=message, + nation=nation, + radiation=game_data['radiation'], + treasures=game_data['treasures'], + prices=game_data['prices'], + colors=game_data['colors'], + seasonal_mod=game_data['seasonal_mod'] + ) + + 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") + 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 }") + + # color bloc bonus + colors = {} + for color in colors_query.colors: + colors[color.color] = color.turn_bonus * 12 + + # 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 + } + + # 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 + + # 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 + } + + 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) + + return { + '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'] + e = discord.Embed( + title=f"Revenue for {data['nation_name']}", + color=ctx.author.color, + 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']) + + embeds.append(e) + + # Paginate the results + await ctx.paginate(pages=embeds) async def setup(bot: Brahmos): await bot.add_cog(Banking(bot)) From 32176514e372115980fa4c1ba522a3bc3b583cd8 Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 25 May 2025 21:06:44 +0530 Subject: [PATCH 03/45] alias and function definition cannot be the same --- exts/banking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exts/banking.py b/exts/banking.py index 03f5845..669c995 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -927,7 +927,7 @@ class Banking(commands.Cog): @commands.has_any_role("The Croak Council", "Government") @commands.command(aliases=["refill"]) - async def refill(self, ctx: commands.Context, ids: commands.Greedy[int]): + async def resource_refill(self, ctx: commands.Context, ids: commands.Greedy[int]): """ Revenue calculation from nations by fetching cities and projects. """ From a68f853d7881571aa0a59100af89203b97107137 Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 25 May 2025 21:09:25 +0530 Subject: [PATCH 04/45] changes --- exts/banking.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/exts/banking.py b/exts/banking.py index 669c995..fd5c976 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1344,7 +1344,10 @@ class Banking(commands.Cog): treasures=game_data['treasures'], prices=game_data['prices'], colors=game_data['colors'], - seasonal_mod=game_data['seasonal_mod'] + seasonal_mod=game_data['seasonal_mod'], + build = None, + single_city = False, + include_spies = True ) return revenue From 974d60b60973bf7906d4870cc0dbb6c11ad14fdd Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 25 May 2025 21:13:21 +0530 Subject: [PATCH 05/45] facepalm --- exts/banking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exts/banking.py b/exts/banking.py index fd5c976..3633c5d 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1337,7 +1337,7 @@ class Banking(commands.Cog): async def calculate_revenue(self, message: discord.Message, nation: dict, game_data: dict) -> dict: """Calculate revenue for a nation.""" - revenue = await revenue_calc( + revenue = await self.revenue_calc( message=message, nation=nation, radiation=game_data['radiation'], From 727f301ea7da123e3115149151cc765d3a7f22b2 Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 25 May 2025 21:23:17 +0530 Subject: [PATCH 06/45] changes --- exts/banking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exts/banking.py b/exts/banking.py index 3633c5d..935a130 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -987,7 +987,7 @@ class Banking(commands.Cog): 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, 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 From db733b6bbd5f7d7670da73c2962a5d5a2631d121 Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 25 May 2025 21:24:47 +0530 Subject: [PATCH 07/45] changes --- exts/banking.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index 935a130..b34f4c7 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -987,7 +987,7 @@ class Banking(commands.Cog): await ctx.send(f"> Error getting game data: {str(e)}") - async def revenue_calc(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 @@ -1338,7 +1338,6 @@ class Banking(commands.Cog): async def calculate_revenue(self, message: discord.Message, nation: dict, game_data: dict) -> dict: """Calculate revenue for a nation.""" revenue = await self.revenue_calc( - message=message, nation=nation, radiation=game_data['radiation'], treasures=game_data['treasures'], From 5060f9eec1d688df5b44b1dfe9c2c4d94038f8cc Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 25 May 2025 21:26:24 +0530 Subject: [PATCH 08/45] misspelling --- exts/banking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exts/banking.py b/exts/banking.py index b34f4c7..d851f0b 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1040,7 +1040,7 @@ class Banking(commands.Cog): base_com = 2 if nation['recycling_initiative'] == True: rec_poll = 75 - if nation['green_technologues'] == True: + if nation['green_technologies'] == True: manu_poll_mod = 0.75 farm_poll_mod = 0.5 subw_poll_red = 70 From 761f87de8baba7bba28812d1a8dd252317056fc1 Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 25 May 2025 21:29:49 +0530 Subject: [PATCH 09/45] spelling, also only 10198 for testing --- exts/banking.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index d851f0b..598c318 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -933,7 +933,7 @@ class Banking(commands.Cog): """ data = await self.kit.query( "alliances", - {"id": [10177, 10198]}, + {"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, " \ @@ -1047,7 +1047,7 @@ class Banking(commands.Cog): rss_upkeep_mod = 0.9 if nation['clinical_research_center'] == True: hos_dis_red = 3.5 - if nation['specialized_police_training'] == True: + if nation['specialized_police_training_program'] == True: hos_dis_red = 3.5 if nation['uranium_enrichment_program'] == True: uranium_mod = 2 From b18d2f7b452c8f9be83eb55853eb4c6c7181fb5b Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 25 May 2025 21:31:29 +0530 Subject: [PATCH 10/45] another spelling --- exts/banking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exts/banking.py b/exts/banking.py index 598c318..a0bf2be 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1148,7 +1148,7 @@ class Banking(commands.Cog): commerce = base_com if city['powered']: rss_upkeep += 4000 * city['oil_refinery'] * rss_upkeep_mod - pollution += 32 * city['oil+refinery'] * manu_poll_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 From 07b61045f3d7030f7b2233992960835fa6d4293c Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 25 May 2025 21:33:09 +0530 Subject: [PATCH 11/45] fix --- exts/banking.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index a0bf2be..9504a84 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1174,7 +1174,7 @@ class Banking(commands.Cog): civil_upkeep += city['subway'] * 3250 civil_upkeep += city['supermarket'] * 600 civil_upkeep += city['bank'] * 1800 - civil_upkeep += city['mall'] * 5400 + civil_upkeep += city['shopping_mall'] * 5400 civil_upkeep += city['stadium'] * 12150 police_stations = city['police_station'] @@ -1184,7 +1184,7 @@ class Banking(commands.Cog): pollution += city['hospital'] * 4 pollution -= city['recycling_center'] * rec_poll pollution -= city['subway'] * subw_poll_red - pollution += city['mall'] * 2 + pollution += city['shopping_mall'] * 2 pollution += city['stadium'] * 5 city['real_pollution'] = pollution @@ -1195,7 +1195,7 @@ class Banking(commands.Cog): commerce += city['subway'] * 8 commerce += city['supermarket'] * 3 commerce += city['bank'] * 5 - commerce += city['mall'] * 9 + commerce += city['shopping_mall'] * 9 commerce += city['stadium'] * 12 city['real_commerce'] = commerce From 675873b3e2e7ab0d5d5898a98818f5bf8bd2a0f4 Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 25 May 2025 21:38:15 +0530 Subject: [PATCH 12/45] changes --- exts/banking.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/exts/banking.py b/exts/banking.py index 9504a84..ce796fc 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1022,6 +1022,8 @@ class Banking(commands.Cog): policy_bonus_text = "" treasure_text = "" footer = "" + + city = city.to_dict() if nation['iron_works'] == True: ste_mod = 1.36 From 073dec2be01f3388921fcbb12ed2414dbdacd615 Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 25 May 2025 21:52:45 +0530 Subject: [PATCH 13/45] nation['cities'] to nation.cities --- exts/banking.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index ce796fc..8420278 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1023,7 +1023,6 @@ class Banking(commands.Cog): treasure_text = "" footer = "" - city = city.to_dict() if nation['iron_works'] == True: ste_mod = 1.36 @@ -1073,7 +1072,7 @@ class Banking(commands.Cog): await message.edit(content="Something is wrong with the build you sent!") return land = 0 - for city in nation['cities']: + for city in nation.cities: land += city['land'] city = {} for key, value in build.items(): @@ -1081,11 +1080,11 @@ class Banking(commands.Cog): 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'] - nation['cities'] = [city] + city['date'] = nation.cities[math.ceil(nation['num_cities']/2)]['date'] + nation.cities = [city] #print(city) - for city in nation['cities']: + for city in nation.cities: total_infra += city['infrastructure'] base_pop = city['infrastructure'] * 100 pollution = 0 @@ -1297,10 +1296,10 @@ class Banking(commands.Cog): 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] + 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']) From b7f4abc45468c70b28176ec9b62ec0f4f38bbd69 Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 25 May 2025 22:02:04 +0530 Subject: [PATCH 14/45] changes --- exts/banking.py | 250 ++++++++++++++++++++++++------------------------ 1 file changed, 125 insertions(+), 125 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index 8420278..fed85ab 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1024,33 +1024,33 @@ class Banking(commands.Cog): footer = "" - if nation['iron_works'] == True: + if nation.iron_works == True: ste_mod = 1.36 - if nation['bauxite_works'] == True: + if nation.bauxite_works == True: alu_mod = 1.36 - if nation['arms_stockpile'] == True: + if nation.arms_stockpile == True: mun_mod = 1.34 - if nation['emergency_gasoline_reserve'] == True: + if nation.emergency_gasoline_reserve == True: gas_mod = 2 - if nation['mass_irrigation'] == True: + if nation.mass_irrigation == True: food_land_mod = 400 - if nation['international_trade_center'] == True: + if nation.international_trade_center == True: max_commerce = 115 - if nation['telecommunications_satellite'] == True: + if nation.telecommunications_satellite == True: max_commerce = 125 base_com = 2 - if nation['recycling_initiative'] == True: + if nation.recycling_initiative == True: rec_poll = 75 - if nation['green_technologies'] == True: + if nation.green_technologies == True: manu_poll_mod = 0.75 farm_poll_mod = 0.5 subw_poll_red = 70 rss_upkeep_mod = 0.9 - if nation['clinical_research_center'] == True: + if nation.clinical_research_center == True: hos_dis_red = 3.5 - if nation['specialized_police_training_program'] == True: + if nation.specialized_police_training_program == True: hos_dis_red = 3.5 - if nation['uranium_enrichment_program'] == True: + if nation.uranium_enrichment_program == True: uranium_mod = 2 coal = 0 @@ -1073,40 +1073,40 @@ class Banking(commands.Cog): return land = 0 for city in nation.cities: - land += city['land'] + land += city.land 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['powered'] = True - city['date'] = nation.cities[math.ceil(nation['num_cities']/2)]['date'] + 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'] nation.cities = [city] #print(city) for city in nation.cities: - total_infra += city['infrastructure'] - base_pop = city['infrastructure'] * 100 + 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 + unpowered_infra = city.infrastructure + 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']): + 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']): + for coal_plant in range(city.coal_power): power_upkeep += 1200 pollution += 8 for level in range(5): @@ -1114,117 +1114,117 @@ class Banking(commands.Cog): unpowered_infra -= 100 coal -= 1.2 - rss_upkeep += 400 * city['coal_mine'] * rss_upkeep_mod - pollution += 12 * city['coal_mine'] - coal += 3 * city['coal_mine'] * (1 + ((0.5 * (city['coal_mine'] - 1)) / (10 - 1))) + rss_upkeep += 400 * city.coal_mine * rss_upkeep_mod + pollution += 12 * city.coal_mine + coal += 3 * city.coal_mine * (1 + ((0.5 * (city.coal_mine - 1)) / (10 - 1))) - rss_upkeep += 600 * city['oil_well'] * rss_upkeep_mod - pollution += 12 * city['oil_well'] - oil += 3 * city['oil_well'] * (1 + ((0.5 * (city['oil_well'] - 1)) / (10 - 1))) + rss_upkeep += 600 * city.oil_well * rss_upkeep_mod + pollution += 12 * city.oil_well + oil += 3 * city.oil_well * (1 + ((0.5 * (city.oil_well - 1)) / (10 - 1))) - 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 + 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 - rss_upkeep += 1500 * city['lead_mine'] * rss_upkeep_mod - pollution += 12 * city['lead_mine'] - lead += 3 * city['lead_mine'] * (1 + ((0.5 * (city['lead_mine'] - 1)) / (10 - 1))) + rss_upkeep += 1500 * city.lead_mine * rss_upkeep_mod + pollution += 12 * city.lead_mine + lead += 3 * city.lead_mine * (1 + ((0.5 * (city.lead_mine - 1)) / (10 - 1))) - rss_upkeep += 1600 * city['iron_mine'] * rss_upkeep_mod - pollution += 12 * city['iron_mine'] - iron += 3 * city['iron_mine'] * (1 + ((0.5 * (city['iron_mine'] - 1)) / (10 - 1))) + rss_upkeep += 1600 * city.iron_mine * rss_upkeep_mod + pollution += 12 * city.iron_mine + iron += 3 * city.iron_mine * (1 + ((0.5 * (city.iron_mine - 1)) / (10 - 1))) - 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))) + 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))) - 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 + 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 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 + 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 - 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 + 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 - 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 + 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 - 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 + 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 - civil_upkeep += city['shopping_mall'] * 5400 - civil_upkeep += city['stadium'] * 12150 + 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 - police_stations = city['police_station'] - hospitals = city['hospital'] + police_stations = city.police_station + hospitals = city.hospital - pollution += city['police_station'] - pollution += city['hospital'] * 4 - pollution -= city['recycling_center'] * rec_poll - pollution -= city['subway'] * subw_poll_red - pollution += city['shopping_mall'] * 2 - pollution += city['stadium'] * 5 + pollution += city.police_station + pollution += city.hospital * 4 + pollution -= city.recycling_center * rec_poll + pollution -= city.subway * subw_poll_red + pollution += city.shopping_mall * 2 + pollution += city.stadium * 5 - city['real_pollution'] = pollution + city.real_pollution = pollution if pollution < 0: pollution = 0 - city['pollution'] = pollution + city.pollution = pollution - commerce += city['subway'] * 8 - commerce += city['supermarket'] * 3 - commerce += city['bank'] * 5 - commerce += city['shopping_mall'] * 9 - commerce += city['stadium'] * 12 + commerce += city.subway * 8 + commerce += city.supermarket * 3 + commerce += city.bank * 5 + commerce += city.shopping_mall * 9 + commerce += city.stadium * 12 - city['real_commerce'] = commerce + city.real_commerce = commerce if commerce > max_commerce: commerce = max_commerce - city['commerce'] = commerce + city.commerce = commerce else: police_stations = 0 hospitals = 0 - crime_rate = ((103 - commerce)**2 + (city['infrastructure'] * 100))/(111111) - police_stations * pol_cri_red - city['real_crime_rate'] = crime_rate + 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 - city['real_disease_rate'] = disease_rate + 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 + 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 + city.disease_rate = disease_rate disease_deaths = base_pop * (disease_rate/100) if disease_deaths < 0: disease_deaths = 0 - city_age = (datetime.datetime.utcnow() - datetime.datetime.strptime(city['date'], "%Y-%m-%d")).days + city_age = (datetime.datetime.utcnow() - datetime.datetime.strptime(city.date, "%Y-%m-%d")).days if city_age == 0: city_age = 1 population = ((base_pop - disease_deaths - crime_deaths) * (1 + math.log(city_age)/15)) @@ -1236,10 +1236,10 @@ class Banking(commands.Cog): for treasure in treasures: if treasure['nation'] == None: continue - if treasure['nation']['id'] == nation['id']: + if treasure['nation']['id'] == nation.id: nation_treasure_bonus += treasure['bonus'] / 100 - if nation['alliance']: - if treasure['nation']['alliance_id'] == nation['alliance_id']: + if nation.alliance: + if treasure['nation']['alliance_id'] == nation.alliance_id: alliance_treasures += 1 if alliance_treasures > 0: nation_treasure_bonus += math.sqrt(alliance_treasures * 4) / 100 @@ -1247,47 +1247,47 @@ class Banking(commands.Cog): treasure_text = f"\n\nTreasure Bonus: ${round(money_income * (nation_treasure_bonus - 1)):,}" if not single_city: - color_bonus = colors[nation['color']] + color_bonus = colors[nation.color] color_text = f"\n\nColor Trade Bloc Bonus: ${round(color_bonus):,}" food -= nationpop / 1000 - if nation['num_cities'] < 11: - new_player_bonus = 2.1 - 0.1 * nation['num_cities'] + if nation.num_cities < 11: + new_player_bonus = 2.1 - 0.1 * nation.num_cities new_player_text = f"\n\nNew Player Bonus: ${round((new_player_bonus - 1) * money_income):,}" - if nation['dompolicy'] == "Open Markets": + if nation.dompolicy == "Open Markets": policy_bonus = 1.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']: + for war in nation.wars: if war['turnsleft'] > 0: at_war = True if include_spies: - military_upkeep += nation['spies'] * 2400 + military_upkeep += nation.spies * 2400 if not at_war: - military_upkeep += nation['soldiers'] * 1.25 - food -= nation['soldiers'] / 750 - military_upkeep += nation['tanks'] * 50 - military_upkeep += nation['aircraft'] * 500 - military_upkeep += nation['ships'] * 3750 - military_upkeep += nation['missiles'] * 21000 - military_upkeep += nation['nukes'] * 31500 + military_upkeep += nation.soldiers * 1.25 + food -= nation.soldiers / 750 + military_upkeep += nation.tanks * 50 + military_upkeep += nation.aircraft * 500 + military_upkeep += nation.ships * 3750 + military_upkeep += nation.missiles * 21000 + 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['nukes'] * 52500 + 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.nukes * 52500 else: - military_upkeep += int(city['barracks']) * 3000 * 1.25 - military_upkeep += int(city['factory']) * 250 * 50 - military_upkeep += int(city['hangar']) * 15 * 500 - military_upkeep += int(city['drydock']) * 5 * 3750 + military_upkeep += int(city.barracks) * 3000 * 1.25 + military_upkeep += int(city.factory) * 250 * 50 + military_upkeep += int(city.hangar) * 15 * 500 + military_upkeep += int(city.drydock) * 5 * 3750 - if nation['dompolicy'] == "Imperialism": + if nation.dompolicy == "Imperialism": mil_cost = 0.95 policy_bonus_text = f"\n\nImperialism Bonus: ${round(military_upkeep * 0.05):,}" if food < 0: @@ -1327,7 +1327,7 @@ class Banking(commands.Cog): 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['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}" From 3da237aceb30a2c02aa8237f5e794cba139c3548 Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 25 May 2025 22:04:18 +0530 Subject: [PATCH 15/45] strptime is updated but code is not --- exts/banking.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/exts/banking.py b/exts/banking.py index fed85ab..9328c4a 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1224,7 +1224,11 @@ class Banking(commands.Cog): disease_deaths = base_pop * (disease_rate/100) if disease_deaths < 0: disease_deaths = 0 - city_age = (datetime.datetime.utcnow() - datetime.datetime.strptime(city.date, "%Y-%m-%d")).days + if isinstance(city.date, str): + city_date = datetime.datetime.strptime(city.date, "%Y-%m-%d") + else: + city_date = city.date + 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)) From 58fcd42961f1ee0395a5bf62708fc012b4fb03e8 Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 25 May 2025 22:13:03 +0530 Subject: [PATCH 16/45] raise errors --- exts/banking.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index 9328c4a..cf4d04e 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -977,8 +977,7 @@ class Banking(commands.Cog): }) except Exception as e: - await ctx.send(f"> Error calculating revenue for {nation.nation_name}: {str(e)}") - continue + raise e # Format and send the results await self.send_revenue_results(ctx, revenue_data) From b30bade32e537d3ac3496329888e5c72e04e7543 Mon Sep 17 00:00:00 2001 From: un1xx Date: Sun, 25 May 2025 22:40:14 +0530 Subject: [PATCH 17/45] update --- exts/banking.py | 696 +++++++++++++++++++++++++++++------------------- 1 file changed, 416 insertions(+), 280 deletions(-) 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)) From 70e66852d3421459f119e8d91824c0c2777252ce Mon Sep 17 00:00:00 2001 From: un1xx Date: Sun, 25 May 2025 22:47:57 +0530 Subject: [PATCH 18/45] update --- exts/banking.py | 1 + 1 file changed, 1 insertion(+) diff --git a/exts/banking.py b/exts/banking.py index 964a810..3c51a15 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1320,6 +1320,7 @@ class Banking(commands.Cog): alliance_treasures = 0 nation_treasure_bonus = 1 for treasure in treasures: + await message.channel.send(treasure) if treasure["nation"] == None: continue if treasure["nation"]["id"] == nation.id: From 840f6cead854cf294668c1f81b434f94167a50dd Mon Sep 17 00:00:00 2001 From: un1xx Date: Sun, 25 May 2025 22:51:35 +0530 Subject: [PATCH 19/45] update --- exts/banking.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index 3c51a15..9cfd29e 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1319,19 +1319,18 @@ class Banking(commands.Cog): alliance_treasures = 0 nation_treasure_bonus = 1 - for treasure in treasures: - await message.channel.send(treasure) - if treasure["nation"] == None: - continue - if treasure["nation"]["id"] == nation.id: - nation_treasure_bonus += treasure["bonus"] / 100 - if nation.alliance: - 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)):,}" + # for treasure in treasures: + # if treasure["nation"] == None: + # continue + # if treasure["nation"]["id"] == nation.id: + # nation_treasure_bonus += treasure["bonus"] / 100 + # if nation.alliance: + # 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] From dc96447bd40654add27f039d4c03a5510abbaa77 Mon Sep 17 00:00:00 2001 From: un1xx Date: Sun, 25 May 2025 22:52:43 +0530 Subject: [PATCH 20/45] update --- exts/banking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exts/banking.py b/exts/banking.py index 9cfd29e..3a12ddf 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1340,7 +1340,7 @@ class Banking(commands.Cog): if nation.num_cities < 11: new_player_bonus = 2.1 - 0.1 * nation.num_cities new_player_text = f"\n\nNew Player Bonus: ${round((new_player_bonus - 1) * money_income):,}" - if nation.dompolicy == "Open Markets": + if nation.domestic_policy == "Open Markets": policy_bonus = 1.01 policy_bonus_text = ( f"\n\nOpen Markets Bonus: ${round(money_income * 0.01):,}" From d971a6b9ffa89e801fbb6dc94bdb02c725e65b56 Mon Sep 17 00:00:00 2001 From: un1xx Date: Sun, 25 May 2025 22:53:50 +0530 Subject: [PATCH 21/45] update --- exts/banking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exts/banking.py b/exts/banking.py index 3a12ddf..51534e8 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1375,7 +1375,7 @@ class Banking(commands.Cog): military_upkeep += int(city.hangar) * 15 * 500 military_upkeep += int(city.drydock) * 5 * 3750 - if nation.dompolicy == "Imperialism": + if nation.domestic_policy == "Imperialism": mil_cost = 0.95 policy_bonus_text = ( f"\n\nImperialism Bonus: ${round(military_upkeep * 0.05):,}" From 239d8f31296f1f6261340e3879254c2ae96ac9fe Mon Sep 17 00:00:00 2001 From: un1xx Date: Sun, 25 May 2025 23:05:18 +0530 Subject: [PATCH 22/45] update --- exts/banking.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index 51534e8..0893093 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -928,7 +928,7 @@ class Banking(commands.Cog): """ data = await self.kit.query( "alliances", - {"id": [10198]}, + {"id": [10198, 10177]}, "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, " @@ -1319,18 +1319,18 @@ class Banking(commands.Cog): alliance_treasures = 0 nation_treasure_bonus = 1 - # for treasure in treasures: - # if treasure["nation"] == None: - # continue - # if treasure["nation"]["id"] == nation.id: - # nation_treasure_bonus += treasure["bonus"] / 100 - # if nation.alliance: - # 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)):,}" + for treasure in treasures: + if treasure.nation == None: + continue + if treasure.nation.id == nation.id: + nation_treasure_bonus += treasure.bonus / 100 + if nation.alliance: + 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] @@ -1552,16 +1552,16 @@ class Banking(commands.Cog): "food": prices_data.food, } - 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": [], "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) return { "prices": prices, - "treasures": treasures, + "treasures": treasures_data.treasures, "radiation": radiation, "seasonal_mod": seasonal_mod, "colors": colors, From c3e61792ccf13c4b4201006a263e3e98de13896e Mon Sep 17 00:00:00 2001 From: un1xx Date: Sun, 25 May 2025 23:06:26 +0530 Subject: [PATCH 23/45] update --- exts/banking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exts/banking.py b/exts/banking.py index 0893093..ef45cb5 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1561,7 +1561,7 @@ class Banking(commands.Cog): return { "prices": prices, - "treasures": treasures_data.treasures, + "treasures": treasures_query.treasures, "radiation": radiation, "seasonal_mod": seasonal_mod, "colors": colors, From 10809e1c760af5324051b5f609dc13a289ab00bd Mon Sep 17 00:00:00 2001 From: un1xx Date: Sun, 25 May 2025 23:07:34 +0530 Subject: [PATCH 24/45] update --- exts/banking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exts/banking.py b/exts/banking.py index ef45cb5..c47ff9d 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1498,7 +1498,7 @@ class Banking(commands.Cog): treasures_query = await self.kit.query( "treasures", {}, - "name, bonus, spawn_date, nation_id, nation { alliance_id }", + "name, bonus, spawn_date, nation_id, nation { alliance_id, id }", ) # color bloc bonus From caf8c94666d6c8a56a8b9d6aba1ae47d14afa4cb Mon Sep 17 00:00:00 2001 From: un1xx Date: Sun, 25 May 2025 23:09:20 +0530 Subject: [PATCH 25/45] update --- exts/banking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exts/banking.py b/exts/banking.py index c47ff9d..85215a2 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1324,7 +1324,7 @@ class Banking(commands.Cog): continue if treasure.nation.id == nation.id: nation_treasure_bonus += treasure.bonus / 100 - if nation.alliance: + if nation.alliance_id: if treasure.nation.alliance_id == nation.alliance_id: alliance_treasures += 1 if alliance_treasures > 0: From ca77a071aeab96ffd79a4d1ec7e05a701568562e Mon Sep 17 00:00:00 2001 From: un1xx Date: Sun, 25 May 2025 23:10:36 +0530 Subject: [PATCH 26/45] update --- exts/banking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exts/banking.py b/exts/banking.py index 85215a2..08f03ed 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -929,7 +929,7 @@ class Banking(commands.Cog): data = await self.kit.query( "alliances", {"id": [10198, 10177]}, - "id, nations {id, nation_name, continent, color, war_policy, domestic_policy, beige_turns, num_cities, soldiers, tanks" + "id, nations {id, alliance_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, " From 157158fee3de3e85e70e1342f6ffc6b35276b704 Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 1 Jun 2025 18:37:00 +0530 Subject: [PATCH 27/45] removed all monetary/manufacturing calculation --- exts/banking.py | 266 +----------------------------------------------- 1 file changed, 5 insertions(+), 261 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index 08f03ed..a32f7b9 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -994,8 +994,6 @@ class Banking(commands.Cog): single_city: bool = False, include_spies: bool = False, ) -> dict: - max_commerce = 100 - base_com = 0 hos_dis_red = 2.5 alu_mod = 1 mun_mod = 1 @@ -1003,11 +1001,9 @@ class Banking(commands.Cog): manu_poll_mod = 1 farm_poll_mod = 0.5 subw_poll_red = 45 - rss_upkeep_mod = 1 ste_mod = 1 rec_poll = 70 pol_cri_red = 2.5 - food_land_mod = 500 uranium_mod = 1 rss_upkeep = 0 civil_upkeep = 0 @@ -1037,20 +1033,12 @@ class Banking(commands.Cog): mun_mod = 1.34 if nation.emergency_gasoline_reserve == True: gas_mod = 2 - if nation.mass_irrigation == True: - food_land_mod = 400 - if nation.international_trade_center == True: - max_commerce = 115 - if nation.telecommunications_satellite == True: - max_commerce = 125 - base_com = 2 if nation.recycling_initiative == True: rec_poll = 75 if nation.green_technologies == True: manu_poll_mod = 0.75 farm_poll_mod = 0.5 subw_poll_red = 70 - rss_upkeep_mod = 0.9 if nation.clinical_research_center == True: hos_dis_red = 3.5 if nation.specialized_police_training_program == True: @@ -1107,7 +1095,7 @@ class Banking(commands.Cog): for level in range(2): if unpowered_infra > 0: unpowered_infra -= 1000 - uranium -= 1.2 + uranium -= 2.4 for oil_plant in range(city.oil_power): power_upkeep += 1800 pollution += 6 @@ -1123,60 +1111,24 @@ class Banking(commands.Cog): unpowered_infra -= 100 coal -= 1.2 - rss_upkeep += 400 * city.coal_mine * rss_upkeep_mod - pollution += 12 * city.coal_mine + pollution += (12 * city.coal_mine) + (12 * city.oil_well) + (20 * city.uranium_mine) + (12 * city.lead_mine) + + (12 * city.iron_mine) + (12 * city.bauxite_mine) + (2 * city.farm * farm_poll_mod) coal += 3 * city.coal_mine * (1 + ((0.5 * (city.coal_mine - 1)) / (10 - 1))) - - rss_upkeep += 600 * city.oil_well * rss_upkeep_mod - pollution += 12 * city.oil_well oil += 3 * city.oil_well * (1 + ((0.5 * (city.oil_well - 1)) / (10 - 1))) - - 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 ) - - rss_upkeep += 1500 * city.lead_mine * rss_upkeep_mod - pollution += 12 * city.lead_mine lead += 3 * city.lead_mine * (1 + ((0.5 * (city.lead_mine - 1)) / (10 - 1))) - - rss_upkeep += 1600 * city.iron_mine * rss_upkeep_mod - pollution += 12 * city.iron_mine iron += 3 * city.iron_mine * (1 + ((0.5 * (city.iron_mine - 1)) / (10 - 1))) - - 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))) ) - - 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 - ) - 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 @@ -1184,14 +1136,6 @@ class Banking(commands.Cog): * (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 @@ -1205,14 +1149,6 @@ class Banking(commands.Cog): * (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 @@ -1220,14 +1156,6 @@ class Banking(commands.Cog): * (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 @@ -1235,24 +1163,6 @@ class Banking(commands.Cog): * (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 - - police_stations = city.police_station - hospitals = city.hospital pollution += city.police_station pollution += city.hospital * 4 @@ -1265,121 +1175,10 @@ class Banking(commands.Cog): if pollution < 0: pollution = 0 city.pollution = pollution - - commerce += city.subway * 8 - commerce += city.supermarket * 3 - commerce += city.bank * 5 - commerce += city.shopping_mall * 9 - commerce += city.stadium * 12 - - city.real_commerce = commerce - if commerce > max_commerce: - commerce = max_commerce - city.commerce = commerce - else: police_stations = 0 hospitals = 0 - 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 - ) - 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) - if disease_deaths < 0: - disease_deaths = 0 - if isinstance(city.date, str): - city_date = datetime.datetime.strptime(city.date, "%Y-%m-%d") - else: - city_date = city.date - 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 - ) - 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: - continue - if treasure.nation.id == nation.id: - nation_treasure_bonus += treasure.bonus / 100 - if 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):,}" - food -= nationpop / 1000 - - if nation.num_cities < 11: - new_player_bonus = 2.1 - 0.1 * nation.num_cities - new_player_text = f"\n\nNew Player Bonus: ${round((new_player_bonus - 1) * money_income):,}" - if nation.domestic_policy == "Open Markets": - policy_bonus = 1.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: - at_war = True - if include_spies: - military_upkeep += nation.spies * 2400 - if not at_war: - military_upkeep += nation.soldiers * 1.25 - food -= nation.soldiers / 750 - military_upkeep += nation.tanks * 50 - military_upkeep += nation.aircraft * 500 - military_upkeep += nation.ships * 3750 - military_upkeep += nation.missiles * 21000 - 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.nukes * 52500 - else: - military_upkeep += int(city.barracks) * 3000 * 1.25 - military_upkeep += int(city.factory) * 250 * 50 - military_upkeep += int(city.hangar) * 15 * 500 - military_upkeep += int(city.drydock) * 5 * 3750 - - if nation.domestic_policy == "Imperialism": - mil_cost = 0.95 - 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):,}*)" @@ -1394,71 +1193,20 @@ class Banking(commands.Cog): 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 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 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}" + f"Coal: {round(coal):,}\nOil: {round(oil):,}\nLead: {round(lead):,}\nIron: {round(iron):,}\nBauxite: {round(bauxite):,}{starve_money_text}" ) return rev_obj @@ -1477,7 +1225,6 @@ class Banking(commands.Cog): single_city=False, include_spies=True, ) - return revenue async def get_game_data(self) -> dict: @@ -1577,15 +1324,12 @@ class Banking(commands.Cog): for data in revenue_data: revenue = data["revenue"] e = discord.Embed( - title=f"Revenue for {data['nation_name']}", + title=f"Raws consumption for {data['nation_name']}", color=ctx.author.color, 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"]) From 60154ed1bf162a7e4061841be795f2f8e429d956 Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 1 Jun 2025 19:03:34 +0530 Subject: [PATCH 28/45] updated calculations --- .gitignore | 1 + exts/banking.py | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 849df44..2a5d217 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ store *.pyo *.pyd .venv +krampus_calc.java diff --git a/exts/banking.py b/exts/banking.py index a32f7b9..08dd355 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1030,7 +1030,7 @@ class Banking(commands.Cog): if nation.bauxite_works == True: alu_mod = 1.36 if nation.arms_stockpile == True: - mun_mod = 1.34 + mun_mod = 1.20 if nation.emergency_gasoline_reserve == True: gas_mod = 2 if nation.recycling_initiative == True: @@ -1161,7 +1161,6 @@ class Banking(commands.Cog): 6 * city.munitions_factory * (1 + ((0.5 * (city.munitions_factory - 1)) / (5 - 1))) - * mun_mod ) pollution += city.police_station From a6ac1caff4ed288964891564bdbfe8ed8bdbb1a5 Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 1 Jun 2025 19:10:58 +0530 Subject: [PATCH 29/45] changes --- exts/banking.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index 08dd355..2c09a92 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -972,12 +972,19 @@ class Banking(commands.Cog): "revenue": revenue, } ) + nation_rss = { + "nation_coal": nation.coal, + "nation_oil": nation.oil, + "nation_iron": nation.iron, + "nation_bauxite": nation.bauxite, + "nation_lead": nation.lead + } except Exception as e: await ctx.cbsend(f"{traceback.format_exc()}") # Format and send the results - await self.send_revenue_results(ctx, revenue_data) + await self.send_revenue_results(ctx, revenue_data, nation_rss) except Exception as e: await ctx.send(f"> Error getting game data: {str(e)}") @@ -1313,7 +1320,7 @@ class Banking(commands.Cog): "colors": colors, } - async def send_revenue_results(self, ctx: commands.Context, revenue_data: list): + async def send_revenue_results(self, ctx: commands.Context, revenue_data: list, nation_rss: dict): """Format and send the revenue calculation results.""" if not revenue_data: return await ctx.send("> No revenue data to display.") @@ -1328,7 +1335,9 @@ class Banking(commands.Cog): timestamp=datetime.datetime.utcnow(), ) - e.add_field(name="Net Revenue", value=revenue["net_rev_txt"], inline=False) + e.add_field(name="Net raws production", value=revenue["net_rev_txt"], inline=False) + e.add_field(name="On Nation", value=f"Coal: {nation_rss[nation_coal]}\nIron: {nation_rss[nation_iron]}\nTBC", inline=False) + if revenue["footer"]: e.set_footer(text=revenue["footer"]) From cb6e88758df51c21d33befe0193f651e9889a750 Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 1 Jun 2025 19:12:47 +0530 Subject: [PATCH 30/45] changes --- exts/banking.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index 2c09a92..918d07b 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -970,21 +970,19 @@ class Banking(commands.Cog): "nation_id": nation.id, "nation_name": nation.nation_name, "revenue": revenue, + "nation_coal": nation.coal, + "nation_oil": nation.oil, + "nation_iron": nation.iron, + "nation_bauxite": nation.bauxite, + "nation_lead": nation.lead, } ) - nation_rss = { - "nation_coal": nation.coal, - "nation_oil": nation.oil, - "nation_iron": nation.iron, - "nation_bauxite": nation.bauxite, - "nation_lead": nation.lead - } except Exception as e: await ctx.cbsend(f"{traceback.format_exc()}") # Format and send the results - await self.send_revenue_results(ctx, revenue_data, nation_rss) + await self.send_revenue_results(ctx, revenue_data) except Exception as e: await ctx.send(f"> Error getting game data: {str(e)}") @@ -1336,7 +1334,7 @@ class Banking(commands.Cog): ) e.add_field(name="Net raws production", value=revenue["net_rev_txt"], inline=False) - e.add_field(name="On Nation", value=f"Coal: {nation_rss[nation_coal]}\nIron: {nation_rss[nation_iron]}\nTBC", inline=False) + e.add_field(name="On Nation", value=f"Coal: {data[nation_coal]}\nIron: {data[nation_iron]}\nTBC", inline=False) if revenue["footer"]: From f29a3c08f40f128126f6f96ac1452dacf2a1752e Mon Sep 17 00:00:00 2001 From: karan Date: Sun, 1 Jun 2025 19:16:15 +0530 Subject: [PATCH 31/45] expose nation rss in embed --- exts/banking.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index 918d07b..4210e08 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1318,7 +1318,7 @@ class Banking(commands.Cog): "colors": colors, } - async def send_revenue_results(self, ctx: commands.Context, revenue_data: list, nation_rss: dict): + 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.") @@ -1334,8 +1334,7 @@ class Banking(commands.Cog): ) e.add_field(name="Net raws production", value=revenue["net_rev_txt"], inline=False) - e.add_field(name="On Nation", value=f"Coal: {data[nation_coal]}\nIron: {data[nation_iron]}\nTBC", inline=False) - + e.add_field(name="On Nation", value=f"Coal: {data['nation_coal']}\nOil: {data['nation_oil']}\nIron: {data['nation_iron']}\nBauxite: {data['nation_bauxite']}\nLead: {data['nation_lead']}", inline=False) if revenue["footer"]: e.set_footer(text=revenue["footer"]) From e4148743d1fb497c240899ccebce3fdbcb3a4572 Mon Sep 17 00:00:00 2001 From: un1xx Date: Fri, 6 Jun 2025 19:04:21 +0530 Subject: [PATCH 32/45] update raws cmd --- exts/banking.py | 101 ++++++++++++++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 37 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index 4210e08..012de61 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -23,6 +23,7 @@ from utils.base import BasicView from utils.emojis import Emojis from utils.paginator import Paginator + class BaseMul: money = 1000000 food = 5000 @@ -921,14 +922,22 @@ class Banking(commands.Cog): ) @commands.has_any_role("The Croak Council", "Government") - @commands.command(aliases=["refill"]) - async def resource_refill(self, ctx: CustomCtx, ids: commands.Greedy[int]): + @commands.command() + async def raws(self, ctx: CustomCtx, ids: commands.Greedy[int]): """ Revenue calculation from nations by fetching cities and projects. """ - data = await self.kit.query( - "alliances", - {"id": [10198, 10177]}, + try: + revenue_data = await self.get_alliance_rev(ids) + + # 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 get_alliance_rev(self, ids: list): + query_text = ( "id, nations {id, alliance_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, " @@ -937,12 +946,17 @@ class Banking(commands.Cog): "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}}", + "bank, shopping_mall, stadium, barracks, factory, hangar, drydock}}" ) + data = await self.kit.query("alliances", {"id": [10177]}, query_text) + data2 = data = await self.dkit.query("alliances", {"id": [10198]}, query_text) + nations = [] for alliance in data.alliances: nations.extend(alliance.nations) + for alliance in data2.alliances: + nations.extend(alliance.nations) if ids: notinalliance = [n for n in ids if n not in [n.id for n in nations]] @@ -955,37 +969,31 @@ class Banking(commands.Cog): revenue_data = [] message = await ctx.send("Calculating revenue for nations...") - try: - game_data = await self.get_game_data() + game_data = await self.get_game_data() - for nation in nations: - try: - if (nation.id not in self.WARCHEST_IDS) and (not ids): - continue + 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 = await self.calculate_revenue(message, nation, game_data) - revenue_data.append( - { - "nation_id": nation.id, - "nation_name": nation.nation_name, - "revenue": revenue, - "nation_coal": nation.coal, - "nation_oil": nation.oil, - "nation_iron": nation.iron, - "nation_bauxite": nation.bauxite, - "nation_lead": nation.lead, - } - ) + revenue_data.append( + { + "nation_id": nation.id, + "nation_name": nation.nation_name, + "revenue": revenue, + "nation_coal": nation.coal, + "nation_oil": nation.oil, + "nation_iron": nation.iron, + "nation_bauxite": nation.bauxite, + "nation_lead": nation.lead, + } + ) - except Exception as 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)}") + except Exception as e: + await ctx.cbsend(f"{traceback.format_exc()}") + return revenue_data async def revenue_calc( message: discord.Message, @@ -1116,8 +1124,17 @@ class Banking(commands.Cog): unpowered_infra -= 100 coal -= 1.2 - pollution += (12 * city.coal_mine) + (12 * city.oil_well) + (20 * city.uranium_mine) + (12 * city.lead_mine) - + (12 * city.iron_mine) + (12 * city.bauxite_mine) + (2 * city.farm * farm_poll_mod) + pollution += ( + (12 * city.coal_mine) + + (12 * city.oil_well) + + (20 * city.uranium_mine) + + (12 * city.lead_mine) + ) + ( + +(12 * city.iron_mine) + + (12 * city.bauxite_mine) + + (2 * city.farm * farm_poll_mod) + ) coal += 3 * city.coal_mine * (1 + ((0.5 * (city.coal_mine - 1)) / (10 - 1))) oil += 3 * city.oil_well * (1 + ((0.5 * (city.oil_well - 1)) / (10 - 1))) uranium += ( @@ -1333,8 +1350,14 @@ class Banking(commands.Cog): timestamp=datetime.datetime.utcnow(), ) - e.add_field(name="Net raws production", value=revenue["net_rev_txt"], inline=False) - e.add_field(name="On Nation", value=f"Coal: {data['nation_coal']}\nOil: {data['nation_oil']}\nIron: {data['nation_iron']}\nBauxite: {data['nation_bauxite']}\nLead: {data['nation_lead']}", inline=False) + e.add_field( + name="Net raws production", value=revenue["net_rev_txt"], inline=False + ) + e.add_field( + name="On Nation", + value=f"Coal: {data['nation_coal']}\nOil: {data['nation_oil']}\nIron: {data['nation_iron']}\nBauxite: {data['nation_bauxite']}\nLead: {data['nation_lead']}", + inline=False, + ) if revenue["footer"]: e.set_footer(text=revenue["footer"]) @@ -1344,6 +1367,10 @@ class Banking(commands.Cog): # Paginate the results await ctx.paginate(pages=embeds) + @commands.has_any_role("The Croak Council", "Government") + @commands.command() + async def refill(): ... + async def setup(bot: Brahmos): await bot.add_cog(Banking(bot)) From 2e2a749e1adc807413c32b906a43acc1c3687051 Mon Sep 17 00:00:00 2001 From: un1xx Date: Fri, 6 Jun 2025 19:07:15 +0530 Subject: [PATCH 33/45] update raws cmd --- exts/banking.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index 012de61..5402413 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1367,9 +1367,9 @@ class Banking(commands.Cog): # Paginate the results await ctx.paginate(pages=embeds) - @commands.has_any_role("The Croak Council", "Government") - @commands.command() - async def refill(): ... + # @commands.has_any_role("The Croak Council", "Government") + # @commands.command() + # async def refill(): ... async def setup(bot: Brahmos): From 88c24a93fa71964ce435c1d5d2987bef8055e76f Mon Sep 17 00:00:00 2001 From: un1xx Date: Fri, 6 Jun 2025 19:09:43 +0530 Subject: [PATCH 34/45] update raws cmd --- exts/banking.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index 5402413..4752dc7 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -927,6 +927,7 @@ class Banking(commands.Cog): """ Revenue calculation from nations by fetching cities and projects. """ + message = await ctx.send("Calculating revenue for nations...") try: revenue_data = await self.get_alliance_rev(ids) @@ -967,7 +968,6 @@ class Banking(commands.Cog): await ctx.send(f"> {notinalliance} not in MILF or DILF") revenue_data = [] - message = await ctx.send("Calculating revenue for nations...") game_data = await self.get_game_data() @@ -992,7 +992,7 @@ class Banking(commands.Cog): ) except Exception as e: - await ctx.cbsend(f"{traceback.format_exc()}") + raise e return revenue_data async def revenue_calc( From 4296738220bd601a44c7a55845d24bea6ba7eb7a Mon Sep 17 00:00:00 2001 From: un1xx Date: Fri, 6 Jun 2025 19:15:04 +0530 Subject: [PATCH 35/45] update raws cmd --- exts/banking.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index 4752dc7..4ecdabf 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -962,10 +962,10 @@ class Banking(commands.Cog): if ids: notinalliance = [n for n in ids if n not in [n.id for n in nations]] nations = [n for n in nations if n.id in ids] - if not nations: - return await ctx.send(f"> {ids} not in MILF or DILF") - if notinalliance: - await ctx.send(f"> {notinalliance} not in MILF or DILF") + # if not nations: + # return await ctx.send(f"> {ids} not in MILF or DILF") + # if notinalliance: + # await ctx.send(f"> {notinalliance} not in MILF or DILF") revenue_data = [] @@ -976,7 +976,7 @@ class Banking(commands.Cog): if (nation.id not in self.WARCHEST_IDS) and (not ids): continue - revenue = await self.calculate_revenue(message, nation, game_data) + revenue = await self.calculate_revenue(None, nation, game_data) revenue_data.append( { From 4453d6a551feff44cfbad31960221cbff5e48a63 Mon Sep 17 00:00:00 2001 From: un1xx Date: Fri, 6 Jun 2025 19:17:38 +0530 Subject: [PATCH 36/45] update raws cmd --- exts/banking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exts/banking.py b/exts/banking.py index 4ecdabf..479fb99 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -951,7 +951,7 @@ class Banking(commands.Cog): ) data = await self.kit.query("alliances", {"id": [10177]}, query_text) - data2 = data = await self.dkit.query("alliances", {"id": [10198]}, query_text) + data2 = await self.dkit.query("alliances", {"id": [10198]}, query_text) nations = [] for alliance in data.alliances: From 2fd8d32335dfb77beaa480e8d2ac0472dd9c1690 Mon Sep 17 00:00:00 2001 From: un1xx Date: Fri, 6 Jun 2025 19:30:54 +0530 Subject: [PATCH 37/45] update raws cmd --- exts/banking.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/exts/banking.py b/exts/banking.py index 479fb99..3a89c46 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -939,7 +939,7 @@ class Banking(commands.Cog): async def get_alliance_rev(self, ids: list): query_text = ( - "id, nations {id, alliance_id, nation_name, continent, color, war_policy, domestic_policy, beige_turns, num_cities, soldiers, tanks" + "id, nations {id, alliance_id, nation_name,flag, 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, " @@ -988,6 +988,7 @@ class Banking(commands.Cog): "nation_iron": nation.iron, "nation_bauxite": nation.bauxite, "nation_lead": nation.lead, + "nation_flag": nation.flag } ) @@ -1348,7 +1349,9 @@ class Banking(commands.Cog): title=f"Raws consumption for {data['nation_name']}", color=ctx.author.color, timestamp=datetime.datetime.utcnow(), + url=f"https://politicsandwar.com/nation/id={data.get('nation_id')}" ) + e.set_thumbnail(url=data.get("nation_flag")) e.add_field( name="Net raws production", value=revenue["net_rev_txt"], inline=False From 843e32067a7c0357d806b392ce35b8cfbe225226 Mon Sep 17 00:00:00 2001 From: un1xx Date: Fri, 6 Jun 2025 21:09:42 +0530 Subject: [PATCH 38/45] update refill cmd --- exts/banking.py | 188 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 184 insertions(+), 4 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index 3a89c46..eec54ef 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -988,7 +988,8 @@ class Banking(commands.Cog): "nation_iron": nation.iron, "nation_bauxite": nation.bauxite, "nation_lead": nation.lead, - "nation_flag": nation.flag + "nation_flag": nation.flag, + "num_cities": nation.num_cities } ) @@ -1230,6 +1231,11 @@ class Banking(commands.Cog): rev_obj["net_rev_txt"] = ( f"Coal: {round(coal):,}\nOil: {round(oil):,}\nLead: {round(lead):,}\nIron: {round(iron):,}\nBauxite: {round(bauxite):,}{starve_money_text}" ) + rev_obj["bauxite"] = bauxite + rev_obj["coal"] = coal + rev_obj["iron"] = iron + rev_obj["lead"] = lead + rev_obj["oil"] = oil return rev_obj async def calculate_revenue( @@ -1370,9 +1376,183 @@ class Banking(commands.Cog): # Paginate the results await ctx.paginate(pages=embeds) - # @commands.has_any_role("The Croak Council", "Government") - # @commands.command() - # async def refill(): ... + @commands.has_any_role("The Croak Council", "Government") + @commands.command() + async def refill(self, ctx: CustomCtx, ids: commands.Greedy[int]): + revenue_data = await self.get_alliance_rev(ids) + await ctx.cbsend(revenue_data[0]) + + def calc_tosend(raw: float, on_nation: float): + return int(7 * abs(raw) - on_nation) + + embeds = [] + e = discord.Embed( + title="Raws to Refill", + timestamp=datetime.datetime.now(), + color=ctx.author.color, + ) + total = { + "oil": 0, + "coal": 0, + "lead": 0, + "iron": 0, + "bauxite": 0 + } + count = 0 + + for data in revenue_data: + oil = data.get("oil") + coal = data.get("coal") + lead = data.get("lead") + iron = data.get("iron") + bauxite = data.get("bauxite") + data["refill"] = dict() + text = "" + if oil < 0: + tosend = calc_tosend(oil, data.get("nation_oil")) + data["refill"].update(oil=tosend) + text += f"{Emojis.oil} {tosend:,}\n" + total["oil"] += tosend + if coal < 0: + tosend = calc_tosend(coal, data.get("nation_coal")) + data["refill"].update(coal=tosend) + text += f"{Emojis.coal} {tosend:,}" + total["coal"] += tosend + if lead < 0: + tosend = calc_tosend(lead, data.get("nation_lead")) + data["refill"].update(lead=tosend) + text += f"{Emojis.lead} {tosend:,}" + total["lead"] += tosend + if iron < 0: + tosend = calc_tosend(iron, data.get("nation_iron")) + data["refill"].update(iron=tosend) + text += f"{Emojis.iron} {tosend:,}" + total["iron"] += tosend + if bauxite < 0: + tosend = calc_tosend(bauxite, data.get("nation_bauxite")) + data["refill"].update(bauxite=tosend) + text += f"{Emojis.bauxite} {tosend:,}" + total["bauxite"] += tosend + + e.add_field( + name=f"{data.get('nation_name')} (c{data.get('num_cities')})", + value=( + f"[go to nation](https://politicsandwar.com/nation/id={rd.get('id')}) \n\n" + f"{text}" + ), + ) + 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 data in revenue_data: + i += 1 + e.description += f"{i}. [{data.get('nation_name')}](https://politicsandwar.com/nation/id={data.get('nation_id')})\n" + + e.description += ( + "\n **Total raws to transfer**\n" + f"{Emojis.oil} {total.get('oil'):,}\n" + f"{Emojis.coal} {total.get('coal'):,}\n" + f"{Emojis.lead} {total.get('lead'):,}\n" + f"{Emojis.iron} {total.get('iron'):,}\n" + f"{Emojis.bauxite} {total.get('bauxite'):,}\n" + ) + embeds.insert(0, 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 = "" + 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 data in revenue_data: + try: + if data["refill"]: + await kit.mutation( + "bankWithdraw", + { + "receiver": rd.get("id"), + "receiver_type": 1, + "note": "raws refill", + **data["refill"] + }, + "id", + ) + pprint.pprint(data, stream=logstream, indent=3) + logmsg += f"{data.get('nation_name')} <:tick:1275839665819353148>\n" + else: + pprint.pprint( + f"{data.get('nation_name')} (already filled)", + stream=logstream, + indent=3, + ) + logmsg += f"{data.get('nation_name')} (already filled)\n" + e.description = logmsg + await interaction.message.edit(embed=e) + await asyncio.sleep(1) + except Exception as err: + pprint.pprint( + f"{data.get('nation_name')} -> {err}", stream=logstream, indent=3 + ) + logmsg += f"{data.get('nation_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)] + ) async def setup(bot: Brahmos): From 708bffde8f95acae7c469c9874b05ef151a01e9e Mon Sep 17 00:00:00 2001 From: un1xx Date: Fri, 6 Jun 2025 21:12:16 +0530 Subject: [PATCH 39/45] update refill cmd --- exts/banking.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/exts/banking.py b/exts/banking.py index eec54ef..ace4b3c 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1408,6 +1408,8 @@ class Banking(commands.Cog): bauxite = data.get("bauxite") data["refill"] = dict() text = "" + if oil is None: + await ctx.send(data) if oil < 0: tosend = calc_tosend(oil, data.get("nation_oil")) data["refill"].update(oil=tosend) From 2efd6161adb681d1491679fbc269d3a67b5ad173 Mon Sep 17 00:00:00 2001 From: un1xx Date: Fri, 6 Jun 2025 21:15:42 +0530 Subject: [PATCH 40/45] update refill cmd --- exts/banking.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index ace4b3c..cc93e02 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1380,8 +1380,6 @@ class Banking(commands.Cog): @commands.command() async def refill(self, ctx: CustomCtx, ids: commands.Greedy[int]): revenue_data = await self.get_alliance_rev(ids) - await ctx.cbsend(revenue_data[0]) - def calc_tosend(raw: float, on_nation: float): return int(7 * abs(raw) - on_nation) @@ -1401,15 +1399,14 @@ class Banking(commands.Cog): count = 0 for data in revenue_data: - oil = data.get("oil") - coal = data.get("coal") - lead = data.get("lead") - iron = data.get("iron") - bauxite = data.get("bauxite") + revenue = data.get("revenue") + oil = revenue.get("oil") + coal = revenue.get("coal") + lead = revenue.get("lead") + iron = revenue.get("iron") + bauxite = revenue.get("bauxite") data["refill"] = dict() text = "" - if oil is None: - await ctx.send(data) if oil < 0: tosend = calc_tosend(oil, data.get("nation_oil")) data["refill"].update(oil=tosend) From cc52ed006fa0ceee64ba753171ce6d26a0dbe1ff Mon Sep 17 00:00:00 2001 From: un1xx Date: Fri, 6 Jun 2025 21:17:15 +0530 Subject: [PATCH 41/45] update refill cmd --- exts/banking.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index cc93e02..0d48958 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1436,7 +1436,7 @@ class Banking(commands.Cog): e.add_field( name=f"{data.get('nation_name')} (c{data.get('num_cities')})", value=( - f"[go to nation](https://politicsandwar.com/nation/id={rd.get('id')}) \n\n" + f"[go to nation](https://politicsandwar.com/nation/id={data.get('nation_id')}) \n\n" f"{text}" ), ) @@ -1517,7 +1517,7 @@ class Banking(commands.Cog): await kit.mutation( "bankWithdraw", { - "receiver": rd.get("id"), + "receiver": data.get("nation_id"), "receiver_type": 1, "note": "raws refill", **data["refill"] From 3e1ff8c71e931a72017e11ee67d665ca15f126e0 Mon Sep 17 00:00:00 2001 From: un1xx Date: Fri, 6 Jun 2025 21:18:14 +0530 Subject: [PATCH 42/45] update refill cmd --- exts/banking.py | 1 + 1 file changed, 1 insertion(+) diff --git a/exts/banking.py b/exts/banking.py index 0d48958..8a1b5f9 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1379,6 +1379,7 @@ class Banking(commands.Cog): @commands.has_any_role("The Croak Council", "Government") @commands.command() async def refill(self, ctx: CustomCtx, ids: commands.Greedy[int]): + await ctx.send(f"> calculating raws") revenue_data = await self.get_alliance_rev(ids) def calc_tosend(raw: float, on_nation: float): return int(7 * abs(raw) - on_nation) From dbec4ee96219b28b06e951de57c7720f8d8eda76 Mon Sep 17 00:00:00 2001 From: un1xx Date: Fri, 6 Jun 2025 21:24:28 +0530 Subject: [PATCH 43/45] update refill cmd --- exts/banking.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index 8a1b5f9..acf1518 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1382,7 +1382,10 @@ class Banking(commands.Cog): await ctx.send(f"> calculating raws") revenue_data = await self.get_alliance_rev(ids) def calc_tosend(raw: float, on_nation: float): - return int(7 * abs(raw) - on_nation) + net = int(7 * abs(raw) - on_nation) + if net < 0: + return 0 + return net embeds = [] e = discord.Embed( @@ -1433,13 +1436,13 @@ class Banking(commands.Cog): data["refill"].update(bauxite=tosend) text += f"{Emojis.bauxite} {tosend:,}" total["bauxite"] += tosend + + if not text: + text = "already satisfied" e.add_field( name=f"{data.get('nation_name')} (c{data.get('num_cities')})", - value=( - f"[go to nation](https://politicsandwar.com/nation/id={data.get('nation_id')}) \n\n" - f"{text}" - ), + value=text ) count += 1 if count == 9: From f7e65b0a17a6ac5f4a579dc2806f8a6f0389725a Mon Sep 17 00:00:00 2001 From: un1xx Date: Fri, 6 Jun 2025 21:31:08 +0530 Subject: [PATCH 44/45] update refill cmd --- exts/banking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exts/banking.py b/exts/banking.py index acf1518..828c22a 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1517,7 +1517,7 @@ class Banking(commands.Cog): await interaction.message.edit(embed=e, view=self.v) for data in revenue_data: try: - if data["refill"]: + if data["refill"] and sum(data["refill"].values()): await kit.mutation( "bankWithdraw", { From f68566d4e6ed5187280f5d42c01affdf9381a6b8 Mon Sep 17 00:00:00 2001 From: un1xx Date: Fri, 6 Jun 2025 22:17:52 +0530 Subject: [PATCH 45/45] update refill cmd --- exts/banking.py | 91 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 75 insertions(+), 16 deletions(-) diff --git a/exts/banking.py b/exts/banking.py index 828c22a..d0c379a 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -61,6 +61,23 @@ class BaseMul: } +class TransferFlags(commands.FlagConverter, delimiter=" ", prefix="--"): + money: int = commands.flag(default=0) + food: int = commands.flag(default=0) + uranium: int = commands.flag(default=0) + gasoline: int = commands.flag(default=0) + munitions: int = commands.flag(default=0) + steel: int = commands.flag(default=0) + aluminum: int = commands.flag(default=0) + coal: int = commands.flag(default=0) + iron: int = commands.flag(default=0) + lead: int = commands.flag(default=0) + bauxite: int = commands.flag(default=0) + oil: int = commands.flag(default=0) + nation: List[int] = commands.flag(default=[]) + alliance: Optional[int] = commands.flag(default=None) + + class Banking(commands.Cog): def __init__(self, bot: Brahmos): self.bot = bot @@ -394,6 +411,17 @@ class Banking(commands.Cog): await interaction.message.edit(view=None) logstream.seek(0) await ctx.send(file=discord.File(logstream, filename="log.txt")) + e.title = "Resources Transferred" + e.color = discord.Color.green() + e.description = ( + 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'):,}" + ) paginator = ctx.Paginator(pages=embeds) await paginator.start( @@ -989,7 +1017,7 @@ class Banking(commands.Cog): "nation_bauxite": nation.bauxite, "nation_lead": nation.lead, "nation_flag": nation.flag, - "num_cities": nation.num_cities + "num_cities": nation.num_cities, } ) @@ -1355,7 +1383,7 @@ class Banking(commands.Cog): title=f"Raws consumption for {data['nation_name']}", color=ctx.author.color, timestamp=datetime.datetime.utcnow(), - url=f"https://politicsandwar.com/nation/id={data.get('nation_id')}" + url=f"https://politicsandwar.com/nation/id={data.get('nation_id')}", ) e.set_thumbnail(url=data.get("nation_flag")) @@ -1381,8 +1409,9 @@ class Banking(commands.Cog): async def refill(self, ctx: CustomCtx, ids: commands.Greedy[int]): await ctx.send(f"> calculating raws") revenue_data = await self.get_alliance_rev(ids) + def calc_tosend(raw: float, on_nation: float): - net = int(7 * abs(raw) - on_nation) + net = int(7 * abs(raw) - on_nation) if net < 0: return 0 return net @@ -1393,13 +1422,7 @@ class Banking(commands.Cog): timestamp=datetime.datetime.now(), color=ctx.author.color, ) - total = { - "oil": 0, - "coal": 0, - "lead": 0, - "iron": 0, - "bauxite": 0 - } + total = {"oil": 0, "coal": 0, "lead": 0, "iron": 0, "bauxite": 0} count = 0 for data in revenue_data: @@ -1415,7 +1438,7 @@ class Banking(commands.Cog): tosend = calc_tosend(oil, data.get("nation_oil")) data["refill"].update(oil=tosend) text += f"{Emojis.oil} {tosend:,}\n" - total["oil"] += tosend + total["oil"] += tosend if coal < 0: tosend = calc_tosend(coal, data.get("nation_coal")) data["refill"].update(coal=tosend) @@ -1436,13 +1459,13 @@ class Banking(commands.Cog): data["refill"].update(bauxite=tosend) text += f"{Emojis.bauxite} {tosend:,}" total["bauxite"] += tosend - + if not text: text = "already satisfied" e.add_field( name=f"{data.get('nation_name')} (c{data.get('num_cities')})", - value=text + value=text, ) count += 1 if count == 9: @@ -1524,7 +1547,7 @@ class Banking(commands.Cog): "receiver": data.get("nation_id"), "receiver_type": 1, "note": "raws refill", - **data["refill"] + **data["refill"], }, "id", ) @@ -1542,15 +1565,28 @@ class Banking(commands.Cog): await asyncio.sleep(1) except Exception as err: pprint.pprint( - f"{data.get('nation_name')} -> {err}", stream=logstream, indent=3 + f"{data.get('nation_name')} -> {err}", + stream=logstream, + indent=3, + ) + logmsg += ( + f"{data.get('nation_name')} <:cross:1275839683984621568>\n" ) - logmsg += f"{data.get('nation_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")) + e.title = "raws transferred" + e.description = ( + f"{Emojis.oil} {total.get('oil'):,}\n" + f"{Emojis.coal} {total.get('coal'):,}\n" + f"{Emojis.lead} {total.get('lead'):,}\n" + f"{Emojis.iron} {total.get('iron'):,}\n" + f"{Emojis.bauxite} {total.get('bauxite'):,}\n" + ) + await ctx.send(embed=e) paginator = ctx.Paginator(pages=embeds) await paginator.start( @@ -1558,5 +1594,28 @@ class Banking(commands.Cog): ) + @commands.command() + async def tf(self, ctx: CustomCtx, flags: TransferFlags): + """ + Transfer resources to a nation or alliance. + """ + nation_ids = flags.nation + alliance_id = flags.alliance + resources = { + "money": flags.money, + "food": flags.food, + "uranium": flags.uranium, + "gasoline": flags.gasoline, + "munitions": flags.munitions, + "steel": flags.steel, + "aluminum": flags.aluminum, + "coal": flags.coal, + "iron": flags.iron, + "lead": flags.lead, + "bauxite": flags.bauxite, + "oil": flags.oil, + } + + async def setup(bot: Brahmos): await bot.add_cog(Banking(bot))