Created
November 29, 2016 20:47
-
-
Save polyjitter/1b5cf0155542184b6212aaf1312ea47a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import discord | |
from discord.ext import commands | |
import traceback | |
class Info(): | |
def __init__(self, bot): | |
self.bot = bot | |
@commands.group(pass_context=True) | |
async def info(self, ctx): | |
'''Lets me snoop on all your private shnizz.''' | |
@info.command(name='server', aliases=['guild', 'discord', 'thisdangchat'], pass_context=True) | |
async def _serverinfo(self, ctx, *, server_str: str=None): | |
'''Provides info on a server.''' | |
if ctx.message.channel.is_private and server_str is None: | |
await self.bot.say(embed = discord.Embed(color = 15746887, | |
description = '**Error**: _Cannot be used in a DM without an explicit server._')) | |
return | |
if server_str is None: | |
server = ctx.message.server | |
else: | |
server = self.bot.get_server(server_str) | |
if server is None: | |
try: | |
server = self.discord.utils.get(bot.servers, name=server_str) | |
except Exception as e: | |
error_embed = discord.Embed(color = 15746887, | |
description = "**{}**: _{}_".format(e.__class__.__name__, str(e))) | |
traceback.print_exc() | |
await self.bot.say(embed = error_embed) | |
return | |
info_embed = discord.Embed() | |
info_embed.set_author(name = server.name, | |
icon_url = server.icon_url) | |
if server.owner is None: | |
server_owner = "**Error**: _Owner could not be found._" | |
else: | |
server_owner = server.owner.mention | |
info_embed.color = server.owner.color | |
info_embed.add_field(name = "Owner", value = server_owner) | |
info_embed.add_field(name = "ID", value = server.id) | |
info_embed.add_field(name = "Created At", value = server.created_at) | |
info_embed.add_field(name = "Channels", value = len(server.channels)) | |
info_embed.add_field(name = "Members", value = server.member_count) | |
info_embed.add_field(name = "Roles", value = len(server.roles)) | |
info_embed.add_field(name = "Region", value = str(server.region).replace("-", " ").title()) | |
info_embed.add_field(name = "AFK Timeout", value = "{} Minutes".format(server.afk_timeout/60).replace(".0", "")) | |
info_embed.add_field(name = "AFK Channel", value = server.afk_channel) | |
info_embed.add_field(name = "Verification Level", value = str(server.verification_level).title()) | |
if len(str(server.emojis)) < 1024 and server.emojis: | |
emoji_list = " ".join([str(emoji) for emoji in server.emojis]) | |
info_embed.add_field(name = "Emojis", value = emoji_list, inline = False) | |
elif len(str(server.emojis)) >= 1024: | |
emoji_list = "**Error**: _Too many emojis_" | |
info_embed.add_field(name = "Emojis", value = emoji_list, inline = False) | |
await self.bot.say(embed = info_embed) | |
@info.command(name='channel', aliases=['group', 'dm', 'pm', 'room', 'wall'], pass_context=True) | |
async def _channelinfo(self, ctx, *, channel: discord.Channel=None): | |
'''Provides info on a channel.''' | |
if channel is None: | |
channel = ctx.message.channel | |
if channel.is_private: | |
channel_topic = "Direct Message." | |
if channel.topic is "" or channel.topic is None: | |
channel_topic = "No Topic." | |
else: | |
channel_topic = channel.topic | |
info_embed = discord.Embed(description="_{}_".format(channel_topic)) | |
if channel.is_private: | |
info_embed.set_author(name = "DM: {}".format(channel.user.name)) | |
else: | |
info_embed.set_author(name = "#{}".format(channel.name)) | |
info_embed.add_field(name = "ID", value = channel.id) | |
info_embed.add_field(name = "Created At", value = channel.created_at) | |
if not channel.is_private: | |
info_embed.add_field(name = "Default", value = channel.is_default) | |
info_embed.add_field(name = "Position", value = channel.position + 1) | |
await self.bot.say(embed = info_embed) | |
@info.command(name='role', aliases=['title', 'tag', 'coloredbullshit'], pass_context=True) | |
async def _roleinfo(self, ctx, *, role: discord.Role=None): | |
'''Provides info on a role.''' | |
if ctx.message.channel.is_private: | |
await self.bot.say(embed = discord.Embed(color = 15746887, | |
description = "**Error**: _Cannot be used in a DM._")) | |
return | |
if role is None: | |
await self.bot.say(embed = discord.Embed(color = 15746887, | |
description = "**Error**: _No role provided._")) | |
return | |
info_embed = discord.Embed(color = role.color) | |
info_embed.set_author(name = "@{}".format(role.name)) | |
info_embed.add_field(name = "ID", value = role.id) | |
info_embed.add_field(name = "Created At", value = role.created_at) | |
if role.color.value is 0: | |
role_color = "None" | |
else: | |
role_color = role.color | |
info_embed.add_field(name = "Color", value = role_color) | |
info_embed.add_field(name = "Displayed Separately", value = role.hoist) | |
info_embed.add_field(name = "Mentionable", value = role.mentionable) | |
info_embed.add_field(name = "Position", value = role.position) | |
permissions_list = [] | |
for permission in iter(role.permissions): | |
if permission[1]: | |
permissions_list.append(permission[0]) | |
permissions_str = ", ".join(permissions_list).replace("_", " ").title() | |
if len(permissions_str) >= 1000: | |
info_embed.add_field(name = "Permissions", value = "***Error:***_Too many permissions._", inline=False) | |
elif len(permissions_str) == 0: | |
info_embed.add_field(name = "Permissions", value = "None", inline=False) | |
else: | |
info_embed.add_field(name = "Permissions", value = permissions_str, inline=False) | |
await self.bot.say(embed = info_embed) | |
@info.command(name='user', aliases=['person', 'account', 'member', 'muthafucka'], pass_context=True) | |
async def _userinfo(self, ctx, *, user : discord.Member=None): | |
'''Provides info on a user.''' | |
if user is None: | |
user = ctx.message.author | |
if ctx.message.channel.is_private: | |
embed_color = discord.Color.default() | |
else: | |
embed_color = user.color | |
info_embed = (discord.Embed(color = embed_color)) | |
info_embed.set_author(name = "@{}#{}".format(user.name, user.discriminator)) | |
info_embed.set_thumbnail(url = user.avatar_url) | |
info_embed.add_field(name = "ID", value = user.id) | |
info_embed.add_field(name = "Created At", value = user.created_at) | |
if not ctx.message.channel.is_private: | |
info_embed.add_field(name = "Joined At", value = user.joined_at) | |
info_embed.add_field(name = "Status", value = str(user.status).title()) | |
info_embed.add_field(name = "Nickname", value = user.nick) | |
if user.color.value is 0: | |
user_color = "None" | |
else: | |
user_color = user.color | |
info_embed.add_field(name = "Color", value = user_color) | |
info_embed.add_field(name = "Game", value = user.game) | |
role_list = ", ".join(role.name for role in user.roles[1:]) | |
if len(role_list) >= 500: | |
info_embed.add_field(name = "Roles", value = "**Error:***_Too many roles._", inline=False) | |
elif len(role_list) == 0: | |
info_embed.add_field(name = "Roles", value = "None", inline=False) | |
else: | |
info_embed.add_field(name = "Roles", value = role_list, inline=False) | |
await self.bot.say(embed=info_embed) | |
@info.command(name='emoji', aliases=['emote', 'facething'], pass_context=True) | |
async def _emojiinfo(self, ctx, *, emoji: discord.Emoji=None): | |
'''Provides info on an emoji.''' | |
if emoji is None: | |
await bot.say(color = 15746887, | |
description = "**Error**: _No emoji provided._") | |
return | |
info_embed = discord.Embed() | |
info_embed.set_author(name = ":{}:".format(emoji.name)) | |
info_embed.set_thumbnail(url = emoji.url) | |
info_embed.add_field(name = "ID", value = emoji.id) | |
info_embed.add_field(name = "Server", value = emoji.server.name) | |
info_embed.add_field(name = "Created At", value = str(emoji.created_at)) | |
info_embed.add_field(name = "Twitch Integrated", value = emoji.managed) | |
await self.bot.say(embed=info_embed) | |
@commands.group(pass_context=True, invoke_without_command=True) | |
async def count(self, ctx): | |
'''Counts things I am in or have.''' | |
count_embed = discord.Embed() | |
count_embed.add_field(name="Servers", value=len(self.bot.servers)) | |
await self.bot.say(embed=count_embed) | |
@count.command(name='servers', aliases=['myhells', 'server', 'guilds', 'discords'], pass_context=True) | |
async def _servercount(self, ctx): | |
'''Counts my servers.''' | |
count_embed = discord.Embed() | |
server_num = len(self.bot.servers) | |
server_list = ", ".join([server.name for server in self.bot.servers]) | |
count_embed.description = "_I am in {} servers._\n\n{}".format(server_num, server_list) | |
await self.bot.say(embed=count_embed) | |
def setup(bot): | |
bot.add_cog(Info(bot)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment