feat: only work on specified minutes
This commit is contained in:
parent
5dcb2d2bf3
commit
1a0cc18de5
@ -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": {
|
||||
|
15
exts/post.py
15
exts/post.py
@ -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
|
||||
await cog._postLine.start()
|
||||
await bot.add_cog(cog)
|
||||
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()
|
||||
|
3
main.py
3
main.py
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user