fix: post problem
This commit is contained in:
parent
1f1bfa15f9
commit
d6160f3ac1
@ -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>
|
@ -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()
|
||||
|
5
main.py
5
main.py
@ -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__':
|
||||
|
Loading…
Reference in New Issue
Block a user