1
0
Autopost/exts/post.py

33 lines
1011 B
Python
Raw Normal View History

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
2024-10-20 21:03:58 +09:00
from main import Autoposter
2023-11-23 14:42:39 +09:00
2023-11-24 09:15:54 +09:00
class Post(commands.Cog):
2024-10-14 20:09:51 +09:00
def __init__(self, bot: Autoposter) -> None:
2023-11-23 14:42:39 +09:00
self.bot = bot
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
line = await self.bot.get_random_line()
2023-11-24 16:05:57 +09:00
template = self.bot.config.note
result = template.replace("{text}", line.text).replace("{from}", line.where).replace("{number}", line.number)
2024-10-14 20:09:51 +09:00
await self.bot.client.note.action.send(text=result, visibility=self.visibility)
2023-11-23 14:42:39 +09:00
2024-10-14 20:09:51 +09:00
async def setup(bot: Autoposter):
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()