mirror of https://github.com/stijndcl/didier
Port slash commands to pc
parent
e3a788f6c9
commit
3444414638
|
@ -84,4 +84,5 @@ class DBSlash(commands.Cog):
|
|||
|
||||
|
||||
def setup(client: Didier):
|
||||
client.add_cog(DBSlash(client))
|
||||
# client.add_cog(DBSlash(client))
|
||||
pass
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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 startup.didier import Didier
|
||||
|
@ -9,15 +9,10 @@ class DefineSlash(commands.Cog):
|
|||
def __init__(self, client: Didier):
|
||||
self.client: Didier = client
|
||||
|
||||
@slash_command(name="define",
|
||||
description="Urban Dictionary",
|
||||
options=[
|
||||
Option("query", "Search query", OptionType.STRING, required=True)
|
||||
]
|
||||
)
|
||||
async def _define_slash(self, interaction: SlashInteraction, query):
|
||||
@slash_command(name="define", description="Urban Dictionary")
|
||||
async def _define_slash(self, ctx: ApplicationContext, query: Option(str, "Search query", required=True)):
|
||||
embed = Definition(query).to_embed()
|
||||
await interaction.reply(embed=embed)
|
||||
await ctx.respond(embed=embed)
|
||||
|
||||
|
||||
def setup(client: Didier):
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from discord.ext import commands
|
||||
from dislash import SlashInteraction, slash_command, Option, OptionType
|
||||
from functions import config, checks
|
||||
from discord.commands import Option, SlashCommandGroup, ApplicationContext, permissions
|
||||
from functions import config
|
||||
from functions.football import get_matches, get_table, get_jpl_code
|
||||
from startup.didier import Didier
|
||||
|
||||
|
@ -9,35 +9,28 @@ class FootballSlash(commands.Cog):
|
|||
def __init__(self, client: Didier):
|
||||
self.client: Didier = client
|
||||
|
||||
@slash_command(name="jpl", description="Jupiler Pro League commands")
|
||||
async def _jpl_group(self, interaction: SlashInteraction):
|
||||
pass
|
||||
_jpl_group = SlashCommandGroup("jpl", "Jupiler Pro League commands")
|
||||
|
||||
@_jpl_group.sub_command(name="matches",
|
||||
description="Schema voor een bepaalde speeldag",
|
||||
options=[
|
||||
Option("day", "Speeldag (default huidige)", OptionType.INTEGER)
|
||||
]
|
||||
)
|
||||
async def _jpl_matches_slash(self, interaction: SlashInteraction, day: int = None):
|
||||
@_jpl_group.command(name="matches", description="Schema voor een bepaalde speeldag")
|
||||
async def _jpl_matches_slash(self, ctx: ApplicationContext,
|
||||
day: Option(int, name="day", description="Speeldag (default huidige)", required=False, default=None)
|
||||
):
|
||||
# Default is current day
|
||||
if day is None:
|
||||
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")
|
||||
async def _jpl_table_slash(self, interaction: SlashInteraction):
|
||||
await interaction.reply(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="table", description="Huidige rangschikking")
|
||||
async def _jpl_table_slash(self, ctx: ApplicationContext):
|
||||
await ctx.respond(get_table())
|
||||
|
||||
@_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()
|
||||
config.config("jpl", code)
|
||||
await interaction.reply(f"Done (code: {code})")
|
||||
await ctx.respond(f"Done (code: {code})")
|
||||
|
||||
|
||||
def setup(client: Didier):
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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 startup.didier import Didier
|
||||
|
@ -9,20 +9,11 @@ class FunSlash(commands.Cog):
|
|||
def __init__(self, client: Didier):
|
||||
self.client: Didier = client
|
||||
|
||||
@slash_command(
|
||||
name="xkcd",
|
||||
description="Zoek xkcd comics",
|
||||
options=[
|
||||
Option(
|
||||
"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())
|
||||
@slash_command(name="xkcd", description="Zoek xkcd comics")
|
||||
async def _xkcd_slash(self, ctx: ApplicationContext,
|
||||
num: Option(int, description="Nummer van de comic (default de comic van vandaag).", required=False, default=None)
|
||||
):
|
||||
return await ctx.respond(embed=XKCDEmbed(num).create())
|
||||
|
||||
|
||||
def setup(client: Didier):
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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 startup.didier import Didier
|
||||
|
||||
|
@ -8,20 +8,15 @@ class GoogleSlash(commands.Cog):
|
|||
def __init__(self, client: Didier):
|
||||
self.client: Didier = client
|
||||
|
||||
@slash_command(name="google",
|
||||
description="Google search",
|
||||
options=[
|
||||
Option("query", "Search query", OptionType.STRING, required=True)
|
||||
]
|
||||
)
|
||||
async def _google_slash(self, interaction: SlashInteraction, query: str):
|
||||
@slash_command(name="google", description="Google search")
|
||||
async def _google_slash(self, ctx: ApplicationContext, query: Option(str, "Search query")):
|
||||
result = google_search(query)
|
||||
|
||||
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)
|
||||
await interaction.reply(embed=embed)
|
||||
await ctx.respond(embed=embed)
|
||||
|
||||
|
||||
def setup(client: Didier):
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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.embeds.food import Menu
|
||||
|
@ -14,39 +14,22 @@ class SchoolSlash(commands.Cog):
|
|||
def __init__(self, client: Didier):
|
||||
self.client: Didier = client
|
||||
|
||||
@slash_command(
|
||||
name="eten",
|
||||
description="Menu in de UGENT resto's op een bepaalde dag",
|
||||
options=[
|
||||
Option(
|
||||
"dag",
|
||||
description="Dag",
|
||||
type=OptionType.STRING
|
||||
)
|
||||
]
|
||||
)
|
||||
async def _food_slash(self, interaction: SlashInteraction, dag: str = None):
|
||||
@slash_command(name="eten", description="Menu in de UGent resto's op een bepaalde dag")
|
||||
async def _food_slash(self, ctx: ApplicationContext,
|
||||
dag: Option(str, description="Dag", required=False, default=None)
|
||||
):
|
||||
embed = Menu(dag).to_embed()
|
||||
await interaction.reply(embed=embed)
|
||||
await ctx.respond(embed=embed)
|
||||
|
||||
@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()
|
||||
await interaction.reply(embed=embed)
|
||||
await ctx.respond(embed=embed)
|
||||
|
||||
@slash_command(
|
||||
name="les",
|
||||
description="Lessenrooster voor [Dag] (default vandaag)",
|
||||
options=[
|
||||
Option(
|
||||
"dag",
|
||||
description="dag",
|
||||
type=OptionType.STRING,
|
||||
required=False
|
||||
)
|
||||
]
|
||||
)
|
||||
async def _schedule_slash(self, interaction: SlashInteraction, day: str = None):
|
||||
@slash_command(name="les", description="Lessenrooster voor [Dag] (default vandaag)",)
|
||||
async def _schedule_slash(self, ctx: ApplicationContext,
|
||||
day: Option(str, description="Dag", required=False, default=None)
|
||||
):
|
||||
"""It's late and I really don't want to refactor the original right now"""
|
||||
if day is not None:
|
||||
day = day.lower()
|
||||
|
@ -55,21 +38,21 @@ class SchoolSlash(commands.Cog):
|
|||
|
||||
# Person explicitly requested a weekend-day
|
||||
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)
|
||||
|
||||
s = schedule.Schedule(date, int(config.get("year")), int(config.get("semester")), day is not None)
|
||||
|
||||
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
|
||||
if interaction.guild is None:
|
||||
minor_roles = [*schedule.find_minor(self.client, interaction.author.id)]
|
||||
return await interaction.reply(embed=s.create_schedule(minor_roles=minor_roles).to_embed())
|
||||
if ctx.guild is None:
|
||||
minor_roles = [*schedule.find_minor(self.client, ctx.interaction.user.id)]
|
||||
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):
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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 startup.didier import Didier
|
||||
|
@ -9,18 +9,14 @@ class TranslateSlash(commands.Cog):
|
|||
def __init__(self, client: Didier):
|
||||
self.client: Didier = client
|
||||
|
||||
@slash_command(
|
||||
name="translate",
|
||||
description="Google Translate",
|
||||
options=[
|
||||
Option("text", "Tekst om te vertalen", OptionType.STRING, required=True),
|
||||
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"):
|
||||
@slash_command(name="translate", description="Google Translate")
|
||||
async def _translate_slash(self, ctx: ApplicationContext,
|
||||
text: Option(str, description="Tekst om te vertalen"),
|
||||
from_lang: Option(str, description="Taal om van te vertalen (default auto-detect)", default="auto"),
|
||||
to_lang: Option(str, description="Taal om naar te vertalen (default NL)", default="nl")
|
||||
):
|
||||
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):
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
python-dotenv==0.14.0
|
||||
beautifulsoup4==4.9.1
|
||||
discord.py==1.7.3
|
||||
# discord.py==1.7.3
|
||||
git+https://github.com/Rapptz/discord-ext-menus@master
|
||||
discord-ext-ipc==2.0.0
|
||||
psycopg2==2.8.5
|
||||
|
@ -20,5 +20,5 @@ dacite~=1.6.0
|
|||
pytest==6.2.4
|
||||
markdownify==0.9.2
|
||||
|
||||
# Experimental package for slash commands & menus
|
||||
dislash.py==1.4.9
|
||||
# Beta version of Discord.py fork
|
||||
py-cord==2.0.0b1
|
|
@ -2,7 +2,7 @@ from data.snipe import Snipe
|
|||
from discord.ext import commands, ipc
|
||||
from dislash import InteractionClient
|
||||
import os
|
||||
from settings import HOST_IPC, SLASH_TEST_GUILDS
|
||||
from settings import HOST_IPC
|
||||
from startup.init_files import check_all
|
||||
from typing import Dict
|
||||
|
||||
|
@ -32,9 +32,6 @@ class Didier(commands.Bot):
|
|||
# Remove default help command
|
||||
self.remove_command("help")
|
||||
|
||||
# Create interactions client
|
||||
self.interactions = InteractionClient(self, test_guilds=SLASH_TEST_GUILDS)
|
||||
|
||||
# Load all extensions
|
||||
self.init_extensions()
|
||||
|
||||
|
|
Loading…
Reference in New Issue