Esempio n. 1
0
from sbnc.proxy import Proxy
from plugins.ui import UIPlugin

proxy_svc = ServiceRegistry.get(Proxy.package)
ui_svc = ServiceRegistry.get(UIPlugin.package)

class TestPlugin(Plugin):
    """Just a test plugin."""

    package = 'info.shroudbnc.plugins.plugin101'
    name = 'Test Plugin 101'
    description = __doc__
    
    def __init__(self):
        try:
            user = proxy_svc.create_user('shroud')
            user_config_proxy = user.get_plugin_config(Proxy)
            user_config_proxy.set('password', 'keks')
            user_config_proxy.set('admin', True)
            user_config_proxy.set('away', 'moo!')
            user_config_proxy.set('server_address', ('irc.quakenet.org', 6667))
        except ValueError:
            pass
        
        ui_svc.register_command('moo', self._cmd_moo_handler, 'User', 'says moo', 'Syntax: moo')

    def _cmd_moo_handler(self, clientobj, params, notice):
        ui_svc.send_sbnc_reply(clientobj, 'Moo!', notice)

ServiceRegistry.register(TestPlugin)
Esempio n. 2
0
            message = message_node.value
            ui_svc.send_sbnc_reply(clientobj, '[%s] %s: %s' %
                                   (datetime.utcfromtimestamp(message['timestamp']),
                                   message['source'], message['text']), notice)
            
        if notice:
            erasecmd = '/sbnc erase'
        else:
            erasecmd = '/msg -sBNC erase'
            
        ui_svc.send_sbnc_reply(clientobj, 'End of LOG. Use \'%s\' to ' % (erasecmd) +
                               'remove this log.', notice)
    
    def erase_querylog(self, userobj):
        querylog = self.get_querylog(userobj)
        querylog.clear()
    
    def _cmd_erase_handler(self, clientobj, params, notice):
        querylog = self.get_querylog(clientobj.owner)
        messages = querylog.attributes
        
        if len(messages) == 0:
            ui_svc.send_sbnc_reply(clientobj, 'Your personal log is empty.', notice)
            return

        self.erase_querylog(clientobj.owner)
        
        ui_svc.send_sbnc_reply(clientobj, 'Done.', notice)
    
ServiceRegistry.register(QueryLogPlugin)
Esempio n. 3
0
            return

        user = params[0]

        if not user in proxy_svc.users:
            ui_svc.send_sbnc_reply(clientobj, "There's no such user.", notice)
            return

        userobj = proxy_svc.users[user]

        userobj.admin = False

        ui_svc.send_sbnc_reply(clientobj, "Done.", notice)

    def _cmd_unsuspend_handler(self, clientobj, params, notice):
        if len(params) < 1:
            ui_svc.send_sbnc_reply(clientobj, "Syntax: unsuspend <username>", notice)
            return

        # TODO: implement

        pass

    def _cmd_who_handler(self, clientobj, params, notice):
        # TODO: implement

        pass


ServiceRegistry.register(AdminCommandPlugin)
Esempio n. 4
0
File: ui.py Progetto: BiohZn/sbncng
            
            for line in self.commands[command]['help_text'].split('\n'):
                self.send_sbnc_reply(clientobj, line, notice)
        else:
            self.send_sbnc_reply(clientobj, '--The following commands are available to you--', notice)
            self.send_sbnc_reply(clientobj, '--Used as \'/sbnc <command>\', or \'/msg -sbnc <command>\'', notice)
            
            cmds = {}
            
            for command, cmdobj in self.commands.items():
                if not cmdobj['access_check'](clientobj):
                    continue
                
                if not cmdobj['category'] in cmds:
                    cmds[cmdobj['category']] = {}
                    
                cmds[cmdobj['category']][command] = cmdobj
                
            for category in sorted(cmds):
                self.send_sbnc_reply(clientobj, '--', notice)
                self.send_sbnc_reply(clientobj, category + ' commands', notice)
                
                for command in sorted(cmds[category]):
                    cmdobj = cmds[category][command]
                    
                    self.send_sbnc_reply(clientobj, command +  ' - ' + cmdobj['description'], notice)
                    
            self.send_sbnc_reply(clientobj, 'End of HELP.', notice)

ServiceRegistry.register(UIPlugin)
Esempio n. 5
0
    def __init__(self):
        self._session = None
    
    def start(self, dsn, debug=False):
        """Initializes a database connection for the specified connection string."""
    
        engine = create_engine(dsn, echo=debug)
    
        metadata = _ModelBase.metadata
        metadata.create_all(engine)
    
        SessionClass = sessionmaker(bind=engine)
    
        self._session = SessionClass()
    
        try:
            root = self._session.query(Node).filter_by(name='root', parent=None).one()
        except NoResultFound:
            root = Node('root')
            self._session.add(root)
    
        self._root_node = root
    
    def get_session(self):
        return self._session
    
    def get_root_node(self):
        return self._root_node

ServiceRegistry.register(DirectoryService)
Esempio n. 6
0
    def __init__(self):
        proxy_svc.client_registration_event.add_listener(self._client_registration_handler,
                                                         Event.PostObserver)

        proxy_svc.client_connection_closed_event.add_listener(self._client_closed_handler,
                                                       Event.PostObserver)

        # TODO: implement setting

    def _client_registration_handler(self, evt, clientobj):        
        if clientobj.owner.irc_connection == None or not clientobj.owner.irc_connection.registered:
            return

        clientobj.owner.irc_connection.send_message('AWAY')
        
    def _client_closed_handler(self, evt, clientobj):
        if clientobj.owner.irc_connection == None or not clientobj.owner.irc_connection.registered:
            return

        user_config = clientobj.owner.get_plugin_config(self.__class__)
        away_text = user_config.get('away', None)

        if away_text == None or away_text == '':
            return
        
        if len(clientobj.owner.client_connections) == 0 or \
                clientobj.owner.client_connections == [clientobj]:
            clientobj.owner.irc_connection.send_message('AWAY', away_text)

ServiceRegistry.register(AwayCommandPlugin)
Esempio n. 7
0
        return Event.Handled

    def check_password(self, password):
        return password != None and self._config.get('password', None) == password

    def _get_last_reconnect(self):
        return self._config.get('last_reconnect', None)
    
    def _set_last_reconnect(self, value):
        self._config.set('last_reconnect', value)

    last_reconnect = property(_get_last_reconnect, _set_last_reconnect)
    
    def _get_password(self):
        return self._config.get('password', None)
    
    def _set_password(self, value):
        self._config.set('password', value)

    password = property(_get_password, _set_password)

    def _get_admin(self):
        return self._config.get('admin', None)
    
    def _set_admin(self, value):
        self._config.set('admin', value)

    admin = property(_get_admin, _set_admin)

ServiceRegistry.register(Proxy)