refactor and bug fixes.

This commit is contained in:
sudobh committed 2025-11-10 01:54:57 +05:30
1 parent 58908ee3d6
commit 15207fe11a
9 files changed
+1394 -294

No files matched your search

+96 -36
View File
@@ -1,12 +1,15 @@
import aiohttp
import asyncio
import datetime
import os
import random
from typing import List, Literal, Optional
from typing import Optional
import aiohttp
import discord
from discord.ext import commands
import pnwkit
import pytz
from discord.ext import commands, tasks
from discord.utils import format_dt
from pnwkit import Order, OrderBy
from botclass import Brahmos, CustomCtx
@@ -27,32 +30,11 @@ class Misc(commands.Cog):
bot_key_api_key=os.getenv("pnwACCKEY"),
aiohttp_session=aiohttp.ClientSession(loop=self.bot.loop),
)
self.send_daily_message.start()
@commands.command(name="sex")
async def sex(self, ctx: CustomCtx):
"""
sex
"""
replies_rare = [
"https://media.discordapp.net/attachments/943540698492334123/1215965590037069944/QQmVi9s.png",
"https://tenor.com/view/houshou-marine-sexy-treasure-box-im-your-treasure-box-ride-gif-26351095",
]
def cog_unload(self):
self.send_daily_message.cancel()
replies_common = [
"# SEXOOOO",
"nope",
"kys",
"yes",
"not with u lmao",
"in your dreams",
"no",
]
num = random.randint(1, 10)
reply = random.choice(replies_common)
if num <= 2:
reply = replies_rare[random.randint(0, 1)]
await ctx.send(reply)
@commands.command(name="snowflake")
async def snowflake(self, ctx: CustomCtx, snowflake: int):
@@ -68,30 +50,108 @@ class Misc(commands.Cog):
color=0x2F3136,
)
await ctx.send(embed=embed)
@commands.command(name="alliance")
async def alliance(self, ctx: CustomCtx, id: Optional[int] = 10177):
try:
result = await self.kit.query(
"nations",
{"alliance_id": id,
"orderBy": OrderBy("cities", Order.DESC),
"first": 300
{
"alliance_id": id,
"orderBy": OrderBy("cities", Order.DESC),
"first": 300,
},
"id, nation_name, num_cities, alliance {name}"
"id, nation_name, num_cities, alliance {name}",
)
string = f"Nations in alliance {result.nations[0].alliance.name}\n"
i=0
i = 0
for nation in result.nations:
i+=1
string += f"{i:>3}. {nation.id} c{nation.num_cities} {nation.nation_name}\n"
i += 1
string += (
f"{i:>3}. {nation.id} c{nation.num_cities} {nation.nation_name}\n"
)
await ctx.cbsend(string)
except IndexError:
return await ctx.send("> alliance not found.")
except Exception as e:
return await ctx.cbsend(e)
@commands.command(name="color")
async def color(self, ctx):
"""
return members not olive colored in the alliance
"""
res = await self.kit.query(
"nations",
{"alliance_id": [10177, 10198]},
"id, leader_name, nation_name, color, vacation_mode_turns",
)
nations = [
n for n in res.nations if n.color != "olive" and n.vacation_mode_turns == 0
]
await ctx.send(
"> nations not olive:\n"
+ "\n".join(
[
f"[{n.nation_name}](<https://politicsandwar.com/nation/id={n.id}>) [{n.leader_name}]"
for n in nations
]
)
)
def seconds_until_target(self, hour: int, minute: int = 0):
now = datetime.datetime.now()
target = now.replace(hour=hour, minute=minute, second=0, microsecond=0)
if target < now:
target += datetime.timedelta(days=1)
return (target - now).total_seconds()
@tasks.loop(hours=24)
async def send_daily_message(self):
channel = self.bot.get_channel(1356234853217075200)
res = await self.kit.query(
"nations",
{"alliance_id": [10177, 10198], "alliance_position": [2, 3, 4, 5]},
"id, leader_name, nation_name, color, vacation_mode_turns, last_active",
)
nations = [
n
for n in res.nations
if n.color not in ["olive", "beige"] and n.vacation_mode_turns == 0
]
await channel.send(
"> nations not olive:\n"
+ "\n".join(
[
f"[{n.nation_name}](<https://politicsandwar.com/nation/id={n.id}>) [{n.leader_name}]"
for n in nations
]
)
)
inactives = []
for nation in res.nations:
if nation.vacation_mode_turns != 0:
continue
utcnow = datetime.datetime.now().replace(tzinfo=pytz.utc)
delta = utcnow - nation.last_active
if delta > datetime.timedelta(days=3, hours=12):
inactives.append(nation)
if inactives:
await channel.send(
"> Inactive nations:\n"
+ "\n".join(
[
f"[{n.nation_name}](<https://politicsandwar.com/nation/id={n.id}>) [{n.leader_name}] {format_dt(n.last_active)}"
for n in inactives
]
)
)
@send_daily_message.before_loop
async def before_send_daily_message(self):
await self.bot.wait_until_ready()
seconds = self.seconds_until_target(2, 5)
await asyncio.sleep(seconds)
async def setup(bot: commands.Bot):