예제 #1
0
    async def on_guild_join(self, guild):
        with self.bot.scoped_session() as session:
            find_or_create_guild(session, guild.id)

        # Add entry for guild prefix in the cache
        self.bot.cache.update_prefix(guild.id, None)

        await guild.owner.send(t("welcome_message").format(guild.name))
예제 #2
0
    async def event(self, ctx):
        """Create a new event"""
        # Clean up event channels that may have been deleted
        # while the bot was offline.
        self.sync_event_channels.call(ctx.guild.id)

        with self.bot.scoped_session() as session:
            guild = find_or_create_guild(session, ctx.guild.id)

        if not HavePermission(ctx.author, guild).event():
            return await ctx.send(t("error.missing_permissions"))

        with self.bot.scoped_session() as session:
            event_channels = (
                session.query(EventChannel).filter_by(guild_id=ctx.guild.id).all()
            )
            user = find_or_create_user(session, ctx.author.id)

        event = Event()

        await ctx.author.send(t("event.title_prompt"))
        event.title = await self.title_input.call(ctx.author, ctx.author.dm_channel)

        await ctx.author.send(t("event.description_prompt"))
        event.description = await self.description_input.call(
            ctx.author, ctx.author.dm_channel
        )
        event.organizer = user

        await ctx.author.send(t("event.capacity_prompt"))
        event.capacity = await self.capacity_input.call(
            ctx.author, ctx.author.dm_channel
        )

        event.event_channel = await self._get_event_channel(ctx, event_channels)

        await ctx.author.send(embed=TimeZoneEmbed().call())
        event.time_zone = await self.time_zone_input.call(
            ctx.author, ctx.author.dm_channel
        )

        await ctx.author.send(t("event.start_time_prompt"))
        event.start_time = await self.start_time_input.call(
            ctx.author, ctx.author.dm_channel, event.time_zone
        )

        channel = self.bot.get_channel(event.event_channel.id)
        await ctx.author.send(t("event.created").format(channel.mention))

        with self.bot.scoped_session() as session:
            session.add(event)

        with self.bot.scoped_session() as session:
            events = (
                session.query(Event)
                .filter_by(event_channel_id=event.event_channel_id)
                .all()
            )

        await self.list_events.call(events, channel)
예제 #3
0
    async def channel(self, ctx):
        """Create a new event channel"""
        with self.bot.scoped_session() as session:
            guild = find_or_create_guild(session, ctx.guild.id)

        if not HavePermission(ctx.author, guild).channel():
            return await ctx.send(t("error.missing_permissions"))

        with self.bot.scoped_session() as session:
            channel_count = event_channel_count_for_guild(session, ctx.guild.id)

        if channel_count >= self.MAX_CHANNELS:
            return await ctx.send(t("channel.channel_limit"))

        channel = await self.bot.create_discord_event_channel(
            ctx.guild, ctx.channel.category
        )
        event_channel = EventChannel(id=channel.id, guild_id=ctx.guild.id)

        with self.bot.scoped_session() as session:
            session.add(event_channel)
            events = event_channel.events

        await self.list_events.call(events, channel)
        await ctx.send(t("channel.channel_created").format(channel.mention))
예제 #4
0
    async def delete(self, ctx, *, role: discord.Role):
        """Change or view the minimum role required to delete events"""
        with self.bot.scoped_session() as session:
            guild = find_or_create_guild(session, ctx.guild.id)
            guild.delete_role_id = role.id
            session.add(guild)

        await ctx.send(t("role.delete_role_changed").format(role))
예제 #5
0
    async def prefix(self, ctx, new_prefix):
        """Update the server's command prefix"""
        with self.bot.scoped_session() as session:
            guild = find_or_create_guild(session, ctx.guild.id)
            guild.prefix = new_prefix
            session.add(guild)

        self.bot.cache.update_prefix(ctx.guild.id, new_prefix)
        await ctx.send(t("prefix.changed").format(new_prefix))
예제 #6
0
    async def delete_error(self, ctx, error):
        if isinstance(error, commands.MissingRequiredArgument):
            with self.bot.scoped_session() as session:
                guild = find_or_create_guild(session, ctx.guild.id)

            role = discord.utils.get(ctx.guild.roles, id=guild.delete_role_id)

            await ctx.send(
                t("role.delete_role_current").format(role, ctx.prefix))
예제 #7
0
    async def call(self, event, payload):
        channel = self.bot.get_channel(payload.channel_id)

        if payload.emoji.name == emoji.CLOCK:
            # We generally clear the reaction later on, but as we could we
            # waiting on the user to input a time zone, we don't want this
            # reaction to hang around for too long.
            await self.bot.remove_reaction(payload)

            discord_user = self.bot.get_user(payload.user_id)

            with self.bot.scoped_session() as session:
                apollo_user = find_or_create_user(session, payload.user_id)

            await self.request_local_start_time.call(apollo_user, discord_user, event)

        if payload.emoji.name == emoji.SKULL:
            member = self.bot.find_guild_member(payload.guild_id, payload.user_id)

            with self.bot.scoped_session() as session:
                guild = find_or_create_guild(session, payload.guild_id)

            if event.organizer_id != member.id and not HavePermission(member, guild).delete():
                return await member.send("You don't have permission to do that.")

            with self.bot.scoped_session() as session:
                session.delete(event)

            await channel.delete_messages([discord.Object(id=event.message_id)])

            with self.bot.scoped_session() as session:
                event_count = event_count_for_event_channel(session, channel.id)

            if event_count == 0:
                await channel.send(t("channel.no_events"))

            return

        rsvp_status = EMOJI_STATUSES.get(payload.emoji.name)
        if rsvp_status:
            await self.update_response.call(event.id, payload.user_id, rsvp_status)

            with self.bot.scoped_session() as session:
                responses = responses_for_event(session, event.id)

            await self.update_event.call(event, responses, channel)
예제 #8
0
    async def on_guild_join(self, guild):
        with self.bot.scoped_session() as session:
            find_or_create_guild(session, guild.id)

        # Add entry for guild prefix in the cache
        self.bot.cache.update_prefix(guild.id, None)