phenom4n4n / phen-cogs

My public cogs for Red, Discord bot.
https://phen-cogs.readthedocs.io/en/latest/
MIT License
120 stars 71 forks source link

[repo] dpy2 asynchronous cog loading changes #129

Closed japandotorg closed 2 years ago

japandotorg commented 2 years ago

So uhh the dpy2 wasn't working for my dpy2_unstable branch of red and then i figured that it was bc the extensions weren't awaited, this PR will address those changes for the dpy2_unstable branch of red, had to have it done bc phen-cogs being the most used red-cog at the moment

  1. Have you tested the PR?
    • yes i have, and it works just as fine now with the dpy2_unstable branch
phenom4n4n commented 2 years ago

Thanks for this PR. In order for it to be fully complete, the cogs should take advantage of the benefits that come with asynchronous cog loading. Specifically, the following changes also need to be made:

If you have questions about making these changes, feel free to ask in a comment.

japandotorg commented 2 years ago

sure, thanks for informing me, i'll start addressing them as soon as i'm on my pc and yes i'll post a comment if i need any help or whatsoever

japandotorg commented 2 years ago

After checking all the files thoroughly i have awaited all the coroutines and all the possible stuff that needed to be made asynchronous ( where i felt it was the right thing to do ), and I guess this is it for now, let me know if anything else needs a change or whatsoever.

japandotorg commented 2 years ago

alright ty for pointing out all the stuff, i'll change them right away and test them

japandotorg commented 2 years ago

i'll start testing all the changes now

japandotorg commented 2 years ago

error so the TagScriptEngine lib needs changes to be made.

japandotorg commented 2 years ago

custom-ping-error

this was invoked when testing the customping cog, was working fine before making the cog_load change.

japandotorg commented 2 years ago
AttributeError: 'Member' object has no attribute 'avatar_url'
Ignoring exception in command tree:
Traceback (most recent call last):
  File "/root/env/lib/python3.9/site-packages/discord/app_commands/tree.py", line 881, in wrapper
    await self.call(interaction)
  File "/root/env/lib/python3.9/site-packages/discord/app_commands/tree.py", line 1020, in call
    command, options = self._get_app_command_options(data)
  File "/root/env/lib/python3.9/site-packages/discord/app_commands/tree.py", line 911, in _get_app_command_options
    raise CommandNotFound(name, parents)
discord.app_commands.errors.CommandNotFound: Application command 'ping' not found
Ignoring exception in view <ConfirmationView timeout=60 children=2> for item <Button style=<ButtonStyle.secondary: 2> url=None disabled=True label='No' emoji=None row=None>:
Traceback (most recent call last):
  File "/root/env/lib/python3.9/site-packages/discord/ui/view.py", line 413, in _scheduled_task
    await item.callback(interaction)
  File "/root/.local/share/Red-DiscordBot/data/esdeath/cogs/CogManager/cogs/slashtags/views.py", line 108, in no
    await self.disable_all(button, interaction)
  File "/root/.local/share/Red-DiscordBot/data/esdeath/cogs/CogManager/cogs/slashtags/views.py", line 115, in disable_all
    await interaction.response.edit_message(view=self)
AttributeError: 'Button' object has no attribute 'response'
[08:26:05] CRITICAL [red.main] Caught unhandled exception in <Task finished name='discord-ui-view-timeout-2e45611ecbe546b2fc67c08cbc5c188a' coro=<ConfirmationView.on_timeout() done, defined at /root/.local/share/Red-DiscordBot/data/esdeath/cogs/CogManager/cogs/slashtags/views.py:117> exception=NotFound('404 Not Found (error code: 10008): Unknown Message')>:
Task exception was never retrieved
╭───────────────────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────────────────────────────────────────────────────╮
│ /root/.local/share/Red-DiscordBot/data/esdeath/cogs/CogManager/cogs/slashtags/views.py:119 in on_timeout                                                                                                    │
│ ❱ 119         await self.message.edit(view=self)                                                                                                                                                            │
│ /root/env/lib/python3.9/site-packages/discord/message.py:1984 in edit                                                                                                                                       │
│ ❱ 1984         data = await self._state.http.edit_message(self.channel.id, self.id,                                                                                                                         │
│        params=params)                                                                                                                                                                                       │
│ /root/env/lib/python3.9/site-packages/discord/http.py:493 in request                                                                                                                                        │
│ ❱  493                             raise NotFound(response, data)                                                                                                                                           │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
NotFound: 404 Not Found (error code: 10008): Unknown Message
Ignoring exception in command tree:
Traceback (most recent call last):
  File "/root/env/lib/python3.9/site-packages/discord/app_commands/tree.py", line 881, in wrapper
    await self.call(interaction)
  File "/root/env/lib/python3.9/site-packages/discord/app_commands/tree.py", line 1020, in call
    command, options = self._get_app_command_options(data)
  File "/root/env/lib/python3.9/site-packages/discord/app_commands/tree.py", line 911, in _get_app_command_options
    raise CommandNotFound(name, parents)
discord.app_commands.errors.CommandNotFound: Application command 'hi' not found

this is the error for slashtags

japandotorg commented 2 years ago

Okay so after extensive use of my single braincell I've fixed whatever I could and tested each and every cog + the sub commands, and all that is left are the tags and slashtags cog ( TagScriptEngine lib related ) and the customping cog.

phenom4n4n commented 2 years ago

error

so the TagScriptEngine lib needs changes to be made.

These changes have already been made, you need to install the dpy2 branch instead.

japandotorg commented 2 years ago

The dpy2 branch of TagScriptEngine??

phenom4n4n commented 2 years ago
Ignoring exception in command tree:

Traceback (most recent call last):

  File "/root/env/lib/python3.9/site-packages/discord/app_commands/tree.py", line 881, in wrapper

    await self.call(interaction)

  File "/root/env/lib/python3.9/site-packages/discord/app_commands/tree.py", line 1020, in call

    command, options = self._get_app_command_options(data)

  File "/root/env/lib/python3.9/site-packages/discord/app_commands/tree.py", line 911, in _get_app_command_options

    raise CommandNotFound(name, parents)

discord.app_commands.errors.CommandNotFound: Application command 'hi' not found

this is the error for slashtags

Do slashtags still work when invoked? As far as I can tell, this error should only be logged implicitly but won't prevent slashtags from being invoked. I'm going to fix it at a later date.

phenom4n4n commented 2 years ago

Ignoring exception in view <AkiView timeout=60 children=8> for item <Button style=<ButtonStyle.success: 3> url=None disabled=False label='yes' emoji=None row=None>:

Traceback (most recent call last):

  File "/root/env/lib/python3.9/site-packages/discord/ui/view.py", line 413, in _scheduled_task

    await item.callback(interaction)

  File "/root/.local/share/Red-DiscordBot/data/esdeath/cogs/CogManager/cogs/aki/views.py", line 44, in yes

    await self.answer_question("yes", interaction)

  File "/root/.local/share/Red-DiscordBot/data/esdeath/cogs/CogManager/cogs/aki/views.py", line 87, in answer_question

    await self.send_current_question(interaction)

  File "/root/.local/share/Red-DiscordBot/data/esdeath/cogs/CogManager/cogs/aki/views.py", line 167, in send_current_question

    await self.edit(interaction)

  File "/root/.local/share/Red-DiscordBot/data/esdeath/cogs/CogManager/cogs/aki/views.py", line 156, in edit

    await interaction.message.edit(embed=self.current_question_embed(), view=self)

AttributeError: 'Button' object has no attribute 'message'

fixed the error for aki

I forgot about this change, can you go through all view callbacks in the repo and change the signature from (self, button: discord.ui.Button, interaction: discord.Interaction) to `(self, interaction: discord.Interaction, button: discord.ui.Button)?

phenom4n4n commented 2 years ago

The dpy2 branch of TagScriptEngine??

Yeah, but that's unrelated to this PR.

japandotorg commented 2 years ago

Do slashtags still work when invoked? As far as I can tell, this error should only be logged implicitly but won't prevent slashtags from being invoked. I'm going to fix it at a later date.

nope it doesn't for some reason, thought it would be bc of the lib, but I guess I'm wrong here.

japandotorg commented 2 years ago

I forgot about this change, can you go through all view callbacks in the repo and change the signature from (self, button: discord.ui.Button, interaction: discord.Interaction) to `(self, interaction: discord.Interaction, button: discord.ui.Button)?

Sure, i'll address them and do it right away.

phenom4n4n commented 2 years ago

Thanks for making the changes I asked for throughout this PR!