A bunch of small fixes
This commit is contained in:
parent
1993bcacc6
commit
bd94f1b67f
1 changed files with 12 additions and 12 deletions
24
bot.py
24
bot.py
|
@ -61,23 +61,23 @@ class bot:
|
||||||
self.exit("Lost connection to the server")
|
self.exit("Lost connection to the server")
|
||||||
self.log(f"Joined {server} successfully!")
|
self.log(f"Joined {server} successfully!")
|
||||||
|
|
||||||
def join(self, chan: str) -> None:
|
def join(self, chan: str, origin: str) -> None:
|
||||||
log(f"Joining {chan}...", server)
|
self.log(f"Joining {chan}...")
|
||||||
chan = chan.replace(" ", "")
|
chan = chan.replace(" ", "")
|
||||||
if "," in chan:
|
if "," in chan:
|
||||||
chans = chan.split(",")
|
chans = chan.split(",")
|
||||||
for subchan in chans:
|
for subchan in chans:
|
||||||
joinchan(subchan, origin, chanList)
|
self.join(subchan, origin)
|
||||||
return
|
return
|
||||||
if chan.startswith("0") or (chan == "#main" and lock):
|
if chan.startswith("0") or (chan == "#main" and lock):
|
||||||
if origin != "null":
|
if origin != "null":
|
||||||
sendmsg(f"Refusing to join channel {chan} (protected)", origin)
|
self.sendmsg(f"Refusing to join channel {chan} (protected)", origin)
|
||||||
return
|
return
|
||||||
if chan in channels and lock:
|
if chan in channels and lock:
|
||||||
if origin != "null":
|
if origin != "null":
|
||||||
sendmsg(f"I'm already in {chan}.", origin)
|
self.sendmsg(f"I'm already in {chan}.", origin)
|
||||||
return
|
return
|
||||||
send(f"JOIN {chan}\n")
|
self.send(f"JOIN {chan}\n")
|
||||||
while True:
|
while True:
|
||||||
ircmsg = self.recv().decode()
|
ircmsg = self.recv().decode()
|
||||||
if ircmsg != "":
|
if ircmsg != "":
|
||||||
|
@ -90,7 +90,7 @@ class bot:
|
||||||
if ircmsg.startswith("PING "):
|
if ircmsg.startswith("PING "):
|
||||||
self.ping(ircmsg)
|
self.ping(ircmsg)
|
||||||
elif len(ircmsg.split("\x01")) == 3:
|
elif len(ircmsg.split("\x01")) == 3:
|
||||||
CTCPHandler(ircmsg, isRaw=True)
|
self.CTCP(ircmsg, isRaw=True)
|
||||||
elif code == 403:
|
elif code == 403:
|
||||||
self.log(f"Joining {chan} failed", "WARN")
|
self.log(f"Joining {chan} failed", "WARN")
|
||||||
if origin != "null":
|
if origin != "null":
|
||||||
|
@ -99,21 +99,21 @@ class bot:
|
||||||
elif code == 473:
|
elif code == 473:
|
||||||
self.log(f"Joining {chan} failed (+i)", "WARN")
|
self.log(f"Joining {chan} failed (+i)", "WARN")
|
||||||
if origin != "null":
|
if origin != "null":
|
||||||
sendmsg(f"{chan} is +i, and I'm not invited.", origin)
|
self.sendmsg(f"{chan} is +i, and I'm not invited.", origin)
|
||||||
break
|
break
|
||||||
elif code == 520:
|
elif code == 520:
|
||||||
self.log(f"Joining {chan} failed (+O)", "WARN")
|
self.log(f"Joining {chan} failed (+O)", "WARN")
|
||||||
if origin != "null":
|
if origin != "null":
|
||||||
sendmsg(f"{chan} is +O, and I'm not an operator.", origin)
|
self.sendmsg(f"{chan} is +O, and I'm not an operator.", origin)
|
||||||
elif code == 366:
|
elif code == 366:
|
||||||
log(f"Joining {chan} succeeded", server)
|
log(f"Joining {chan} succeeded", server)
|
||||||
if origin != "null":
|
if origin != "null":
|
||||||
sendmsg(f"Joined {chan}", origin)
|
self.sendmsg(f"Joined {chan}", origin)
|
||||||
self.channels[chan] = 0
|
self.channels[chan] = 0
|
||||||
break
|
break
|
||||||
|
|
||||||
def send(self, command: str) -> int:
|
def send(self, command: str) -> int:
|
||||||
return ircsock.send(bytes(command))
|
return self.sock.send(bytes(command))
|
||||||
|
|
||||||
def recv(self) -> bytes:
|
def recv(self) -> bytes:
|
||||||
if self.queue:
|
if self.queue:
|
||||||
|
@ -127,7 +127,7 @@ class bot:
|
||||||
def log(self, message: object, level: str = "LOG") -> None:
|
def log(self, message: object, level: str = "LOG") -> None:
|
||||||
log(message, self.server)
|
log(message, self.server)
|
||||||
|
|
||||||
def exit(message: object) -> NoReturn:
|
def exit(self, message: object) -> NoReturn:
|
||||||
log(message, self.server, "EXIT")
|
log(message, self.server, "EXIT")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue