mirror of
https://github.com/zoriya/Nemo.git
synced 2025-12-06 02:46:10 +00:00
Finishing the stop command
This commit is contained in:
@@ -3,7 +3,7 @@ import os
|
|||||||
TOKEN = os.environ["NEMO_TOKEN"]
|
TOKEN = os.environ["NEMO_TOKEN"]
|
||||||
|
|
||||||
CATEGORY_NAME = "EVENTS"
|
CATEGORY_NAME = "EVENTS"
|
||||||
ORGANIZATION_NAME = "organization"
|
ORGANIZATION_NAME = "organisation"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ def organizer_only(f):
|
|||||||
member: discord.Member = kwargs["member"]
|
member: discord.Member = kwargs["member"]
|
||||||
channel: discord.TextChannel = kwargs["message"].channel
|
channel: discord.TextChannel = kwargs["message"].channel
|
||||||
event: int = kwargs["event"]
|
event: int = kwargs["event"]
|
||||||
if "administrator" in channel.permissions_for(member):
|
if channel.permissions_for(member).administrator:
|
||||||
return await f(*args, **kwargs)
|
return await f(*args, **kwargs)
|
||||||
if any(x for x in member.roles if x.name == f"{config.ORGANIZER_PREFIX}{event}"):
|
if any(x for x in member.roles if x.name == f"{config.ORGANIZER_PREFIX}{event}"):
|
||||||
return await f(*args, **kwargs)
|
return await f(*args, **kwargs)
|
||||||
|
|||||||
10
main.py
10
main.py
@@ -44,6 +44,10 @@ async def help_msg(channel: discord.TextChannel):
|
|||||||
async def create_event(reaction: discord.Reaction, message: discord.Message, member: discord.Member, guild: discord.Guild, **_):
|
async def create_event(reaction: discord.Reaction, message: discord.Message, member: discord.Member, guild: discord.Guild, **_):
|
||||||
list_msg: discord.Message = [x async for x in message.channel.history() if config.LIST_KEY in x.content][0]
|
list_msg: discord.Message = [x async for x in message.channel.history() if config.LIST_KEY in x.content][0]
|
||||||
index = get_new_event_index(list_msg)
|
index = get_new_event_index(list_msg)
|
||||||
|
if index == -1:
|
||||||
|
await reaction.remove(member)
|
||||||
|
return
|
||||||
|
|
||||||
await edit_event_status(index, config.CONFIGURING_EVENT.replace("@User", f"<@{member.id}>"), list_msg)
|
await edit_event_status(index, config.CONFIGURING_EVENT.replace("@User", f"<@{member.id}>"), list_msg)
|
||||||
await reaction.remove(member)
|
await reaction.remove(member)
|
||||||
|
|
||||||
@@ -62,8 +66,10 @@ async def create_event(reaction: discord.Reaction, message: discord.Message, mem
|
|||||||
|
|
||||||
|
|
||||||
def get_new_event_index(msg: discord.Message):
|
def get_new_event_index(msg: discord.Message):
|
||||||
|
if config.EMPTY_KEY in msg.content:
|
||||||
|
return 1
|
||||||
for x in msg.content.split('\n'):
|
for x in msg.content.split('\n'):
|
||||||
if config.EMPTY_KEY in x or config.EMPTY_SLOT in x:
|
if config.EMPTY_SLOT in x:
|
||||||
return int(x[2:x.index(':')])
|
return int(x[2:x.index(':')])
|
||||||
last_slot = msg.content.split('\n')[-1]
|
last_slot = msg.content.split('\n')[-1]
|
||||||
slot = int(last_slot[2:last_slot.index(':')]) + 1
|
slot = int(last_slot[2:last_slot.index(':')]) + 1
|
||||||
@@ -83,7 +89,6 @@ async def edit_event_status(index: int, text: str, list_msg: discord.Message):
|
|||||||
@nemo.command("!stop")
|
@nemo.command("!stop")
|
||||||
@helper.event_command
|
@helper.event_command
|
||||||
@helper.organizer_only
|
@helper.organizer_only
|
||||||
@helper.auto_delete
|
|
||||||
async def stop(*,
|
async def stop(*,
|
||||||
channel: discord.TextChannel,
|
channel: discord.TextChannel,
|
||||||
member: discord.Member,
|
member: discord.Member,
|
||||||
@@ -91,6 +96,7 @@ async def stop(*,
|
|||||||
guild: discord.Guild,
|
guild: discord.Guild,
|
||||||
event: int,
|
event: int,
|
||||||
**_):
|
**_):
|
||||||
|
await message.delete()
|
||||||
msg = await channel.send(config.STOP_MSG.replace("@User", f"<@{member.id}>"))
|
msg = await channel.send(config.STOP_MSG.replace("@User", f"<@{member.id}>"))
|
||||||
await msg.add_reaction("✅")
|
await msg.add_reaction("✅")
|
||||||
try:
|
try:
|
||||||
|
|||||||
4
nemo.py
4
nemo.py
@@ -15,12 +15,14 @@ class Nemo(discord.Client):
|
|||||||
|
|
||||||
async def on_message(self, message: discord.Message):
|
async def on_message(self, message: discord.Message):
|
||||||
cmd = message.content.split()
|
cmd = message.content.split()
|
||||||
|
if not any(cmd):
|
||||||
|
return
|
||||||
f = self.commands.get(cmd[0])
|
f = self.commands.get(cmd[0])
|
||||||
if f is None:
|
if f is None:
|
||||||
return
|
return
|
||||||
print(f"{message.author.display_name} used the command: '{cmd[0]}'")
|
print(f"{message.author.display_name} used the command: '{cmd[0]}'")
|
||||||
try:
|
try:
|
||||||
await f(cmd[1::], message=message, guild=message.guild, channel=message.channel)
|
await f(args=cmd[1::], message=message, guild=message.guild, channel=message.channel, member=message.author)
|
||||||
except Exception:
|
except Exception:
|
||||||
await message.channel.send(f"Fatal error: {traceback.format_exc()}")
|
await message.channel.send(f"Fatal error: {traceback.format_exc()}")
|
||||||
raise
|
raise
|
||||||
|
|||||||
Reference in New Issue
Block a user