fix: 매번 대사를 일일히 Fetch하는 것은 자원 낭비임
This commit is contained in:
parent
8c495c7024
commit
2f4f028225
@ -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)
|
||||
|
||||
|
8
main.py
8
main.py
@ -76,14 +76,16 @@ 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])
|
||||
result = random.randint(1, count)
|
||||
number = result + 2
|
||||
number = 0
|
||||
while number in ignore or number == 0:
|
||||
result = random.randint(1, count)
|
||||
number = result + 2
|
||||
return await Line.from_number(number, sheet)
|
||||
|
||||
async def get_line(self, number: int) -> Line:
|
||||
|
Loading…
Reference in New Issue
Block a user