blob: 2b8a90256f5361f511730f3d0c1badd59eabef73 (
plain)
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
|
import sys
import math
import collections
import zokket
from bot import Bot
botname_prefix = 'audzx'
queue = collections.deque()
rate = 5.0 # messages
per = 8.0 # seconds
max_workers = 6
channel = '#test123aszz'
if len(sys.argv) == 2:
channel = sys.argv[1]
if channel[0] != '#':
channel = '#' + channel
linecount = 0
for line in sys.stdin:
queue.append(line.strip())
linecount += 1
workers = int(math.ceil(linecount / rate))
if workers > max_workers:
workers = max_workers
if workers == 0:
sys.exit(1)
print 'starting {} worker threads'.format(workers)
threads = []
for i in range(workers):
botname = botname_prefix + chr(97 + i)
threads.append(Bot(channel, threads, queue, botname, rate, per))
for bot in threads:
bot.start()
zokket.DefaultRunloop.run()
|