MAJOR REWORK 2
This commit is contained in:
parent
a514b0432e
commit
14bec4c9f9
1 changed files with 31 additions and 2 deletions
33
bot.py
33
bot.py
|
@ -4,7 +4,7 @@ from overrides import bytes, bbytes
|
|||
from logs import log
|
||||
import re
|
||||
from typing import NoReturn
|
||||
|
||||
from config import npbase, servers, __version__
|
||||
|
||||
class bot:
|
||||
def __init__(server: str):
|
||||
|
@ -26,10 +26,39 @@ class bot:
|
|||
self.exitcode = f"bye {botnick.lower()}"
|
||||
self.np = re.compile(npbase.replace("MAX", f"{nicklen}"))
|
||||
self.queue = []
|
||||
self.__version__ = "v1.0.5"
|
||||
self.socket = socket(AF_INET, SOCK_STREAM)
|
||||
log(f"Start init for {server}", self.server)
|
||||
|
||||
def connect(self) -> None:
|
||||
self.log(f"Joining {server}...")
|
||||
self.socket.connect((self.address, self.port))
|
||||
self.send(f"USER {botnick} {botnick} {botnick} {botnick}\n")
|
||||
self.send(f"NICK {botnick}\n")
|
||||
while (
|
||||
ircmsg.find("MODE " + botnick) == -1 and ircmsg.find("PRIVMSG " + botnick) == -1
|
||||
):
|
||||
ircmsg = self.recv().decode()
|
||||
if ircmsg != "":
|
||||
print(bytes(ircmsg).lazy_decode())
|
||||
if ircmsg.find("NICKLEN=") != -1:
|
||||
self.nicklen = int(ircmsg.split("NICKLEN=")[1].split(" ")[0])
|
||||
self.np = re.compile(npbase.replace("MAX", f"{nicklen}"))
|
||||
self.log(f"NICKLEN set to {nicklen}")
|
||||
if ircmsg.find("Nickname") != -1:
|
||||
self.warn("Nickname in use")
|
||||
self.botnick = f"{botnick}{r.randint(0,1000)}"
|
||||
self.send(f"NICK {botnick}\n")
|
||||
self.log(f"botnick is now {botnick}")
|
||||
if ircmsg.startswith("PING "):
|
||||
self.ping(ircmsg)
|
||||
if len(ircmsg.split("\x01")) == 3:
|
||||
self.CTCPHandler(ircmsg, isRaw=True)
|
||||
if ircmsg.find("Closing Link") != -1:
|
||||
self.exit("Closing Link")
|
||||
else:
|
||||
self.exit("Lost connection to the server")
|
||||
self.log(f"Joined {server} successfully!")
|
||||
|
||||
def send(self, command: str) -> int:
|
||||
return ircsock.send(bytes(command))
|
||||
|
||||
|
|
Loading…
Reference in a new issue