1
0

fix: some problems

This commit is contained in:
オスカー、 2023-11-23 17:24:00 +09:00
parent b96d459131
commit 323b6a7a86
No known key found for this signature in database
GPG Key ID: B1EFBBF5C93FF78F
2 changed files with 16 additions and 8 deletions

View File

@ -1,6 +1,5 @@
import random
from datetime import datetime
from gspread.worksheet import Worksheet
from mipa.ext import commands, tasks
from mipa.ext.commands.bot import Bot
# from mipa.ext.commands.context import Context
@ -11,8 +10,12 @@ class Autopost(commands.Cog):
self.bot = bot
self.posted = []
@tasks.loop(seconds=1800)
@tasks.loop(seconds=60)
async def _postLine(self) -> None:
now = datetime.now()
if now.minute not in [30, 00]:
return
line = self.bot.get_line()
while line in self.posted:
line = self.bot.get_line()

15
main.py
View File

@ -1,12 +1,13 @@
import asyncio
import os
import random
#from typing import Optional
#import aiomysql
import gspread
from aiohttp import ClientWebSocketResponse
from gspread.worksheet import Worksheet
#from mipac.models.notification import NotificationNote
from mipac.models.notification import NotificationNote
from mipa.ext import commands
# from mipac.models.note import Note
from dotenv import load_dotenv
@ -51,8 +52,7 @@ class MyBot(commands.Bot):
return worksheet
def get_line(self) -> str:
def get_line(self) -> str:
sheet: Worksheet = self.bot.get_worksheet()
sheet: Worksheet = self.get_worksheet()
response = sheet.get("F4")
if response is None or response == "":
return
@ -80,8 +80,13 @@ class MyBot(commands.Bot):
# print(f'{note.author.username}: {note.content}')
async def on_mention(self, notice: NotificationNote):
print(f"{notice.note.author.username} requested {notice.note.content}")
await note.action.reply()
sheet = self.get_worksheet()
line = self.get_line()
result = sheet.find(line, in_column=4)
number = result.row - 2
where = sheet.get(f"C{result.row}")
where = where[0][0]
await notice.note.api.action.reply(content=f"{line}\n \n<small>- {where}에서 발췌됨. ({number}번 대사)</small>", visibility="home", reply_id=notice.note.id)
if __name__ == '__main__':