corpnewt / CorpBot.py

A very clumsy python bot for discord
MIT License
194 stars 91 forks source link

PCPP Command #147

Closed polarflex closed 9 months ago

polarflex commented 9 months ago

I could be stupid, however whenever I try to use the $pcpp list, whatever link I try or whatever I do, the bot always responds with: Something went wrong! Make sure you use a valid pcpartpicker link.

Along with that, the autopcpp command once sent it says "Auto pcpartpicker disabled", afterwards if you send it again it doesn't reply with anything, and once again after sending that it just says "Auto pcpartpicker disabled". After "turning on" the autopcpp command, and sending a link, the bot does nothing.

corpnewt commented 9 months ago

Can you send the pcpartpicker link you're using?

-CorpNewt

polarflex commented 9 months ago

Here it is: https://pcpartpicker.com/list/8JdBGP

I tried using it without https:// before as well.

corpnewt commented 9 months ago

It appears to work fine on my instance of the bot. You could look into adding some debug prints in the PCPP.py file and see if that reveals anything else.

Screenshot_20231211-114441

-CorpNewt

polarflex commented 9 months ago

I'll try redownloading the source and reconfiguring it again, if that doesn't work I'll see if I can debug it.

corpnewt commented 9 months ago

Sounds good, please let me know how it goes.

-CorpNewt

polarflex commented 9 months ago

Just reinstalled it, maybe there is something that I haven't setup but I still got the same error: image

Gonna see if I can add the prints now.

polarflex commented 9 months ago

Just leads me to the if condition: print(f"Processing PCPP command with URL: {url}, Style: {style}, Escape: {escape}") output = await PCPP.getMarkdown(url, style, escape) if not output: print("PCPP command failed. Invalid pcpartpicker link.") msg = 'Something went wrong! Make sure you use a valid pcpartpicker link.' return await ctx.send(msg) if len(output) > 2000: msg = "That's an *impressive* list of parts - but the max length allowed for messages in Discord is 2000 characters, and you're at *{}*.".format(len(output)) msg += '\nMaybe see if you can prune up that list a bit and try again?' return await ctx.send(msg) print("PCPP command successful. Sending output.") await ctx.send(output)

image

image

polarflex commented 9 months ago

Erm the code wasn't supposed to be like that, here's a screenshot for better readability: image

corpnewt commented 9 months ago

Maybe try commenting out the try/except here and see if it throws an exception: https://github.com/corpnewt/CorpBot.py/blob/rewrite/Cogs/PCPP.py#L125

It may also be related to the User-Agent passed, but I would think that would prevent it from working for me as well.

polarflex commented 9 months ago

Yes it did, here's the full log: Ignoring exception in command pcpp: Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 178, in wrapped ret = await coro(*args, **kwargs) File "C:\Users\user\Desktop\CorpBot.py-rewrite\Cogs\Hw.py", line 96, in pcpp output = await PCPP.getMarkdown(url, style, escape) File "C:\Users\user\Desktop\CorpBot.py-rewrite\Cogs\PCPP.py", line 134, in getMarkdown for i in response.split("\n"): UnboundLocalError: local variable 'response' referenced before assignment

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\bot.py", line 347, in invoke await ctx.command.invoke(ctx) File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 950, in invoke await injected(*ctx.args, **ctx.kwargs) File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 187, in wrapped raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an exception: UnboundLocalError: local variable 'response' referenced before assignment

corpnewt commented 9 months ago

You'd still need the line where response is set, just comment out (or remove) the try/except stuffs. The following line still needs to be there:

response = await DL.async_text(url,{"user-agent":"Mozilla"})

You can also try removing the User-Agent:

response = await DL.async_text(url)
polarflex commented 9 months ago

Got this error now:

Processing PCPP command with URL: https://pcpartpicker.com/list/sJdBGP, Style: normal, Escape: False Ignoring exception in command pcpp: Traceback (most recent call last): File "C:\Users\chima\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 178, in wrapped ret = await coro(*args, **kwargs) File "C:\Users\chima\Desktop\CorpBot.py-rewrite\Cogs\Hw.py", line 96, in pcpp output = await PCPP.getMarkdown(url, style, escape) File "C:\Users\chima\Desktop\CorpBot.py-rewrite\Cogs\PCPP.py", line 127, in getMarkdown response = await DL.async_text(url,{"user-agent":"Mozilla"}) File "C:\Users\chima\Desktop\CorpBot.py-rewrite\Cogs\DL.py", line 48, in async_text data = await async_dl(url, headers, ssl) File "C:\Users\chima\Desktop\CorpBot.py-rewrite\Cogs\DL.py", line 34, in async_dl assert response.status == 200 AssertionError

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:\Users\chima\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\bot.py", line 347, in invoke await ctx.command.invoke(ctx) File "C:\Users\chima\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 950, in invoke await injected(*ctx.args, **ctx.kwargs) File "C:\Users\chima\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 187, in wrapped raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AssertionError:

image

polarflex commented 9 months ago

I tried removing the user agent as well

corpnewt commented 9 months ago

Yeah, pcpartpicker is returning a status that is not 200, which means something is wrong reaching the site/loading the URL. It's likely a network error of some kind, but I don't know beyond that. You can edit DL.py to print what the status code is and see, but I would bet it's a 403 forbidden or similar. If you have a VPN, try changing your connection or similar.

polarflex commented 9 months ago

Yes I got: assert response.status == 200, f"status isn't ok: {response.status}, url: {url}" AssertionError: status isn't ok: 403, url: https://pcpartpicker.com/list/sJdBGP

pcpp hates me :(

corpnewt commented 9 months ago

It does sound like it's quite angry with you :/

You can try a VPN, another computer, etc - but I'm not sure what else to tell you. I hope you're able to get the issue resolved, but as it's not a problem with the bot itself I'll close this issue thread.

-CorpNewt

polarflex commented 4 months ago

This is quite old now, but I tried it on an Azure Linux Server and I still had the same problem, if you are using a hosting which one are you using?

corpnewt commented 4 months ago

I run the bot on a local machine - and I have not had any issues with PCPP.

-CorpNewt

polarflex commented 4 months ago

Alright thanks I'll get my friend to try it

corpnewt commented 4 months ago

Hopefully that's all it is!

-CorpNewt