def __init__(self, reactor, conf_filename, conf_json): self.reactor = reactor self.connections = dict() self.config_filename = conf_filename self.config = conf_json self.plugins = PluginManager() self.cmdprefix = self.config.get('command-prefix', '@').encode('ascii')
class LanguageManager(): def __init__(self): self.pm = PluginManager('lang') self.pm.loadPlugins() self.language = self.pm.getPlugin("en") def setLanguage(self, languagekey): self.language = self.pm.getPlugin(languagekey) def get(self, key): if self.language.map[key] == None: return key else: return self.language.map[key]
class AppModel(): def __init__(self): self.logger = logging.getLogger('picsort') self.sourceDir = None self.targetDir = None self.theme = None self.images = [] self.counter = 0 self.windowWidth = None self.windowHeight = None self.isrunning = True self.original = None self.img = None self.windowapp = WindowApp(self) self.windowapp.start() self.inputprocessor = InputProcessor(self) self.renderer = ScreenRenderer(self) self.pluginmanager = PluginManager(tools.getResource("plugins")) self.pluginmanager.addDirectory(os.path.join(tools.getHome(), ".picsortPlugins")) self.pluginmanager.loadPlugins() self.showHelp = True self.showNumbers = True self.isRotated = False for plugin in self.pluginmanager.plugins: try: self.pluginmanager.plugins[plugin].init(self) except Exception, e: self.logger.warn("Error while init for: " + plugin) self.logger.warn(plugin + " -> " + str(e))
def __init__(self): # basic variables self.start_time = time.time() self.running = True self.do_restart = False # stores all queued messages from all connections self.queued_messages = queue.Queue() # format: [{ # "conn": BotConnection, "raw": str, "prefix": str, "command": str, "params": str, "nick": str, # "user": str, "host": str, "mask": str, "paramlist": list[str], "lastparam": str # }] # stores each bot server connection self.connections = [] # set up logging self.logger = get_logger() self.logger.debug("Logging system initialised.") # declare and create data folder self.data_dir = os.path.abspath('data') if not os.path.exists(self.data_dir): self.logger.debug("Data folder not found, creating.") os.mkdir(self.data_dir) # set up config self.config = config.Config(self) self.logger.debug("Config system initialised.") # setup db db_path = self.config.get('database', 'sqlite:///cloudbot.db') self.db_engine = create_engine(db_path) self.db_factory = sessionmaker(bind=self.db_engine) self.db_session = scoped_session(self.db_factory) self.db_metadata = MetaData() # set botvars.metadata so plugins can access when loading botvars.metadata = self.db_metadata self.logger.debug("Database system initialised.") # Bot initialisation complete self.logger.debug("Bot setup completed.") self.threads = {} # create bot connections self.create_connections() # run plugin loader self.plugin_manager = PluginManager(self) self.loader = PluginLoader(self)
def __init__(self): self.pm = PluginManager('lang') self.pm.loadPlugins() self.language = self.pm.getPlugin("en")
class Fubot(object): """The Fubot""" quitting = False quitmsg = 'time to go' def __init__(self, reactor, conf_filename, conf_json): self.reactor = reactor self.connections = dict() self.config_filename = conf_filename self.config = conf_json self.plugins = PluginManager() self.cmdprefix = self.config.get('command-prefix', '@').encode('ascii') def _connect(self): """Connect to networks""" for nwconfig in self.config['networks']: network = FuFactory(self.reactor, self, nwconfig) self.connections[network.name] = network self.plugins.add_network(network.name) network.connect() log.msg('Connected to network [%s] as [%s]' % (network.name, network.protocol.nickname)) def add_channel(self, network, channel): self.plugins.add_channel(network, channel) def _sigint(self, signal, frame): """Sigint handler""" log.msg('Received SIGINT') self.stop('Oh my, received SIGINT :/') def start(self): """Load all plugins in the config file and connect to all networks in the config file """ # Get plugins from config file and load them plugins = self.config.get('plugins', []) for plugin in plugins: self.plugins.enable_global(plugin.get('name', '')) # Connect to the networks self._connect() def stop(self, msg='time to go'): """Stop all plugins and disconnect from all networks""" if self.quitting: return self.quitting = True for name in self.connections: log.msg('Disconnecting from network [%s]' % name) connection = self.connections[name].connection if connection: connection.quit(msg) self.connections = {} self.plugins.stop() self.reactor.callLater(2, self.reactor.stop) quit = stop def help(self, proto, user, channel, args): """Help the user""" help = '' user = user[0] if args: command = args[0] plugins = self.plugins.filter(network=proto.network, channel=channel, interface=IMsgHandler, command=command) if plugins: help = '[%s] %s' % (command, plugins[0].help(command)) else: help = 'Sorry, can\'t help you with that command...' else: plugins = self.plugins.filter(network=proto.network, channel=channel, interface=IMsgHandler) help = 'Commands: ' for plugin in plugins: help += plugin.list_commands()[0] + ' ' proto.msg(channel, '%s: %s' % (user, help)) def info(self, proto, user, channel, args): """Give some bot info""" proto.msg(channel, 'Hi %s! Im fubot, another useless bot. See %s' % (user[0], 'https://git hub.com/fbs/fubot') + ' to find out more about the sad mess that I am') def admin(self, proto, user, channel, message): pass def handle_privmsg(self, proto, user, channel, message): """Handle private messages""" cmd = '' args = '' user = _split_user(user) internalcmd = {'info': self.info, 'help': self.help, 'admin': self.admin} # " @command arg1 arg2" -> ['@command', 'arg1', 'arg2'] # " @ command arg1" -> ['@', 'arg1'] msglst = [w for w in message.split(' ') if w] # Private messages dont have to start with the command prefix if channel == proto.nickname: # print 'channel is nick' channel = user[0] if msglst[0][0] == self.cmdprefix: cmd = msglst[0][1:] else: cmd = msglst[0] args = msglst[1:] # Channel messages do elif msglst[0][0] == self.cmdprefix: cmd = msglst[0][1:] args = msglst[1:] # Skip invalid commands else: return rawplugins = self.plugins.filter(network=proto.network, channel=channel, interface=IRawMsgHandler) for plugin in rawplugins: plugin.handle(proto, user, channel, message) if cmd in internalcmd: internalcmd[cmd](proto, user, channel, args) return plugins = self.plugins.filter(network=proto.network, channel=channel, interface=IMsgHandler, command=cmd) for plugin in plugins: # log.msg("Plugin found: %s" % plugin.name) plugin.handle(proto, cmd, user, channel, args)