Added /register, /unregister and stubs for jailing and channel maintenance (#8)
This commit is contained in:
54
cogs/register.py
Normal file
54
cogs/register.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from bson.errors import InvalidId
|
||||
from discord import ApplicationContext, Cog, option, slash_command
|
||||
from discord.utils import basic_autocomplete
|
||||
|
||||
from classes import PycordEvent, PycordGuild, PycordUser
|
||||
from classes.pycord_bot import PycordBot
|
||||
from modules.utils import autocomplete_active_events
|
||||
|
||||
|
||||
class Register(Cog):
|
||||
"""Cog with the event registration command."""
|
||||
|
||||
def __init__(self, bot: PycordBot):
|
||||
self.bot: PycordBot = bot
|
||||
|
||||
# TODO Introduce i18n
|
||||
@slash_command(
|
||||
name="register",
|
||||
description="Enter the selected event",
|
||||
)
|
||||
@option(
|
||||
"event",
|
||||
description="Name of the event",
|
||||
autocomplete=basic_autocomplete(autocomplete_active_events),
|
||||
)
|
||||
async def command_register(self, ctx: ApplicationContext, event: str) -> None:
|
||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||
|
||||
try:
|
||||
pycord_event: PycordEvent = await self.bot.find_event(event_id=event)
|
||||
except (InvalidId, RuntimeError):
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Event was not found.")
|
||||
return
|
||||
|
||||
if not guild.is_configured():
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Guild is not configured.")
|
||||
return
|
||||
|
||||
user: PycordUser = await self.bot.find_user(ctx.author)
|
||||
|
||||
if pycord_event._id in user.registered_event_ids:
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("You are already registered for this event.")
|
||||
return
|
||||
|
||||
await user.event_register(pycord_event._id, cache=self.bot.cache)
|
||||
|
||||
await ctx.respond("Ok.")
|
||||
|
||||
|
||||
def setup(bot: PycordBot) -> None:
|
||||
bot.add_cog(Register(bot))
|
60
cogs/unregister.py
Normal file
60
cogs/unregister.py
Normal file
@@ -0,0 +1,60 @@
|
||||
from bson.errors import InvalidId
|
||||
from discord import ApplicationContext, Cog, option, slash_command
|
||||
from discord.utils import basic_autocomplete
|
||||
|
||||
from classes import PycordEvent, PycordGuild, PycordUser
|
||||
from classes.pycord_bot import PycordBot
|
||||
from modules.utils import autocomplete_user_registered_events
|
||||
|
||||
|
||||
class Unregister(Cog):
|
||||
"""Cog with the event unregistration command."""
|
||||
|
||||
def __init__(self, bot: PycordBot):
|
||||
self.bot: PycordBot = bot
|
||||
|
||||
# TODO Introduce i18n
|
||||
@slash_command(
|
||||
name="unregister",
|
||||
description="Leave the selected event",
|
||||
)
|
||||
@option(
|
||||
"event",
|
||||
description="Name of the event",
|
||||
autocomplete=basic_autocomplete(autocomplete_user_registered_events),
|
||||
)
|
||||
@option("confirm", description="Confirmation of the operation", required=False)
|
||||
async def command_unregister(self, ctx: ApplicationContext, event: str, confirm: bool = False) -> None:
|
||||
if confirm is None or not confirm:
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Operation not confirmed.")
|
||||
return
|
||||
|
||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||
|
||||
try:
|
||||
pycord_event: PycordEvent = await self.bot.find_event(event_id=event)
|
||||
except (InvalidId, RuntimeError):
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Event was not found.")
|
||||
return
|
||||
|
||||
if not guild.is_configured():
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Guild is not configured.")
|
||||
return
|
||||
|
||||
user: PycordUser = await self.bot.find_user(ctx.author)
|
||||
|
||||
if pycord_event._id not in user.registered_event_ids:
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("You are not registered for this event.")
|
||||
return
|
||||
|
||||
await user.event_unregister(pycord_event._id, cache=self.bot.cache)
|
||||
|
||||
await ctx.respond("Ok.")
|
||||
|
||||
|
||||
def setup(bot: PycordBot) -> None:
|
||||
bot.add_cog(Unregister(bot))
|
88
cogs/user.py
Normal file
88
cogs/user.py
Normal file
@@ -0,0 +1,88 @@
|
||||
from discord import (
|
||||
ApplicationContext,
|
||||
SlashCommandGroup,
|
||||
User,
|
||||
option,
|
||||
)
|
||||
from discord.ext.commands import Cog
|
||||
|
||||
from classes.pycord_bot import PycordBot
|
||||
|
||||
|
||||
class User(Cog):
|
||||
"""Cog with user management commands."""
|
||||
|
||||
def __init__(self, bot: PycordBot):
|
||||
self.bot: PycordBot = bot
|
||||
|
||||
# TODO Introduce i18n
|
||||
command_group: SlashCommandGroup = SlashCommandGroup("user", "User management")
|
||||
|
||||
# TODO Implement the command
|
||||
@command_group.command(
|
||||
name="create_channel",
|
||||
description="Create channel for the user",
|
||||
)
|
||||
@option(
|
||||
"user",
|
||||
description="Selected user",
|
||||
)
|
||||
async def command_user_create_channel(self, ctx: ApplicationContext, user: User) -> None:
|
||||
await ctx.respond("Not implemented.")
|
||||
|
||||
# TODO Implement the command
|
||||
@command_group.command(
|
||||
name="update_channel",
|
||||
description="Update user's channel",
|
||||
)
|
||||
@option(
|
||||
"user",
|
||||
description="Selected user",
|
||||
)
|
||||
async def command_user_update_channel(self, ctx: ApplicationContext, user: User) -> None:
|
||||
await ctx.respond("Not implemented.")
|
||||
|
||||
# TODO Implement the command
|
||||
@command_group.command(
|
||||
name="delete_channel",
|
||||
description="Delete user's channel",
|
||||
)
|
||||
@option(
|
||||
"user",
|
||||
description="Selected user",
|
||||
)
|
||||
@option("confirm", description="Confirmation of the operation", required=False)
|
||||
async def command_user_delete_channel(
|
||||
self, ctx: ApplicationContext, user: User, confirm: bool = False
|
||||
) -> None:
|
||||
await ctx.respond("Not implemented.")
|
||||
|
||||
# TODO Implement the command
|
||||
@command_group.command(
|
||||
name="jail",
|
||||
description="Jail the user",
|
||||
)
|
||||
@option(
|
||||
"user",
|
||||
description="Selected user",
|
||||
)
|
||||
@option("confirm", description="Confirmation of the operation", required=False)
|
||||
async def command_user_jail(self, ctx: ApplicationContext, user: User, confirm: bool = False) -> None:
|
||||
await ctx.respond("Not implemented.")
|
||||
|
||||
# TODO Implement the command
|
||||
@command_group.command(
|
||||
name="unjail",
|
||||
description="Unjail the user",
|
||||
)
|
||||
@option(
|
||||
"user",
|
||||
description="Selected user",
|
||||
)
|
||||
@option("confirm", description="Confirmation of the operation", required=False)
|
||||
async def command_user_unjail(self, ctx: ApplicationContext, user: User, confirm: bool = False) -> None:
|
||||
await ctx.respond("Not implemented.")
|
||||
|
||||
|
||||
def setup(bot: PycordBot) -> None:
|
||||
bot.add_cog(User(bot))
|
Reference in New Issue
Block a user