-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcbot2.py
More file actions
55 lines (43 loc) · 1.44 KB
/
cbot2.py
File metadata and controls
55 lines (43 loc) · 1.44 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import socket
from config import *
sockChan = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sockChan.connect((BotServer, BotPort))
def SendIRC (msg):
sockChan.sendall(bytes(f'{str(msg)} \r\n', 'UTF-8'))
SendIRC(f'USER {BotIdent} * * :{BotRealname}')
SendIRC(f'NICK {BotNick}')
connected = True
def main():
try:
while connected:
line = sockChan.recv(2040).decode('UTF-8')
print(line)
if line != "":
lline = line.split()
if 'PING' in lline[0]:
SendIRC(f'PONG {lline[1]}')
if '433' in lline[0]:
SendIRC(f'NICK {BotAlt}')
if '001' in lline[0]:
SendIRC(f'JOIN {BotHome}')
if 'PRIVMSG' in lline[1]:
zline = lline.split('!')
zline = zline.split(':')
zline = zline.split('@')
nick = zline[0]
ident = zline[1]
host = zline[2]
targ = zline[4]
text = zline[5]
if 'NOTICE' in lline[1]:
zline = lline.split('!')
zline = zline.split(':')
zline = zline.split('@')
nick = zline[0]
ident = zline[1]
host = zline[2]
targ = zline[4]
text = zline[5]
except Exception as iconnex:
print(f'Exception: {str(iconnex)}')
main()