thread, séparation des fichiers, toussa...
This commit is contained in:
parent
557ec8bebd
commit
b9af403a43
|
@ -58,3 +58,6 @@ docs/_build/
|
||||||
# PyBuilder
|
# PyBuilder
|
||||||
target/
|
target/
|
||||||
|
|
||||||
|
# vim
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
#!/bin/env python
|
||||||
|
|
||||||
|
import time
|
||||||
|
import threading
|
||||||
|
#from core import Sexiibot
|
||||||
|
|
||||||
|
class Channel(object):
|
||||||
|
"""Channel class"""
|
||||||
|
|
||||||
|
def __init__(self, name, bot, extensions=None):
|
||||||
|
bot.join(name)
|
||||||
|
self.__name = name
|
||||||
|
self.__bot = bot
|
||||||
|
self.__in = open(bot.getIrcPath() + "%s/in" % name, 'w', 1)
|
||||||
|
self.__out = open(bot.getIrcPath() + "%s/out" % name, 'r')
|
||||||
|
self.__exts = extentions
|
||||||
|
self.__mode = None
|
||||||
|
self.__alive = True
|
||||||
|
self.__thread = threading.Thread(target=watch).start()
|
||||||
|
|
||||||
|
|
||||||
|
def message(self, msg):
|
||||||
|
self.__in.write(msg + "\n")
|
||||||
|
|
||||||
|
def action(self, action):
|
||||||
|
self.message("/j %s" % action)
|
||||||
|
|
||||||
|
def leave(self, msg="sexiibot, the bot you're dreaming about"):
|
||||||
|
self.message("/l %s" % msg)
|
||||||
|
self.__alive = False
|
||||||
|
self.__thread.join()
|
||||||
|
self.__in.close()
|
||||||
|
self.__out.close()
|
||||||
|
|
||||||
|
def watch(self):
|
||||||
|
while self.__alive:
|
||||||
|
line = self.__out.readline()
|
||||||
|
if line:
|
||||||
|
print(line) #À ce stade du développement on ne traite rien
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
|
@ -2,30 +2,12 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from channel import Channel
|
||||||
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):
|
class Sexiibot(object):
|
||||||
"""Core sexiibot class"""
|
"""Core sexiibot class"""
|
||||||
|
|
||||||
def __init__(self, new=True, server, port=None, ssl=False, channel, nick, realname=None, extensions, iipath=None)
|
def __init__(self, server, nick, new=True, port=None, ssl=False, channel=None, realname=None, extensions=None, iipath=None):
|
||||||
if new:
|
if new:
|
||||||
self.__server = server
|
self.__server = server
|
||||||
else:
|
else:
|
||||||
|
@ -34,7 +16,8 @@ class Sexiibot(object):
|
||||||
self.__ssl = ssl
|
self.__ssl = ssl
|
||||||
self.__channels = channels
|
self.__channels = channels
|
||||||
self.__nick = nick
|
self.__nick = nick
|
||||||
self.__realname = realname
|
if not realname is None:
|
||||||
|
self.__realname = nick
|
||||||
else:
|
else:
|
||||||
self.__realname = realname
|
self.__realname = realname
|
||||||
self.__in = None
|
self.__in = None
|
||||||
|
@ -43,7 +26,7 @@ class Sexiibot(object):
|
||||||
sekf.__iiproc = None
|
sekf.__iiproc = None
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
exists = os.path.isfile("%s/irc/%s/in" % (os.environ["HOME"], self.__server))
|
exists = os.path.isfile(self.getIrcPath() + "in")
|
||||||
if not self.__server is None:
|
if not self.__server is None:
|
||||||
# Check if a ii instance isn't already running on our potentially existing FIFO
|
# Check if a ii instance isn't already running on our potentially existing FIFO
|
||||||
if exists:
|
if exists:
|
||||||
|
@ -59,13 +42,17 @@ class Sexiibot(object):
|
||||||
if self.__ssl:
|
if self.__ssl:
|
||||||
cmd += ["-e", "ssl"]
|
cmd += ["-e", "ssl"]
|
||||||
self.__iiproc = subprocess.Popen(cmd) # self.__iiproc.terminate() later to stop
|
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)
|
self.__in = open(self.getIrcPath() + "in", 'w', 1)
|
||||||
|
self.__out = open(self.getIrcPath() + "out", 'r')
|
||||||
|
|
||||||
def messageServer(self, message):
|
def messageServer(self, message):
|
||||||
self.__in.write(message + "\n")
|
self.__in.write(message + "\n")
|
||||||
|
|
||||||
def join(self, channel):
|
def join(self, channel):
|
||||||
messageServer("/j %s" % channel)
|
self.messageServer("/j %s" % channel)
|
||||||
|
|
||||||
def messageChannel(self, channel, message):
|
def messageChannel(self, channel, message):
|
||||||
self.__channels[channel].message(message)
|
self.__channels[channel].message(message)
|
||||||
|
|
||||||
|
def getIrcPath():
|
||||||
|
return "%s/irc/%s/" % (os.environ["HOME"], self.__server)
|
||||||
|
|
Loading…
Reference in New Issue