Created
July 17, 2021 13:02
-
-
Save CrocodileCroco/48e9ad540b4e67f36e892c69f4d9be53 to your computer and use it in GitHub Desktop.
Bot Python 3 IRC (compatible unrealircd 5)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| import socket | |
| import time | |
| s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| HOST = '127.0.0.1' #irc server | |
| PORT = 6667 #port | |
| NICK = 'testbot' | |
| USERNAME = 'testbot' | |
| REALNAME = 'bot test' | |
| print('soc created |', s) | |
| remote_ip = socket.gethostbyname(HOST) | |
| print('ip of irc server is:', remote_ip) | |
| s.connect((HOST, PORT)) | |
| print('connected to: ', HOST, PORT) | |
| nick_cr = ('NICK ' + NICK + '\r\n').encode() | |
| s.send(nick_cr) | |
| usernam_cr= ('USER testbot localhost * :bot test \r\n').encode() | |
| s.send(usernam_cr) | |
| pingreceived = 0 | |
| while 1: | |
| data = s.recv(4096).decode('utf-8') | |
| if len(data) > 0: | |
| print("[DATA]" + data) | |
| if data.find('PING') != -1: | |
| s.send(str('PONG ' + data.split(':')[1] + '\r\n').encode()) | |
| print('PONG sent n') | |
| if pingreceived == 0: | |
| print("join channel NOW") | |
| s.send('JOIN #testbot \r\n'.encode()) #chanel | |
| pingreceived = 1 | |
| if data.find('testbot!testbot') != -1: | |
| pass | |
| else: | |
| if data.find('PRIVMSG #testbot :Salut') != -1: | |
| s.send((str('PRIVMSG #testbot Salut \r\n').encode())) | |
| s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment