<commit_before>
import discord
from discord.ext import commands

from utilities import checks

def setup(bot):
	bot.add_cog(RotMG(bot))

class RotMG(commands.Cog):
	
	def __init__(self, bot):
		self.bot = bot
	
	async def cog_check(self, ctx):
		return await checks.not_forbidden().predicate(ctx)
	
	@commands.group(aliases = ["realmofthemadgod"], invoke_without_command = True, case_insensitive = True)
	async def rotmg(self, ctx, player : str):
		'''Realm of the Mad God player information'''
		url = "https://nightfirec.at/realmeye-api/?player={}".format(player)
		# http://webhost.ischool.uw.edu/~joatwood/realmeye_api/0.3/
		async with ctx.bot.aiohttp_session.get(url) as resp:
			data = await resp.json()
		if "error" in data:
			await ctx.embed_reply("Error: " + data["error"])
			return
		embed = discord.Embed(title = data["player"], url = "https://www.realmeye.com/player/{}".format(player), color = ctx.bot.bot_color)
		embed.set_author(name = ctx.author.display_name, icon_url = ctx.author.avatar_url)
		if data["donator"] == "true": embed.description = "Donator"
		embed.add_field(name = "Characters", value = data["chars"])
		embed.add_field(name = "Total Fame", value = "{:,}".format(data["fame"]))
		embed.add_field(name = "Fame Rank", value = "{:,}".format(data["fame_rank"]))
		embed.add_field(name = "Class Quests Completed", value = data["rank"])
		embed.add_field(name = "Account Fame", value = "{:,}".format(data["account_fame"]))
		embed.add_field(name = "Account Fame Rank", value = "{:,}".format(data["account_fame_rank"]))
		embed.add_field(name = "Created", value = data["created"])
		embed.add_field(name = "Total Exp", value = "{:,}".format(data["exp"]))
		embed.add_field(name = "Exp Rank", value = "{:,}".format(data["exp_rank"]))
		embed.add_field(name = "Last Seen", value = data["player_last_seen"])
		if "guild" in data:
			embed.add_field(name = "Guild", value = data["guild"])
			embed.add_field(name = "Guild Position", value = data["guild_rank"])
		if data["desc1"] or data["desc2"] or data["desc3"]:
			embed.add_field(name = "Description", value = "{}\n{}\n{}".format(data["desc1"], data["desc2"], data["desc3"]))
		await ctx.send(embed = embed)
	
	@rotmg.command(name = "characters")
	async def rotmg_characters(self, ctx, player : str):
		'''Realm of the Mad God player characters information'''
		url = "https://nightfirec.at/realmeye-api/?player={}".format(player)
		# http://webhost.ischool.uw.edu/~joatwood/realmeye_api/0.3/
		async with ctx.bot.aiohttp_session.get(url) as resp:
			data = await resp.json()
		if "error" in data:
			await ctx.embed_reply("Error: " + data["error"])
			return
		embed = discord.Embed(title = "{}'s Characters".format(data["player"]), color = ctx.bot.bot_color)
		embed.set_author(name = ctx.author.display_name, icon_url = ctx.author.avatar_url)<commit_msg>[Discord] Check existence of created data from RotMG API before using it<commit_after>
import discord
from discord.ext import commands

from utilities import checks

def setup(bot):
	bot.add_cog(RotMG(bot))

class RotMG(commands.Cog):
	
	def __init__(self, bot):
		self.bot = bot
	
	async def cog_check(self, ctx):
		return await checks.not_forbidden().predicate(ctx)
	
	@commands.group(aliases = ["realmofthemadgod"], invoke_without_command = True, case_insensitive = True)
	async def rotmg(self, ctx, player : str):
		'''Realm of the Mad God player information'''
		url = "https://nightfirec.at/realmeye-api/?player={}".format(player)
		# http://webhost.ischool.uw.edu/~joatwood/realmeye_api/0.3/
		async with ctx.bot.aiohttp_session.get(url) as resp:
			data = await resp.json()
		if "error" in data:
			await ctx.embed_reply("Error: " + data["error"])
			return
		embed = discord.Embed(title = data["player"], url = "https://www.realmeye.com/player/{}".format(player), color = ctx.bot.bot_color)
		embed.set_author(name = ctx.author.display_name, icon_url = ctx.author.avatar_url)
		if data["donator"] == "true": embed.description = "Donator"
		embed.add_field(name = "Characters", value = data["chars"])
		embed.add_field(name = "Total Fame", value = "{:,}".format(data["fame"]))
		embed.add_field(name = "Fame Rank", value = "{:,}".format(data["fame_rank"]))
		embed.add_field(name = "Class Quests Completed", value = data["rank"])
		embed.add_field(name = "Account Fame", value = "{:,}".format(data["account_fame"]))
		embed.add_field(name = "Account Fame Rank", value = "{:,}".format(data["account_fame_rank"]))
		if created := data.get("created"):
			embed.add_field(name = "Created", value = created)
		embed.add_field(name = "Total Exp", value = "{:,}".format(data["exp"]))
		embed.add_field(name = "Exp Rank", value = "{:,}".format(data["exp_rank"]))
		embed.add_field(name = "Last Seen", value = data["player_last_seen"])
		if "guild" in data:
			embed.add_field(name = "Guild", value = data["guild"])
			embed.add_field(name = "Guild Position", value = data["guild_rank"])
		if data["desc1"] or data["desc2"] or data["desc3"]:
			embed.add_field(name = "Description", value = "{}\n{}\n{}".format(data["desc1"], data["desc2"], data["desc3"]))
		await ctx.send(embed = embed)
	
	@rotmg.command(name = "characters")
	async def rotmg_characters(self, ctx, player : str):
		'''Realm of the Mad God player characters information'''
		url = "https://nightfirec.at/realmeye-api/?player={}".format(player)
		# http://webhost.ischool.uw.edu/~joatwood/realmeye_api/0.3/
		async with ctx.bot.aiohttp_session.get(url) as resp:
			data = await resp.json()
		if "error" in data:
			await ctx.embed_reply("Error: " + data["error"])
			return
		embed = discord.Embed(title = "{}'s Characters".format(data["player"]), color = ctx.bot.bot_color)
		embed.set_author(name = ctx.author.display_name, icon_url = ctx.author.avatar_url)
{'fraction_non_alphanumeric': 0.18156570039923625, 'fraction_numerical': 0.003471619510501649, 'mean_word_length': 5.052521008403361, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3787318', 'n_tokens_mistral': 2155, 'n_tokens_neox': 2011, 'n_words': 423}