]> jfr.im git - irc/rizon/acid.git/blame - pyva/pyva/src/main/python/esim/cmd_admin.py
Split pyva plugin into pyva.core and pyva.pyva
[irc/rizon/acid.git] / pyva / pyva / src / main / python / esim / cmd_admin.py
CommitLineData
685e346e
A
1
2import pseudoclient.sys_base
3
4from datetime import datetime
5from utils import *
6
7#---------------------------------------------------------------------#
8
9from pseudoclient import cmd_admin
10from pseudoclient.cmd_admin import \
11 admin_unregistered, \
12 admin_log, \
13 admin_msg, \
14 admin_opt, \
15 admin_db
16
17#---------------------------------------------------------------------#
18
19def admin_chan(self, source, target, pieces):
20 def subcmd_highlight(self, action, channel, source, target, pieces):
21 if channel in self.channels:
22 cur_state = self.channels[channel].highlight
23 self.channels.set(channel, 'highlight', not cur_state)
24 self.msg(target, 'Toggled highlight for channel @b%s@b. Current state: %s.' % (channel, 'disabled' if cur_state else 'enabled'))
25 else:
26 self.msg(target, 'Channel @b%s@b is not in the database.' % channel)
27
28 return True
29
30 return cmd_admin.admin_chan(self, source, target, pieces, meta={
31 'cmds':{
32 'highlight': subcmd_highlight,
33 'm': subcmd_highlight
34 },
35 'extra_info': lambda chan: ' News: @b%s@b. Highlight: @b%s@b.' \
36 % ('enabled' if chan.news else 'disabled', 'enabled' if chan.highlight else 'disabled')
37 })
38
39#---------------------------------------------------------------------#
40
41def admin_user(self, source, target, pieces):
42 def extra_info(user):
43 # i am too tired to think about how to write this as a lambda
44 m = ''
45 if user.citizen != None:
46 m += ' Citizen: @b%s@b.' % user.citizen
47 if user.company != None:
48 m += ' Company: @b%s@b.' % user.company
49 return m
50
51
52 return cmd_admin.admin_user(self, source, target, pieces, meta={
53 'extra_info': extra_info
54 })
55
56#---------------------------------------------------------------------#
57
58def admin_sys(self, source, target, pieces):
59 if len(pieces) < 2:
60 return False
61
62 starget = pieces[0]
63 operation = pieces[1]
64 names = []
65 subsystems = []
66
67 if 'o' in starget:
68 names.append('options')
69 subsystems.append(self.options)
70
71 if 'u' in starget:
72 names.append('users')
73 subsystems.append(self.users)
74
75 if 'c' in starget:
76 names.append('channels')
77 subsystems.append(self.channels)
78
79 if 'a' in starget:
80 names.append('auth')
81 subsystems.append(self.auth)
82
83 if 'f' in starget:
84 names.append('antiflood')
85 subsystems.append(self.antiflood)
86
87# if 'r' in starget:
88# names.append('article')
89# subsystems.append(self.article)
90
91 if len(names) == 0:
92 return False
93
94 if operation in ['u', 'update']:
95 for subsystem in subsystems:
96 subsystem.force()
97
98 self.msg(target, 'Forced update for @b%s@b.' % '@b, @b'.join(names))
99 elif operation in ['r', 'reload']:
100 for subsystem in subsystems:
101 subsystem.reload()
102
103 self.msg(target, 'Forced reload for @b%s@b.' % '@b, @b'.join(names))
104 elif operation in ['d', 'delay']:
105 if len(pieces) == 2:
106 for subsystem in subsystems:
107 self.msg(target, 'Auto-update delay for @b%s@b is %d seconds.' % (subsystem.name, subsystem.delay))
108 else:
109 try:
110 seconds = int(pieces[2])
111 except:
112 return False
113
114 if seconds < 10:
115 self.msg(target, 'Auto-update delay must be greater than 10 seconds.')
116 return True
117
118 for subsystem in subsystems:
119 subsystem.set_option('update_period', seconds)
120 subsystem.reload()
121
122 self.msg(target, 'Auto-update delay for @b%s@b set to @b%d@b seconds.' % ('@b, @b'.join(names), seconds))
123 else:
124 return False
125
126 return True
127
128def admin_status(self, source, target, pieces):
129 if len(pieces) < 1:
130 pass
131 elif pieces[0] == 'on':
132 self.online = True
133 self.offline_msg = None
134 elif pieces[0] == 'off':
135 self.online = False
136 self.offline_msg = ' '.join(pieces[1:]) if len(pieces) > 1 else None
137 else:
138 return False
139
140 self.msg(target, 'Module status: @b%s@b' % ('online' if self.online else 'offline'))
141 return True
142
143def admin_stats(self, source, target, pieces):
144 self.msg(target, 'Registered users: @b%d@b.' % len(self.users.list_all()))
145 self.msg(target, 'Registered channels: @b%d@b.' % len(self.channels.list_all()))
146 return True
147
148def get_commands():
149 return {
150 'chan' : (admin_chan, '<ban|unban|info|add|remove|list|blist|highlight> <channel> [reason]'),
151 'unreg' : (admin_unregistered, '<check|list|part> - remove unregistered channels'),
152 'user' : (admin_user, '<ban|unban|info|add|remove|list|blist|highlight> <user> [reason]'),
153 'stats' : (admin_stats, 'counts registered users and channels'),
154 'db' : (admin_db, '[on|off] - enables/disables auto commits to db'),
155 'opt' : (admin_opt, '[get|set|clear] [option] [value] - manipulates options (list all if no arguments)'),
156 '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))'),
157 'log' : (admin_log, '[level] - gets or sets the log level (0-7).'),
158 'msg' : (admin_msg, '<message> - sends a message to all channels'),
159 'status' : (admin_status, '<on/off> - disables/enables API commands (use when API is down)'),
160 }
161