示例#1
0
def main():
    loop = asyncio.get_event_loop()

    # run a test server
    server = IrcServer.from_config(dict(
        loop=loop,
        servername='test',
        includes=['irc3d.plugins.core'],
    ))
    server.run(forever=False)

    cfg = dict(
        host='localhost',
        port=6667,
        nick='sender',
        includes=[__name__],
        loop=loop,
    )
    # this bot will send the file
    sender = irc3.IrcBot.from_config(cfg)
    sender.run(forever=False)

    file_received = asyncio.Future()

    def f():
        # this bot will receive the file
        receiver.run(forever=False)
    # assume receiver is created *after* sender
    receiver = irc3.IrcBot.from_config(cfg,
                                       nick='receiver',
                                       file_received=file_received)
    loop.call_later(.2, receiver.run, False)

    loop.run_until_complete(file_received)
示例#2
0
def main():
    loop = asyncio.get_event_loop()

    # run a test server
    server = IrcServer.from_config(
        dict(
            loop=loop,
            servername='test',
            includes=['irc3d.plugins.core'],
        ))
    server.run(forever=False)

    end_chat = asyncio.Future()

    cfg = dict(
        host='localhost',
        port=6667,
        nick='sender',
        includes=['irc3.plugins.dcc', __name__],
        loop=loop,
        end_chat=end_chat,
    )
    # this bot will send the file
    sender = irc3.IrcBot.from_config(cfg)
    sender.run(forever=False)

    def f():
        # this bot will receive the file
        receiver.run(forever=False)

    # assume receiver is created *after* sender
    receiver = irc3.IrcBot.from_config(cfg, nick='receiver')
    loop.call_later(.2, receiver.run, False)

    loop.run_until_complete(end_chat)
示例#3
0
def main():
    # logging configuration
    logging.config.dictConfig(irc3.config.LOGGING)

    loop = asyncio.get_event_loop()

    server = IrcServer.from_argv(loop=loop)
    bot = irc3.IrcBot.from_argv(loop=loop).run()

    loop.run_forever()
示例#4
0
def main():
    # logging configuration
    logging.config.dictConfig(irc3.config.LOGGING)

    loop = asyncio.get_event_loop()

    server = IrcServer.from_argv(loop=loop)
    bot = irc3.IrcBot.from_argv(loop=loop).run()

    loop.run_forever()
示例#5
0
 def __init__(self, bot):
     self.bot = bot
     if bot is not None:
         self.log = bot.log
         self.loop = bot.loop
         plugin = bot.get_plugin('alain.alain3.AfpySocial').send_alain_tweet
         self.send_tweet = plugin.send_tweet
     else:
         self.loop = asyncio.get_event_loop()
     self.loop.call_later(self.delay, self.check_tweets)
     self.fd = os.path.expanduser('~/.irc3/last_meetup_id')
示例#6
0
 def test_async_plugin(self):
     bot = self.callFTU(nick='foo', loop=asyncio.get_event_loop())
     bot.include('async_command')
     plugin = bot.get_plugin(command.Commands)
     mask = utils.IrcString('*****@*****.**')
     res = plugin.on_command('get', mask, mask.nick, data='')
     assert isinstance(res, asyncio.Task)
     res2 = plugin.on_command('get', mask, mask.nick, data='')
     assert res2 is None
     plugin.on_command('put', mask, mask.nick, data='xx yy')
     bot.loop.run_until_complete(res)
     assert res.result() == ['xx', 'yy']
示例#7
0
 def test_async_plugin(self):
     bot = self.callFTU(nick='foo', loop=asyncio.get_event_loop())
     bot.include('async_command')
     plugin = bot.get_plugin(command.Commands)
     mask = utils.IrcString('*****@*****.**')
     res = plugin.on_command('get', mask, mask.nick, data='')
     assert isinstance(res, asyncio.Task)
     res2 = plugin.on_command('get', mask, mask.nick, data='')
     assert res2 is None
     plugin.on_command('put', mask, mask.nick, data='xx yy')
     bot.loop.run_until_complete(res)
     assert res.result() == ['xx', 'yy']
示例#8
0
    def bootstrapIrc3(self):
        # Create the asyncio loop
        loop = asyncio.get_event_loop()
        end_callback = asyncio.Future()

        # Save the end method to be called after posting the message
        self.config['end_callback'] = end_callback
        self.config['includes'] = [__name__]

        # Create the bot and run it once
        sender = irc3.IrcBot.from_config(self.config)
        sender.run(forever=False)

        # Set the asyncio resolve Future
        loop.run_until_complete(end_callback)
示例#9
0
def main():
    loop = asyncio.get_event_loop()

    server = IrcServer.from_argv(loop=loop)
    bot = irc3.IrcBot.from_argv(loop=loop)

    def factory(i):
        irc3.IrcBot.from_argv(
            loop=loop, i=i,
            nick=bot.nick + str(i),
            realname=bot.config.realname + str(i),
        )

    for i in range(1, server.config.client_amount):
        loop.call_later(.1 * i, factory, i)

    loop.run_forever()
示例#10
0
def main():
    loop = asyncio.get_event_loop()
    config = {
        'loop': loop,
        'nick': 'chater',
        'channel': '#irc3',
        'host': 'irc.freenode.net',
        'debug': True,
        'verbose': True,
        'raw': True,
        'includes': ['spy'],
    }
    chater = irc3.IrcBot.from_config(config)
    chater.run(forever=False)
    config.update({
        'nick': 'spyer',
        'channel': '#irc3_dev',
        'chater': chater,
    })
    spyer = irc3.IrcBot.from_config(config)
    spyer.run(forever=False)
    print('serving')
    loop.run_forever()
示例#11
0
文件: testing.py 项目: winny-/irc3
def call_soon(func, *args):
    func(*args)
    return asyncio.Handle(func, args, asyncio.get_event_loop())
示例#12
0
文件: testing.py 项目: winny-/irc3
def call_later(i, func, *args):
    if func.__name__ in dir(IrcBot):
        func(*args)
    return asyncio.Handle(func, args, asyncio.get_event_loop())
示例#13
0
class TestAsync(BotTestCase):

    name = 'irc3.plugins.async'
    config = dict(includes=[name], loop=asyncio.get_event_loop())

    def test_whois_fail(self):
        bot = self.callFTU()
        assert len(bot.registry.events_re['in']) == 0
        task = bot. async .whois(nick='gawel')
        assert len(bot.registry.events_re['in']) > 2
        bot.dispatch(':localhost 401 me gawel :No such nick')
        bot.loop.run_until_complete(task)
        result = task.result()
        assert result['success'] is False
        assert len(bot.registry.events_re['in']) == 0

    def test_whois_success(self):
        bot = self.callFTU()
        assert len(bot.registry.events_re['in']) == 0
        task = bot. async .whois(nick='GaWel')
        assert len(bot.registry.events_re['in']) > 2
        bot.dispatch(':localhost 311 me gawel username localhost * :realname')
        bot.dispatch(':localhost 319 me gawel :@#irc3')
        bot.dispatch(':localhost 312 me gawel localhost :Paris, FR')
        bot.dispatch(':localhost 671 me gawel :is using a secure connection')
        bot.dispatch(':localhost 330 me gawel gawel :is logged in as')
        bot.dispatch(':localhost 318 me gawel :End')
        bot.loop.run_until_complete(task)
        assert len(bot.registry.events_re['in']) == 0
        result = task.result()
        assert result['success']
        assert result['timeout'] is False
        assert result['username'] == 'username'
        assert result['realname'] == 'realname'

    def test_whois_timeout(self):
        bot = self.callFTU()
        assert len(bot.registry.events_re['in']) == 0
        task = bot. async .whois(nick='GaWel', timeout=.1)
        assert len(bot.registry.events_re['in']) > 2
        bot.loop.run_until_complete(task)
        result = task.result()
        assert result['timeout'] is True

    def test_who_channel(self):
        bot = self.callFTU()
        assert len(bot.registry.events_re['in']) == 0
        task = bot. async .who('#irc3')
        assert len(bot.registry.events_re['in']) == 2
        bot.dispatch(
            ':card.freenode.net 352 nick #irc3 ~irc3 host1 srv1 irc3 H :0 bot')
        bot.dispatch(
            ':card.freenode.net 352 nick #irc3 ~gael host2 srv2 gawel H@ :1 g')
        bot.dispatch(':card.freenode.net 315 nick #irc3 :End of /WHO list.')
        bot.loop.run_until_complete(task)
        result = task.result()
        assert result['timeout'] is False
        assert len(result['users']) == 2

    def test_who_nick(self):
        bot = self.callFTU()
        assert len(bot.registry.events_re['in']) == 0
        task = bot. async .who('irc3')
        assert len(bot.registry.events_re['in']) == 2
        bot.dispatch(
            ':card.freenode.net 352 nick * ~irc3 host1 serv1 irc3 H :0 bot')
        bot.dispatch(':card.freenode.net 315 nick irc3 :End of /WHO list.')
        bot.loop.run_until_complete(task)
        result = task.result()
        assert result['timeout'] is False
        assert result['hopcount'] == '0'

    def test_ison(self):
        bot = self.callFTU()
        assert len(bot.registry.events_re['in']) == 0
        task = bot. async .ison('GaWel', timeout=.1)
        assert len(bot.registry.events_re['in']) > 0
        bot.dispatch(':localhost 303 me :gawel')
        bot.loop.run_until_complete(task)
        result = task.result()
        assert result['timeout'] is False
        assert result['names'] == ['gawel']

    def test_names(self):
        bot = self.callFTU()
        assert len(bot.registry.events_re['in']) == 0
        task = bot. async .names('#irc3')
        assert len(bot.registry.events_re['in']) == 2
        bot.dispatch(':card.freenode.net 353 nick @ #irc3 :irc3 @gawel')
        bot.dispatch(':card.freenode.net 353 nick @ #irc3 :+panoramisk')
        bot.dispatch(':card.freenode.net 366 nick #irc3 :End of /NAMES list.')
        bot.loop.run_until_complete(task)
        result = task.result()
        assert result['timeout'] is False
        assert len(result['names']) == 3
示例#14
0
def call_soon(func, *args):
    func(*args)
    return asyncio.Handle(func, args, asyncio.get_event_loop())
示例#15
0
def call_later(i, func, *args):
    if func.__name__ in dir(IrcBot):
        func(*args)
    return asyncio.Handle(func, args, asyncio.get_event_loop())