add alliance cmd

This commit is contained in:
un1xx committed 2025-05-09 22:39:57 +05:30
1 parent 90740244d3
commit b5863b9e27
3 files changed
+151 -6

No files matched your search

+36
View File
@@ -1,9 +1,13 @@
import aiohttp
import datetime
import os
import random
from typing import List, Literal, Optional
import discord
from discord.ext import commands
import pnwkit
from pnwkit import Order, OrderBy
from botclass import Brahmos, CustomCtx
@@ -11,6 +15,18 @@ from botclass import Brahmos, CustomCtx
class Misc(commands.Cog):
def __init__(self, bot: Brahmos):
self.bot = bot
self.kit = pnwkit.QueryKit(
api_key=os.getenv("pnwAPIKEY"),
bot_key=os.getenv("pnwBOTKEY"),
bot_key_api_key=os.getenv("pnwACCKEY"),
aiohttp_session=aiohttp.ClientSession(loop=self.bot.loop),
)
self.dkit = 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),
)
@commands.command(name="sex")
async def sex(self, ctx: CustomCtx):
@@ -52,6 +68,26 @@ 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": 10177,
"orderBy": OrderBy("cities", Order.DESC)
},
"id, nation_name, num_cities, alliance {name}"
)
except Exception as e:
return await ctx.cbsend(e)
string = f"Nations in alliance {result.nations[0].alliance.name}\n"
i=0
for nation in result.nations:
i+=1
string += f"{i:>3}. {nation.id} c{nation.num_cities} {nation.nation_name}\n"
await ctx.cbsend(string)
async def setup(bot: commands.Bot):