From d5cb8b7ea7db5c0eba5dafc2466a0f23f0f49d02 Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Tue, 14 Jul 2020 23:03:52 +0200
Subject: [PATCH] Finishing the stop command
---
config.py | 2 +-
helper.py | 2 +-
main.py | 10 ++++++++--
nemo.py | 4 +++-
4 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/config.py b/config.py
index 7749be7..14b1c96 100644
--- a/config.py
+++ b/config.py
@@ -3,7 +3,7 @@ import os
TOKEN = os.environ["NEMO_TOKEN"]
CATEGORY_NAME = "EVENTS"
-ORGANIZATION_NAME = "organization"
+ORGANIZATION_NAME = "organisation"
diff --git a/helper.py b/helper.py
index fd858ed..23f2563 100644
--- a/helper.py
+++ b/helper.py
@@ -26,7 +26,7 @@ def organizer_only(f):
member: discord.Member = kwargs["member"]
channel: discord.TextChannel = kwargs["message"].channel
event: int = kwargs["event"]
- if "administrator" in channel.permissions_for(member):
+ if channel.permissions_for(member).administrator:
return await f(*args, **kwargs)
if any(x for x in member.roles if x.name == f"{config.ORGANIZER_PREFIX}{event}"):
return await f(*args, **kwargs)
diff --git a/main.py b/main.py
index f49837a..4603ef2 100644
--- a/main.py
+++ b/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, **_):
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)
+ if index == -1:
+ await reaction.remove(member)
+ return
+
await edit_event_status(index, config.CONFIGURING_EVENT.replace("@User", f"<@{member.id}>"), list_msg)
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):
+ if config.EMPTY_KEY in msg.content:
+ return 1
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(':')])
last_slot = msg.content.split('\n')[-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")
@helper.event_command
@helper.organizer_only
-@helper.auto_delete
async def stop(*,
channel: discord.TextChannel,
member: discord.Member,
@@ -91,6 +96,7 @@ async def stop(*,
guild: discord.Guild,
event: int,
**_):
+ await message.delete()
msg = await channel.send(config.STOP_MSG.replace("@User", f"<@{member.id}>"))
await msg.add_reaction("✅")
try:
diff --git a/nemo.py b/nemo.py
index fad9770..7716411 100644
--- a/nemo.py
+++ b/nemo.py
@@ -15,12 +15,14 @@ class Nemo(discord.Client):
async def on_message(self, message: discord.Message):
cmd = message.content.split()
+ if not any(cmd):
+ return
f = self.commands.get(cmd[0])
if f is None:
return
print(f"{message.author.display_name} used the command: '{cmd[0]}'")
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:
await message.channel.send(f"Fatal error: {traceback.format_exc()}")
raise