forked from Firepup650/FireBot
add message queue, fix a bug in joining channels, and don't respond to fake PINGs.
This commit is contained in:
parent
a41c64e53c
commit
40d38f3046
1 changed files with 12 additions and 4 deletions
16
ircbot.py
16
ircbot.py
|
@ -89,6 +89,7 @@ if __name__ == "__main__":
|
||||||
np = re.compile(
|
np = re.compile(
|
||||||
npbase.replace("MAX", f"{nicklen}")
|
npbase.replace("MAX", f"{nicklen}")
|
||||||
)
|
)
|
||||||
|
queue = []
|
||||||
log(f"Start init for {server}")
|
log(f"Start init for {server}")
|
||||||
npallowed = ["FireBitBot"]
|
npallowed = ["FireBitBot"]
|
||||||
ESCAPE_SEQUENCE_RE = re.compile(
|
ESCAPE_SEQUENCE_RE = re.compile(
|
||||||
|
@ -119,7 +120,14 @@ def send(command: str, encoding: str = "UTF-8") -> int:
|
||||||
|
|
||||||
|
|
||||||
def recv() -> bytes:
|
def recv() -> bytes:
|
||||||
return bytes(ircsock.recv(2048).strip(b"\r\n"))
|
global queue
|
||||||
|
if queue:
|
||||||
|
return bytes(queue.pop(0))
|
||||||
|
data = bytes(ircsock.recv(2048).strip(b"\r\n"))
|
||||||
|
if b'\r\n' in data:
|
||||||
|
queue.extend(data.split(b'\r\n'))
|
||||||
|
return bytes(queue.pop(0))
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
def ping(ircmsg: str) -> int:
|
def ping(ircmsg: str) -> int:
|
||||||
|
@ -206,7 +214,7 @@ def joinserver():
|
||||||
botnick = f"{botnick}{r.randint(0,1000)}"
|
botnick = f"{botnick}{r.randint(0,1000)}"
|
||||||
send(f"NICK {botnick}\n")
|
send(f"NICK {botnick}\n")
|
||||||
log(f"botnick is now {botnick}")
|
log(f"botnick is now {botnick}")
|
||||||
if ircmsg.find("PING :") != -1:
|
if ircmsg.startswith("PING "):
|
||||||
# pong = "PONG :" + input("Ping?:") + "\n"
|
# pong = "PONG :" + input("Ping?:") + "\n"
|
||||||
# pong = pong.replace("\\\\", "\\")
|
# pong = pong.replace("\\\\", "\\")
|
||||||
ping(ircmsg)
|
ping(ircmsg)
|
||||||
|
@ -247,8 +255,8 @@ def joinchan(chan: str, origin: str, chanList: dict, lock: bool = True):
|
||||||
ircmsg = recv().decode()
|
ircmsg = recv().decode()
|
||||||
if ircmsg != "":
|
if ircmsg != "":
|
||||||
print(bytes(ircmsg).lazy_decode())
|
print(bytes(ircmsg).lazy_decode())
|
||||||
if ircmsg.find("PING :") != -1:
|
if ircmsg.startswith("PING "):
|
||||||
ping()
|
ping(ircmsg)
|
||||||
if len(ircmsg.split("\x01")) == 3:
|
if len(ircmsg.split("\x01")) == 3:
|
||||||
CTCPHandler(ircmsg, isRaw=True)
|
CTCPHandler(ircmsg, isRaw=True)
|
||||||
if ircmsg.find("No such channel") != -1:
|
if ircmsg.find("No such channel") != -1:
|
||||||
|
|
Loading…
Reference in a new issue