Compare commits

...

4 Commits

Author SHA1 Message Date
97a315d2d1 fix giving rep to yourself via different nick with same account
thanks to findus for discovering this :D
2025-05-14 23:38:05 +00:00
b29cf737a7 exit if a TimeoutError occurs 2024-11-26 13:40:06 +00:00
51a37c4562 make 'is_registered' regex a raw string
to fix the following warning with python 3.12:
SyntaxWarning: invalid escape sequence '\S'
2024-06-02 15:13:59 +00:00
34a3f06d91 add socket timeout + exit if connection is lost
Fix #2
2024-01-31 01:01:35 +00:00

17
bert.py
View File

@ -72,7 +72,7 @@ def connect(host, port):
global irc
print("Connecting to "+host+":"+str(port))
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)
@ -140,7 +140,14 @@ def me(chan, msg):
def getData():
try:
raw = irc.recv(4096)
except TimeoutError:
print("Connection timed out!")
sys.exit(0)
if not raw:
print("Connection lost!")
sys.exit(0)
try:
data = raw.decode("UTF-8")
except:
@ -173,7 +180,7 @@ def is_registered(username):
try:
sendRaw("WHOIS "+str(username)+"\n")
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)
for match in matches:
acc_name = match.group(0).split()[3]
@ -358,14 +365,14 @@ def command_loop():
except:
reason = "None"
print("with no reason")
if user == ircnick:
say(channel, "You can't give rep to yourself. Selfish little prick!")
continue
try:
acc_name = is_registered(user)
give_acc = is_registered(ircnick)
print("found account name for "+str(user)+": "+str(acc_name))
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)
elif give_acc == None:
say(channel, "You are not registered!")