-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathirctest.py
40 lines (31 loc) · 1005 Bytes
/
irctest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
import socket
import random
import time
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
HOST = 'irc.netgamers.org' #irc server
PORT = 6667 #port
NICK = 'ibot' + str(random.randint(1,101))
USERNAME = 'Igloo'
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 #ibot \r\n'.encode()) #chanel
time.sleep(1)
#s.send(bytes("JOIN ##ibot \n", "UTF-8"))
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()