Finishing the stop command

This commit is contained in:
Anonymus Raccoon
2020-07-14 23:03:52 +02:00
parent ce0df405c1
commit d5cb8b7ea7
4 changed files with 13 additions and 5 deletions

View File

@@ -3,7 +3,7 @@ import os
TOKEN = os.environ["NEMO_TOKEN"]
CATEGORY_NAME = "EVENTS"
ORGANIZATION_NAME = "organization"
ORGANIZATION_NAME = "organisation"

View File

@@ -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)

10
main.py
View File

@@ -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:

View File

@@ -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