Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Python 3.9.1 #2

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Update to Python 3.9.1 #2

wants to merge 5 commits into from

Conversation

RikiRC
Copy link

@RikiRC RikiRC commented Jan 10, 2021

I have made few changes to made it work with Python 3.9.1 and updated API request.

@Coincident
Copy link

Thank you @RikiRC for the changes. Now the bot runs with the latest version of Python.
However, it never connects. I just get a message saying:
"Connecting to irc.chat.twitch.tv on port 6667..."
and nothing happens for hours.
Is this working for anyone else?

@RikiRC
Copy link
Author

RikiRC commented Feb 15, 2021

Hi @Coincident, I have tested it again and it works ok for me.
Can you double check the parameters that you are providing for chatbot.py? Especially OAuth token, because you need to provide this parameter without oauth: prefix e.g.:

image

Sometimes this bot can't connect first try, so sometimes you have to restart it few times. But if it is connected to irc channel then you see message:
Joining #channel_name
Joined #channel_name

Also bot sends message to twitch chat when connected:

image

@Coincident
Copy link

Coincident commented Feb 15, 2021

Hello. Thanks for the reply. Yeah, I've double-checked. I do not have the "oauth:" prefix in the token string, I've removed it before. I tried starting & stopping the bot multiple times, it never works.

Also, there seems to be an error on line 22: 853f956#diff-ce7c8a3a3f07f8572f7bb29f6313e8feb4a61d0082a8555fcee60ca6aca2cba6L22
This:
url = 'https://api.twitch.tv/kraken/users?login=' + channel
Should be this instead:
url = 'https://api.twitch.tv/kraken/users?login=' + username

Otherwise the bot will only work if channel == username; which means you're using your own Twitch account as the login for the bot. In my case I have made a separate account for the bot, so I had to change the line.
Anyway, even with that fix the bot never connects, no matter how long I wait / how often I restart.

Edit: Nevermind. This is incorrect. There is no error on line 22.

@erwan-b
Copy link

erwan-b commented Feb 15, 2021

Thanks work very well ! 👌

@Coincident
Copy link

Coincident commented Feb 15, 2021

Sorry about the last message; that was a big confusion on my behalf. I reverted the changes to the code and somehow the bot connected this time. I had tried this before and it didn't work. No idea what I did different this time...
Now I consistently get the two messages:
Joining #channel_name
Joined #channel_name

But the bot never responds to any comments or messages, and I never see the "'Received command: ' + cmd" print. The "Connected!" message does not appear at first; it only appears if I use my actual browser to login with the bot's Twitch account and manually join the channel. But even like that, the bot does not respond to commands.

@Coincident
Copy link

Hello again, after several hours of experimenting and researching, I found the culprit of the problem: "channel" has to be entirely in lower-case!

https://discuss.dev.twitch.tv/t/python-bot-irc-problem-just-asking-for-explanation/30123

Now the bot finally works!

@Coincident
Copy link

@RikiRC awesome. That last commit will prevent the next people who try this to run into the same lower-case problem.

I would also recommend another change to prevent more problems:

  • checking if token starts with "oauth:", and if so, truncate the first 6 characters of the string.

print 'Connecting to ' + server + ' on port ' + str(port) + '...'
irc.bot.SingleServerIRCBot.__init__(self, [(server, port, 'oauth:'+token)], username, username)
print('Connecting to ' + server + ' on port ' + str(port) + '...')
irc.bot.SingleServerIRCBot.__init__(self, [(server, port, 'oauth:'+self.token)], username, username)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use super(). To make it more readable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants