1
0

temp: reply to mention

This commit is contained in:
オスカー、 2023-11-23 15:42:58 +09:00 committed by GitHub
parent 48fd87a8dc
commit b96d459131
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

24
main.py
View File

@ -5,6 +5,7 @@ import os
#import aiomysql #import aiomysql
import gspread import gspread
from aiohttp import ClientWebSocketResponse 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 mipa.ext import commands
# from mipac.models.note import Note # from mipac.models.note import Note
@ -43,12 +44,25 @@ class MyBot(commands.Bot):
# else: # else:
# return "Query Successful" # return "Query Successful"
def get_worksheet(self): def get_worksheet(self) -> Worksheet:
gc = gspread.service_account() gc = gspread.service_account()
sh = gc.open_by_url(os.getenv("SPREADSHEET_URL")) sh = gc.open_by_url(os.getenv("SPREADSHEET_URL"))
worksheet = sh.get_worksheet(0) worksheet = sh.get_worksheet(0)
return worksheet return worksheet
def get_line(self) -> str:
def get_line(self) -> str:
sheet: Worksheet = self.bot.get_worksheet()
response = sheet.get("F4")
if response is None or response == "":
return
count = int(response[0][0])
result = random.randint(1, count)
number = result + 2
res = sheet.get(f"D{number}")
text = res[0][0].strip()
return text
async def _connect_channel(self): async def _connect_channel(self):
await self.router.connect_channel(['main', 'global']) await self.router.connect_channel(['main', 'global'])
@ -65,13 +79,13 @@ class MyBot(commands.Bot):
# async def on_note(self, note: Note): # async def on_note(self, note: Note):
# print(f'{note.author.username}: {note.content}') # print(f'{note.author.username}: {note.content}')
# async def on_mention(self, notice: NotificationNote): async def on_mention(self, notice: NotificationNote):
# print(f"{notice.note.author.username} requested {notice.note.content}") print(f"{notice.note.author.username} requested {notice.note.content}")
# await self.progress_command(notice.note) await note.action.reply()
if __name__ == '__main__': if __name__ == '__main__':
bot = MyBot() bot = MyBot()
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
# loop.run_until_complete(bot.create_pool()) # loop.run_until_complete(bot.create_pool())
loop.run_until_complete(bot.start(os.getenv("MISSKEY_ORIGIN"), os.getenv("MISSKEY_TOKEN"))) loop.run_until_complete(bot.start(os.getenv("MISSKEY_ORIGIN"), os.getenv("MISSKEY_TOKEN")))