Create an IRC bot with python
Programing IRC Python
Created At : 2021-06-21 21:25
Count:544 Views ๐ :2220
Create an IRC bot with Python3
Installation of python3.
1 | apt update |
Create the project and start to code.
You have to create a file like โmain.pyโ in a directory where will be your bot.
Import some necessary libraries.
In main.py.
1 | import socket, ssl, threading |
Add the configuration variables.
Donโt forget to comment the code, itโs important.
1 | server = 'irc.evilcorp.ga' # Server |
Connect to the server
1 | socketHandler = socket.socket(socket.AF_INET, socket.SOCK_STREAM)# Opening up a normal socket. |
Create the loop to receive the buffer
1 | while 1: # Be careful with these! it might send you to an infinite loop |
And your code will be just after that with an another elif, like this:
1 | elif ircbuff.find("coffee") != -1: # Bring you a coffee |
And we delete the buffer because the script will process the previous messages and send too much messages to the server.
1 | del ircbuff |
now we have to create the function:
- ping for ping(ircbuff)
- ircsend for ircsend(โ/msg NickServ IDENTIFY โ+password)
- joinchan for joinchan(channel)
- coffee for coffee()
Create the functions
1 | def ircsend(msg): # I had to make another function for send() because in python3 and above the socket incoming and outgoing messages are in bytes format. So you have to encode and decode it accordingly. |
Thanks
Thank to Shadow Lobster for the help.