Exemplo n.º 1
0
    async def hostinfo(self, ctx):
        """List info about the bot's host environment."""

        message = await ctx.channel.send('Gathering info...')

        # cpuCores    = psutil.cpu_count(logical=False)
        # cpuThred    = psutil.cpu_count()
        cpuThred = os.cpu_count()
        cpuUsage = psutil.cpu_percent(interval=1)
        memStats = psutil.virtual_memory()
        memPerc = memStats.percent
        memUsed = memStats.used
        memTotal = memStats.total
        memUsedGB = "{0:.1f}".format(((memUsed / 1024) / 1024) / 1024)
        memTotalGB = "{0:.1f}".format(((memTotal / 1024) / 1024) / 1024)
        currentOS = platform.platform()
        system = platform.system()
        release = platform.release()
        version = platform.version()
        processor = platform.processor()
        botMember = DisplayName.memberForID(self.bot.user.id,
                                            ctx.message.guild)
        botName = DisplayName.name(botMember)
        currentTime = int(time.time())
        timeString = ReadableTime.getReadableTimeBetween(
            self.startTime, currentTime)
        pythonMajor = sys.version_info.major
        pythonMinor = sys.version_info.minor
        pythonMicro = sys.version_info.micro
        pythonRelease = sys.version_info.releaselevel
        pyBit = struct.calcsize("P") * 8
        process = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'],
                                   shell=False,
                                   stdout=subprocess.PIPE)
        git_head_hash = process.communicate()[0].strip()

        threadString = 'thread'
        if not cpuThred == 1:
            threadString += 's'

        msg = '***{}\'s*** **Home:**\n'.format(botName)
        msg += '```\n'
        msg += 'OS       : {}\n'.format(currentOS)
        msg += 'Hostname : {}\n'.format(platform.node())
        msg += 'Language : Python {}.{}.{} {} ({} bit)\n'.format(
            pythonMajor, pythonMinor, pythonMicro, pythonRelease, pyBit)
        msg += 'Commit   : {}\n\n'.format(git_head_hash.decode("utf-8"))
        msg += ProgressBar.center(
            '{}% of {} {}'.format(cpuUsage, cpuThred, threadString),
            'CPU') + '\n'
        msg += ProgressBar.makeBar(int(round(cpuUsage))) + "\n\n"
        msg += ProgressBar.center(
            '{} ({}%) of {}GB used'.format(memUsedGB, memPerc, memTotalGB),
            'RAM') + '\n'
        msg += ProgressBar.makeBar(int(round(memPerc))) + "\n\n"
        msg += '{} uptime```'.format(timeString)

        await message.edit(content=msg)
Exemplo n.º 2
0
    async def hostinfo(self, ctx):
        """List info about the bot's host environment."""
        # cpuCores    = psutil.cpu_count(logical=False)
        # cpuThred    = psutil.cpu_count()
        cpuThred = os.cpu_count()
        cpuUsage = psutil.cpu_percent(interval=1)
        memStats = psutil.virtual_memory()
        memPerc = memStats.percent
        memUsed = memStats.used
        memTotal = memStats.total
        memUsedGB = "{0:.1f}".format(((memUsed / 1024) / 1024) / 1024)
        memTotalGB = "{0:.1f}".format(((memTotal / 1024) / 1024) / 1024)
        currentOS = platform.platform()
        system = platform.system()
        release = platform.release()
        version = platform.version()
        processor = platform.processor()
        botMember = DisplayName.memberForID(self.bot.user.id,
                                            ctx.message.server)
        botName = DisplayName.name(botMember)
        currentTime = int(time.time())
        timeString = ReadableTime.getReadableTimeBetween(
            self.startTime, currentTime)
        pythonMajor = sys.version_info.major
        pythonMinor = sys.version_info.minor
        pythonMicro = sys.version_info.micro
        pythonRelease = sys.version_info.releaselevel

        msg = '***{}\'s*** **Home:**\n'.format(botName)
        msg += '```{}\n'.format(currentOS)
        msg += 'Python {}.{}.{} {}\n'.format(pythonMajor, pythonMinor,
                                             pythonMicro, pythonRelease)
        msg += '{}% of {} ({} thread[s])\n'.format(cpuUsage, processor,
                                                   cpuThred)
        msg += ProgressBar.makeBar(int(round(cpuUsage))) + "\n"
        msg += '{} ({}%) of {}GB RAM used\n'.format(memUsedGB, memPerc,
                                                    memTotalGB)
        msg += ProgressBar.makeBar(int(round(memPerc))) + "\n"
        msg += 'Hostname: {}\n'.format(platform.node())
        msg += '{} uptime```'.format(timeString)

        await self.bot.send_message(ctx.message.channel, msg)