1
0

feat: only work on specified minutes

This commit is contained in:
オスカー、 2023-11-26 18:26:37 +09:00
parent 5dcb2d2bf3
commit 1a0cc18de5
No known key found for this signature in database
GPG Key ID: B1EFBBF5C93FF78F
3 changed files with 16 additions and 5 deletions

View File

@ -1,8 +1,9 @@
{
"token": "YOUR_ACCESS_TOKEN_HERE",
"origin": "YOUR_MISSKEY_SERVER_HERE",
"max_duplicate": 3,
"duplicateQueueAfter": 3,
"rate": 60,
"startFrom": 30,
"visibility": "home",
"worksheet": "YOUR_WORKSHEET_URL_HERE",
"template": {

View File

@ -1,3 +1,6 @@
import asyncio
from datetime import datetime
from mipa.ext import commands, tasks
from mipa.ext.commands.bot import Bot
@ -12,7 +15,7 @@ class Post(commands.Cog):
@tasks.loop(seconds=1800)
async def _postLine(self) -> None:
line = self.bot.get_random_line()
while line in self.posted:
while line.text in self.posted:
line = self.bot.get_random_line()
template = self.bot.config.note
result = template.replace("{text}", line.text).replace("{from}", line.where).replace("{number}", line.number)
@ -24,7 +27,13 @@ class Post(commands.Cog):
async def setup(bot: Bot):
cog = Post(bot)
await bot.add_cog(cog)
if bot.config.rate is not None:
cog._postLine.seconds = bot.config.rate * 60
if bot.config.start_time is not None:
print("Waiting until time is coming")
now = datetime.now()
while now.minute != bot.config.start:
await asyncio.sleep(1)
now = datetime.now()
await cog._postLine.start()
await bot.add_cog(cog)

View File

@ -15,8 +15,9 @@ class Config:
raw = json.load(file)
self.token = raw.get("token")
self.origin = raw.get("origin")
self.max = raw.get("max_duplicate")
self.max = raw.get("duplicateQueueAfter")
self.rate = raw.get("rate")
self.start_time = raw.get("startFrom")
self.visibility = raw.get("visibility")
self.worksheet = raw.get("worksheet")
template = raw.get("template")