refactor: move get line to main
This commit is contained in:
parent
eff7634e83
commit
48fd87a8dc
@ -10,24 +10,12 @@ class Autopost(commands.Cog):
|
|||||||
def __init__(self, bot: Bot) -> None:
|
def __init__(self, bot: Bot) -> None:
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.posted = []
|
self.posted = []
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
@tasks.loop(seconds=1800)
|
@tasks.loop(seconds=1800)
|
||||||
async def _postLine(self) -> None:
|
async def _postLine(self) -> None:
|
||||||
line = self.get_line()
|
line = self.bot.get_line()
|
||||||
while line in self.posted:
|
while line in self.posted:
|
||||||
line = self.get_line()
|
line = self.bot.get_line()
|
||||||
await self.bot.client.note.action.send(content=line, visibility="home")
|
await self.bot.client.note.action.send(content=line, visibility="home")
|
||||||
self.posted.append(line)
|
self.posted.append(line)
|
||||||
if len(self.posted) > self.bot.max_count:
|
if len(self.posted) > self.bot.max_count:
|
||||||
@ -37,4 +25,4 @@ class Autopost(commands.Cog):
|
|||||||
async def setup(bot: Bot):
|
async def setup(bot: Bot):
|
||||||
cog = Autopost(bot)
|
cog = Autopost(bot)
|
||||||
await cog._postLine.start()
|
await cog._postLine.start()
|
||||||
await bot.add_cog(cog)
|
await bot.add_cog(cog)
|
||||||
|
Loading…
Reference in New Issue
Block a user