Compare commits
4 Commits
f92d59dd91
...
master
Author | SHA1 | Date | |
---|---|---|---|
97a315d2d1 | |||
b29cf737a7 | |||
51a37c4562 | |||
34a3f06d91 |
19
bert.py
19
bert.py
@ -72,7 +72,7 @@ def connect(host, port):
|
|||||||
global irc
|
global irc
|
||||||
print("Connecting to "+host+":"+str(port))
|
print("Connecting to "+host+":"+str(port))
|
||||||
context = ssl.create_default_context()
|
context = ssl.create_default_context()
|
||||||
with socket.create_connection((host, port)) as sock:
|
with socket.create_connection((host, port), timeout=180) as sock:
|
||||||
irc = context.wrap_socket(sock, server_hostname=host)
|
irc = context.wrap_socket(sock, server_hostname=host)
|
||||||
|
|
||||||
|
|
||||||
@ -140,7 +140,14 @@ def me(chan, msg):
|
|||||||
|
|
||||||
|
|
||||||
def getData():
|
def getData():
|
||||||
raw = irc.recv(4096)
|
try:
|
||||||
|
raw = irc.recv(4096)
|
||||||
|
except TimeoutError:
|
||||||
|
print("Connection timed out!")
|
||||||
|
sys.exit(0)
|
||||||
|
if not raw:
|
||||||
|
print("Connection lost!")
|
||||||
|
sys.exit(0)
|
||||||
try:
|
try:
|
||||||
data = raw.decode("UTF-8")
|
data = raw.decode("UTF-8")
|
||||||
except:
|
except:
|
||||||
@ -173,7 +180,7 @@ def is_registered(username):
|
|||||||
try:
|
try:
|
||||||
sendRaw("WHOIS "+str(username)+"\n")
|
sendRaw("WHOIS "+str(username)+"\n")
|
||||||
user_info = getMessage()
|
user_info = getMessage()
|
||||||
regex = r"330 "+str(re.escape(nick))+" "+str(re.escape(username))+" \S+ :is logged in as"
|
regex = rf"330 {str(re.escape(nick))} {str(re.escape(username))} \S+ :is logged in as"
|
||||||
matches = re.finditer(regex, user_info, re.MULTILINE)
|
matches = re.finditer(regex, user_info, re.MULTILINE)
|
||||||
for match in matches:
|
for match in matches:
|
||||||
acc_name = match.group(0).split()[3]
|
acc_name = match.group(0).split()[3]
|
||||||
@ -358,14 +365,14 @@ def command_loop():
|
|||||||
except:
|
except:
|
||||||
reason = "None"
|
reason = "None"
|
||||||
print("with no reason")
|
print("with no reason")
|
||||||
if user == ircnick:
|
|
||||||
say(channel, "You can't give rep to yourself. Selfish little prick!")
|
|
||||||
continue
|
|
||||||
try:
|
try:
|
||||||
acc_name = is_registered(user)
|
acc_name = is_registered(user)
|
||||||
give_acc = is_registered(ircnick)
|
give_acc = is_registered(ircnick)
|
||||||
print("found account name for "+str(user)+": "+str(acc_name))
|
print("found account name for "+str(user)+": "+str(acc_name))
|
||||||
if acc_name != None and give_acc != None:
|
if acc_name != None and give_acc != None:
|
||||||
|
if acc_name == give_acc:
|
||||||
|
say(channel, "You can't give rep to yourself. Selfish little prick!")
|
||||||
|
continue
|
||||||
give_rep(acc_name, user, give_acc, reason, channel)
|
give_rep(acc_name, user, give_acc, reason, channel)
|
||||||
elif give_acc == None:
|
elif give_acc == None:
|
||||||
say(channel, "You are not registered!")
|
say(channel, "You are not registered!")
|
||||||
|
Reference in New Issue
Block a user