fix: post problem
This commit is contained in:
parent
1f1bfa15f9
commit
d6160f3ac1
@ -7,4 +7,11 @@
|
|||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="PyNamespacePackagesService">
|
||||||
|
<option name="namespacePackageFolders">
|
||||||
|
<list>
|
||||||
|
<option value="$MODULE_DIR$/exts" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
</module>
|
</module>
|
@ -1,11 +1,11 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from mipa.ext import commands, tasks
|
from mipa.ext import commands, tasks
|
||||||
from mipa.ext.commands.bot import Bot
|
from ..main import Autoposter
|
||||||
|
|
||||||
|
|
||||||
class Post(commands.Cog):
|
class Post(commands.Cog):
|
||||||
def __init__(self, bot: Bot) -> None:
|
def __init__(self, bot: Autoposter) -> None:
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.visibility = bot.config.visibility or "home"
|
self.visibility = bot.config.visibility or "home"
|
||||||
self.rate = bot.config.rate or 30
|
self.rate = bot.config.rate or 30
|
||||||
@ -23,10 +23,10 @@ class Post(commands.Cog):
|
|||||||
line = await self.bot.get_random_line()
|
line = await 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)
|
||||||
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)
|
cog = Post(bot)
|
||||||
await bot.add_cog(cog)
|
await bot.add_cog(cog)
|
||||||
await cog._postLine.start()
|
await cog._postLine.start()
|
||||||
|
5
main.py
5
main.py
@ -1,6 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import gspread_asyncio
|
import gspread_asyncio
|
||||||
from aiohttp import ClientWebSocketResponse
|
from aiohttp import ClientWebSocketResponse
|
||||||
@ -77,7 +78,7 @@ class Autoposter(commands.Bot):
|
|||||||
worksheet = await spreadsheet.get_worksheet(0)
|
worksheet = await spreadsheet.get_worksheet(0)
|
||||||
return worksheet
|
return worksheet
|
||||||
|
|
||||||
async def get_random_line(self) -> Line:
|
async def get_random_line(self) -> Optional[Line]:
|
||||||
sheet: Worksheet = await self.get_worksheet()
|
sheet: Worksheet = await self.get_worksheet()
|
||||||
response = await sheet.get("F4")
|
response = await sheet.get("F4")
|
||||||
if response is None or response == "":
|
if response is None or response == "":
|
||||||
@ -119,7 +120,7 @@ class Autoposter(commands.Bot):
|
|||||||
line: Line = await self.get_random_line()
|
line: Line = await self.get_random_line()
|
||||||
template = self.config.reply
|
template = self.config.reply
|
||||||
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)
|
||||||
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__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user