Skip to content
This repository has been archived by the owner on Jan 1, 2021. It is now read-only.

Commit

Permalink
add about command
Browse files Browse the repository at this point in the history
  • Loading branch information
jgayfer committed Sep 25, 2017
1 parent cd39d73 commit c796210
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 22 deletions.
63 changes: 63 additions & 0 deletions cogs/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import discord
from discord.ext import commands
import pytz
import psutil

from cogs.utils.messages import MessageManager
from cogs.utils import constants
Expand All @@ -12,6 +13,7 @@ class General:

def __init__(self, bot):
self.bot = bot
self.process = psutil.Process()


@commands.command()
Expand Down Expand Up @@ -53,6 +55,67 @@ async def feedback_error(self, ctx, error):
await manager.clear()


@commands.command()
async def about(self, ctx):
"""Display information about the bot itself"""
embed = discord.Embed(colour=constants.BLUE)
#embed.url = 'https://discordapp.com/oauth2/authorize?client_id=335084645743984641&scope=bot&permissions=523344'

embed.description = ("[Invite Spirit](https://discordapp.com/oauth2/authorize?client_id=335084645743984641&scope=bot&permissions=523344)\n"
+ "[Spirit Support Server](https://discord.gg/GXCFpkr)")

owner = self.bot.get_user(118926942404608003)
embed.set_author(name=str(owner), icon_url=owner.avatar_url)

# statistics
total_members = sum(1 for _ in self.bot.get_all_members())
total_online = len({m.id for m in self.bot.get_all_members() if m.status is discord.Status.online})
total_unique = len(self.bot.users)

voice_channels = []
text_channels = []
for guild in self.bot.guilds:
voice_channels.extend(guild.voice_channels)
text_channels.extend(guild.text_channels)

text = len(text_channels)
voice = len(voice_channels)

embed.add_field(name='Members', value='{} total\n{} unique\n{} unique online'.format(total_members, total_unique, total_online))
embed.add_field(name='Channels', value='{} total\n{} text\n{} voice'.format(text + voice, text, voice))

memory_usage = "%0.2f" % (self.process.memory_full_info().uss / 1024**2)
cpu_usage = "%0.2f" % (self.process.cpu_percent() / psutil.cpu_count())
embed.add_field(name='Process', value='{} MiB\n{}% CPU'.format(memory_usage, cpu_usage))

embed.add_field(name='Guilds', value=len(self.bot.guilds))
embed.add_field(name='Commands Run', value=self.bot.command_count)
embed.add_field(name='Uptime', value=self.get_bot_uptime(brief=True))

embed.set_footer(text='Made with discord.py', icon_url='http://i.imgur.com/5BFecvA.png')
await ctx.send(embed=embed)


def get_bot_uptime(self, *, brief=False):
now = datetime.utcnow()
delta = now - self.bot.uptime
hours, remainder = divmod(int(delta.total_seconds()), 3600)
minutes, seconds = divmod(remainder, 60)
days, hours = divmod(hours, 24)

if not brief:
if days:
fmt = '{d} days, {h} hours, {m} minutes, and {s} seconds'
else:
fmt = '{h} hours, {m} minutes, and {s} seconds'
else:
fmt = '{h}h {m}m {s}s'
if days:
fmt = '{d}d ' + fmt

return fmt.format(d=days, h=hours, m=minutes, s=seconds)


async def on_guild_join(self, guild):
"""Send welcome message to the server owner"""
message = ("Greetings! My name is **{}**, and my sole responsibility is to help you and "
Expand Down
22 changes: 0 additions & 22 deletions cogs/owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,3 @@ async def broadcast_error(self, ctx, error):
manager = MessageManager(self.bot, ctx.author, ctx.channel, ctx.prefix, [ctx.message])
await manager.say("You didn't include a broadcast message")
return await manager.clear()


@commands.command(hidden=True)
async def botstats(self, ctx):
"""Displays the bot's stats"""
manager = MessageManager(self.bot, ctx.author, ctx.channel, ctx.prefix, [ctx.message])

if ctx.author.id not in constants.OWNERS:
return

num_guilds = len(self.bot.guilds)
users = []
for guild in self.bot.guilds:
if guild.id not in constants.SERVERS_NO_COUNT:
guild_users = [user for user in guild.members if not user.bot]
users.extend(guild_users)
num_users = len(set(users))

e = discord.Embed(title='{} Stats'.format(self.bot.user.name), colour=constants.BLUE)
e.description = "**Servers**: {}\n**Users**: {}".format(num_guilds, num_users)
await ctx.channel.send(embed=e)
await manager.clear()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pymysql==0.7.11
pytz==2017.2
psutil==5.3.1
6 changes: 6 additions & 0 deletions spirit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging
import asyncio
import datetime

import discord
from discord.ext import commands
Expand Down Expand Up @@ -41,10 +42,15 @@ def __init__(self, token):
super().__init__(command_prefix=_prefix_callable)
self.token = token
self.db = DBase('credentials.json')
self.uptime = datetime.datetime.utcnow()
self.command_count = 0

def run(self):
super().run(token, reconnect=True)

async def on_command(self, ctx):
self.command_count += 1


if __name__ == '__main__':

Expand Down

0 comments on commit c796210

Please sign in to comment.