async def _parse_date(self, ctx: commands.Context, *, date: str): """ date parser """ try: date = parse.Date.parse(date) except (error.ParserError) as e: await ctx.message.add_reaction("\U0000274e") await ctx.send(format.inline(e.original)) else: await ctx.message.add_reaction("\U00002705") await ctx.send(format.inline(format.humanize_datetime(date)))
async def _parse_boolean(self, ctx: commands.Context, *, boolean: str): """ boolean parser """ try: boolean = parse.boolean(boolean) except (error.ParserError) as e: await ctx.message.add_reaction("\U0000274e") await ctx.send(format.inline(e.original)) else: await ctx.message.add_reaction("\U00002705") await ctx.send(format.inline(boolean))
async def _parse_color(self, ctx: commands.Context, *, color: str): """ color parser """ try: color = parse.Color.parse(color) except (error.ParserError) as e: await ctx.message.add_reaction("\U0000274e") await ctx.send(format.inline(e.original)) else: await ctx.message.add_reaction("\U00002705") await ctx.send(format.inline(color))
async def _parse_url(self, ctx: commands.Context, *, url: str): """ url parser """ try: url = parse.url(url) except (error.ParserError) as e: await ctx.message.add_reaction("\U0000274e") await ctx.send(format.inline(e.original)) else: await ctx.message.add_reaction("\U00002705") await ctx.send(format.inline(url))
async def _parse_version(self, ctx: commands.Context, version: str): """ version parser """ try: version = parse.version(version) except (error.ParserError) as e: await ctx.message.add_reaction("\U0000274e") await ctx.send(format.inline(e.original)) else: await ctx.message.add_reaction("\U00002705") await ctx.send(format.inline(version))
async def _parse_snowflake(self, ctx: commands.Context, snowflake: int): """ snowflake parser """ try: snowflake = parse.snowflake(snowflake) except (error.ParserError) as e: await ctx.message.add_reaction("\U0000274e") await ctx.send(format.inline(e.original)) else: await ctx.message.add_reaction("\U00002705") await ctx.send(format.inline(snowflake))
async def _parse_flags(self, ctx: commands.Context, *, flags: str): """ flags parser """ try: flags = parse.Flags.parse(flags) except (error.ParserError) as e: await ctx.message.add_reaction("\U0000274e") await ctx.send(format.inline(e.original)) else: await ctx.message.add_reaction("\U00002705") await ctx.send(format.inline(flags))
async def uptime(self, ctx): """shows bot uptime""" td = datetime.datetime.utcnow() - self.bot.uptime await self.bot.sendc( ctx, fmt.inline( f"Botuptime: {td.days} Days, {td.seconds // 3600} Hours and {(td.seconds // 60) % 60} Minutes" ), )
async def imdb_search(self, query_type, query: str): emb = None rip = "" search_url = f"http://www.omdbapi.com/?apikey={self.config['omdb']}&type={query_type}&s={query}" async with aiohttp.ClientSession() as session: async with session.get(search_url) as search_response: if search_response.status != 200: err = f"The api-webserver responded with a code:{search_response.status} - {search_response.reason}" raise NerpyException(err) search_result = await search_response.json() if search_result["Response"] == "True": id_url = ( f"http://www.omdbapi.com/?apikey={self.config['omdb']}&i=" + search_result["Search"][0]["imdbID"]) async with session.get(id_url) as id_response: if id_response.status != 200: err = f"The api-webserver responded with a code:{id_response.status} - {id_response.reason}" raise NerpyException(err) id_result = await id_response.json() emb = discord.Embed(title=id_result["Title"]) emb.description = id_result["Plot"] emb.set_thumbnail(url=id_result["Poster"]) emb.add_field(name=fmt.bold("Released"), value=id_result["Released"]) emb.add_field(name=fmt.bold("Genre"), value=id_result["Genre"]) emb.add_field(name=fmt.bold("Runtime"), value=id_result["Runtime"]) emb.add_field(name=fmt.bold("Country"), value=id_result["Country"]) emb.add_field(name=fmt.bold("Language"), value=id_result["Language"]) emb.add_field(name=fmt.bold("Director"), value=id_result["Director"]) emb.add_field(name=fmt.bold("Actors"), value=id_result["Actors"]) emb.set_footer( text="Powered by https://www.omdbapi.com/") else: rip = fmt.inline("No movie found with this search query") return rip, emb
async def membercount(self, ctx): """displays the current membercount of the server [bot-moderator]""" await self.bot.sendc(ctx, fmt.inline(f"There are currently {ctx.guild.member_count} members on this discord"))