Beispiel #1
0
    async def seteventrole_error(self, ctx, error):
        if isinstance(error, commands.MissingRequiredArgument):
            manager = MessageManager(ctx)
            event_role = get_event_role(ctx)

            if not event_role:
                role_display = 'None (anyone can make events)'
            else:
                role_display = format_role_name(event_role)

            await manager.send_message(
                "The current event role is: **{}**\n\n".format(role_display) +
                "To change the event role, use '{}settings seteventrole <role_name>'"
                .format(ctx.prefix))
            await manager.clean_messages()
Beispiel #2
0
    async def event(self, ctx):
        """
        Create an event in the events channel

        After invoking the event command, the bot will ask
        you to enter the event details. Once the event
        is created, it will appear in the upcoming-events
        channel. The upcoming-events channel is designed with
        the assumption that it isn't used for anything but
        displaying events; non event messages will be deleted.

        Users will be able to accept and decline the
        event by adding reactions. If a maximum number
        of attendees is set and the event is full,
        additional attendees will be placed in a standby
        section. If a spot opens up, the user at the
        top of the standby section will be automatically
        moved into the event.

        By default, everyone can make events. However, a minimum role
        requirement to create events can be defined in the settings.
        See `help settings seteventrole` for more information.

        The event creator and those with the Manage Sever permission
        can delete events by reacting to the event message with \U0001f480.
        """
        manager = MessageManager(self.bot, ctx.author, ctx.channel, ctx.prefix,
                                 [ctx.message])
        event_role = get_event_role(self.bot, ctx.guild)
        member_permissions = ctx.author.permissions_in(ctx.channel)

        if event_role:
            if ctx.author.top_role < event_role:
                event_role_str = format_role_name(event_role)
                await manager.say(
                    "You must be of role **{}** or higher to do that.".format(
                        event_role))
                return await manager.clear()

        await manager.say(
            'Event creation instructions have been messaged to you')

        res = await manager.say_and_wait("Enter event title:", dm=True)
        if not res:
            return await manager.clear()
        title = res.content

        description = ""
        res = await manager.say_and_wait(
            "Enter event description (type 'none' for no description):",
            dm=True)
        if not res:
            return await manager.clear()
        if res.content.upper() != 'NONE':
            description = res.content

        max_members = 0
        while not max_members:
            res = await manager.say_and_wait(
                "Enter the maximum numbers of attendees (type 'none' for no maximum):",
                dm=True)
            if not res:
                return await manager.clear()
            if res.content.upper() == 'NONE':
                break
            elif is_int(res.content) and int(res.content) in range(1, 10000):
                max_members = int(res.content)
            else:
                await manager.say(
                    "Invalid entry. Must be a number between 1 and 9999.",
                    dm=True)

        start_time = None
        while not start_time:
            res = await manager.say_and_wait(
                "Enter event time (YYYY-MM-DD HH:MM AM/PM):", dm=True)
            if not res:
                return await manager.clear()
            start_time_format = '%Y-%m-%d %I:%M %p'
            try:
                start_time = datetime.strptime(res.content, start_time_format)
            except ValueError:
                await manager.say("Invalid event time!", dm=True)

        time_zone = None
        while not time_zone:
            res = await manager.say_and_wait(
                "Enter the time zone (PST, EST, etc):", dm=True)
            if not res:
                return await manager.clear()
            user_timezone = "".join(res.content.upper().split())
            if user_timezone not in constants.TIME_ZONES:
                await manager.say("Unsupported time zone", dm=True)
            else:
                time_zone = user_timezone

        affected_rows = self.bot.db.create_event(title, start_time, time_zone,
                                                 ctx.guild.id, description,
                                                 max_members, ctx.author.id)
        if affected_rows == 0:
            await manager.say("An event with that name already exists!",
                              dm=True)
            return await manager.clear()

        event_channel = await self.get_events_channel(ctx.guild)
        await manager.say("Event created! The " + event_channel.mention +
                          " channel will be updated momentarily.",
                          dm=True)
        await self.list_events(ctx.guild)
        await manager.clear()