mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 15:48:29 +02:00
Remove broken libraries & functionality, format slash command usage
This commit is contained in:
parent
06dc3d3fb9
commit
7ad2bf351e
9 changed files with 18 additions and 223 deletions
|
|
@ -1,11 +1,10 @@
|
|||
from dislash import SlashInteraction
|
||||
from discord import Interaction
|
||||
|
||||
from data import constants
|
||||
from data.snipe import Snipe, Action, should_snipe
|
||||
import datetime
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from dislash.application_commands.errors import InteractionCheckFailure
|
||||
from functions import checks, easterEggResponses, stringFormatters
|
||||
from functions.database import stats, muttn, custom_commands, commands as command_stats
|
||||
import pytz
|
||||
|
|
@ -86,6 +85,7 @@ class Events(commands.Cog):
|
|||
Logs commands in your terminal.
|
||||
:param ctx: Discord Context
|
||||
"""
|
||||
print("a")
|
||||
print(stringFormatters.format_command_usage(ctx))
|
||||
|
||||
command_stats.invoked(command_stats.InvocationType.TextCommand)
|
||||
|
|
@ -123,24 +123,27 @@ class Events(commands.Cog):
|
|||
await self.sendErrorEmbed(err, "Command", usage)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_slash_command(self, interaction: SlashInteraction):
|
||||
async def on_interaction(self, interaction: Interaction):
|
||||
"""
|
||||
Function called whenever someone uses a slash command
|
||||
"""
|
||||
if not interaction.is_command():
|
||||
return
|
||||
|
||||
print(stringFormatters.format_slash_command_usage(interaction))
|
||||
|
||||
command_stats.invoked(command_stats.InvocationType.SlashCommand)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_slash_command_error(self, interaction, err):
|
||||
async def on_application_command_error(self, ctx: discord.ApplicationContext, err):
|
||||
# Debugging Didier shouldn't spam the error logs
|
||||
if self.client.user.id != int(constants.didierId):
|
||||
raise err
|
||||
|
||||
if isinstance(err, InteractionCheckFailure):
|
||||
return await interaction.reply("Je hebt geen toegang tot dit commando.", ephemeral=True)
|
||||
if isinstance(err, commands.CheckFailure):
|
||||
return await ctx.respond("Je hebt geen toegang tot dit commando.", ephemeral=True)
|
||||
|
||||
usage = stringFormatters.format_slash_command_usage(interaction)
|
||||
usage = stringFormatters.format_slash_command_usage(ctx.interaction)
|
||||
await self.sendErrorEmbed(err, "Slash Command", usage)
|
||||
|
||||
@commands.Cog.listener()
|
||||
|
|
|
|||
27
cogs/ipc.py
27
cogs/ipc.py
|
|
@ -1,27 +0,0 @@
|
|||
from discord.ext import commands, ipc
|
||||
|
||||
|
||||
class IPC(commands.Cog):
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
|
||||
@ipc.server.route()
|
||||
async def send_dm(self, data):
|
||||
print("got here")
|
||||
user = self.client.get_user(data.user)
|
||||
await user.send(data.message)
|
||||
print("sent")
|
||||
return True
|
||||
|
||||
@ipc.server.route()
|
||||
async def get_bot_latency(self, data):
|
||||
"""
|
||||
Get Didier's latency
|
||||
"""
|
||||
|
||||
return self.client.latency * 1000
|
||||
|
||||
|
||||
def setup(client):
|
||||
# client.add_cog(IPC(client))
|
||||
pass
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
import datetime
|
||||
import json
|
||||
|
||||
from discord.ext import commands
|
||||
from dislash import SlashInteraction, slash_command, Option, OptionType, check
|
||||
from functions.checks import isMe
|
||||
from functions.timeFormatters import fromString
|
||||
from startup.didier import Didier
|
||||
|
||||
|
||||
class DBSlash(commands.Cog):
|
||||
def __init__(self, client: Didier):
|
||||
self.client: Didier = client
|
||||
|
||||
@slash_command(name="db")
|
||||
@check(isMe)
|
||||
async def _db_slash(self, interaction: SlashInteraction):
|
||||
pass
|
||||
|
||||
@_db_slash.sub_command_group(name="add")
|
||||
async def _add_slash(self, interaction: SlashInteraction):
|
||||
pass
|
||||
|
||||
@_add_slash.sub_command(
|
||||
name="deadline",
|
||||
options=[
|
||||
Option(
|
||||
"year",
|
||||
description="Year (1-based)",
|
||||
type=OptionType.INTEGER,
|
||||
required=True
|
||||
),
|
||||
Option(
|
||||
"course",
|
||||
description="Course (abbreviated)",
|
||||
type=OptionType.STRING,
|
||||
required=True
|
||||
),
|
||||
Option(
|
||||
"name",
|
||||
description="Name of the deadline/project",
|
||||
type=OptionType.STRING,
|
||||
required=True
|
||||
),
|
||||
Option(
|
||||
"date",
|
||||
description="Date (DD/MM)",
|
||||
type=OptionType.STRING,
|
||||
required=True
|
||||
),
|
||||
Option(
|
||||
"time",
|
||||
description="Timestamp (HH:MM or HH:MM:SS)",
|
||||
type=OptionType.STRING,
|
||||
required=False
|
||||
)
|
||||
]
|
||||
)
|
||||
async def _add_deadline_slash(self, interaction: SlashInteraction, year: int, course: str, name: str, date: str, time: str = "00:00:00"):
|
||||
with open("files/deadlines.json", "r") as f:
|
||||
deadlines = json.load(f)
|
||||
|
||||
date += "/" + str(datetime.datetime.now().year)
|
||||
|
||||
# Fix format
|
||||
if time.count(":") == 1:
|
||||
time += ":00"
|
||||
|
||||
dt = fromString(f"{date} {time}", formatString="%d/%m/%Y %H:%M:%S", tzinfo=None)
|
||||
|
||||
# Add year & course if necessary
|
||||
if str(year) not in deadlines:
|
||||
deadlines[str(year)] = {}
|
||||
|
||||
if course not in deadlines[str(year)]:
|
||||
deadlines[str(year)][course] = {}
|
||||
|
||||
deadlines[str(year)][course][name] = round(dt.timestamp())
|
||||
|
||||
with open("files/deadlines.json", "w") as f:
|
||||
json.dump(deadlines, f)
|
||||
|
||||
await interaction.reply("Addition successful", ephemeral=True)
|
||||
|
||||
|
||||
def setup(client: Didier):
|
||||
# client.add_cog(DBSlash(client))
|
||||
pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue