Added async repo checking

This commit is contained in:
2025-02-23 23:53:10 +00:00
parent 3e8a780ad4
commit c9c7cba7a1

29
main.py
View File

@@ -2,6 +2,9 @@
import discord
from sys import argv
from threading import Thread
from time import sleep
import asyncio
import PICable
if len(argv) != 3:
@@ -13,6 +16,28 @@ intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
def reply_msg(message, owner, repo):
asyncio.run(reply_msg_async(message, owner, repo))
return
async def reply_msg_async(message, owner, repo):
await message.reply(PICable.PICable(owner, repo, github_token))
return
async def check_repo_async(message, owner, repo):
sent = await message.reply('Checking ' + owner + '/' + repo + '.. /')
thread = Thread(target=reply_msg, args=(message, owner, repo))
thread.start()
counter = 0
chars = '-\\|/'
while thread.is_alive():
char = chars[counter]
await sent.edit(content='Checking ' + owner + '/' + repo + '.. ' + char)
counter += 1
counter %= 4
await asyncio.sleep(3)
return
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
@@ -31,8 +56,8 @@ async def on_message(message):
await message.reply('Usage:\n\t$picable <owner> <repo>')
return
await message.reply('Checking ' + parts[1] + '/' + parts[2] + '...')
await message.reply(PICable.PICable(parts[1], parts[2], github_token))
loop = asyncio.get_event_loop()
loop.create_task(check_repo_async(message, parts[1], parts[2]))
return