Update misc.py
This commit is contained in:
1 parent
39e1e7b395
commit
f011ae73c5
1 file changed
+33
-1
+33
-1
@@ -1,11 +1,12 @@
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
|
import asyncio
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
from typing import List, Literal, Optional
|
from typing import List, Literal, Optional
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands, tasks
|
||||||
import pnwkit
|
import pnwkit
|
||||||
from pnwkit import Order, OrderBy
|
from pnwkit import Order, OrderBy
|
||||||
|
|
||||||
@@ -26,6 +27,10 @@ class Misc(commands.Cog):
|
|||||||
bot_key_api_key=os.getenv("pnwACCKEY"),
|
bot_key_api_key=os.getenv("pnwACCKEY"),
|
||||||
aiohttp_session=aiohttp.ClientSession(loop=self.bot.loop),
|
aiohttp_session=aiohttp.ClientSession(loop=self.bot.loop),
|
||||||
)
|
)
|
||||||
|
self.send_daily_message.start()
|
||||||
|
|
||||||
|
def cog_unload(self):
|
||||||
|
self.send_daily_message.cancel()
|
||||||
|
|
||||||
@commands.command(name="sex")
|
@commands.command(name="sex")
|
||||||
async def sex(self, ctx: CustomCtx):
|
async def sex(self, ctx: CustomCtx):
|
||||||
@@ -105,6 +110,33 @@ class Misc(commands.Cog):
|
|||||||
"> nations not olive:\n" + "\n".join([f"[{n.nation_name}](<https://politicsandwar.com/nation/id={n.id}>) [{n.leader_name}]" for n in nations])
|
"> 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.utcnow()
|
||||||
|
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]},
|
||||||
|
"id, leader_name, nation_name, color"
|
||||||
|
)
|
||||||
|
nations = [n for n in res.nations if n.color != "olive"]
|
||||||
|
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])
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@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):
|
async def setup(bot: commands.Bot):
|
||||||
await bot.add_cog(Misc(bot))
|
await bot.add_cog(Misc(bot))
|
||||||
Reference in new issue
Block a user