From 557ec8bebdb781d5efd61e28655132e8a013d232 Mon Sep 17 00:00:00 2001 From: raspbeguy Date: Wed, 1 Jun 2016 01:28:18 +0200 Subject: [PATCH] J'aurais ptet mieux fait de faire un UML finallement... --- sexiibot/core.py | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/sexiibot/core.py b/sexiibot/core.py index 2ec22e2..dc37a32 100644 --- a/sexiibot/core.py +++ b/sexiibot/core.py @@ -3,6 +3,25 @@ import os import subprocess +class Channel(object): + """Channel class""" + + def __init__(self, name, network, nick, extensions=None): + self.__name = name + self.__nick = nick + self.__in = open("%s/irc/%s/%s/in" % (os.environ["HOME"], network, name), "w", 1) + self.__out = open("%s/irc/%s/%s/out" % (os.environ["HOME"], network, name), "r") + self.__exts = extentions + self.__mode = None + + def message(self, message): + self.__in.write(message + "\n") + + def action(self, action): + message("/j %s" % action) + + + class Sexiibot(object): """Core sexiibot class""" @@ -13,15 +32,13 @@ class Sexiibot(object): self.__server = None self.__port = port self.__ssl = ssl - self.__channel = channel + self.__channels = channels self.__nick = nick self.__realname = realname else: self.__realname = realname - self.__extensions = extensions - self.__mode = None - self.__servfifo = None - self.__chanfifo = None + self.__in = None + self.__out = None self.__iipath = iipath sekf.__iiproc = None @@ -33,8 +50,22 @@ class Sexiibot(object): print("FIFO for that server already exist.") print("Please clean the irc folder and try again.") sys.exit(1) - cmd = [iipath, "-s", self.__server, "-n", self.__nick, "-f", self.__realnamei] + if self.__port is None: + if self.__ssl: + self.__port = 6697 + else: + self.__port = 6667 + cmd = [iipath, "-s", self.__server, "-p", self.__port, "-n", self.__nick, "-f", self.__realname] if self.__ssl: cmd += ["-e", "ssl"] self.__iiproc = subprocess.Popen(cmd) # self.__iiproc.terminate() later to stop - + self.__in = open("%s/irc/%s/in" % (os.environ["HOME"], self.__server), "w", 1) + + def messageServer(self, message): + self.__in.write(message + "\n") + + def join(self, channel): + messageServer("/j %s" % channel) + + def messageChannel(self, channel, message): + self.__channels[channel].message(message)