示例#1
0
    def __init__(self, ctx, guild_config, guilds_db):
        self.ctx = ctx
        self.bot = ctx.bot
        self.guilds_db = guilds_db
        self.message = ctx.message
        self.channel = ctx.channel
        self.guild = ctx.guild
        self.author = ctx.author
        self.guild_config = guild_config
        self.manage_messages = self.channel.permissions_for(
            self.guild.me).manage_messages

        self.embed = Embed(ctx=ctx)
        self.current_page = None
        self.previous_page = None
        self.paginating = True
        self.match = None

        self.main_page_emojis = [
            ('📄', self.set_default_channel, ''),
            ('📣', self.set_default_mention, ''),
            ('⚙️', self.toggle_event_system, ''),
        ]

        for event in SKYBLOCK_EVENTS.keys():
            self.main_page_emojis.append(
                (SKYBLOCK_EVENTS[event]['emoji'], self.show_event_page, event))
        self.main_page_emojis.append(('✅', self.enable_all_events, ''))
        self.main_page_emojis.append(('❎', self.disable_all_events, ''))

        self.event_page_emojis = [('📄', self.set_event_channel, ''),
                                  ('📣', self.set_event_mention, ''),
                                  ('✅', self.enable_event, ''),
                                  ('❎', self.disable_event, ''),
                                  ('⬅️', self.default_page, 'default')]
示例#2
0
    async def on_ready(self):
        # Start all skyblock event schedules
        cog = self.bot.get_cog('Skyblock')
        text = ''
        for event in SKYBLOCK_EVENTS.keys():
            text += await cog.schedule_event(event)
        print(text)

        print(f'Logged on as {self.bot.user}! (ID: {self.bot.user.id})')
示例#3
0
    async def disable_all_events(self):
        # Check if all events are not already disabled
        to_update = {}
        for event in SKYBLOCK_EVENTS.keys():
            if self.guild_config['events'][event]['enabled']:
                self.guild_config['events'][event]['enabled'] = False
                to_update.update({f'events.{event}.enabled': False})

        if to_update:
            await self.guilds_db.update_one({'_id': self.guild_config['_id']},
                                            {'$set': to_update})

            await self.default_page(with_emoji=False)
示例#4
0
    async def enable_all_events(self):
        # Check if all events are not already enabled
        to_update = {}
        for event in SKYBLOCK_EVENTS.keys():
            if not self.guild_config['events'][event]['enabled'] and (
                    self.guild_config['events'][event]['webhook_data']
                    is not None
                    or self.guild_config['events']['default_webhook_data']
                    is not None):
                self.guild_config['events'][event]['enabled'] = True
                to_update.update({f'events.{event}.enabled': True})

        if to_update:
            await self.guilds_db.update_one({'_id': self.guild_config['_id']},
                                            {'$set': to_update})

            await self.default_page(with_emoji=False)
示例#5
0
    async def stop(self, ctx, *, event_name):
        """ 
        Enter <event name> to stop that event schedule or `all` to stop all.
        """
        _text = ''
        _found = False
        for event in SKYBLOCK_EVENTS.keys():
            if event_name.lower() in (SKYBLOCK_EVENTS[event]['name'].lower(),
                                      'all', event.lower()):
                _found = True
                _text += await self.delete_event_schedule(event)

        if not _found:
            await ctx.send(
                f'{ctx.author.mention}, Failed to start {event_name}.')
        else:
            await ctx.send(f'{ctx.author.mention}\n{_text}')
示例#6
0
    async def set_default_channel(self):
        to_delete = [
            await self.ctx.send(
                f'{self.author.mention}\nWhich channel would you want to set the default event alert?\n'
                f'Please mention/enter channel or None to unset channel.\n'
                f'The bot will automatically create webhook for you.')
        ]

        def message_check(m):
            if m.author.id == self.author.id and m.channel.id == self.channel.id:
                if m.clean_content.lower() == 'exit':
                    raise SessionTimeout
                if m.clean_content.isdigit() or len(
                        m.channel_mentions) == 1 or m.clean_content.lower(
                        ) == 'none':
                    return True
            return False

        try:
            msg = await self.bot.wait_for('message',
                                          check=message_check,
                                          timeout=30.0)
        except (discord.NotFound, discord.Forbidden,
                aiohttp.ClientResponseError):
            to_delete.append(
                await
                self.ctx.send(f'{self.author.mention}, Input session closed.'))
            await asyncio.sleep(4)
        else:
            to_delete.append(msg)

            if msg.clean_content.lower() == 'none' or (
                    msg.clean_content.isdigit()
                    and int(msg.clean_content) == 0):
                # Check if it's not already empty
                if self.guild_config['events'][
                        'default_webhook_data'] is not None:
                    # Try delete old webhook
                    try:
                        splitted_webhook_data = self.guild_config['events'][
                            'default_webhook_data'].split('/')
                        old_webhook = Webhook.partial(
                            splitted_webhook_data[0],
                            splitted_webhook_data[1],
                            adapter=AsyncWebhookAdapter(self.bot.http_session))
                        await old_webhook.delete(
                            reason=
                            f'Member: {self.author.id} deleted channel for default alert.'
                        )
                    except Exception:
                        pass

                    to_update = {}
                    for event in SKYBLOCK_EVENTS.keys():
                        # Try disable event if event webhook url is empty
                        if self.guild_config['events'][event][
                                'webhook_data'] is None:
                            self.guild_config['events'][event][
                                'enabled'] = False
                            to_update.update(
                                {f'events.{event}.enabled': False})

                    to_update.update({'events.default_webhook_data': None})
                    self.guild_config['events']['default_webhook_data'] = None
                    await self.guilds_db.update_one(
                        {'_id': self.guild_config['_id']}, {'$set': to_update})

                    await self.default_page(with_emoji=False)
            else:
                if msg.clean_content.isdigit():
                    channel = self.guild.get_channel(int(msg.clean_content))
                else:
                    channel = self.guild.get_channel(
                        msg.raw_channel_mentions[0])

                if isinstance(channel, TextChannel):
                    webhook_data = self.guild_config['events'][
                        'default_webhook_data']

                    # Check if it's not already the same channel
                    if webhook_data is None or webhook_data.split(
                            '/')[2] != channel.id:
                        # Try delete old webhook if not the same
                        if webhook_data is not None:
                            try:
                                splitted_webhook_data = webhook_data.split('/')
                                old_webhook = Webhook.partial(
                                    splitted_webhook_data[0],
                                    splitted_webhook_data[1],
                                    adapter=AsyncWebhookAdapter(
                                        self.bot.http_session))

                                await old_webhook.delete(
                                    reason=
                                    f'Member: {self.author.id} deleted channel for default alert.'
                                )
                            except Exception:
                                pass

                        # Check webhook permission
                        if not channel.permissions_for(
                                self.guild.me).manage_webhooks:
                            to_delete.append(await
                                             send_no_permission_embed(self.ctx
                                                                      ))
                            await asyncio.sleep(4)
                            return

                        # Create and update default webhook
                        webhook = await channel.create_webhook(
                            name='Default Skyblock Events Alert',
                            reason=
                            f'Member: {self.author.id} created default webhook for skyblock events alert.'
                        )

                        self.guild_config['events'][
                            'default_webhook_data'] = f'{webhook.id}/{webhook.token}/{channel.id}'
                        await self.guilds_db.update_one(
                            {'_id': self.guild_config['_id']}, {
                                '$set': {
                                    'events.default_webhook_data':
                                    f'{webhook.id}/{webhook.token}/{channel.id}'
                                }
                            })

                        await self.default_page(with_emoji=False)
                else:
                    to_delete.append(await self.ctx.send(
                        f'{self.author.mention}, Invalid channel.'))
                    await asyncio.sleep(4)

        try:
            await self.channel.delete_messages(to_delete)
        except Exception:
            pass