python irc bot ping answer - python

I'm trying to write a simple IRC bot in Python. My bot would connect to a server, join a channel and then print to the console the messages received by the bot.
I did it, but the server always disconnects me after a while because of ping timeout. I tried to use some libraries (python-irc and oyoyo) and they both ALLEGEDLY handle automatically the ping-pong messages with the server. But I tried with irc.abjects.net and irc.criten.net and with both of them these libraries failed.
Then I made a script based on this one: http://hawkee.com/snippet/9725/. And it failed too. So... I suppose the problem is very stupid and simple, but I jsut can't figure out a solution.
Note: with the library irc3 the ping-pong works fine, but it uses asyncio, which conflicts with some other parts of my code (not related to irc). So I can't use it.

Related

Is there a ready-made function for http_wait in telethon?

I need to use http_wait link with telethon, are there already made functions in the library to use that specific method?
I need to receive messages as soon as they occur is large broadcast channels, now the updates come 5-20 seconds late
Clients using the Telegram API, such as Telethon, connect to the Telegram servers directly via a TCP socket. While connected, Telegram decides when and where to deliver the updates. Telegram's API doesn't really offer a way to "poll" for these updates.
If Telegram is delivering them slowly, it's probably to reduce load, or because the channel is too large, or because the client is not being actively used. In essence, it's not something the library can "fix".

Can't get my threading to work properly in this simple chat program

We are doing a simple chat program in python using the PyZMQ library. So that two clients can talk to each other via a server. But we cant get our threading to work properly.. We need one thread to check the socket for incoming messages, and one that sends messages to the socket. But right now the program simply freezes, and I cant figure out why.
Code here: https://gist.github.com/TheFelixR/1be20e8f510266d152d6947bddf0b31a

real time communication between python server and a python client(not a browser)

Back in the javascript world there is a library all the socket part called socket.io
the way it works is by send and receiving the data by and events.
for example: the server can send to the client an event called "msg_received" with the message itself as the data.
in python it seems to not be as asynchronous as its in javascript. its also not working with events but only with strings which is a bit diffrent than how i use to work with the sockets.
i.e socket.send(<string>), socket.recv(<integer>)
i would love if anyone could put some light the issue to explain to me how it works in python since i've searched all over the internet and couldn't find an answer.. or point me to a similar library like the one i mentioned above.

Interconnecting AMQP and XMPP

I'm looking for a way to write a XMPP bot that would listen to a RabbitMQ queue and send messages to the XMPP channel notifying users of any new issues ( already got Nagios sending notifications to RabbitMQ).
I've tried using xmppy and it stopped working and I stumbled across SleekXMPP which looks fairly better.
I'm just wondering if I define a AMQP listener to automatically call the XMPP "send" method in the bot. So it would be listening both on AMQP and XMPP at the same time.
Thank you for your help!
Edit: Would BOSH be much better solution here ?
The most interesting part of your solution will be that many libraries in this space assume that they are the only event loop. You'll either need to put each in its own thread (seemingly easier, but fraught with lurking locking issues), use a non-blocking I/O approach like Twisted (but you'll need an AMQP library), or extract the socket file descriptors out of each of the libraries you're using and run select() or poll() over them to tell when there is data to read. Of these three, the Twisted approach seems easiest to me.
BOSH will just make the problem more difficult. Don't go that way.
This is really quite simple. I suggest that you start by writing an AMQP listener that simply prints out received messages. Once you get that working it should be obvious how to integrate that into an XMPP bot.
You can use ejabberd and a xmpp plugin like this https://github.com/rabbitmq/rabbitmq-xmpp

IRC client in python

I'm writing python code for IRC client.
I want to understand how IRC client and server communicating each other.
Can anyone give me good tutorial or IRC communication architecture to understand it in depth?
Thanks
The IRC RFC documentation is an important reference, but the most helpful first introduction I've found on communication between IRC client and server was really simple.
First, you need access to a *nix shell (e.g. ssh into your web host running Linux).
In the command line, open up a direct connection to an IRC server using the program 'nc'. Then you can type RFC commands directly, and see the response. Try typing
$ nc wright.freenode.net 6667
PASS whateveryoulike
NICK yournick
USER username 0 * :Real Name
There is output from the server amidst this, but now you've logged into and "registered" your user. Note: your nick isn't registered (ala NickServ), I'm referring to registering a user as outlined in section 3.1 of the RFC 2812 IRC Client Protocol.
You can now join a channel:
JOIN #yourtestchannel
See who's in the channel:
WHO #yourtestchannel
Send yourself a msg:
PRIVMSG yournick Message Text Here
Chat into the channel (send the channel a msg):
PRIVMSG #yourtestchannel Message Text Here
This is especially helpful if you're connected to the same server and channel with a different nick in a real IRC client. You can chat with yourself and msg one nick to the other, and see the "raw" IRC output that you'll have to parse to write your own client or bot.
For example, someone chatting in a channel looks something like this:
:SomeDude28!SomeDude28#hoststring-with_various_parts PRIVMSG #channel :Hey guys, what's up?
Using the RFC, you can play around with whatever functionality you want, and, more importantly, figure out how you'll need to parse things.
Oh, and don't forget to PONG occasionally, or when prompted with a PING, to avoid ping timeout.
If you want to reinvent the wheel, then you have to implement the RFC and do everything from scratch.
If you don't want to do that and would require some level of abstraction to ease your development (and which you should), then see Twisted.
There is also a Python IRC client library.
For most protocols a good way to start is to look for a document called RFC. There's one for many protocols and it defines - in depth - how it should behave.
You can find the one for IRC here.

Categories