-
Notifications
You must be signed in to change notification settings - Fork 46
/
benches.py
51 lines (39 loc) · 1.33 KB
/
benches.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
import random
from irc3.compat import asyncio
from irc3d import IrcServer
import irc3
@irc3.plugin
class Plugin(object):
def __init__(self, context):
self.log = context.log
self.context = context
self.name = context.config.name
self.channel = '#' + context.config.channel
@irc3.event(irc3.rfc.CONNECTED)
def connected(self, **kw):
self.context.join(self.channel)
def msg(self):
s = ' '.join([self.name for i in range(random.randint(1, 10))])
s += random.choice([' ?', '', ' !', ' #@!', ' '])
self.context.privmsg(self.channel, s)
self.context.loop.call_later(
random.randint(3, 20), self.msg)
@irc3.event(irc3.rfc.JOIN)
def join(self, mask=None, **kw):
if mask.nick == self.context.nick:
self.context.loop.call_later(
random.randint(3, 20), self.msg)
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()