44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
import asyncio
|
|
from sys import argv
|
|
|
|
import discord
|
|
from discord.ext import commands
|
|
|
|
import PICable
|
|
|
|
if len(argv) != 3:
|
|
print("Usage:\n\t" + argv[0] + " <discord_token> <github_token>")
|
|
exit(1)
|
|
discord_token = argv[1]
|
|
github_token = argv[2]
|
|
|
|
intents = discord.Intents.default()
|
|
intents.message_content = True
|
|
client = commands.Bot(command_prefix="/", intents=intents)
|
|
|
|
|
|
async def reply_message_async(interaction: discord.Interaction, owner: str, repo: str):
|
|
await interaction.followup.send(PICable.PICable(owner, repo, github_token))
|
|
return
|
|
|
|
|
|
@client.event
|
|
async def on_ready():
|
|
print(f"We have logged in as {client.user}")
|
|
await client.change_presence(activity=discord.Game("with PIC ideas"))
|
|
try:
|
|
synced = await client.tree.sync()
|
|
print(f"Synced {len(synced)} command(s)")
|
|
except Exception as e:
|
|
print(f"Failed to sync commands: {e}")
|
|
|
|
|
|
@client.tree.command(name="picable", description="Check if a Github repository is eligible for PIC")
|
|
@discord.app_commands.describe(owner="The owner of the repository", repository="The name of the repository")
|
|
async def picable(interaction: discord.Interaction, owner: str, repository: str):
|
|
await interaction.response.defer(ephemeral=False, thinking=True)
|
|
asyncio.create_task(reply_message_async(interaction, owner, repository))
|
|
|
|
|
|
client.run(discord_token)
|