From ab4e50c74d59fb56823518a09ad8cd0d476c0723 Mon Sep 17 00:00:00 2001 From: sidekek Date: Mon, 25 Oct 2021 13:51:40 -0400 Subject: [PATCH] sum stuff --- bot.py | 6 +++++- message.py | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/bot.py b/bot.py index 73d3da8..0319814 100644 --- a/bot.py +++ b/bot.py @@ -7,7 +7,11 @@ def default_event_handler(msg, ctx): elif msg.command == "001": message.manual("", "JOIN", ["#qrs"]).send(ctx.socket) elif msg.command == "PRIVMSG" and "\x01VERSION\x01" in msg.parameters: - message.manual(":"+msg.parameters[0], "PRIVMSG", [msg.prefix[1:].split("!")[0], ":\x01dorfl bot\x01"]).send(s) + message.manual(":"+msg.parameters[0], "PRIVMSG", [msg.prefix[1:].split("!")[0], ":\x01dorfl bot\x01"]).send(ctx.socket) + if msg.command == "PRIVMSG": + pm = privmsg.parse(msg) + if pm.bod == ".hello": + privmsg.build(ctx.nick, pm.to, "hello, world!").msg.send(ctx.socket) class bot: def __init__(self): self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) diff --git a/message.py b/message.py index 05821f1..80d6e96 100644 --- a/message.py +++ b/message.py @@ -33,12 +33,24 @@ class message: class privmsg: def __init__(self): self.msg = message() + self.fr = "" + self.to = "" + self.bod = "" @staticmethod def build(fro, to, body): pm = privmsg() pm.msg.prefix = ":"+fro pm.msg.command = "PRIVMSG" - pm.msg.parameters[0] = to + pm.msg.parameters.append(to) for word in body.split(" "): pm.msg.parameters.append(word) - pm.msg.parameters[1] = ":"+pm.msg.parameters[1] \ No newline at end of file + pm.msg.parameters[1] = ":"+pm.msg.parameters[1] + return pm + @staticmethod + def parse(msg): + pm = privmsg() + pm.msg = msg + pm.fr = msg.prefix[1:] + pm.to = msg.parameters[0] + pm.bod = (" ".join(msg.parameters) if not(type(msg.parameters) == type(str)) else msg.parameters).split(":")[1] + return pm \ No newline at end of file