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

can i write to a friend in a whisper directly without a bot? #2

Closed
rnyPlanet opened this issue Feb 25, 2021 · 6 comments
Closed

can i write to a friend in a whisper directly without a bot? #2

rnyPlanet opened this issue Feb 25, 2021 · 6 comments

Comments

@rnyPlanet
Copy link

Hello. I'm new, wondering if I can write to my friend whisper without a bot? so I have his nickname and I want to write to him through python and accept whisper from him, maybe so? looking all day, nothing ...

@tomaarsen
Copy link
Owner

tomaarsen commented Feb 25, 2021

Hey @rnyPlanet !

This is technically possible, but definitely more work than simply logging into Twitch and whispering him there, or adding him on another communication platform like Discord.

But considering you asked, you shall receive:

One way to go about this is to add a bot to your own Twitch channel, so that it can listen to whispers too. Then, every time we get a message from Twitch we'll check whether it's a WHISPER from our friend. If so, we'll print it.
Furthermore, we will continuously allow you to write up a message to send him too.

class MyBot:
    def __init__(self):
        self.host = "irc.chat.twitch.tv"
        self.port = 6667
        self.nick = "<user_name>"
        self.chan = "#" + self.nick
        self.auth = "oauth:<authentication>"

        self.friend_nick = "<your_friends_nick>"
        
        # Send along all required information, and the bot will start 
        # sending messages to your callback function. (self.message_handler in this case)
        self.ws = TwitchWebsocket(host=self.host, 
                                  port=self.port,
                                  chan=self.chan,
                                  nick=self.nick,
                                  auth=self.auth,
                                  callback=self.message_handler,
                                  capability=["membership", "tags", "commands"],
                                  live=True)
        self.ws.start_nonblocking()
        # Infinitely loop so we can type what we want to send
        while True:
            # Allow us to type our message to send to the friend.
            message = input("Send the following message to " + self.friend_nick + ":\n>")
            self.send_whisper(self.friend_nick, message)

    def message_handler(self, m):
        # Check if we received a whisper from the friend
        if m.type == "WHISPER" and m.user == self.friend_nick:
            print(time.time(), m.user, ":", m.message)

if __name__ == "__main__":
    MyBot()

However, do note that I do not think it is not required to connect to a Twitch channel's chat to listen to WHISPER messages, but my TwitchWebsocket will automatically connect. That's just how it's implemented, because I use it for specifically connecting to Twitch chats.

But again, my recommendation is for you two to get in touch via some other medium.

@rnyPlanet
Copy link
Author

Hey @rnyPlanet !

thank you so much. I need this to work, receive whispers and send in telegrams (by notification type). I can not always go to twitch. I will try your code, thanks again)

@rnyPlanet
Copy link
Author

@cubiedev
your code works perfectly, but an error "Your settings prevent you from sending this whisper." when sending whisper. maybe you had such an error and is there a solution?

@rnyPlanet
Copy link
Author

@tomaarsen
Copy link
Owner

That is a shame. Whispers have given me troubles in the past too.

@rnyPlanet
Copy link
Author

I sympathize for the time spent and still I am grateful for the help)

That is a shame. Whispers have given me troubles in the past too.

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

No branches or pull requests

2 participants