Skip to content

Commit

Permalink
Merge pull request #198 from Skynet0/bump-asyncio
Browse files Browse the repository at this point in the history
Async logging startup for aiohttp
  • Loading branch information
TheOriginalSoni authored Nov 17, 2024
2 parents 5ee0a74 + 3fa6fa5 commit 49df46b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def main():
@client.event
async def on_ready():
"""When the bot starts up"""
await logging_utils.open_session()
await client.change_presence(
activity=nextcord.Activity(
type=nextcord.ActivityType.watching, name="you solve👀 | ~help"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
aiohttp==3.9.0
aiohttp==3.11.2
black==24.10.0
dateparser==1.2.0
emoji==2.14.0
Expand Down
16 changes: 10 additions & 6 deletions utils/logging_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
"""

webhook_url = os.getenv("WEBHOOK_URL")
session = aiohttp.ClientSession()
webhook = None
if webhook_url is not None and webhook_url != "":
webhook = Webhook.from_url(webhook_url, session=session)


async def open_session():
global session, webhook
session = aiohttp.ClientSession()
if webhook_url:
webhook = Webhook.from_url(webhook_url, session=session)


def log_to_file(filename: str, text: str):
Expand All @@ -24,7 +27,7 @@ def log_to_file(filename: str, text: str):

async def send_to_webhook(text: str):
"""Send log to webhook"""
if webhook is not None:
if webhook:
await webhook.send(text)
log_to_file(error_constants.ERROR_WEBHOOKFILE, text)

Expand All @@ -43,4 +46,5 @@ async def log_command(command: str, guild, channel, author: str) -> None:


async def close_session():
session.close()
if session:
await session.close()

0 comments on commit 49df46b

Please # to comment.