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