]>
jfr.im git - irc/rizon/acid.git/blob - pyva/src/main/python/esim/cmd_admin.py
2 import pseudoclient
.sys_base
4 from datetime
import datetime
7 #---------------------------------------------------------------------#
9 from pseudoclient
import cmd_admin
10 from pseudoclient
.cmd_admin
import \
17 #---------------------------------------------------------------------#
19 def 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'))
26 self
.msg(target
, 'Channel @b%s@b is not in the database.' % channel
)
30 return cmd_admin
.admin_chan(self
, source
, target
, pieces
, meta
={
32 'highlight': subcmd_highlight
,
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')
39 #---------------------------------------------------------------------#
41 def admin_user(self
, source
, target
, pieces
):
43 # i am too tired to think about how to write this as a lambda
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
52 return cmd_admin
.admin_user(self
, source
, target
, pieces
, meta
={
53 'extra_info': extra_info
56 #---------------------------------------------------------------------#
58 def admin_sys(self
, source
, target
, pieces
):
68 names
.append('options')
69 subsystems
.append(self
.options
)
73 subsystems
.append(self
.users
)
76 names
.append('channels')
77 subsystems
.append(self
.channels
)
81 subsystems
.append(self
.auth
)
84 names
.append('antiflood')
85 subsystems
.append(self
.antiflood
)
88 # names.append('article')
89 # subsystems.append(self.article)
94 if operation
in ['u', 'update']:
95 for subsystem
in subsystems
:
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
:
103 self
.msg(target
, 'Forced reload for @b%s@b.' % '@b, @b'.join(names
))
104 elif operation
in ['d', 'delay']:
106 for subsystem
in subsystems
:
107 self
.msg(target
, 'Auto-update delay for @b%s@b is %d seconds.' % (subsystem
.name
, subsystem
.delay
))
110 seconds
= int(pieces
[2])
115 self
.msg(target
, 'Auto-update delay must be greater than 10 seconds.')
118 for subsystem
in subsystems
:
119 subsystem
.set_option('update_period', seconds
)
122 self
.msg(target
, 'Auto-update delay for @b%s@b set to @b%d@b seconds.' % ('@b, @b'.join(names
), seconds
))
128 def admin_status(self
, source
, target
, pieces
):
131 elif pieces
[0] == 'on':
133 self
.offline_msg
= None
134 elif pieces
[0] == 'off':
136 self
.offline_msg
= ' '.join(pieces
[1:]) if len(pieces
) > 1 else None
140 self
.msg(target
, 'Module status: @b%s@b' % ('online' if self
.online
else 'offline'))
143 def 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()))
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)'),