예제 #1
0
파일: hubbub.py 프로젝트: NURDspace/jsonbot
 def incoming(self, data):
     """ process incoming hubbub data. """
     result = feedparser.parse(data)
     url = find_self_url(result.feed.links)
     logging.debug("hubbub - in - %s - %s" % (url, data))
     try:
         item = self.byurl(url)
         if not item: logging.warn("hubbub - can't find feed for %s" % url) ; return
         if not item.data.running: logging.warn("hubbub - %s is not in running mode" % item.data.url) ; return
         if not item.data.url or item.data.url == 'urlnotset':
             item.data.url = url
             item.save()
         if item:
             loopover = item.data.watchchannels
             name = item.data.name
         else: logging.warn("hubbub - can't find %s item" % url) ; return
         logging.warn("loopover in %s peek is: %s" % (name, loopover))
         counter = 1
         for i in loopover:
             if len(i) == 3:
                 try: (botname, type, channel) = i
                 except:
                     try: (botname, type, channel) = loads(i)
                     except:
                         logging.warn('hubbub - %s is not in the format (botname, bottype, channel)' % str(item))
                         continue
             else:
                 logging.warn('hubbub - %s is not in the format (botname, bottype, channel)' % item.data.url)
                 continue
             counter += 1
             start_new_thread(self.work, (botname, type, channel, result.entries, url), {"_countdown": counter})
     except Exception, ex: handle_exception(txt=url)
     return True
예제 #2
0
파일: wait.py 프로젝트: melmothx/jsonbot
 def register(self, cmnd, catch, queue, timeout=15):
     """ register wait for cmnd. """
     logging.debug('irc - wait - registering for cmnd ' + cmnd)
     self.ticket += 1
     self.waitlist.insert(0, (cmnd, catch, queue, self.ticket))
     if timeout: thr.start_new_thread(self.dotimeout, (timeout, self.ticket))
     return self.ticket
예제 #3
0
def handle_fleetconnect(bot, ievent):
    """ arguments: <botname> - connect a fleet bot to it's server. """
    try:
        botname = ievent.args[0]
    except IndexError:
        ievent.missing('<botname>')
        return
    try:
        fleet = getfleet()
        fleetbot = fleet.byname(botname)
        if fleetbot:
            start_new_thread(fleetbot.connect, ())
            ievent.reply('%s connect thread started' % botname)
        else:
            ievent.reply("can't connect %s .. trying enable" % botname)
            cfg = Config('fleet' + os.sep + stripname(botname) + os.sep +
                         'config')
            cfg['disable'] = 0
            if not cfg.name: cfg.name = botname
            cfg.save()
            bot = fleet.makebot(cfg.type, cfg.name, cfg)
            if bot:
                ievent.reply('enabled and started %s bot' % botname)
                start_new_thread(bot.start, ())
            else:
                ievent.reply("can't make %s bot" % cfg.name)
    except Exception, ex:
        ievent.reply(str(ex))
예제 #4
0
 def handle_privmsg(self, ievent):
     """ check if PRIVMSG is command, if so dispatch. """
     if ievent.nick in self.nicks401:
         logging.debug("%s - %s is available again" % (self.name, ievent.nick))
         self.nicks401.remove(ievent.nick)
     if not ievent.txt: return
     chat = re.search(dccchatre, ievent.txt)
     if chat:
         if self.users.allowed(ievent.userhost, 'USER'):
             start_new_thread(self._dccconnect, (ievent.nick, ievent.userhost, chat.group(1), chat.group(2))) 
             return
     if '\001' in ievent.txt:
         Irc.handle_privmsg(self, ievent)
         return
     ievent.bot = self
     ievent.sock = self.sock
     chan = ievent.channel
     if chan == self.nick:
         ievent.msg = True
         ievent.speed =  4
         ievent.printto = ievent.nick
         ccs = ['!', '@', self.cfg['defaultcc']]
         self.privwait.check(ievent)
         if ievent.isresponse:
             return
         if self.cfg['noccinmsg'] and self.msg:
             self.put(ievent)
         elif ievent.txt[0] in ccs: 
             self.put(ievent)
         return
     self.put(ievent)
     if not ievent.iscmnd(): self.privwait.check(ievent)
예제 #5
0
def fleet_add(bot, ievent):
    """ add a fleet bot. """
    try:
        name, type, server, nick = ievent.rest.split()
    except ValueError:
        ievent.missing("<name> <type> <server>|<botjid> <nick>|<passwd>")
        return
    bots = ievent.rest.split()
    fleet = getfleet()
    bot = fleet.byname(name)
    if bot:
        event.reply("%s bot already exists" % name)
        return
    cfg = Config('fleet' + os.sep + stripname(name) + os.sep + 'config')
    cfg.disable = 0
    if type == "irc":
        cfg.port = 6667
        cfg.server = server
        cfg.nick = nick
    elif type in ["xmpp", "sxmpp"]:
        cfg.port = 4442
        cfg.host = server
        try:
            n, serv = cfg.host.split("@")
        except (ValueError, TypeError):
            pass
        cfg.server = serv
        cfg.password = nick
    cfg.save()
    bot = fleet.makebot(type, name, cfg)
    ievent.reply('enabled and started %s bot - %s' % (name, cfg.filename))
    start_new_thread(bot.start, ())
예제 #6
0
def fleet_enable(bot, ievent):
    """ enable a fleet bot. """
    if not ievent.rest:
        ievent.missing("list of fleet bots")
        return
    bots = ievent.rest.split()
    fleet = getfleet()
    for name in bots:
        bot = fleet.byname(name)
        if bot:
            bot.cfg.load()
            bot.cfg['disable'] = 0
            bot.cfg.save()
            ievent.reply('enabled %s' % name)
            start_new_thread(bot.connect, ())
        elif name in fleet.avail():
            cfg = Config('fleet' + os.sep + stripname(name) + os.sep +
                         'config')
            cfg['disable'] = 0
            cfg.save()
            bot = fleet.makebot(cfg.type, cfg.name, cfg)
            if not bot:
                ievent.reply("can't make %s bot - %s" % (cfg.name, cfg.type))
                return
            ievent.reply('enabled and started %s bot' % name)
            start_new_thread(bot.start, ())
        else:
            ievent.reply('no %s bot in fleet' % name)
예제 #7
0
파일: fleet.py 프로젝트: code2u/jsb
def fleet_add(bot, ievent):
    """ arguments: <name> <type> <server>|<botjid> <nick>|<passwd> - add a newly created bot to the fleet. """
    try:
        name, type, server, nick = ievent.rest.split()
    except ValueError: ievent.missing("<name> <type> <server>|<botjid> <nick>|<passwd>") ; return
    type = type.lower()
    fleet = getfleet()
    bot = fleet.byname(name)
    if bot: event.reply("%s bot already exists" % name) ; return
    cfg = Config('fleet' + os.sep + stripname(name) + os.sep + 'config')
    cfg.disable = 0
    if type == "irc":
        cfg.port = 6667
        cfg.server = server
        cfg.nick = nick
    elif type in ["xmpp", "sxmpp"]:
        cfg.port = 4442
        cfg.host = server
        try: n, serv = cfg.host.split("@")
        except (ValueError, TypeError): pass
        cfg.server = serv
        cfg.password = nick
    cfg.save()
    bot = fleet.makebot(type, name, cfg)
    fleet.addbot(bot)
    if bot:
        ievent.reply('enabled and started %s bot - %s' % (name, cfg.filename))
        start_new_thread(bot.start, ())
    else: ievent.reply("can't make %s bot" % cfg.name)
예제 #8
0
파일: fleet.py 프로젝트: code2u/jsb
def handle_fleetconnect(bot, ievent):
    """ arguments: <botname> - connect a fleet bot to it's server. """
    try: botname = ievent.args[0]
    except IndexError:
        ievent.missing('<botname>')
        return
    try:
        fleet = getfleet()
        fleetbot = fleet.byname(botname)
        if fleetbot:
            start_new_thread(fleetbot.connect, ())
            ievent.reply('%s connect thread started' % botname)
        else:
            ievent.reply("can't connect %s .. trying enable" % botname)
            cfg = Config('fleet' + os.sep + stripname(botname) + os.sep + 'config')
            cfg['disable'] = 0
            if not cfg.name: cfg.name = botname
            cfg.save()
            bot = fleet.makebot(cfg.type, cfg.name, cfg)
            if bot:
                ievent.reply('enabled and started %s bot' % botname)
                start_new_thread(bot.start, ())
            else: ievent.reply("can't make %s bot" % cfg.name)
    except Exception, ex:
        ievent.reply(str(ex))
예제 #9
0
 def register(self, catch, queue, timeout=15):
     """ register wait for privmsg. """
     logging.debug('xmpp.wait - registering for %s' % catch)
     self.ticket += 1
     self.waitlist.append((catch, queue, self.ticket))
     if timeout:
         thr.start_new_thread(self.dotimeout, (timeout, self.ticket))
     return self.ticket
예제 #10
0
def handle_chat(bot, ievent):
    """ chat .. start a bot initiated dcc chat session. """
    if not bot.type == 'irc':
        ievent.reply("chat only works on irc bots")
        return
    i = ievent
    thr.start_new_thread(bot._dcclisten, (i.nick, i.userhost, i.channel))
    ievent.reply('dcc chat request sent')
예제 #11
0
파일: wait.py 프로젝트: melmothx/jsonbot
 def register(self, catch, queue, timeout=15):
     """ register wait for privmsg. """
     logging.debug('xmpp.wait - registering for %s' % catch)
     self.ticket += 1
     self.waitlist.append((catch, queue, self.ticket))
     if timeout:
         thr.start_new_thread(self.dotimeout, (timeout, self.ticket))
     return self.ticket
예제 #12
0
def handle_markovlearnadd(bot, ievent):
    """ add log or url to be learned at startup or reload """
    try: item = ievent.args[0]
    except IndexError: ievent.missing('<channel>|<url>|spider:<url>') ; return
    if item in markovlearn.data.l: ievent.reply('%s is already in learnlist' % item) ; return
    markovlearn.data.l.append(item)
    markovlearn.save()
    start_new_thread(markovtrain, (markovlearn.data.l,))
    ievent.reply('done')
예제 #13
0
def init():
    """ init plugin """
    if not cfg.get('enable'): return 1
    callbacks.add("PRIVMSG", cb_markovtalk, cb_markovtalk_test, threaded=True)
    callbacks.add('JOIN', cb_markovjoin, threaded=True)
    callbacks.add('MESSAGE', cb_markovtalk, cb_markovtalk_test, threaded=True)
    callbacks.add('CONSOLE', cb_markovtalk, cb_markovtalk_test, threaded=True)
    start_new_thread(markovtrain, (markovlearn.data.l,))
    return 1
예제 #14
0
 def check(self):
     """ run check to see if job needs to be scheduled. """
     if self.next <= time.time():
         logging.info('running %s - %s' % (str(self.func), self.description))
         self.next = time.time() + self.interval
         thr.start_new_thread(self.do, ())
         self.counts += 1
         if self.repeat > 0 and self.counts >= self.repeat: return False
     return True
예제 #15
0
파일: markov.py 프로젝트: Petraea/jsonbot
def init():
    """ init plugin """
    if not cfg.get('enable'): return 1
    callbacks.add("PRIVMSG", cb_markovtalk, cb_markovtalk_test, threaded=True)
    callbacks.add('JOIN', cb_markovjoin, threaded=True)
    callbacks.add('MESSAGE', cb_markovtalk, cb_markovtalk_test, threaded=True)
    callbacks.add('CONSOLE', cb_markovtalk, cb_markovtalk_test, threaded=True)
    start_new_thread(markovtrain, (markovlearn.data.l, ))
    return 1
예제 #16
0
 def check(self):
     """ run check to see if job needs to be scheduled. """
     if self.next <= time.time():
         logging.info('running %s - %s' %
                      (str(self.func), self.description))
         self.next = time.time() + self.interval
         thr.start_new_thread(self.do, ())
         self.counts += 1
         if self.repeat > 0 and self.counts >= self.repeat: return False
     return True
예제 #17
0
def init():
    global server
    if "host" not in cfg.data or "port" not in cfg.data:
        cfg.data["host"] = "localhost"
        cfg.data["port"] = 54321
        cfg.data["botnames"] = ["default-sxmpp",]
        cfg.data["aliases"] = {}
        cfg.save()
    server = SocketServer.TCPServer((cfg.data["host"], int(cfg.data["port"])), IrcCatListener)
    logging.warn("starting irccat server on %s:%s" % (cfg.data["host"], cfg.data["port"]))
    start_new_thread(server.serve_forever, ())
예제 #18
0
파일: markov.py 프로젝트: Petraea/jsonbot
def handle_markovlearnadd(bot, ievent):
    """ add log or url to be learned at startup or reload """
    try:
        item = ievent.args[0]
    except IndexError:
        ievent.missing('<channel>|<url>|spider:<url>')
        return
    if item in markovlearn.data.l:
        ievent.reply('%s is already in learnlist' % item)
        return
    markovlearn.data.l.append(item)
    markovlearn.save()
    start_new_thread(markovtrain, (markovlearn.data.l, ))
    ievent.reply('done')
예제 #19
0
파일: bot.py 프로젝트: code2u/jsb
 def connect(self, reconnect=False):
     """ connect the xmpp server. """
     if not XMLStream.doconnect(self): return False
     iq = self.makeready()
     if not iq:
         logging.error('%s - connect to %s:%s (%s) failed' % (self.cfg.name, self.cfg.host, self.cfg.port, self.cfg.server))
         return
     self.logon(self.cfg.user, self.cfg.password, iq)
     self._raw("<presence/>")
     start_new_thread(self._keepalive, ())
     if self.cfg.keepchannelsalive: start_new_thread(self._keepchannelsalive, ())
     if self.cfg.doroster: self.requestroster()
     self.connectok.set()
     self.sock.settimeout(None)
     return True
예제 #20
0
파일: server.py 프로젝트: Petraea/jsonbot
 def start(self):
     """ start the REST server. """
     self.name = calledfrom(sys._getframe(0))
     self.stop = False
     self.running = False
     self.handlers = {}
     self.webmods = {}
     self.state = ObjectState()
     self.state.define('whitelistenable', 0)
     self.state.define('whitelist', [])
     self.state.define('blacklist', [])
     self.state.define('disable', [])
     self.poll = select.poll()
     self.poll.register(self)
     start_new_thread(self.serve, ())
예제 #21
0
def handle_testplugs(bot, event):
    """ no arguments - test the plugins by executing all the available examples. """
    global teller
    try:
        loop = int(event.args[0])
    except (ValueError, IndexError):
        loop = 1
    try:
        threaded = event.args[1]
    except (ValueError, IndexError):
        threaded = 0
    try:
        filter = event.args[2]
    except (ValueError, IndexError):
        filter = ""
    threads = []
    teller = 0
    for i in range(loop):
        if threaded:
            threads.append(start_new_thread(dotest, (bot, event, filter)))
        else:
            dotest(bot, event)
    if threads:
        for thread in threads:
            thread.join()
    event.reply('%s tests run' % teller)
    if errors:
        event.reply("there are %s errors .. " % len(errors))
        for cmnd, error in errors.iteritems():
            event.reply("%s - %s" % (cmnd, error))
    else:
        event.reply("no errors")
    event.outqueue.append(None)
예제 #22
0
def handle_testplugs(bot, event):
    """ no arguments - test the plugins by executing all the available examples. """
    bot.plugs.loadall(force=True)
    global teller
    try:
        loop = int(event.args[0])
    except (ValueError, IndexError):
        loop = 1
    try:
        threaded = event.args[1]
    except (ValueError, IndexError):
        threaded = 0
    threads = []
    teller = 0
    # event.dontclose = True
    for i in range(loop):
        if threaded:
            threads.append(start_new_thread(dotest, (bot, event)))
        else:
            dotest(bot, event)
    if threads:
        for thread in threads:
            thread.join()
    event.reply("%s tests run" % teller)
    if errors:
        event.reply("there are %s errors .. " % len(errors))
        for cmnd, error in errors.iteritems():
            event.reply("%s - %s" % (cmnd, error))
    else:
        event.reply("no errors")
    event.outqueue.put_nowait(None)
예제 #23
0
def markovtrain(l):
    """ train items in list """
    time.sleep(1)
    logging.warn("list to scan is: %s" % ",".join(l))
    for i in l:
        if i.startswith('http://'): start_new_thread(markovlearnurl, (i,))
        elif i.startswith('spider://'): start_new_thread(markovlearnspider, (i,))
        elif i.startswith('spiders://'): start_new_thread(markovlearnspider, (i,))
        else: start_new_thread(markovlearnlog, (i,))
    return 1
예제 #24
0
파일: bot.py 프로젝트: melmothx/jsonbot
 def connect(self, reconnect=True):
     """ connect the xmpp server. """
     try:
         if not XMLStream.connect(self):
             logging.error('%s - connect to %s:%s failed' % (self.name, self.host, self.port))
             return
         else: logging.warn('%s - connected' % self.name)
         self.logon(self.cfg.user, self.cfg.password)
         start_new_thread(self._keepalive, ())
         self.requestroster()
         self._raw("<presence/>")
         self.connectok.set()
         self.sock.settimeout(None)
         return True
     except Exception, ex:
         handle_exception()
         if reconnect:
             return self.reconnect()
예제 #25
0
파일: bot.py 프로젝트: Petraea/jsonbot
 def handle_privmsg(self, ievent):
     """ check if PRIVMSG is command, if so dispatch. """
     if ievent.nick in self.nicks401:
         logging.debug("%s - %s is available again" % (self.cfg,name, ievent.nick))
         self.nicks401.remove(ievent.nick)
     if not ievent.txt: return
     ievent.nodispatch = False
     chat = re.search(dccchatre, ievent.txt)
     if chat:
         if self.users.allowed(ievent.userhost, 'USER'):
             start_new_thread(self._dccconnect, (ievent.nick, ievent.userhost, chat.group(1), chat.group(2))) 
             return
     if '\001' in ievent.txt:
         Irc.handle_privmsg(self, ievent)
         return
     ievent.bot = self
     ievent.sock = self.sock
     chan = ievent.channel
     self.put(ievent)
예제 #26
0
def fleet_add(bot, ievent):
    """ arguments: <name> <type> <server>|<botjid> <nick>|<jabberpasswd> [<ircpass>] - add a newly created bot to the fleet. """
    try:
        name, type, server, nick, password = ievent.rest.split()
    except ValueError:
        try:
            name, type, server, nick = ievent.rest.split()
            password = ""
        except ValueError:
            ievent.missing(
                "<name> <type> <server>|<botjid> <nick>|<jabberpass> [<ircpasswd>]"
            )
            return
    type = type.lower()
    fleet = getfleet()
    bot = fleet.byname(name)
    if bot:
        ievent.reply("%s bot already exists" % name)
        return
    cfg = Config('fleet' + os.sep + stripname(name) + os.sep + 'config')
    cfg.disable = 0
    if type == "irc":
        cfg.port = 6667
        cfg.server = server
        cfg.nick = nick
        cfg.password = password
    elif type in ["xmpp", "sxmpp"]:
        cfg.port = 4442
        cfg.host = server
        try:
            n, serv = cfg.host.split("@")
        except (ValueError, TypeError):
            pass
        cfg.server = serv
        cfg.password = nick
    cfg.save()
    bot = fleet.makebot(type, name, cfg)
    fleet.addbot(bot)
    if bot:
        ievent.reply('enabled and started %s bot - %s' % (name, cfg.filename))
        start_new_thread(bot.start, ())
    else:
        ievent.reply("can't make %s bot" % cfg.name)
예제 #27
0
파일: bot.py 프로젝트: Lujeni/old-projects
 def handle_privmsg(self, ievent):
     """ check if PRIVMSG is command, if so dispatch. """
     if ievent.nick in self.nicks401:
         logging.debug("%s - %s is available again" % (self.cfg,name, ievent.nick))
         self.nicks401.remove(ievent.nick)
     if not ievent.txt: return
     ievent.nodispatch = False
     chat = re.search(dccchatre, ievent.txt)
     if chat:
         if self.users.allowed(ievent.userhost, 'USER'):
             start_new_thread(self._dccconnect, (ievent.nick, ievent.userhost, chat.group(1), chat.group(2))) 
             return
     if '\001' in ievent.txt:
         Irc.handle_privmsg(self, ievent)
         return
     ievent.bot = self
     ievent.sock = self.sock
     chan = ievent.channel
     self.put(ievent)
예제 #28
0
def init_threaded():
    global server
    global outputthread
    if server: logging.warn("doorsense server is already running.") ; return
    if not cfg.data.enable: logging.warn("doorsense is not enabled.") ; return 
    time.sleep(3)
    if "host" not in cfg.data or "port" not in cfg.data:
        cfg.data["host"] = ""
        cfg.data["port"] = 55555
        cfg.data["botnames"] = ["default-sxmpp",]
        tcppassword.data['password']='******'
        tcppassword.save()
        cfg.save()
    try:
        server = SocketServer.TCPServer((cfg.data["host"], int(cfg.data["port"])), doorsenseListener)
    except Exception, ex: logging.error(str(ex)) ; return
    logging.warn("starting doorsense server on %s:%s" % (cfg.data["host"], cfg.data["port"]))
    start_new_thread(server.serve_forever, ())
    outputthread = doorsenseOutputThread()
    outputthread.start()
예제 #29
0
파일: markov.py 프로젝트: Petraea/jsonbot
def markovtrain(l):
    """ train items in list """
    time.sleep(1)
    logging.warn("list to scan is: %s" % ",".join(l))
    for i in l:
        if i.startswith('http://'): start_new_thread(markovlearnurl, (i, ))
        elif i.startswith('spider://'):
            start_new_thread(markovlearnspider, (i, ))
        elif i.startswith('spiders://'):
            start_new_thread(markovlearnspider, (i, ))
        else:
            start_new_thread(markovlearnlog, (i, ))
    return 1
예제 #30
0
파일: irccat.py 프로젝트: Petraea/jsonbot
def init_threaded():
    global server
    global outputthread
    if server: logging.warn("irccat server is already running.") ; return
    if not cfg.data.enable: logging.warn("irccat is not enabled.") ; return 
    time.sleep(3)
    if "host" not in cfg.data or "port" not in cfg.data:
        cfg.data["host"] = "localhost"
        cfg.data["port"] = 54321
        cfg.data["botnames"] = ["default-sxmpp",]
        cfg.data["aliases"] = {}
    if not cfg.data.aliases: cfg.data.aliases = {}
    cfg.save()
    try:
        server = SocketServer.TCPServer((cfg.data["host"], int(cfg.data["port"])), IrcCatListener)
    except Exception, ex: logging.error(str(ex)) ; return
    logging.warn("starting irccat server on %s:%s" % (cfg.data["host"], cfg.data["port"]))
    start_new_thread(server.serve_forever, ())
    outputthread = IrcCatOutputThread()
    outputthread.start()
예제 #31
0
파일: udp.py 프로젝트: code2u/jsb
def init():
    """ init the udp plugin. """
    if cfg['udp']:
        global udplistener
        start_new_thread(udplistener._listen, ())
        start_new_thread(udplistener._handleloop, ())
        start_new_thread(udplistener._outloop, ())
    return 1
예제 #32
0
파일: udp.py 프로젝트: melmothx/jsonbot
def init():
    """ init the udp plugin. """
    if cfg['udp']:
        global udplistener
        start_new_thread(udplistener._listen, ())
        start_new_thread(udplistener._handleloop, ())
        start_new_thread(udplistener._outloop, ())
    return 1
예제 #33
0
파일: fleet.py 프로젝트: melmothx/jsonbot
def fleet_enable(bot, ievent):
    """ enable a fleet bot. """
    if not ievent.rest:
        ievent.missing("list of fleet bots")
        return
    bots = ievent.rest.split()
    fleet = getfleet()
    for name in bots:
        bot = fleet.byname(name)
        if bot:
            bot.cfg.load()
            bot.cfg['disable'] = 0
            bot.cfg.save()
            ievent.reply('enabled %s' % name)
            start_new_thread(bot.connect, ())
        elif name in fleet.avail():
            cfg = Config('fleet' + os.sep + stripname(name) + os.sep + 'config')
            cfg['disable'] = 0
            cfg.save()
            bot = fleet.makebot(cfg.type, cfg.name, cfg)
            if not bot: ievent.reply("can't make %s bot - %s" % (cfg.name, cfg.type)) ; return
            ievent.reply('enabled and started %s bot' % name)
            start_new_thread(bot.start, ())
        else: ievent.reply('no %s bot in fleet' % name)
예제 #34
0
def init_threaded():
    global server
    if server: logging.warn("irccat2 server is already running.") ; return
    if not cfg.enable: logging.warn("irccat2 is not enabled.") ; return 
    time.sleep(2)
    if "host" not in cfg or "port" not in cfg:
        cfg["host"] = "localhost"
        cfg["port"] = 54321
        cfg["botnames"] = ["default-sxmpp",]
        cfg["aliases"] = {}
    if not cfg.aliases: cfg.aliases = {}
    cfg.save()
    try:
        server = SocketServer.TCPServer((cfg["host"], int(cfg["port"])), IrcCatListener)
    except Exception, ex: logging.error(str(ex)) ; return
    logging.warn("starting irccat2 server on %s:%s" % (cfg["host"], cfg["port"]))
    thr = start_new_thread(server.serve_forever, ())
    thr.join(3)
예제 #35
0
def init_threaded():
    global server
    if server: logging.warn("irccat2 server is already running.") ; return
    if not cfg.enable: logging.warn("irccat2 is not enabled.") ; return 
    time.sleep(2)
    cfg["host"] = cfg["host"] or "localhost"
    cfg["port"] = cfg["port"] or 54321
    cfg["botnames"] = cfg["botnames"] or ["default-sxmpp",]
    cfg["aliases"] = cfg["aliases"] or {}
    if not cfg.aliases: cfg.aliases = {}
    cfg.save()
    try:
        server = SocketServer.TCPServer((cfg["host"], int(cfg["port"])), IrcCatListener)
    except socket.error, ex: logging.error("socket error occured: %s" % str(ex)) ; return
    except BotNotEnabled, ex: logging.warn("%s bot is not enabled" % str(ex)) ; return
    except Exception, ex: handle_exception() ; return
    logging.warn("starting irccat2 server on %s:%s" % (cfg["host"], cfg["port"]))
    thr = start_new_thread(server.serve_forever, ())
    thr.join(3)
예제 #36
0
파일: irccat2.py 프로젝트: Petraea/jsonbot
def shutdown():
    global server
    if server:
        logging.warn("shutting down the irccat2 server")
        start_new_thread(server.shutdown, ())
        time.sleep(2)
예제 #37
0
파일: mpd.py 프로젝트: melmothx/jsonbot
 def start(self):
     self.running = True
     start_new_thread(self.watch, ())
예제 #38
0
            return
        self._dodcc(sock, nick, userhost, channel)

    def _dodcc(self, sock, nick, userhost, channel=None):
        """ send welcome message and loop for dcc commands. """
        if not nick or not userhost: return
        try:
            sock.send('Welcome to the GOZERBOT partyline ' + nick + " ;]\n")
            partylist = partyline.list_nicks()
            if partylist: sock.send("people on the partyline: %s\n" % ' .. '.join(partylist))
            sock.send("control character is ! .. bot broadcast is @\n")
        except Exception, ex:
            handle_exception()
            logging.error('%s - dcc error: %s' % (self.name, str(ex)))
            return
        start_new_thread(self._dccloop, (sock, nick, userhost, channel))

    def _dccloop(self, sock, nick, userhost, channel=None):

        """ loop for dcc commands. """

        sockfile = sock.makefile('r')
        sock.setblocking(True)
        res = ""
        partyline.add_party(self, sock, nick, userhost, channel)

        while 1:
            time.sleep(0.001)
            try:
                res = sockfile.readline()
                logging.debug("%s - dcc - %s got %s" % (self.name, userhost, res))
예제 #39
0
 def start(self):
     self.running = True
     start_new_thread(self.watch, ())
예제 #40
0
파일: core.py 프로젝트: melmothx/jsonbot
 def logon(self):
     """ called upon logon on the server. """
     start_new_thread(self._doprocess, ())
예제 #41
0
파일: core.py 프로젝트: melmothx/jsonbot
 def logon(self):
     """ called upon logon on the server. """
     start_new_thread(self._doprocess, ())
예제 #42
0
파일: bot.py 프로젝트: NURDspace/jsonbot
 def session_start(self, event):
     logging.warn("session started")
     self.xmpp.send_presence()
     start_new_thread(self.joinchannels, ())
예제 #43
0
 def start(self):
     """ start the watcher. """
     self.running = True
     start_new_thread(self.watch, ())
예제 #44
0
 def _dccresume(self, sock, nick, userhost, channel=None):
     """ resume dcc loop. """
     if not nick or not userhost: return
     start_new_thread(self._dccloop, (sock, nick, userhost, channel))
예제 #45
0
파일: irccat.py 프로젝트: NURDspace/jsonbot
    time.sleep(3)
    if "host" not in cfg.data or "port" not in cfg.data:
        cfg.data["host"] = "localhost"
        cfg.data["port"] = 54321
        cfg.data["botnames"] = ["default-sxmpp"]
        cfg.data["aliases"] = {}
    if not cfg.data.aliases:
        cfg.data.aliases = {}
    cfg.save()
    try:
        server = SocketServer.TCPServer((cfg.data["host"], int(cfg.data["port"])), IrcCatListener)
    except Exception, ex:
        logging.error(str(ex))
        return
    logging.warn("starting irccat server on %s:%s" % (cfg.data["host"], cfg.data["port"]))
    start_new_thread(server.serve_forever, ())
    outputthread = IrcCatOutputThread()
    outputthread.start()


## plugin shutdonw


def shutdown():
    global server
    if server:
        logging.warn("shutting down the irccat server")
        server.shutdown()
    if outputthread:
        outputthread.stop()
예제 #46
0
파일: irccat2.py 프로젝트: Petraea/jsonbot
    cfg.save()
    try:
        server = SocketServer.TCPServer((cfg["host"], int(cfg["port"])),
                                        IrcCatListener)
    except socket.error, ex:
        logging.error("socket error occured: %s" % str(ex))
        return
    except BotNotEnabled, ex:
        logging.warn("%s bot is not enabled" % str(ex))
        return
    except Exception, ex:
        handle_exception()
        return
    logging.warn("starting irccat2 server on %s:%s" %
                 (cfg["host"], cfg["port"]))
    thr = start_new_thread(server.serve_forever, ())
    thr.join(3)


def shutdown():
    global server
    if server:
        logging.warn("shutting down the irccat2 server")
        start_new_thread(server.shutdown, ())
        time.sleep(2)


## irccat2_add_alias command


def handle_irccat2_add_alias(bot, ievent):
예제 #47
0
파일: mpd.py 프로젝트: code2u/jsb
 def start(self):
     """ start the watcher. """
     self.running = True
     start_new_thread(self.watch, ())
예제 #48
0
def shutdown():
    global server
    if server:
        logging.warn("shutting down the irccat2 server")
        start_new_thread(server.shutdown, ())
        time.sleep(2)
예제 #49
0
파일: bot.py 프로젝트: Petraea/jsonbot
 def session_start(self, event):
     logging.warn("session started")
     self.xmpp.send_presence()
     start_new_thread(self.joinchannels, ())