feat: only work on specified minutes
This commit is contained in:
parent
5dcb2d2bf3
commit
1a0cc18de5
@ -1,8 +1,9 @@
|
|||||||
{
|
{
|
||||||
"token": "YOUR_ACCESS_TOKEN_HERE",
|
"token": "YOUR_ACCESS_TOKEN_HERE",
|
||||||
"origin": "YOUR_MISSKEY_SERVER_HERE",
|
"origin": "YOUR_MISSKEY_SERVER_HERE",
|
||||||
"max_duplicate": 3,
|
"duplicateQueueAfter": 3,
|
||||||
"rate": 60,
|
"rate": 60,
|
||||||
|
"startFrom": 30,
|
||||||
"visibility": "home",
|
"visibility": "home",
|
||||||
"worksheet": "YOUR_WORKSHEET_URL_HERE",
|
"worksheet": "YOUR_WORKSHEET_URL_HERE",
|
||||||
"template": {
|
"template": {
|
||||||
|
13
exts/post.py
13
exts/post.py
@ -1,3 +1,6 @@
|
|||||||
|
import asyncio
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from mipa.ext import commands, tasks
|
from mipa.ext import commands, tasks
|
||||||
from mipa.ext.commands.bot import Bot
|
from mipa.ext.commands.bot import Bot
|
||||||
|
|
||||||
@ -12,7 +15,7 @@ class Post(commands.Cog):
|
|||||||
@tasks.loop(seconds=1800)
|
@tasks.loop(seconds=1800)
|
||||||
async def _postLine(self) -> None:
|
async def _postLine(self) -> None:
|
||||||
line = self.bot.get_random_line()
|
line = self.bot.get_random_line()
|
||||||
while line in self.posted:
|
while line.text in self.posted:
|
||||||
line = self.bot.get_random_line()
|
line = self.bot.get_random_line()
|
||||||
template = self.bot.config.note
|
template = self.bot.config.note
|
||||||
result = template.replace("{text}", line.text).replace("{from}", line.where).replace("{number}", line.number)
|
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):
|
async def setup(bot: Bot):
|
||||||
cog = Post(bot)
|
cog = Post(bot)
|
||||||
|
await bot.add_cog(cog)
|
||||||
if bot.config.rate is not None:
|
if bot.config.rate is not None:
|
||||||
cog._postLine.seconds = bot.config.rate * 60
|
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 cog._postLine.start()
|
||||||
await bot.add_cog(cog)
|
|
||||||
|
3
main.py
3
main.py
@ -15,8 +15,9 @@ class Config:
|
|||||||
raw = json.load(file)
|
raw = json.load(file)
|
||||||
self.token = raw.get("token")
|
self.token = raw.get("token")
|
||||||
self.origin = raw.get("origin")
|
self.origin = raw.get("origin")
|
||||||
self.max = raw.get("max_duplicate")
|
self.max = raw.get("duplicateQueueAfter")
|
||||||
self.rate = raw.get("rate")
|
self.rate = raw.get("rate")
|
||||||
|
self.start_time = raw.get("startFrom")
|
||||||
self.visibility = raw.get("visibility")
|
self.visibility = raw.get("visibility")
|
||||||
self.worksheet = raw.get("worksheet")
|
self.worksheet = raw.get("worksheet")
|
||||||
template = raw.get("template")
|
template = raw.get("template")
|
||||||
|
Loading…
Reference in New Issue
Block a user