diff --git a/app/cogs/actual_utils.py b/app/cogs/actual_utils.py index 27b2835e..eead5eed 100644 --- a/app/cogs/actual_utils.py +++ b/app/cogs/actual_utils.py @@ -1,4 +1,5 @@ from discord.ext import commands +from discord.commands import Option import discord import os import get_from_reddit @@ -10,8 +11,19 @@ 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): + @commands.slash_command( + guild_ids=None, + name="youtube", + aliases=["yt"], + description="Search youtube for the passed in query", + ) + async def youtube( + self, + ctx, + query: Option( + str, "What video you want to search for on youtube", required=True + ), + ): import re from urllib import parse, request @@ -21,7 +33,8 @@ class ActualUtils(commands.Cog): result = "https://www.youtube.com/watch?v=" + search_results[0] - await ctx.reply(result) + await ctx.defer() + await ctx.followup.send(result) @commands.command(name="issue") async def issue(self, ctx: commands.Context): @@ -67,19 +80,32 @@ class ActualUtils(commands.Cog): ) @commands.has_role("stable-diffuser") - @commands.command(name="sd") - async def sd(self, ctx: commands.Context, *, prompt): + @commands.slash_command( + guild_ids=None, + name="sd", + description="Pass a prompt and optinal negative prompt to stable diffusion", + ) + async def sd( + self, + ctx: commands.Context, + positive_prompt: Option( + str, "The positive prompt to send to stable-diffusion", required=True + ), + negative_prompt: Option( + str, + "An optinal negative prompt to send to stable-diffusion", + required=False, + ), + ): import socket import stable_diffusion port = "7860" ip = "192.168.1.80" steps = 20 - negatives = "" - positives = prompt # Send my requests to my gaming computer with the 3080 (if its up) - if ctx.message.author.id == 144986109804412928: + if ctx.author.id == 144986109804412928: ip = "192.168.1.188" steps = 60 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -90,14 +116,16 @@ class ActualUtils(commands.Cog): ip = "192.168.1.80" try: - original_message = await ctx.reply( + await ctx.defer() + original_message = await ctx.followup.send( "Please be patient, I'm generating your image" ) - if ";" in prompt: - positives = prompt.split(";")[0] - negatives = prompt.split(";")[1] file_path = await stable_diffusion.generate_image( - ip=ip, port=port, positives=positives, negatives=negatives, steps=steps + ip=ip, + port=port, + positives=positive_prompt, + negatives=negative_prompt or None, + steps=steps, ) await original_message.edit( content="", @@ -113,11 +141,16 @@ class ActualUtils(commands.Cog): ) @commands.has_role("Track day gamers") - @commands.command(name="trackdays") + @commands.slash_command( + guild_ids=None, + name="trackdays", + description="Query motorsportsreg.com for a list of trackdays going on at Buttonwillow and Thunderhill", + ) async def trackdays(self, ctx: commands.Context): import trackdays - for track, events in trackdays.get_msreg().items(): + shid = await trackdays.get_msreg() + for track, events in shid.items(): embed = discord.Embed( description=":checkered_flag: **Upcoming events at %s**:checkered_flag: " % track, @@ -136,8 +169,7 @@ class ActualUtils(commands.Cog): embed.add_field( name="Event URL", value=track_day["event_url"], inline=False ) - - await ctx.reply(embed=embed) + await ctx.send(embed=embed) @commands.command(name="corona", aliases=["covid"]) async def corona(self, ctx: commands.Context, *, location=None): diff --git a/app/cogs/poll.py b/app/cogs/poll.py index cd264ab6..133cb017 100644 --- a/app/cogs/poll.py +++ b/app/cogs/poll.py @@ -35,7 +35,10 @@ class QuickPoll(commands.Cog): for x, option in enumerate(options): description += "\n {} {}".format(reactions[x], option) embed = discord.Embed(title=question, description="".join(description)) - react_message = await ctx.send(embed=embed) + + await ctx.defer() + react_message = await ctx.followup.send(embed=embed) + for reaction in reactions[: len(options)]: await react_message.add_reaction(reaction) embed.set_footer(text="Poll ID: {}".format(react_message.id)) diff --git a/app/help_methods.py b/app/help_methods.py index e61eb7cc..68aa7a4e 100644 --- a/app/help_methods.py +++ b/app/help_methods.py @@ -79,7 +79,7 @@ def get_help_message(method): "emoji": [ "Uploads the passed in URL to the server as an emoji.", "\nDiscord does not support GIFS. It will throw an error if you try." - "\nUsage: !emoji http://pictures.com/some_image.png my_new_emoji\n" + "\nUsage: !emoji http://pictures.com/some_image.png my_new_emoji\n", ], "excuse": [ "Generates a random excuse you can give your boss", diff --git a/app/trackdays.py b/app/trackdays.py index 8cba86a2..30d8dd2f 100755 --- a/app/trackdays.py +++ b/app/trackdays.py @@ -1,10 +1,10 @@ from datetime import datetime import json -import requests +import httpx import xmltodict -def get_msreg(): +async def get_msreg(): base_url = "https://api.motorsportreg.com/rest/calendars/organization" orgs = { "speeddistrict": "2E22740B-E8C9-9FB9-21406A496429A28B", @@ -18,13 +18,15 @@ def get_msreg(): "socaldriversclub": "B4FC0113-C903-E9D3-68562D6765806945", } events = {} + client = httpx.AsyncClient() for org_name, org_id in orgs.items(): - xml_blob = requests.get( + xml_blob = await client.get( "%s/%s?exclude_cancelled=true&postalcode=94549&radius=500" % (base_url, org_id) - ).text + ) + awaited_xml_blob = xml_blob.text json_blob = json.loads( - json.dumps(xmltodict.parse(xml_blob)["response"]["events"]) + json.dumps(xmltodict.parse(awaited_xml_blob)["response"]["events"]) ) try: