-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathelitebot.py
69 lines (52 loc) · 1.75 KB
/
elitebot.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/python3
from config import *
import ssl
import socket
import base64
import random
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def decode(bytes):
try: text = bytes.decode('utf-8')
except UnicodeDecodeError:
try: text = bytes.decode('latin1')
except UnicodeDecodeError:
try: text = bytes.decode('iso-8859-1')
except UnicodeDecodeError:
text = bytes.decode('cp1252')
return text
if str(BPORT)[:1] == '+':
print('Use SSL')
ircsock = ssl.wrap_socket(ircsock)
BPORT = int(BPORT[1:])
else:
BPORT = int(BPORT)
ircsock.settimeout(240)
def SendIRC(msg):
if msg != '': ircsock.send(bytes(f'{msg}\r\n','utf-8'))
def SendMsg(msg, target=BHOME):
SendIRC("PRIVMSG "+ target +" :"+ msg)
print(f'Connecting to {BSERVER} :{BPORT}')
ircsock.connect_ex((BSERVER, BPORT))
SendIRC(f'NICK {BNICK}')
SendIRC(f'USER {BIDENT} * * :{BNAME}')
if UseSASL:
SendIRC('CAP REQ :sasl')
while True:
recvText = ircsock.recv(2048)
ircmsg = decode(recvText)
line = ircmsg.strip('\n\r')
word = line.split(" ")
print(ircmsg)
if word[0] == "PING":
pongis = ircmsg.split(' ', 1)[1]
SendIRC(f'PONG {pongis}')
elif line.find('ACK :sasl') != -1 or ircmsg.find('ACK :sasl') != -1:
SendIRC('AUTHENTICATE PLAIN')
elif ircmsg.find('AUTHENTICATE +') != -1:
authpass = SANICK + '\x00' + SANICK + '\x00' + SAPASS
ap_encoded = str(base64.b64encode(authpass.encode('UTF-8')), 'UTF-8')
SendIRC('AUTHENTICATE ' + ap_encoded)
elif ircmsg.find(f' 903 {BNICK} :') != -1:
SendIRC('CAP END')
elif line.find(f' 001 {BNICK} :') != -1:
SendIRC(f'JOIN {BHOME}')