weidengeist / Willowbot

A chat bot intended to be used on Twitch
GNU General Public License v3.0
4 stars 0 forks source link

Can't launch new version #10

Closed LeoAlt8 closed 1 year ago

LeoAlt8 commented 1 year ago

I try different OS and everywhere the same answer. Maybe I'm doing something wrong?

Windows 11 + Python 3.9: image

Ubuntu 20.04 + Python 3.11: image

Ubuntu 22.04 + Python 3.10: image

Files are not created. Directories are not created.

P.S. There was another error "UnicodeEncodeError: 'latin-1' codec can't encode character '\u2573' in position 1: ordinal not in range(256)" Changed the cross to ! in file basics.py
image ➡️ image

weidengeist commented 1 year ago

Thank you very much for pointing this out. The issue was related to a wrong order of loading the modules. I have fixed that and you can create configuration files now.

Furthermore, I have replaced the cross to make Willowbot more compatible with international character sets.

Kind regards, Weidengeist

LeoAlt8 commented 1 year ago

image Windows and Ubuntu

weidengeist commented 1 year ago

A fix for this issue has been uploaded right now.

LeoAlt8 commented 1 year ago

"Twitch's authorization page for access tokens" - does not open image Windows and Ubuntu

Can you tell me which page to open?

weidengeist commented 1 year ago

There was some legacy code in one of the modules that required an oauth in the config file. However, those oauths have been externalized to the logins file, so it won’t be present in the config file anymore. I have removed the check for an oauth in the config file. The new version is up now.

I apologize for the inconvenience.

LeoAlt8 commented 1 year ago

image I deleted all files and did everything from the beginning.

weidengeist commented 1 year ago

The issue was that the bot tried to retrieve information that needs a valid oauth without having one. I have fixed that.

LeoAlt8 commented 1 year ago

image Can you fill it in manually? The received data needs to be entered in logins.py?

weidengeist commented 1 year ago

Yes, indeed. You may put it into you logins.py manually. I will fix the add routine some time later.

LeoAlt8 commented 1 year ago

Does anything need to be changed in the file config.py?

weidengeist commented 1 year ago

Only the default botname should be adjusted. The other keys may keep their values. However, the botname value can be overwritten by using --login [your bot account] as Willowbot option.

LeoAlt8 commented 1 year ago

image image

And launching a bot (mine) on a friend's channel. image

LeoAlt8 commented 1 year ago

I'll cancel access by token for now, so that after you fix everything, I can check from the very beginning. OK?

LeoAlt8 commented 1 year ago

image Win11

The browser does not open. I can't check for Ubuntu right now.

weidengeist commented 1 year ago

This is a strange behaviour. Willowbot should at least establish a local server to provide a platform for the oauth token website integrated in Willowbot. Unfortunately, I cannot reproduce this issue on my Linux machine; I don’t have a Windows machine to test this. My guess is that some Windows 11 security measures prevent Willowbot from starting the server and a path variable for the default browser is missing so that Willowbot/Python does not know what the default browser is nor how to open it.

Please check this behaviour on other operating systems if you can and check both your path variable as well as maybe your firewall configuration. You need to allow localhost on port 3000.

To test the webbrowser module of your Python installation, you may try to start Python on your command line, do an import webbrowser and open an arbitrary website by typing e.g. webbrowser.open("https://duckduckgo.com/"). If this does not work either, the issue is probably not Willowbot-related.

LeoAlt8 commented 1 year ago

To test the webbrowser module of your Python installation, you may try to start Python on your command line, do an import webbrowser and open an arbitrary website by typing e.g. webbrowser.open("https://duckduckgo.com/"). If this does not work either, the issue is probably not Willowbot-related.

image

This works for me. The search engine has opened. 🔼🔼🔼


Launched a bot on Ubuntu. I requested a token, the browser did not open, as on Windows. image

weidengeist commented 1 year ago

Two more things you can here:

  1. Navigate to the Willowbot root directory. In the ./modules directory, you can find oauthTokenRedirectPage.html. Try to open this page with your default browser. If this fails, there might be some incompatibility in the HTML code. If you have other browsers available, you may try those as well. An ungoogled Chromium browser and Firefox (latest version each) work for me.
  2. If the test above succeeds for you, do the same in Python:
    >>> import webbrowser
    >>> webbrowser.open("/This/path/leads/to/Willowbot/modules/oauthTokenRedirectPage.html")

    If both tests open your browser and the oauth template page appears, the next step would be checking how the Willowbot program flows in this section for your configuration.

LeoAlt8 commented 1 year ago

2. If the test above succeeds for you, do the same in Python:

image

  1. Navigate to the Willowbot root directory. In the ./modules directory, you can find oauthTokenRedirectPage.html.

image

weidengeist commented 1 year ago

Please repeat step 2 and replace all backslashes (\) with a slash (/), as Python does not know backslashes without being used in escape sequences. Alternatively, you can precede your path to the HTML file with r like this:

webbrowser.open(r"C:\Users\And\So\On\Willowbot\modules\oauthTokenRedirectPage.html")

The version mentioned first would be:

webbrowser.open("C:/Users/And/So/On/Willowbot/modules/oauthTokenRedirectPage.html")

A third syntax possibility is escaping the backslashes:

webbrowser.open("C:\\Users\\And\\So\\On\\Willowbot\\modules\\oauthTokenRedirectPage.html")
LeoAlt8 commented 1 year ago

image Here's what I opened. The same when opening the file manually.

LeoAlt8 commented 1 year ago

If you need to do the same on Ubuntu, then I can only tomorrow.

weidengeist commented 1 year ago

Windows will suffice for now.

I have just updated the cliOptions.py file so that it will output the target URL in the terminal so that it can be copied and pasted into the browser manually. If even the URL does not show for you, something must be quite off here.

LeoAlt8 commented 1 year ago

Unfortunately it doesn't work for me. And the previous version of the bot will not work? Is it possible to return it? Or has twitch introduced some restrictions?

weidengeist commented 1 year ago

What exactly does not work for you? Is there no URL output when using Willowbot with the --token get option? Which platforms have been tested?

A rollback would be possible, but it would strictly limit Willowbot’s capabilities. Twitch changed the API usage in February this year and externalized various formerly IRC commands to they own API endpoints. You can find a full list of the externalized commands in Twitch’s migration guide. It contains commands like /delete, /ban, /announce, /shoutout, and /timeout. To use the commands of this new API endpoint, a new kind of access token is required. Without that, Willowbot is restricted to simply grab the messages and print a reaction – no auto-deletion, no auto-ban, only simple text messages. You can still generate tokens of the old generation and it will work with Willowbot, but those are close to worthless.

More interesting is the reason why your browser doesn’t show up while there are no issues on my side.

LeoAlt8 commented 1 year ago

Is there no URL output when using Willowbot with the --token get option? Which platforms have been tested?

Yes, it doesn't open. Tried on Windows 11 and Ubuntu 22.04. And I do not have the necessary knowledge to find the cause. And I really like your bot. As far as I understand, testing on a VPS will not work, because you need a browser? And is it generally impossible to run on a VPS with access only through the console?

weidengeist commented 1 year ago

Willowbot should actually show you the URL from where you can retrieve the token in its most recent version. Doesn’t Willowbot do that? The message should look like this:

Trying to open
    https://id.twitch.tv/oauth2/authorize?response_type=token&redirect_uri=http://localhost:3000&client_id=e5kdpgd2bbnbj1u5gbjpzeq7vsgwup&scope=channel_editor+channel_commercial+channel:manage:broadcast+channel:manage:moderators+channel:manage:vips+channel:manage:raids+channel:moderate+channel:read:redemptions+channel:read:subscriptions+chat:edit+chat:read+moderator:manage:announcements+moderator:manage:automod+moderator:manage:banned_users+moderator:manage:blocked_terms+moderator:manage:chat_messages+moderator:manage:chat_settings+moderator:manage:shoutouts+moderator:read:blocked_terms+user:manage:chat_color+user:manage:whispers+user:read:follows+whispers:edit+whispers:read

The URL is neither unique nor secret; you can just copy it from above to generate a token. But if you have the most recent Willowbot version and not even this URL shows up, the program does not flow as it should, which is pretty odd. Not showing the URL means that Willowbot runs in a completely unintended and unexpected way on your machine(s).

I have not tested Willowbot via a VPS, but you will need a local browser – at least for generating the token. However, the actual Willowbot usage can probably happen on a VPS.

Addendum: If you use this URL manually, the redirection will not work, as the Willowbot local server will not run to provide you its webpage. You will have to copy the resulting token from the redirection URL. It’s the hash parameter #access_token= in the URL.

LeoAlt8 commented 1 year ago

What OS, browser, version of Python are you using? I will install on a virtual machine and try it there.

weidengeist commented 1 year ago

I’m on a Linux machine, but the distribution should not matter, neither should the browser, as Python will choose the default one. I am testing Willowbot with Python 3.9.1. I am almost 100% sure that the issue is related to using the VPS.

You still haven’t answered the question if the URL shows up when you use Willowbot with the --token get option.

LeoAlt8 commented 1 year ago

Archive downloaded today.

You still haven’t answered the question if the URL shows up when you use Willowbot with the --token get option.

Win11 image

Ubuntu 22.04 image

I am almost 100% sure that the issue is related to using the VPS.

I didn't try to run it on a VPS.

weidengeist commented 1 year ago

Please try the following to find out where Willowbot leaves the expected behaviour. Replace the first 38 lines of your main_cli.py (including tokenActions(CONFIG, LOGINS)) with the following code:

import sys

# Subdirectories containing routines, class definitions and other important data.
sys.path.append('lang')
sys.path.append('modules')
sys.path.append('modules_opt')

# Load this module first to get the current language and to be able to shot the help info without having to load the actual config before.
from modules.cliOptions import *

print("1")
getLanguage(feedback = True)
print("2")
if '-h' in sys.argv or '--help' in sys.argv:
  showHelp()

if '-cf' in sys.argv or '--configure' in sys.argv:
  createConfigFiles()

# Load all the remaining modules.
from modules.basics import checkTimedCommands  # Import various general functions from the basics(.py) module in ./modules.
print("3")
from modules.basics import getCommands    
print("4")
from modules.basics import getConfig
print("5")
from modules.basics import getLogins
print("6")
from modules.irc import IRC                    # Import the IRC class from the irc(.py) module in ./modules.

# Suppress output in debug mode.
if inOneshotMode():
  globalFeedback = False
else:
  globalFeedback = True

print("7")
LOGINS = getLogins(feedback = globalFeedback)   # Load all available login oauths.
print("8")
CONFIG = getConfig(feedback = globalFeedback)   # Load configuration files. 

print("9")
if '-t' in sys.argv or '--token' in sys.argv:
  tokenActions(CONFIG, LOGINS)
  print("10")

It is basically the same code as before, but some print commands have been inserted to get feedback points. With the code replaced in your main_cli.py, run Willowbot with --token get again and post what it shows.

LeoAlt8 commented 1 year ago

I replaced. image

win11 image

ubuntu image

weidengeist commented 1 year ago

Okay, we need further information, but I have a clue where I have to look. In line 32 of your new main_cli.py, there is a block that contains globalFeedback:

# Suppress output in debug mode.
if inOneshotMode():
  globalFeedback = False
else:
  globalFeedback = True

Comment everything in this line except for the last one and remove the indentation of the last line. It should look like this in the end (Python is indentation-sensitive):

# Suppress output in debug mode.
#if inOneshotMode():
#  globalFeedback = False
#else:
globalFeedback = True

Run the --token get option again and show me the output.

LeoAlt8 commented 1 year ago

image

Is Windows enough for now? image

weidengeist commented 1 year ago

There it is! It is a slight misconception in the default login and config files. I have updated the files now to fix this. You don’t have to download the most recent version immediately. You only have to change IHaveNoName in your config.py to IAmYourFirstBot and your token creation will hopefully succeed.

Thank you very much for your patience to figure this out.

LeoAlt8 commented 1 year ago

A page should have opened asking you to allow Twitch access?

weidengeist commented 1 year ago

Yes, indeed. Just authorize this and you will be redirected to your token page.

Edit: This step is documented in the initial setup section of the README.

LeoAlt8 commented 1 year ago

image This page immediately opened, and not with a request for permission ((

weidengeist commented 1 year ago

This means that you have logged in to a Twitch account in this browser before and the login has been saved to a session cookie of your browser. The token shown now is one for the account you have most recently logged in to.

LeoAlt8 commented 1 year ago

image I deleted everything and downloaded a new archive and did everything from the beginning.

weidengeist commented 1 year ago

Looks alright so far. However, you have to replace IAmYourFirstBot in the config.py file with your actual account name or start Willowbot with the --channel and/or --login option (see chapter 2 of the README).

LeoAlt8 commented 1 year ago

EVERYTHING IS WORKING!!!! 🥰🤩🤪🕺

weidengeist commented 1 year ago

Great! I will have to streamline the initial setup process a bit more and update the README accordingly. I guess this issue can be closed now.

LeoAlt8 commented 1 year ago

Could you please tell me how to transfer it to VPS Ubuntu server?

weidengeist commented 1 year ago

I am sorry. This is beyond my knowledge and not directly linked to Willowbot, so it shouldn’t be discussed here anyway.