Port slash commands to pc

pull/104/head
Stijn De Clercq 2022-02-03 01:43:54 +01:00
parent e3a788f6c9
commit 3444414638
9 changed files with 62 additions and 111 deletions

View File

@ -84,4 +84,5 @@ class DBSlash(commands.Cog):
def setup(client: Didier): def setup(client: Didier):
client.add_cog(DBSlash(client)) # client.add_cog(DBSlash(client))
pass

View File

@ -1,5 +1,5 @@
from discord.ext import commands from discord.ext import commands
from dislash import SlashInteraction, slash_command, Option, OptionType from discord.commands import slash_command, ApplicationContext, Option
from data.embeds.urban_dictionary import Definition from data.embeds.urban_dictionary import Definition
from startup.didier import Didier from startup.didier import Didier
@ -9,15 +9,10 @@ class DefineSlash(commands.Cog):
def __init__(self, client: Didier): def __init__(self, client: Didier):
self.client: Didier = client self.client: Didier = client
@slash_command(name="define", @slash_command(name="define", description="Urban Dictionary")
description="Urban Dictionary", async def _define_slash(self, ctx: ApplicationContext, query: Option(str, "Search query", required=True)):
options=[
Option("query", "Search query", OptionType.STRING, required=True)
]
)
async def _define_slash(self, interaction: SlashInteraction, query):
embed = Definition(query).to_embed() embed = Definition(query).to_embed()
await interaction.reply(embed=embed) await ctx.respond(embed=embed)
def setup(client: Didier): def setup(client: Didier):

View File

@ -1,6 +1,6 @@
from discord.ext import commands from discord.ext import commands
from dislash import SlashInteraction, slash_command, Option, OptionType from discord.commands import Option, SlashCommandGroup, ApplicationContext, permissions
from functions import config, checks from functions import config
from functions.football import get_matches, get_table, get_jpl_code from functions.football import get_matches, get_table, get_jpl_code
from startup.didier import Didier from startup.didier import Didier
@ -9,35 +9,28 @@ class FootballSlash(commands.Cog):
def __init__(self, client: Didier): def __init__(self, client: Didier):
self.client: Didier = client self.client: Didier = client
@slash_command(name="jpl", description="Jupiler Pro League commands") _jpl_group = SlashCommandGroup("jpl", "Jupiler Pro League commands")
async def _jpl_group(self, interaction: SlashInteraction):
pass
@_jpl_group.sub_command(name="matches", @_jpl_group.command(name="matches", description="Schema voor een bepaalde speeldag")
description="Schema voor een bepaalde speeldag", async def _jpl_matches_slash(self, ctx: ApplicationContext,
options=[ day: Option(int, name="day", description="Speeldag (default huidige)", required=False, default=None)
Option("day", "Speeldag (default huidige)", OptionType.INTEGER) ):
]
)
async def _jpl_matches_slash(self, interaction: SlashInteraction, day: int = None):
# Default is current day # Default is current day
if day is None: if day is None:
day = int(config.get("jpl_day")) day = int(config.get("jpl_day"))
await interaction.reply(get_matches(day)) await ctx.respond(get_matches(day))
@_jpl_group.sub_command(name="table", description="Huidige rangschikking") @_jpl_group.command(name="table", description="Huidige rangschikking")
async def _jpl_table_slash(self, interaction: SlashInteraction): async def _jpl_table_slash(self, ctx: ApplicationContext):
await interaction.reply(get_table()) await ctx.respond(get_table())
@_jpl_group.sub_command(name="update", description="Update de code voor deze competitie (owner-only)")
async def _jpl_update_slash(self, interaction: SlashInteraction):
if not await checks.isMe(interaction):
return await interaction.reply(f"Je hebt geen toegang tot dit commando.")
@_jpl_group.command(name="update", description="Update de code voor deze competitie (owner-only)", default_permission=False)
@permissions.is_owner()
async def _jpl_update_slash(self, ctx: ApplicationContext):
code = get_jpl_code() code = get_jpl_code()
config.config("jpl", code) config.config("jpl", code)
await interaction.reply(f"Done (code: {code})") await ctx.respond(f"Done (code: {code})")
def setup(client: Didier): def setup(client: Didier):

View File

@ -1,5 +1,5 @@
from discord.ext import commands from discord.ext import commands
from dislash import SlashInteraction, slash_command, Option, OptionType from discord.commands import slash_command, ApplicationContext, Option
from data.embeds.xkcd import XKCDEmbed from data.embeds.xkcd import XKCDEmbed
from startup.didier import Didier from startup.didier import Didier
@ -9,20 +9,11 @@ class FunSlash(commands.Cog):
def __init__(self, client: Didier): def __init__(self, client: Didier):
self.client: Didier = client self.client: Didier = client
@slash_command( @slash_command(name="xkcd", description="Zoek xkcd comics")
name="xkcd", async def _xkcd_slash(self, ctx: ApplicationContext,
description="Zoek xkcd comics", num: Option(int, description="Nummer van de comic (default de comic van vandaag).", required=False, default=None)
options=[ ):
Option( return await ctx.respond(embed=XKCDEmbed(num).create())
"num",
description="Nummer van de comic (default de comic van vandaag).",
type=OptionType.INTEGER,
required=False
)
]
)
async def _xkcd_slash(self, interaction: SlashInteraction, num: int = None):
return await interaction.reply(embed=XKCDEmbed(num).create())
def setup(client: Didier): def setup(client: Didier):

View File

@ -1,5 +1,5 @@
from discord.ext import commands from discord.ext import commands
from dislash import slash_command, SlashInteraction, Option, OptionType from discord.commands import slash_command, ApplicationContext, Option
from functions.scrapers.google import google_search, create_google_embed from functions.scrapers.google import google_search, create_google_embed
from startup.didier import Didier from startup.didier import Didier
@ -8,20 +8,15 @@ class GoogleSlash(commands.Cog):
def __init__(self, client: Didier): def __init__(self, client: Didier):
self.client: Didier = client self.client: Didier = client
@slash_command(name="google", @slash_command(name="google", description="Google search")
description="Google search", async def _google_slash(self, ctx: ApplicationContext, query: Option(str, "Search query")):
options=[
Option("query", "Search query", OptionType.STRING, required=True)
]
)
async def _google_slash(self, interaction: SlashInteraction, query: str):
result = google_search(query) result = google_search(query)
if not result.results: if not result.results:
return await interaction.reply("Er ging iets fout (Response {})".format(result.status_code)) return await ctx.respond("Er ging iets fout (Response {})".format(result.status_code))
embed = create_google_embed(result) embed = create_google_embed(result)
await interaction.reply(embed=embed) await ctx.respond(embed=embed)
def setup(client: Didier): def setup(client: Didier):

View File

@ -1,5 +1,5 @@
from discord.ext import commands from discord.ext import commands
from dislash import SlashInteraction, slash_command, Option, OptionType from discord.commands import slash_command, ApplicationContext, Option
from data import schedule from data import schedule
from data.embeds.food import Menu from data.embeds.food import Menu
@ -14,39 +14,22 @@ class SchoolSlash(commands.Cog):
def __init__(self, client: Didier): def __init__(self, client: Didier):
self.client: Didier = client self.client: Didier = client
@slash_command( @slash_command(name="eten", description="Menu in de UGent resto's op een bepaalde dag")
name="eten", async def _food_slash(self, ctx: ApplicationContext,
description="Menu in de UGENT resto's op een bepaalde dag", dag: Option(str, description="Dag", required=False, default=None)
options=[ ):
Option(
"dag",
description="Dag",
type=OptionType.STRING
)
]
)
async def _food_slash(self, interaction: SlashInteraction, dag: str = None):
embed = Menu(dag).to_embed() embed = Menu(dag).to_embed()
await interaction.reply(embed=embed) await ctx.respond(embed=embed)
@slash_command(name="deadlines", description="Aanstaande deadlines") @slash_command(name="deadlines", description="Aanstaande deadlines")
async def _deadlines_slash(self, interaction: SlashInteraction): async def _deadlines_slash(self, ctx: ApplicationContext):
embed = Deadlines().to_embed() embed = Deadlines().to_embed()
await interaction.reply(embed=embed) await ctx.respond(embed=embed)
@slash_command( @slash_command(name="les", description="Lessenrooster voor [Dag] (default vandaag)",)
name="les", async def _schedule_slash(self, ctx: ApplicationContext,
description="Lessenrooster voor [Dag] (default vandaag)", day: Option(str, description="Dag", required=False, default=None)
options=[ ):
Option(
"dag",
description="dag",
type=OptionType.STRING,
required=False
)
]
)
async def _schedule_slash(self, interaction: SlashInteraction, day: str = None):
"""It's late and I really don't want to refactor the original right now""" """It's late and I really don't want to refactor the original right now"""
if day is not None: if day is not None:
day = day.lower() day = day.lower()
@ -55,21 +38,21 @@ class SchoolSlash(commands.Cog):
# Person explicitly requested a weekend-day # Person explicitly requested a weekend-day
if day is not None and day.lower() in ("morgen", "overmorgen") and date.weekday() > 4: if day is not None and day.lower() in ("morgen", "overmorgen") and date.weekday() > 4:
return await interaction.reply(f"{capitalize(day)} is het weekend.", ephemeral=True) return await ctx.respond(f"{capitalize(day)} is het weekend.", ephemeral=True)
date = skip_weekends(date) date = skip_weekends(date)
s = schedule.Schedule(date, int(config.get("year")), int(config.get("semester")), day is not None) s = schedule.Schedule(date, int(config.get("year")), int(config.get("semester")), day is not None)
if s.semester_over: if s.semester_over:
return await interaction.reply("Het semester is afgelopen.", ephemeral=True) return await ctx.respond("Het semester is afgelopen.", ephemeral=True)
# DM only shows user's own minor # DM only shows user's own minor
if interaction.guild is None: if ctx.guild is None:
minor_roles = [*schedule.find_minor(self.client, interaction.author.id)] minor_roles = [*schedule.find_minor(self.client, ctx.interaction.user.id)]
return await interaction.reply(embed=s.create_schedule(minor_roles=minor_roles).to_embed()) return await ctx.respond(embed=s.create_schedule(minor_roles=minor_roles).to_embed())
return await interaction.reply(embed=s.create_schedule().to_embed()) return await ctx.respond(embed=s.create_schedule().to_embed())
def setup(client: Didier): def setup(client: Didier):

View File

@ -1,5 +1,5 @@
from discord.ext import commands from discord.ext import commands
from dislash import SlashInteraction, slash_command, Option, OptionType from discord.commands import slash_command, ApplicationContext, Option
from data.embeds.translate import Translation from data.embeds.translate import Translation
from startup.didier import Didier from startup.didier import Didier
@ -9,18 +9,14 @@ class TranslateSlash(commands.Cog):
def __init__(self, client: Didier): def __init__(self, client: Didier):
self.client: Didier = client self.client: Didier = client
@slash_command( @slash_command(name="translate", description="Google Translate")
name="translate", async def _translate_slash(self, ctx: ApplicationContext,
description="Google Translate", text: Option(str, description="Tekst om te vertalen"),
options=[ from_lang: Option(str, description="Taal om van te vertalen (default auto-detect)", default="auto"),
Option("text", "Tekst om te vertalen", OptionType.STRING, required=True), to_lang: Option(str, description="Taal om naar te vertalen (default NL)", default="nl")
Option("from_lang", "Taal om van te vertalen (default auto-detect)", OptionType.STRING), ):
Option("to_lang", "Taal om naar te vertalen (default NL)", OptionType.STRING)
]
)
async def _translate_slash(self, interaction: SlashInteraction, text: str, from_lang: str = "auto", to_lang: str = "nl"):
translation = Translation(text=text, fr=from_lang.lower(), to=to_lang.lower()) translation = Translation(text=text, fr=from_lang.lower(), to=to_lang.lower())
await interaction.reply(embed=translation.to_embed()) await ctx.respond(embed=translation.to_embed())
def setup(client: Didier): def setup(client: Didier):

View File

@ -1,6 +1,6 @@
python-dotenv==0.14.0 python-dotenv==0.14.0
beautifulsoup4==4.9.1 beautifulsoup4==4.9.1
discord.py==1.7.3 # discord.py==1.7.3
git+https://github.com/Rapptz/discord-ext-menus@master git+https://github.com/Rapptz/discord-ext-menus@master
discord-ext-ipc==2.0.0 discord-ext-ipc==2.0.0
psycopg2==2.8.5 psycopg2==2.8.5
@ -20,5 +20,5 @@ dacite~=1.6.0
pytest==6.2.4 pytest==6.2.4
markdownify==0.9.2 markdownify==0.9.2
# Experimental package for slash commands & menus # Beta version of Discord.py fork
dislash.py==1.4.9 py-cord==2.0.0b1

View File

@ -2,7 +2,7 @@ from data.snipe import Snipe
from discord.ext import commands, ipc from discord.ext import commands, ipc
from dislash import InteractionClient from dislash import InteractionClient
import os import os
from settings import HOST_IPC, SLASH_TEST_GUILDS from settings import HOST_IPC
from startup.init_files import check_all from startup.init_files import check_all
from typing import Dict from typing import Dict
@ -32,9 +32,6 @@ class Didier(commands.Bot):
# Remove default help command # Remove default help command
self.remove_command("help") self.remove_command("help")
# Create interactions client
self.interactions = InteractionClient(self, test_guilds=SLASH_TEST_GUILDS)
# Load all extensions # Load all extensions
self.init_extensions() self.init_extensions()