From 2f4f028225dc8874e2857c8f2382d4a6d49b434c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=84=EB=A5=B4=ED=8E=98?= Date: Fri, 1 Dec 2023 10:42:22 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=A7=A4=EB=B2=88=20=EB=8C=80=EC=82=AC?= =?UTF-8?q?=EB=A5=BC=20=EC=9D=BC=EC=9D=BC=ED=9E=88=20Fetch=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EA=B2=83=EC=9D=80=20=EC=9E=90=EC=9B=90=20=EB=82=AD?= =?UTF-8?q?=EB=B9=84=EC=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exts/post.py | 6 ++---- main.py | 8 +++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/exts/post.py b/exts/post.py index 94ef263..62e262f 100644 --- a/exts/post.py +++ b/exts/post.py @@ -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) diff --git a/main.py b/main.py index 903cf27..30c08b2 100644 --- a/main.py +++ b/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: