1
0

fix: 매번 대사를 일일히 Fetch하는 것은 자원 낭비임

This commit is contained in:
オスカー、 2023-12-01 10:42:22 +09:00
parent 8c495c7024
commit 2f4f028225
No known key found for this signature in database
GPG Key ID: B1EFBBF5C93FF78F
2 changed files with 7 additions and 7 deletions

View File

@ -22,13 +22,11 @@ class Post(commands.Cog):
if self.minute >= 60:
self.minute = self.minute - 60
line = await self.bot.get_random_line()
while line.text in self.posted:
line = await self.bot.get_random_line()
line = await self.bot.get_random_line(self.posted)
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)
self.posted.append(line.text)
self.posted.append(line.location)
if len(self.posted) > self.max_count:
self.posted.pop(0)

View File

@ -76,12 +76,14 @@ 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, ignore: list) -> Line:
sheet: Worksheet = await self.get_worksheet()
response = await sheet.get("F4")
if response is None or response == "":
return
count = int(response[0][0])
number = 0
while number in ignore or number == 0:
result = random.randint(1, count)
number = result + 2
return await Line.from_number(number, sheet)