from discord.ext import commands import discord import os import get_from_reddit import core_utils import requests class ActualUtils(commands.Cog): def __init__(self, bot): self.bot: commands.Bot = bot @commands.command(name="youtube", aliases=["yt"]) async def youtube(self, ctx: commands.Context, *, query): import re from urllib import parse, request query_string = parse.urlencode({"search_query": query}) html_content = request.urlopen("http://www.youtube.com/results?" + query_string) search_results = re.findall("\/watch\?v=(.{11})", html_content.read().decode()) result = "https://www.youtube.com/watch?v=" + search_results[0] await ctx.reply(result) @commands.command(name="issue") async def issue(self, ctx: commands.Context): import gitlab await ctx.send(gitlab.parse_message(ctx.message)) @commands.command(name="tts") async def tts(self, ctx: commands.Context): import tts if ctx.message.content.split()[1] == "langs": await ctx.send("Ok {}, check your DMs".format(ctx.message.author.mention)) return await ctx.message.author.send(tts.get_all_langs()) file_path = tts.text_to_speech(ctx.message.content) await ctx.send( file=discord.File( file_path, filename="A Message From {}.mp3".format(ctx.message.author.name), ) ) await ctx.message.delete() os.remove(file_path) @commands.command(name="trackdays") async def trackdays(self, ctx: commands.Context): role = discord.utils.find( lambda r: r.name == "Track day gamers", ctx.message.guild.roles ) if role not in ctx.message.author.roles: return await ctx.send("You cant do that") import trackdays for track, events in trackdays.get_msreg().items(): embed = discord.Embed( description=":checkered_flag: **Upcoming events at %s**:checkered_flag: " % track, color=0x428BCA, type="rich", ) for track_day in events: embed.add_field( name="-------------\n**Event Name**", value=track_day["event_name"], inline=False, ) embed.add_field( name="Date", value=track_day["event_date"], inline=False ) embed.add_field( name="Event URL", value=track_day["event_url"], inline=False ) await ctx.sereplynd(embed=embed) @commands.command(name="corona", aliases=["covid"]) async def corona(self, ctx: commands.Context, *, location=None): import corona async with ctx.message.channel.typing(): result = corona.parse_message(location) await ctx.send(embed=result) @commands.command(name="stock") async def stock(self, ctx: commands.Context): msg = ctx.message.content if len(msg.split()) < 2: import help_methods await ctx.send(help_methods.get_help_message("stock")) import stock results = stock.parse_message(msg) for res in results: await ctx.reply(embed=res) def setup(bot): bot.add_cog(ActualUtils(bot))