Skip to content
multibot.py~ 2.21 KiB
Newer Older
nextime's avatar
nextime committed
###########################################################################
# Copyright (c) 2016-2017 Franco (nextime) Lanza <nextime@nexlab.it>
#
# Multibot daemon
#
# This file is part of multibot.
#
# multibot2 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from twisted.application import service
from twisted.internet import defer, reactor, task, protocol, threads
from nexlibs.utils.genutils import configFile, FakeObject, ConvenienceCaller
from nexlibs import genutils
from nexlibs import webutils as wu
import time, logging, sys, os
from libs.txscheduling import task  as txcron
from libs.txscheduling.cron import CronSchedule, parseCronLine
from libs.txscheduling.interfaces import ISchedule
from netifaces import interfaces, ifaddresses, AF_INET
import struct
import extplugins
import modules
import events
try:
   import hashlib
   md5 = hashlib
   md5.new = hashlib.md5
   sha1 = hashlib.sha1
except:
   import md5
   import sha1


log = logging.getLogger( 'Core' )


class MultibotService(service.Service):


   initialized=False

   def __init__(self, *args, **kwargs):
      log.info('Initializing Core')
      self.curdir=kwargs['curdir']
      self.config=kwargs['config']
      sys.path.append(self.curdir+"/multibot")
      log.debug('Current dir: '+self.curdir)
      if self.parent:
         self.parent.__new__(self.parent, self, *args)


   def configureDaemon(self, force=False):
      if force or not self.initialized:
         # XXX Here configure daemon initialization
         self.initialized=True

   def isStarted(self):
      self.configureDaemon()
      return self.initialized