]> jfr.im git - irc/rizon/acid.git/blame - pyva/pyva/src/main/python/limitserv/cmd_admin.py
Split pyva plugin into pyva.core and pyva.pyva
[irc/rizon/acid.git] / pyva / pyva / src / main / python / limitserv / cmd_admin.py
CommitLineData
685e346e
A
1import pseudoclient.sys_base
2
3from datetime import datetime
4from utils import *
5
6from pseudoclient import cmd_admin
7from pseudoclient.cmd_admin import \
8 admin_unregistered, \
9 admin_chan, \
10 admin_log, \
11 admin_msg, \
12 admin_opt, \
13 admin_db
14
15def admin_sys(self, source, target, pieces):
16 if len(pieces) < 2:
17 return False
18
19 starget = pieces[0]
20 operation = pieces[1]
21 names = []
22 subsystems = []
23
24 if 'o' in starget:
25 names.append('options')
26 subsystems.append(self.options)
27
28 if 'c' in starget:
29 names.append('channels')
30 subsystems.append(self.channels)
31
32 if 'a' in starget:
33 names.append('auth')
34 subsystems.append(self.auth)
35
36 if len(names) == 0:
37 return False
38
39 if operation in ['u', 'update']:
40 for subsystem in subsystems:
41 subsystem.force()
42
43 self.msg(target, 'Forced update for @b%s@b.' % '@b, @b'.join(names))
44 elif operation in ['r', 'reload']:
45 for subsystem in subsystems:
46 subsystem.reload()
47
48 self.msg(target, 'Forced reload for @b%s@b.' % '@b, @b'.join(names))
49 elif operation in ['d', 'delay']:
50 if len(pieces) == 2:
51 for subsystem in subsystems:
52 self.msg(target, 'Auto-update delay for @b%s@b is %d seconds.' % (subsystem.name, subsystem.delay))
53 else:
54 try:
55 seconds = int(pieces[2])
56 except:
57 return False
58
59 if seconds < 10:
60 self.msg(target, 'Auto-update delay must be greater than 10 seconds.')
61 return True
62
63 for subsystem in subsystems:
64 subsystem.set_option('update_period', seconds)
65 subsystem.reload()
66
67 self.msg(target, 'Auto-update delay for @b%s@b set to @b%d@b seconds.' % ('@b, @b'.join(names), seconds))
68 else:
69 return False
70
71 return True
72
73def admin_stats(self, source, target, pieces):
74 self.msg(target, 'Registered channels: @b%d@b.' % len(self.channels.list_all()))
75 return True
76
77def admin_qsize(self, source, target, pieces):
78 self.msg(target, 'Queue size: %d' % len(self.limit_monitor))
79 return True
80
81def admin_delay(self, source, target, pieces):
82 if not pieces:
83 self.msg(target, 'Delay: %d seconds' % self.limit_monitor._delay)
84 return True
85
86 try:
87 new_delay = int(pieces[0])
88 except ValueError:
89 return False
90
91 self.limit_monitor.set_delay(new_delay)
92 self.msg(target, 'New delay set to %d seconds' % new_delay)
93 return True
94
95def get_commands():
96 return {
97 'chan' : (admin_chan, '<ban|unban|info|add|remove|list|blist> <channel> [reason]'),
98 'unreg' : (admin_unregistered, '<check|list|part> - remove unregistered channels'),
99 'stats' : (admin_stats, 'counts registered channels'),
100 'db' : (admin_db, '[on|off] - enables/disables auto commits to db'),
101 'opt' : (admin_opt, '[get|set|clear] [option] [value] - manipulates options (list all if no arguments)'),
102 'sys' : (admin_sys, '<subsystem> <operation> [value] - (subsystems: options (o), channels (c), auth (a)) (operations: update (u), reload (r), delay (d))'),
103 'log' : (admin_log, '[level] - gets or sets the log level (0-7).'),
104 'msg' : (admin_msg, '<message> - sends a message to all channels'),
105 'qsize' : (admin_qsize, '[debug command] shows channel update queue size'),
106 'delay' : (admin_delay, '<new_delay> - (seconds) changes the interval between limit changes')
107 }