2023-11-26 18:26:37 +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
|
|
|
|
|
|
|
|
|
2023-11-24 09:15:54 +09:00
|
|
|
class Post(commands.Cog):
|
2023-11-23 14:42:39 +09:00
|
|
|
def __init__(self, bot: Bot) -> None:
|
|
|
|
self.bot = bot
|
2023-11-24 14:13:21 +09:00
|
|
|
self.visibility = bot.config.visibility or "home"
|
2023-11-29 16:07:57 +09:00
|
|
|
self.rate = bot.config.rate or 30
|
|
|
|
self.minute = bot.config.start_time or 0
|
2023-11-23 14:42:39 +09:00
|
|
|
|
2023-11-29 16:07:57 +09:00
|
|
|
@tasks.loop(seconds=60)
|
2023-11-23 14:42:39 +09:00
|
|
|
async def _postLine(self) -> None:
|
2023-11-29 16:07:57 +09:00
|
|
|
if datetime.now().minute != self.minute:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.minute = self.minute + self.rate
|
|
|
|
if self.minute >= 60:
|
|
|
|
self.minute = self.minute - 60
|
|
|
|
|
2023-12-01 10:47:20 +09:00
|
|
|
line = await self.bot.get_random_line()
|
2023-11-24 16:05:57 +09:00
|
|
|
template = self.bot.config.note
|
2023-11-24 14:13:21 +09:00
|
|
|
result = template.replace("{text}", line.text).replace("{from}", line.where).replace("{number}", line.number)
|
|
|
|
await self.bot.client.note.action.send(content=result, visibility=self.visibility)
|
2023-11-23 14:42:39 +09:00
|
|
|
|
|
|
|
|
|
|
|
async def setup(bot: Bot):
|
2023-11-24 09:15:54 +09:00
|
|
|
cog = Post(bot)
|
2023-11-26 18:26:37 +09:00
|
|
|
await bot.add_cog(cog)
|
2023-11-29 16:07:57 +09:00
|
|
|
await cog._postLine.start()
|