-
-
Save Ilgrim/54077c4b9d94019793b33b8fa0af60e7 to your computer and use it in GitHub Desktop.
IRC bot python 3
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 | |
| s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| HOST = '' #irc server | |
| PORT = 6665 #port | |
| NICK = 'pony_bot' | |
| USERNAME = 'megadeath' | |
| REALNAME = 'little pony' | |
| 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 megadeath megadeath megadeath :rainbow pie \r\n').encode() | |
| s.send(usernam_cr) | |
| s.send('JOIN #mysupertest \r\n'.encode()) #chanel | |
| while 1: | |
| data = s.recv(4096).decode('utf-8') | |
| print(data) | |
| if data.find('PING') != -1: | |
| s.send(str('PONG ' + data.split(':')[1] + '\r\n').encode()) | |
| print('PONG sent \n') | |
| if data.find('hi') != -1: | |
| s.send((str('PRIVMSG ' + data.split()[2]) + ' Hi! \r\n').encode()) | |
| s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment