From 885f62540391aaa8d7451ce40e00915583f3f7a8 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 17:26:48 +0900 Subject: [PATCH] =?UTF-8?q?asyncio=E3=82=92threading=E3=81=AB=E7=BD=AE?= =?UTF-8?q?=E3=81=8D=E6=8F=9B=E3=81=88=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 93530de..10abe07 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -10,6 +10,8 @@ import random import hashlib import openpyxl from openpyxl import Workbook +import threading +import time class DL(): def __init__(self): @@ -769,9 +771,13 @@ class Monitor(): self.fstop_time = kwargs["fstop_time"] self.init_wait_time = 10 - async def search(self): + def start(self, **kwargs): + search_thread = threading.Thread(target=self.search) + search_thread.start() + + def search(self): try: - asyncio.sleep(self.init_wait_time) + time.sleep(self.init_wait_time) while True: cursor = dislocker.db.cursor() cursor.execute("SELECT * FROM pc_list WHERE password_hash IS NOT NULL") @@ -833,7 +839,7 @@ class Monitor(): pass else: pass - asyncio.sleep(self.search_frequency) + time.sleep(self.search_frequency) except Exception as error: @@ -1150,15 +1156,10 @@ async def button_init(interaction: discord.Interaction, text_channel: discord.Te await interaction.response.send_message(f":white_check_mark: ボタンを送信しました!", ephemeral=True) -async def run(): +if dislocker.init_result == "ok": print("Botを起動します...") monitor = Monitor(search_frequency=dislocker.server_config["bot"]["monitor"]["search_frequency"], allowable_time=dislocker.server_config["bot"]["monitor"]["allowable_time"], fstop_time=dislocker.server_config["bot"]["monitor"]["fstop_time"]) - monitor_task = asyncio.create_task(monitor.search()) - client_task = asyncio.create_task(client.run(dislocker.server_config["bot"]["token"])) - await asyncio.gather(monitor_task, client_task) - - -if dislocker.init_result == "ok": - asyncio.run(run()) + monitor.start() + client.run(dislocker.server_config["bot"]["token"]) else: - pass \ No newline at end of file + pass