mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 15:48:29 +02:00
Add commands for deadlines
This commit is contained in:
parent
693fab7833
commit
fccf4efa1f
10 changed files with 183 additions and 3 deletions
|
|
@ -5,6 +5,7 @@ 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
|
||||
|
|
@ -136,6 +137,9 @@ class Events(commands.Cog):
|
|||
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)
|
||||
|
||||
usage = stringFormatters.format_slash_command_usage(interaction)
|
||||
await self.sendErrorEmbed(err, "Slash Command", usage)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
from data import schedule
|
||||
from data.embeds.deadlines import Deadlines
|
||||
from data.embeds.food import Menu
|
||||
from decorators import help
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from enums.help_categories import Category
|
||||
from functions import config, eten, les
|
||||
from functions import config, les
|
||||
from functions.stringFormatters import capitalize
|
||||
from functions.timeFormatters import intToWeekday, skip_weekends
|
||||
from functions.timeFormatters import skip_weekends
|
||||
|
||||
|
||||
class School(commands.Cog):
|
||||
|
|
@ -70,6 +71,11 @@ class School(commands.Cog):
|
|||
await message.pin(reason="Didier Pin door {}".format(ctx.author.display_name))
|
||||
await ctx.message.add_reaction("✅")
|
||||
|
||||
@commands.command(name="Deadlines", aliases=["dl"])
|
||||
@help.Category(category=Category.School)
|
||||
async def deadlines(self, ctx):
|
||||
await ctx.send(embed=Deadlines().to_embed())
|
||||
|
||||
|
||||
def setup(client):
|
||||
client.add_cog(School(client))
|
||||
|
|
|
|||
87
cogs/slash/db_slash.py
Normal file
87
cogs/slash/db_slash.py
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
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 Slash(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")
|
||||
|
||||
# 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(Slash(client))
|
||||
|
|
@ -2,6 +2,7 @@ from discord.ext import commands
|
|||
from dislash import SlashInteraction, slash_command, Option, OptionType
|
||||
|
||||
from data.embeds.food import Menu
|
||||
from data.embeds.deadlines import Deadlines
|
||||
from startup.didier import Didier
|
||||
|
||||
|
||||
|
|
@ -24,6 +25,11 @@ class SchoolSlash(commands.Cog):
|
|||
embed = Menu(dag).to_embed()
|
||||
await interaction.reply(embed=embed)
|
||||
|
||||
@slash_command(name="deadlines", description="Aanstaande deadlines")
|
||||
async def _deadlines_slash(self, interaction: SlashInteraction):
|
||||
embed = Deadlines().to_embed()
|
||||
await interaction.reply(embed=embed)
|
||||
|
||||
|
||||
def setup(client: Didier):
|
||||
client.add_cog(SchoolSlash(client))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue