mirror of https://github.com/stijndcl/didier
Move Pin over to /Discord instead of /School
parent
2f40903579
commit
86dd6cb27b
|
@ -1,4 +1,7 @@
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
from discord import app_commands
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
from database.crud import birthdays
|
from database.crud import birthdays
|
||||||
|
@ -12,9 +15,19 @@ class Discord(commands.Cog):
|
||||||
|
|
||||||
client: Didier
|
client: Didier
|
||||||
|
|
||||||
|
# Context-menu references
|
||||||
|
_pin_ctx_menu: app_commands.ContextMenu
|
||||||
|
|
||||||
def __init__(self, client: Didier):
|
def __init__(self, client: Didier):
|
||||||
self.client = client
|
self.client = client
|
||||||
|
|
||||||
|
self._pin_ctx_menu = app_commands.ContextMenu(name="Pin", callback=self.pin_ctx)
|
||||||
|
self.client.tree.add_command(self._pin_ctx_menu)
|
||||||
|
|
||||||
|
async def cog_unload(self) -> None:
|
||||||
|
"""Remove the commands when the cog is unloaded"""
|
||||||
|
self.client.tree.remove_command(self._pin_ctx_menu.name, type=self._pin_ctx_menu.type)
|
||||||
|
|
||||||
@commands.group(name="Birthday", aliases=["Bd", "Birthdays"], case_insensitive=True, invoke_without_command=True)
|
@commands.group(name="Birthday", aliases=["Bd", "Birthdays"], case_insensitive=True, invoke_without_command=True)
|
||||||
async def birthday(self, ctx: commands.Context, user: discord.User = None):
|
async def birthday(self, ctx: commands.Context, user: discord.User = None):
|
||||||
"""Command to check the birthday of a user"""
|
"""Command to check the birthday of a user"""
|
||||||
|
@ -55,6 +68,41 @@ class Discord(commands.Cog):
|
||||||
if thread.me is not None:
|
if thread.me is not None:
|
||||||
return await ctx.reply()
|
return await ctx.reply()
|
||||||
|
|
||||||
|
@commands.command(name="Pin", usage="[Message]")
|
||||||
|
async def pin(self, ctx: commands.Context, message: Optional[discord.Message] = None):
|
||||||
|
"""Pin a message in the current channel"""
|
||||||
|
# If no message was passed, allow replying to the message that should be pinned
|
||||||
|
if message is None and ctx.message.reference is not None:
|
||||||
|
message = await self.client.resolve_message(ctx.message.reference)
|
||||||
|
|
||||||
|
# Didn't fix it, sad
|
||||||
|
if message is None:
|
||||||
|
return await ctx.reply("Found no message to pin.", delete_after=10)
|
||||||
|
|
||||||
|
if message.pinned:
|
||||||
|
return await ctx.reply("This message has already been pinned.", delete_after=10)
|
||||||
|
|
||||||
|
if message.is_system():
|
||||||
|
return await ctx.reply("Dus jij wil system messages pinnen?\nMag niet.")
|
||||||
|
|
||||||
|
await message.pin(reason=f"Didier Pin by {ctx.author.display_name}")
|
||||||
|
await message.add_reaction("📌")
|
||||||
|
|
||||||
|
async def pin_ctx(self, interaction: discord.Interaction, message: discord.Message):
|
||||||
|
"""Pin a message in the current channel"""
|
||||||
|
# Is already pinned
|
||||||
|
if message.pinned:
|
||||||
|
return await interaction.response.send_message("This message is already pinned.", ephemeral=True)
|
||||||
|
|
||||||
|
if message.is_system():
|
||||||
|
return await interaction.response.send_message(
|
||||||
|
"Dus jij wil system messages pinnen?\nMag niet.", ephemeral=True
|
||||||
|
)
|
||||||
|
|
||||||
|
await message.pin(reason=f"Didier Pin by {interaction.user.display_name}")
|
||||||
|
await message.add_reaction("📌")
|
||||||
|
return await interaction.response.send_message("📌", ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
async def setup(client: Didier):
|
async def setup(client: Didier):
|
||||||
"""Load the cog"""
|
"""Load the cog"""
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
@ -16,19 +14,9 @@ class School(commands.Cog):
|
||||||
|
|
||||||
client: Didier
|
client: Didier
|
||||||
|
|
||||||
# Context-menu references
|
|
||||||
_pin_ctx_menu: app_commands.ContextMenu
|
|
||||||
|
|
||||||
def __init__(self, client: Didier):
|
def __init__(self, client: Didier):
|
||||||
self.client = client
|
self.client = client
|
||||||
|
|
||||||
self._pin_ctx_menu = app_commands.ContextMenu(name="Pin", callback=self.pin_ctx)
|
|
||||||
self.client.tree.add_command(self._pin_ctx_menu)
|
|
||||||
|
|
||||||
async def cog_unload(self) -> None:
|
|
||||||
"""Remove the commands when the cog is unloaded"""
|
|
||||||
self.client.tree.remove_command(self._pin_ctx_menu.name, type=self._pin_ctx_menu.type)
|
|
||||||
|
|
||||||
@commands.hybrid_command(name="deadlines", description="Show upcoming deadlines")
|
@commands.hybrid_command(name="deadlines", description="Show upcoming deadlines")
|
||||||
async def deadlines(self, ctx: commands.Context):
|
async def deadlines(self, ctx: commands.Context):
|
||||||
"""Show upcoming deadlines"""
|
"""Show upcoming deadlines"""
|
||||||
|
@ -38,41 +26,6 @@ class School(commands.Cog):
|
||||||
embed = Deadlines(deadlines).to_embed()
|
embed = Deadlines(deadlines).to_embed()
|
||||||
await ctx.reply(embed=embed, mention_author=False, ephemeral=False)
|
await ctx.reply(embed=embed, mention_author=False, ephemeral=False)
|
||||||
|
|
||||||
@commands.command(name="Pin", usage="[Message]")
|
|
||||||
async def pin(self, ctx: commands.Context, message: Optional[discord.Message] = None):
|
|
||||||
"""Pin a message in the current channel"""
|
|
||||||
# If no message was passed, allow replying to the message that should be pinned
|
|
||||||
if message is None and ctx.message.reference is not None:
|
|
||||||
message = await self.client.resolve_message(ctx.message.reference)
|
|
||||||
|
|
||||||
# Didn't fix it, sad
|
|
||||||
if message is None:
|
|
||||||
return await ctx.reply("Found no message to pin.", delete_after=10)
|
|
||||||
|
|
||||||
if message.pinned:
|
|
||||||
return await ctx.reply("This message is already pinned.", delete_after=10)
|
|
||||||
|
|
||||||
if message.is_system():
|
|
||||||
return await ctx.reply("Dus jij wil system messages pinnen?\nMag niet.")
|
|
||||||
|
|
||||||
await message.pin(reason=f"Didier Pin by {ctx.author.display_name}")
|
|
||||||
await message.add_reaction("📌")
|
|
||||||
|
|
||||||
async def pin_ctx(self, interaction: discord.Interaction, message: discord.Message):
|
|
||||||
"""Pin a message in the current channel"""
|
|
||||||
# Is already pinned
|
|
||||||
if message.pinned:
|
|
||||||
return await interaction.response.send_message("This message is already pinned.", ephemeral=True)
|
|
||||||
|
|
||||||
if message.is_system():
|
|
||||||
return await interaction.response.send_message(
|
|
||||||
"Dus jij wil system messages pinnen?\nMag niet.", ephemeral=True
|
|
||||||
)
|
|
||||||
|
|
||||||
await message.pin(reason=f"Didier Pin by {interaction.user.display_name}")
|
|
||||||
await message.add_reaction("📌")
|
|
||||||
return await interaction.response.send_message("📌", ephemeral=True)
|
|
||||||
|
|
||||||
@commands.hybrid_command(
|
@commands.hybrid_command(
|
||||||
name="fiche", description="Sends the link to the study guide for [Course]", aliases=["guide", "studiefiche"]
|
name="fiche", description="Sends the link to the study guide for [Course]", aliases=["guide", "studiefiche"]
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue