2021-09-16 17:35:06 +00:00
|
|
|
import irctokens
|
2021-10-04 12:48:10 +00:00
|
|
|
|
|
|
|
|
2021-09-16 17:35:06 +00:00
|
|
|
class Util:
|
2021-10-04 12:48:10 +00:00
|
|
|
def __init__(self, config, sock):
|
|
|
|
self.sock = sock
|
|
|
|
self.config = config
|
|
|
|
self.target = ""
|
2021-10-04 15:49:05 +00:00
|
|
|
self.dict = {
|
|
|
|
"\x00": "\\x00",
|
|
|
|
"\x01": "\\x01",
|
|
|
|
"\x02": "\\x02",
|
|
|
|
"\x03": "\\x03",
|
|
|
|
"\x04": "\\x04",
|
|
|
|
"\x05": "\\x05",
|
|
|
|
"\x06": "\\x06",
|
|
|
|
"\x07": "\\x07",
|
|
|
|
"\x08": "\\x08",
|
|
|
|
"\x09": "\\x09",
|
|
|
|
"\x0a": "\\x0a",
|
|
|
|
"\x0b": "\\x0b",
|
|
|
|
"\x0c": "\\x0c",
|
|
|
|
"\x0d": "\\x0d",
|
|
|
|
"\x0e": "\\x0e",
|
|
|
|
"\x0f": "\\x0f",
|
|
|
|
"\x10": "\\x10",
|
|
|
|
"\x11": "\\x11",
|
|
|
|
"\x12": "\\x12",
|
|
|
|
"\x13": "\\x13",
|
|
|
|
"\x14": "\\x14",
|
|
|
|
"\x15": "\\x15",
|
|
|
|
"\x16": "\\x16",
|
|
|
|
"\x17": "\\x17",
|
|
|
|
"\x18": "\\x18",
|
|
|
|
"\x19": "\\x19",
|
|
|
|
"\x1a": "\\x1a",
|
|
|
|
"\x1b": "\\x1b",
|
|
|
|
"\x1c": "\\x1c",
|
|
|
|
"\x1d": "\\x1d",
|
|
|
|
"\x1e": "\\x1e",
|
|
|
|
"\x1f": "\\x1f",
|
|
|
|
}
|
2021-10-04 12:48:10 +00:00
|
|
|
|
|
|
|
def send(self, raw: str):
|
2021-10-04 15:49:05 +00:00
|
|
|
stri = raw
|
|
|
|
for k, v in self.dict.items():
|
|
|
|
stri = stri.replace(k, v)
|
|
|
|
print(f"> {stri}")
|
2021-09-16 17:35:06 +00:00
|
|
|
self.sock.sendall(f"{raw}\r\n".encode("utf8"))
|
2021-10-04 12:48:10 +00:00
|
|
|
|
|
|
|
def quit(self, msg=None):
|
|
|
|
if msg != None:
|
|
|
|
self.send("QUIT :" + msg)
|
|
|
|
else:
|
|
|
|
self.send("QUIT")
|
|
|
|
|
|
|
|
def nick(self, nick=None):
|
|
|
|
if nick == None:
|
|
|
|
self.send("NICK " + self.config.self.nick)
|
|
|
|
else:
|
|
|
|
self.send("NICK " + nick)
|
|
|
|
|
|
|
|
def mesg(self, msg: str, t=None):
|
|
|
|
if t == None:
|
|
|
|
t = self.target
|
|
|
|
msg = str(msg).partition("\n")[0]
|
|
|
|
if len(msg) >= 900:
|
|
|
|
msg = msg[:900]
|
2021-10-03 21:36:22 +00:00
|
|
|
self.mesg("message too long!")
|
2021-10-04 12:48:10 +00:00
|
|
|
self.send(irctokens.build("PRIVMSG", [t, str(msg)]).format())
|