xdcc dump

 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -*- coding: utf-8 -*-
__module_name__ = "shit"
__module_version__ = "1.0"
__module_description__ = "xdcc dumper"
import xchat
import time
from collections import deque
#DCC status (queued=0, active=1, failed=2, done=3, connecting=4 aborted=5).
def check_dcc_list_free():
s = xchat.get_list('dcc')
if sum([1 for i in s if i.status in set((0, 1))]) > 0:
return False
else:
return True
def start_one(nick, num):
#print 'msg %s xdcc send #%s' % (nick, num)
xchat.command('msg %s xdcc send #%s' % (nick, num))
class Dumper:
def __init__(self):
self.myhook = None
self.dq = deque()
self.show_notes = False
self.author = None
def start_batch(self, tasks = None):
# tasks : [(nick, num),]
if tasks is not None:
self.dq.extend(tasks)
def starter(userdata):
if check_dcc_list_free(): # \u043c\u043e\u0436\u0435\u043c \u043d\u043e\u0432\u043e\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u0435 \u0434\u0430\u0432\u0430\u0442\u044c
try:
if self.show_notes:
print 'in queue %s tasks' % len(self.dq)
print 'Deque ' + repr(self.dq)
nick, num = self.dq.popleft()
start_one(nick, num)
except:
if self.show_notes:
print 'tasks ended' # \u0437\u0430\u0434\u0430\u043d\u0438\u0439 \u043d\u0435\u0442
return 1 # \u0431\u0443\u043a\u0441\u0443\u0435\u043c
return 1 # \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0446\u0438\u043a\u043b
self.myhook = xchat.hook_timer(5000, starter)
def start_batch_one_author(self, nick, nums):
tasks = [(nick, num) for num in nums]
self.start_batch(tasks)
def add_tasks(self, tasks):
self.dq.extend(tasks)
def add_tasks_one_author(self, nick, nums):
tasks = [(nick, num)for num in nums]
self.add_tasks(tasks)
def set_author(self, nick):
self.author = nick
def add(self, num, nick=None):
if nick is None:
nick = self.author
self.add_tasks_one_author(nick, [num,])
def silent(self):
self.show_notes = False
def loud(self):
self.show_notes = True
d = Dumper()
d.start_batch()