From 4fd525d912e4809d7f99d1cb68508750a7fe9504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sk=C3=BDpala?= Date: Mon, 27 Mar 2023 23:32:31 +0200 Subject: [PATCH] Added ksp commands --- cogs/ksp.py | 19 +++++++++++++++++++ main.py | 1 + utils/ksp_utils.py | 4 ++++ 3 files changed, 24 insertions(+) create mode 100644 cogs/ksp.py create mode 100644 utils/ksp_utils.py diff --git a/cogs/ksp.py b/cogs/ksp.py new file mode 100644 index 0000000..7177428 --- /dev/null +++ b/cogs/ksp.py @@ -0,0 +1,19 @@ +import discord +from discord.ext import commands +from utils.ksp_utils import * + +class Ksp(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @discord.slash_command() + async def task(self, ctx, task_code): + await ctx.respond( + f'**{task_code}**\n' + f'Task: {task_link(task_code, solution=False)}\n' + f'Solution: {task_link(task_code, solution=True)}', + ephemeral=True + ) + +def setup(bot): + bot.add_cog(Ksp(bot)) diff --git a/main.py b/main.py index ed12002..bb9623a 100644 --- a/main.py +++ b/main.py @@ -8,6 +8,7 @@ bot = commands.Bot() cogs_list = [ 'basic', 'roles', + 'ksp', ] for cog in cogs_list: diff --git a/utils/ksp_utils.py b/utils/ksp_utils.py new file mode 100644 index 0000000..e256957 --- /dev/null +++ b/utils/ksp_utils.py @@ -0,0 +1,4 @@ +KSP_URL = "https://ksp.mff.cuni.cz" + +def task_link(task_code: str, solution : bool = False): + return f"{KSP_URL}/viz/{task_code}/{'reseni' if solution else ''}"