1
0
Autopost/exts/post.py
2024-10-20 21:03:58 +09:00

33 lines
1011 B
Python

from datetime import datetime
from mipa.ext import commands, tasks
from main import Autoposter
class Post(commands.Cog):
def __init__(self, bot: Autoposter) -> None:
self.bot = bot
self.visibility = bot.config.visibility or "home"
self.rate = bot.config.rate or 30
self.minute = bot.config.start_time or 0
@tasks.loop(seconds=60)
async def _postLine(self) -> None:
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()
template = self.bot.config.note
result = template.replace("{text}", line.text).replace("{from}", line.where).replace("{number}", line.number)
await self.bot.client.note.action.send(text=result, visibility=self.visibility)
async def setup(bot: Autoposter):
cog = Post(bot)
await bot.add_cog(cog)
await cog._postLine.start()