コード例 #1
0
    def test_channel_message(self, mock_msg):
        firefly_irc = FireflyIRC(Server(self.hostname, self.config))

        dest = containers.Destination(firefly_irc, '#testchan')
        firefly_irc.msg(dest, 'Hello, world!')

        mock_msg.assert_called_once_with(firefly_irc, '#testchan', 'Hello, world!', None)
コード例 #2
0
    def test_user_notice(self, mock_notice):
        firefly_irc = FireflyIRC(Server(self.hostname, self.config))

        host = containers.Hostmask('[email protected]')
        firefly_irc.notice(host, 'Hello, world!')

        mock_notice.assert_called_once_with(firefly_irc, 'test_nick', 'Hello, world!')
コード例 #3
0
    def test_channel_notice(self, mock_notice):
        firefly_irc = FireflyIRC(Server(self.hostname, self.config))

        dest = containers.Destination(firefly_irc, '#testchan')
        firefly_irc.notice(dest, 'Hello, world!')

        mock_notice.assert_called_once_with(firefly_irc, '#testchan', 'Hello, world!')
コード例 #4
0
    def test_private_action_routed(self, mock_privateAction, mock_channelAction, mock__fire_command,
                                    mock__fire_event):
        firefly_irc = FireflyIRC(Server(self.hostname, self.config))
        firefly_irc.action('[email protected]', 'test_nick', 'waves')

        self.assertEqual(mock_privateAction.call_count, 1)
        mock_channelAction.assert_not_called()
        mock__fire_command.assert_not_called()
コード例 #5
0
    def test_private_notice_routed(self, mock_privateNotice, mock_channelNotice, mock__fire_command,
                                    mock__fire_event):
        firefly_irc = FireflyIRC(Server(self.hostname, self.config))
        firefly_irc.noticed('[email protected]', 'test_nick', 'Hello, world!')

        self.assertEqual(mock_privateNotice.call_count, 1)
        mock_channelNotice.assert_not_called()
        mock__fire_command.assert_not_called()
コード例 #6
0
    def test_private_message_routed(self, mock_privateMessage, mock_channelMessage, mock__fire_command,
                                    mock__fire_event):
        firefly_irc = FireflyIRC(Server(self.hostname, self.config))
        firefly_irc.language.get_reply = mock.Mock()
        firefly_irc.language.get_reply.return_value = None
        firefly_irc.privmsg('[email protected]', 'test_nick', 'Hello, world!')

        self.assertEqual(mock_privateMessage.call_count, 1)
        mock_channelMessage.assert_not_called()
        mock__fire_command.assert_not_called()
コード例 #7
0
    def test_ping_once(self, mock_msg):
        firefly_irc = FireflyIRC(Server(self.hostname, self.config))
        params = {'name': 'ping', 'permission': 'guest'}

        firefly_irc.registry.bind_command('ping', self.PluginTest, self.PluginTest.ping, params)

        dest = containers.Destination(firefly_irc, '#test')
        message = containers.Message('>>> plugintest ping 1', dest, containers.Hostmask('[email protected]'))
        firefly_irc._fire_command('plugintest', 'ping', ['1'], message)

        mock_msg.assert_called_once_with(dest, 'pong')
コード例 #8
0
ファイル: useradd.py プロジェクト: FujiMakoto/firefly-irc
def cli(ctx, email, password, group, nick, display_name, force):
    """
    Creates a new user account
    """
    assert isinstance(ctx, Context)

    # Make sure our configuration directory exists
    config_dir = os.path.join(FireflyIRC.CONFIG_DIR, 'config')
    if not os.path.exists(config_dir):
        os.makedirs(config_dir, 0o755)

    # Make sure the user doesn't already exist in our servers configuration
    users_config = FireflyIRC.load_configuration('users')
    users_cfg_path = os.path.join(config_dir, 'users.cfg')
    if email in users_config.sections():
        ctx.log.info('Configuration for %s already exists', email)
        if not force:
            raise click.ClickException('Configuration for {e} already exists'.format(e=email))
        users_config.remove_section(email)

    # Populate users.cfg
    users_config.add_section(email)
    users_config.set(email, 'Password', bcrypt.encrypt(password))
    users_config.set(email, 'Group', group)
    users_config.set(email, 'Nick', nick)
    users_config.set(email, 'DisplayName', display_name)

    # Write to our users configuration file
    with open(users_cfg_path, 'w') as cf:
        users_config.write(cf)

    click.secho('Configuration for user {e} successfully generated'.format(e=email), bold=True)
    click.secho('Users configuration path: {sp}'.format(sp=users_cfg_path), bold=True)
コード例 #9
0
ファイル: serverdel.py プロジェクト: FujiMakoto/firefly-irc
def cli(ctx, host, no_prompt):
    """
    Deletes an existing server from the configuration
    """
    assert isinstance(ctx, Context)

    # Make sure this host actually exists in our configuration
    servers_config = FireflyIRC.load_configuration('servers')
    server_cfg_path = os.path.join(FireflyIRC.CONFIG_DIR, 'config', 'servers.cfg')
    if host not in servers_config.sections():
        ctx.log.error('No configuration for %s exists', host)
        raise click.ClickException('No configuration for {h} exists'.format(h=host))

    # Confirm
    if not no_prompt:
        click.confirm('You are about to delete the IRC configuration files for {hn}\nAre you sure you want to do this?'
                      .format(hn=host), abort=True)

    # Remove the host from servers.cfg
    servers_config.remove_section(host)
    with open(server_cfg_path, 'w') as cf:
        servers_config.write(cf)

    # Remove the server configuration file if it exists
    hostname_fn = '{h}.cfg'.format(h=re.sub('\s', '_', host))
    host_cfg_path = os.path.join(FireflyIRC.CONFIG_DIR, 'config', 'servers', hostname_fn)
    if os.path.exists(host_cfg_path):
        os.remove(host_cfg_path)

    click.secho('{h} configuration files and server setting attributes removed'.format(h=host), bold=True)
コード例 #10
0
    def test_command_call(self, mock_privateMessage, mock_channelMessage, mock__fire_command,
                          mock__fire_event):
        firefly_irc = FireflyIRC(Server(self.hostname, self.config))
        firefly_irc.language.get_reply = mock.Mock()
        firefly_irc.language.get_reply.return_value = None
        firefly_irc.privmsg('[email protected]', '#testchan', '>>> plugintest ping 3')

        _fire_command_args = mock__fire_command.call_args_list
        self.assertTrue(mock__fire_command.called)
        self.assertEqual(_fire_command_args[0][0][0], 'plugintest')
        self.assertEqual(_fire_command_args[0][0][1], 'ping')
        self.assertListEqual(_fire_command_args[0][0][2], ['3'])

        _fire_event_args = mock__fire_event.call_args_list
        self.assertFalse(_fire_event_args[0][0][1], 'has_reply was True when it should have been False')
        self.assertTrue(_fire_event_args[0][0][2], 'is_command was False when it should have been True')

        channelMessage_args = mock_channelMessage.call_args_list
        self.assertFalse(channelMessage_args[0][0][1], 'has_reply was True when it should have been False')
        self.assertTrue(channelMessage_args[0][0][2], 'is_command was False when it should have been True')
コード例 #11
0
ファイル: start.py プロジェクト: FujiMakoto/firefly-irc
def cli(ctx):
    """
    Start Firefly
    """
    # Make sure we don't already have a PID stored
    if not os.path.exists(FireflyIRC.DATA_DIR):
        os.makedirs(FireflyIRC.DATA_DIR)

    pid_file = os.path.join(FireflyIRC.DATA_DIR, 'firefly.pid')
    if os.path.exists(pid_file):
        raise Exception('An instance of Firefly is already running. Even if you are sure this is not the case, please '
                        'run firefly stop and try again.')

    # Load our first server
    servers_config = FireflyIRC.load_configuration('servers')
    servers = []
    hostnames = servers_config.sections()
    for hostname in hostnames:
        if servers_config.getboolean(hostname, 'Enabled'):
            factory = FireflyFactory(Server(hostname, servers_config))
            servers.append(factory)
            reactor.connectTCP(factory.firefly.server.hostname, factory.firefly.server.port, factory)

    # Write our PID file
    with open(pid_file, "w") as f:
        f.write(str(os.getpid()))

    # Run
    try:
        reactor.run()
    except Exception:
        if os.path.exists(pid_file):
            os.remove(pid_file)
        raise

    if os.path.exists(pid_file):
        os.remove(pid_file)
コード例 #12
0
ファイル: userdel.py プロジェクト: FujiMakoto/firefly-irc
def cli(ctx, email, no_prompt):
    """
    Deletes a user account
    """
    assert isinstance(ctx, Context)

    # Make sure this user actually exists in our configuration
    users_config = FireflyIRC.load_configuration('users')
    users_cfg_path = os.path.join(FireflyIRC.CONFIG_DIR, 'config', 'users.cfg')
    if email not in users_config.sections():
        ctx.log.error('No configuration for %s exists', email)
        raise click.ClickException('No such user: {e}'.format(e=email))

    # Confirm
    if not no_prompt:
        click.confirm('You are about to delete the user account {e} ({n})\nAre you sure you want to do this?'
                      .format(e=email, n=users_config.get(email, 'Nick')), abort=True)

    # Remove the host from servers.cfg
    users_config.remove_section(email)
    with open(users_cfg_path, 'w') as cf:
        users_config.write(cf)

    click.secho('Deleted user account {e}'.format(e=email), bold=True)
コード例 #13
0
 def test_aml_instantiation(self):
     firefly_irc = FireflyIRC(Server(self.hostname, self.config))
     firefly_irc._load_language_interface('aml')
     self.assertIsInstance(firefly_irc.language, AgentMLLanguage)
コード例 #14
0
ファイル: serveradd.py プロジェクト: FujiMakoto/firefly-irc
def cli(ctx, host, port, auto, nick, username, realname, ssl, password, channels, force):
    """
    Generates a new server configuration file
    """
    assert isinstance(ctx, Context)

    # Make sure our configuration directory exists
    config_dir = os.path.join(FireflyIRC.CONFIG_DIR, 'config')
    if not os.path.exists(config_dir):
        os.makedirs(config_dir, 0o755)

    servers_dir = os.path.join(config_dir, 'servers')
    if not os.path.exists(servers_dir):
        os.makedirs(servers_dir, 0o755)

    # Make sure the server doesn't already exist in our servers configuration
    servers_config = FireflyIRC.load_configuration('servers')
    server_cfg_path = os.path.join(config_dir, 'servers.cfg')
    if host in servers_config.sections():
        ctx.log.info('Configuration for %s already exists', host)
        if not force:
            raise click.ClickException('Configuration for {h} already exists'.format(h=host))
        servers_config.remove_section(host)

    # Make sure a configuration file for this server doesn't already exist
    hostname_fn = re.sub('\s', '_', host)
    host_cfg_path = os.path.join(servers_dir, hostname_fn)

    if os.path.exists(host_cfg_path):
        ctx.log.info('Server configuration file %s already exists', hostname_fn)
        if not force:
            raise click.ClickException('Server configuration file {h_fn} already exists'.format(h_fn=host))

    # Populate servers.cfg
    servers_config.add_section(host)
    servers_config.set(host, 'Enabled', True)
    servers_config.set(host, 'Autoconnect', auto)
    servers_config.set(host, 'Nick', nick)
    servers_config.set(host, 'Username', username)
    servers_config.set(host, 'Realname', realname)
    servers_config.set(host, 'Password', password)
    servers_config.set(host, 'Port', port)
    servers_config.set(host, 'SSL', ssl)

    with open(server_cfg_path, 'w') as cf:
        servers_config.write(cf)

    # Create a server configuration file
    channels = [c.strip() for c in channels.split(',')] if channels else []

    host_config = ConfigParser()
    for channel in channels:
        host_config.add_section(channel)
        host_config.set(channel, 'Autojoin', True)
        host_config.set(channel, 'Password', '')

    with open(host_cfg_path, 'w') as cf:
        host_config.write(cf)

    click.secho('Configuration files for {h} successfully generated'.format(h=host), bold=True)
    click.secho('Server configuration path: {sp}'.format(sp=server_cfg_path), bold=True)
    click.secho('Channel configuration path: {cp}'.format(cp=host_cfg_path), bold=True)