Exemplo n.º 1
0
    def run(self, silent=False):
        if custom_help:
            self.client.remove_command('help')
        cog_count = 0
        warnings = []
        cogs = extensions()
        for extension in cogs:
            try:
                self.client.load_extension(extension)
                cog_count += 1
            except Exception as e:
                if not silent:
                    warnings.append(f'Failed to load extension {extension}\n{e}')

        if not silent:
            if not cogs:
                log.warn('No extensions were found.')
            else:
                for x in warnings:
                    y = x.split('\n')
                    log.warning(f'> {y[0]}')
                    log.error(f'> {y[1]}')
                if len(warnings) > 0:
                    # if saved() < enums.LogLevel.error.value:
                    if len(warnings) == 1:
                        log.error(f'> Failed to load {trace.yellow.s}{len(warnings)}{trace.cyan} extension.')
                    else:
                        log.error(f'> Failed to load {trace.yellow.s}{len(warnings)}{trace.cyan} extensions.')
                log.info(f'{trace.cyan}> Loaded {trace.yellow.s}{cog_count}{trace.cyan} extensions!')
Exemplo n.º 2
0
 async def invite_error(self, ctx, err):
     if isinstance(err, commands.CommandInvokeError):
         if '50001' in str(err):
             log.warn(
                 f'Could not find guild in cache. Error message to follow.')
         elif '50013' in str(err):
             log.warn(
                 f'Failed to create invite for guild. Error message to follow.'
             )
Exemplo n.º 3
0
 async def loop(cls, self, ctx):
     if not Player.is_playing(ctx) and not Player.is_paused(ctx) and len(queue[ctx.guild.id]['q']) > 0:
         while Player.has_queue(ctx):
             if not Player.is_playing(ctx) and not Player.is_paused(ctx):
                 try:
                     try:
                         url = queue[ctx.guild.id]['q'][0]['webpage_url']
                     except Exception:
                         url = queue[ctx.guild.id]['q'][0]['id']
                     stream = await YTDLSource.create_source(url=url, loop=self.bot.loop)
                     Player.play(ctx, stream)
                     new = queue[ctx.guild.id]['q'].pop(0)
                     if 'ie_key' in new:  # if Playlist object
                         if new['ie_key'].lower() == 'youtube':
                             added_by = new['discord_mention']
                             data_trunk, new = await Player.info(new['id'], loop=self.bot.loop, ctx=ctx)
                             # new = new[0]  # Format into usable form
                             new.update({'discord_mention': added_by})
                     extractor = Player.Extractor.fetch(new)
                     new = await Player.process_picture(new, extractor[0])
                     # log.debug(new)
                     queue[ctx.guild.id]['playing'].insert(0, new)
                     queue[ctx.guild.id]['player'] = stream
                     embed = tls.Embed(ctx, title=new['title'], url=new['webpage_url'], description='is now playing.')
                     # log.debug(new['pfp'])
                     try:
                         embed.set_author(name=new['uploader'], url=new['uploader_url'], icon_url=new['pfp'])
                     except KeyError as err:
                         embed.set_author(name=new['uploader'], icon_url=new['pfp'])
                     # embed.set_image(url=new['thumbnail'])
                     try:
                         await ctx.send(embed=embed)
                     except Exception as e:
                         log.warn(f'> {e}')
                 except Exception as err:
                     log.debug(f'> {err}')
                     pass
             await asyncio.sleep(4)
Exemplo n.º 4
0
 async def guild_error(self, ctx, err):
     if isinstance(err, commands.CommandInvokeError):
         log.warn(
             f'Could not find guild in cache. Error message to follow.')
Exemplo n.º 5
0
    async def reload(self, ctx, arg='silent'):
        warnings = []
        loading = []
        unloaded = []
        import time
        before = time.monotonic()
        log.info(f'{trace.red.s}> Reloading Extensions')
        loaded = []
        for x in self.bot.extensions:
            loaded.append(x)
        cogs = extensions()
        for x in cogs:
            if x in loaded:
                try:
                    self.bot.reload_extension(x)
                    if not arg == 'silent':
                        log.info(f'{trace.cyan}> Reloaded {trace.yellow.s}{x}')
                    loaded.remove(x)
                except Exception as e:
                    warnings.append(f'Failed to reload extension {x}.\n{e}')
            elif x not in loaded:
                try:
                    self.bot.load_extension(x)
                    loading.append(x)
                except Exception as e:
                    warnings.append(f'Failed to load extension {x}.\n{e}')

        for x in loaded:
            try:
                self.bot.unload_extension(x)
                unloaded.append(x)
                loaded.remove(x)
            except Exception as e:
                warnings.append(f'Failed to unload extension {x}.\n{e}')

        if not cogs:
            log.warn('No extensions were found.')
        else:
            for x in loading:
                log.warn(f'> Loaded {x}')
            for x in unloaded:
                log.error(f'> Unloaded {x}')
            for x in warnings:
                y = x.split('\n')
                log.warn(f'> {y[0]}')
                log.error(f'> {y[1]}')
            ping = round((time.monotonic() - before) * 1000)
            log.info(
                f'{trace.cyan}> Reloaded {trace.yellow.s}{len(self.bot.extensions)} extensions {trace.cyan}in {trace.yellow.s}{ping}ms{trace.cyan}.'
            )
            global lockdown
            lockdown = False
            await ctx.send(
                f'Extensions reloaded. ({len(self.bot.extensions)}) (`{ping}ms`)'
            )
            from core import json
            json.json()  # Reload memory
            from core.bot.login import version
            version.Discord.latest()  # Check for updates for Discord.py
            version.YouTubeDL.latest()  # Check for updates for YouTubeDL
            await tls.Activity.preset(self.bot)  # Update activity