2023-11-23 17:24:00 +09:00
|
|
|
from datetime import datetime
|
2023-11-23 14:42:39 +09:00
|
|
|
|
|
|
|
from mipa.ext import commands, tasks
|
|
|
|
from mipa.ext.commands.bot import Bot
|
|
|
|
# from mipa.ext.commands.context import Context
|
|
|
|
|
|
|
|
|
|
|
|
class Autopost(commands.Cog):
|
|
|
|
def __init__(self, bot: Bot) -> None:
|
|
|
|
self.bot = bot
|
|
|
|
self.posted = []
|
|
|
|
|
2023-11-23 17:24:00 +09:00
|
|
|
@tasks.loop(seconds=60)
|
2023-11-23 14:42:39 +09:00
|
|
|
async def _postLine(self) -> None:
|
2023-11-23 17:24:00 +09:00
|
|
|
now = datetime.now()
|
|
|
|
if now.minute not in [30, 00]:
|
|
|
|
return
|
|
|
|
|
2023-11-23 15:40:16 +09:00
|
|
|
line = self.bot.get_line()
|
2023-11-23 14:42:39 +09:00
|
|
|
while line in self.posted:
|
2023-11-23 15:40:16 +09:00
|
|
|
line = self.bot.get_line()
|
2023-11-23 14:42:39 +09:00
|
|
|
await self.bot.client.note.action.send(content=line, visibility="home")
|
|
|
|
self.posted.append(line)
|
|
|
|
if len(self.posted) > self.bot.max_count:
|
|
|
|
self.posted.pop(0)
|
|
|
|
|
|
|
|
|
|
|
|
async def setup(bot: Bot):
|
|
|
|
cog = Autopost(bot)
|
|
|
|
await cog._postLine.start()
|
2023-11-23 15:40:16 +09:00
|
|
|
await bot.add_cog(cog)
|