Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "support-bot"
dynamic = ["version"]
description = "Support bot written in python to help manage LizardByte communities"
readme = "README.md"
requires-python = ">=3.13"
requires-python = ">=3.14"
license = {text = "AGPL-3.0-only"}
authors = [
{name = "LizardByte", email = "lizardbyte@users.noreply.github.com"}
Expand All @@ -17,7 +17,7 @@ classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Affero General Public License v3.0 only (AGPL-3.0-only)",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
]

dependencies = [
Expand Down
15 changes: 13 additions & 2 deletions src/discord_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(self, *args, **kwargs):
self.DEGRADED = False

self.bot_thread = threading.Thread(target=lambda: None)
self._stopping = False
self.token = os.environ['DISCORD_BOT_TOKEN']
self.db = Database(db_name='discord_bot_database')
self.ephemeral_db = {}
Expand Down Expand Up @@ -260,12 +261,21 @@ def create_thread(
), self.loop)
return future.result()

def _run_threaded(self):
try:
self.loop.run_until_complete(self.start(token=self.token))
except RuntimeError as e:
if self._stopping and str(e) == "Session is closed":
logger.debug("Discord bot startup stopped while closing")
return
raise

def start_threaded(self):
try:
# Login the bot in a separate thread
self._stopping = False
self.bot_thread = threading.Thread(
target=self.loop.run_until_complete,
args=(self.start(token=self.token),),
target=self._run_threaded,
daemon=True
)
self.bot_thread.start()
Expand All @@ -281,6 +291,7 @@ def stop(self, future: asyncio.Future = None):
self.clean_ephemeral_cache.stop()
logger.info("Attempting to close bot connection")
if self.bot_thread is not None and self.bot_thread.is_alive():
self._stopping = True
asyncio.run_coroutine_threadsafe(self.close(), self.loop)
self.bot_thread.join()
logger.info("Closed bot")