1
0

fix: post problem

This commit is contained in:
オスカー、 2024-10-14 20:09:51 +09:00
parent 1f1bfa15f9
commit d6160f3ac1
Signed by: SWREI
GPG Key ID: 139D6573F92DA9F7
3 changed files with 14 additions and 6 deletions

View File

@ -7,4 +7,11 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyNamespacePackagesService">
<option name="namespacePackageFolders">
<list>
<option value="$MODULE_DIR$/exts" />
</list>
</option>
</component>
</module>

View File

@ -1,11 +1,11 @@
from datetime import datetime
from mipa.ext import commands, tasks
from mipa.ext.commands.bot import Bot
from ..main import Autoposter
class Post(commands.Cog):
def __init__(self, bot: Bot) -> None:
def __init__(self, bot: Autoposter) -> None:
self.bot = bot
self.visibility = bot.config.visibility or "home"
self.rate = bot.config.rate or 30
@ -23,10 +23,10 @@ class Post(commands.Cog):
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(content=result, visibility=self.visibility)
await self.bot.client.note.action.send(text=result, visibility=self.visibility)
async def setup(bot: Bot):
async def setup(bot: Autoposter):
cog = Post(bot)
await bot.add_cog(cog)
await cog._postLine.start()

View File

@ -1,6 +1,7 @@
import asyncio
import json
import random
from typing import Optional
import gspread_asyncio
from aiohttp import ClientWebSocketResponse
@ -77,7 +78,7 @@ class Autoposter(commands.Bot):
worksheet = await spreadsheet.get_worksheet(0)
return worksheet
async def get_random_line(self) -> Line:
async def get_random_line(self) -> Optional[Line]:
sheet: Worksheet = await self.get_worksheet()
response = await sheet.get("F4")
if response is None or response == "":
@ -119,7 +120,7 @@ class Autoposter(commands.Bot):
line: Line = await self.get_random_line()
template = self.config.reply
result = template.replace("{text}", line.text).replace("{from}", line.where).replace("{number}", line.number)
await notice.note.api.action.reply(content=result, visibility=notice.note.visibility, reply_id=notice.note.id)
await notice.note.api.action.reply(text=result, visibility=notice.note.visibility)
if __name__ == '__main__':