本文整理汇总了Python中pajbot.managers.AdminLogManager类的典型用法代码示例。如果您正苦于以下问题:Python AdminLogManager类的具体用法?Python AdminLogManager怎么用?Python AdminLogManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AdminLogManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remove_link_whitelist
def remove_link_whitelist(self, **options):
message = options['message']
bot = options['bot']
source = options['source']
if message:
id = None
try:
id = int(message)
except ValueError:
pass
link = self.db_session.query(WhitelistedLink).filter_by(id=id).one_or_none()
if link:
self.whitelisted_links.remove(link)
self.db_session.delete(link)
self.db_session.commit()
else:
bot.whisper(source.username, 'No link with the given id found')
return False
AdminLogManager.post('Whitelist link removed', source, link.domain)
bot.whisper(source.username, 'Successfully removed whitelisted link with id {0}'.format(link.id))
else:
bot.whisper(source.username, 'Usage: !remove link whitelist ID')
return False
示例2: level
def level(self, **options):
message = options['message']
bot = options['bot']
source = options['source']
if message:
msg_args = message.split(' ')
if len(msg_args) > 1:
username = msg_args[0].lower()
new_level = int(msg_args[1])
if new_level >= source.level:
bot.whisper(source.username, 'You cannot promote someone to the same or higher level as you ({0}).'.format(source.level))
return False
# We create the user if the user didn't already exist in the database.
with bot.users.get_user_context(username) as user:
old_level = user.level
user.level = new_level
log_msg = '{}\'s user level changed from {} to {}'.format(
user.username_raw,
old_level,
new_level)
bot.whisper(source.username, log_msg)
AdminLogManager.add_entry('Userlevel edited', source, log_msg)
return True
bot.whisper(source.username, 'Usage: !level USERNAME NEW_LEVEL')
return False
示例3: command_remove
def command_remove(command_id, **options):
with DBManager.create_session_scope() as db_session:
command = db_session.query(Command).filter_by(id=command_id).one_or_none()
if command is None:
return make_response(jsonify({'error': 'Invalid command ID'}), 404)
if command.level > options['user'].level:
abort(403)
log_msg = 'The !{} command has been removed'.format(command.command.split('|')[0])
AdminLogManager.add_entry('Command removed',
options['user'],
log_msg)
db_session.delete(command.data)
db_session.delete(command)
payload = {
'event': 'command.remove',
'data': {
'command_id': command_id
}
}
payload_bytes = json.dumps(payload).encode('utf-8')
try:
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client:
client.connect(config['sock']['sock_file'])
client.sendall(payload_bytes)
return make_response(jsonify({'success': 'good job'}))
except:
log.exception('???')
return make_response(jsonify({'error': 'Could not push update'}))
示例4: modules_edit
def modules_edit(module_id, **options):
module_manager = ModuleManager(None).load(do_reload=False)
current_module = find(lambda m: m.ID == module_id, module_manager.all_modules)
if current_module is None:
return render_template('admin/module_404.html'), 404
sub_modules = []
for module in module_manager.all_modules:
module.db_module = None
with DBManager.create_session_scope() as db_session:
for db_module in db_session.query(Module):
module = find(lambda m: m.ID == db_module.id, module_manager.all_modules)
if module:
module.db_module = db_module
if module.PARENT_MODULE == current_module.__class__:
sub_modules.append(module)
if current_module.db_module is None:
return render_template('admin/module_404.html'), 404
if request.method == 'POST':
form_values = {key: value for key, value in request.form.items()}
res = current_module.parse_settings(**form_values)
if res is False:
return render_template('admin/module_404.html'), 404
current_module.db_module.settings = json.dumps(res)
db_session.commit()
settings = None
try:
settings = json.loads(current_module.db_module.settings)
except (TypeError, ValueError):
pass
current_module.load(settings=settings)
payload = {
'id': current_module.db_module.id,
}
SocketClientManager.send('module.update', payload)
AdminLogManager.post('Module edited', options['user'], current_module.NAME)
return render_template('admin/configure_module.html',
module=current_module,
sub_modules=sub_modules)
else:
settings = None
try:
settings = json.loads(current_module.db_module.settings)
except (TypeError, ValueError):
pass
current_module.load(settings=settings)
return render_template('admin/configure_module.html',
module=current_module,
sub_modules=sub_modules)
示例5: level
def level(bot, source, message, event, args):
if message:
msg_args = message.split(' ')
if len(msg_args) > 1:
username = msg_args[0].lower()
new_level = int(msg_args[1])
if new_level >= source.level:
bot.whisper(source.username, 'You cannot promote someone to the same or higher level as you ({0}).'.format(source.level))
return False
# We create the user if the user didn't already exist in the database.
user = bot.users[username]
old_level = user.level
user.level = new_level
log_msg = '{}\'s user level changed from {} to {}'.format(
user.username_raw,
old_level,
new_level)
bot.whisper(source.username, log_msg)
AdminLogManager.add_entry('Userlevel edited', source, log_msg)
return True
bot.whisper(source.username, 'Usage: !level USERNAME NEW_LEVEL')
return False
示例6: post
def post(self, row_id, **options):
args = self.post_parser.parse_args()
try:
new_state = int(args['new_state'])
except (ValueError, KeyError):
return {'error': 'Invalid `new_state` parameter.'}, 400
with DBManager.create_session_scope() as db_session:
row = db_session.query(Banphrase).filter_by(id=row_id).one_or_none()
if not row:
return {
'error': 'Banphrase with this ID not found'
}, 404
row.enabled = True if new_state == 1 else False
db_session.commit()
payload = {
'id': row.id,
'new_state': row.enabled,
}
AdminLogManager.post('Banphrase toggled',
options['user'],
'Enabled' if row.enabled else 'Disabled',
row.phrase)
SocketClientManager.send('banphrase.update', payload)
return {'success': 'successful toggle', 'new_state': new_state}
示例7: generic_toggle
def generic_toggle(route_key, row_id, **options):
valid_routes = {
'timer': Timer,
'banphrase': Banphrase,
'module': Module,
}
route_name = {
'timer': lambda x: x.name,
'banphrase': lambda x: x.phrase,
'module': lambda x: x.id,
}
route_title = {
'timer': 'Timer',
'banphrase': 'Banphrase',
'module': 'Module',
}
route_validator = {
'module': lambda x: validate_module(x.id)
}
if route_key not in valid_routes:
return make_response(jsonify({'error': 'Invalid route.'}), 400)
if 'new_state' not in request.form:
return make_response(jsonify({'error': 'Missing `new_state` parameter.'}), 400)
try:
new_state = int(request.form['new_state'])
except (ValueError, KeyError):
return make_response(jsonify({'error': 'Invalid `new_state` parameter.'}), 400)
route_value = valid_routes[route_key]
with DBManager.create_session_scope() as db_session:
row = db_session.query(route_value).filter_by(id=row_id).one_or_none()
if row:
validator = route_validator.get(route_key, None)
if validator is not None:
res = validator(row)
if not res:
return make_response(jsonify({'error': 'cannot modify {}'.format(route_key)}), 400)
row.enabled = True if new_state == 1 else False
db_session.commit()
payload = {
'{}_id'.format(route_key): row.id, # remove this
'id': row.id,
'new_state': row.enabled,
}
AdminLogManager.post('{title} toggled'.format(title=route_title[route_key]),
options['user'],
'Enabled' if row.enabled else 'Disabled',
route_name[route_key](row))
SocketClientManager.send('{}.update'.format(route_key), payload)
return make_response(jsonify({'success': 'successful toggle', 'new_state': new_state}))
else:
return make_response(jsonify({'error': 'invalid {} id'.format(route_key)}))
示例8: set_title
def set_title(bot, source, message, event, args):
# XXX: This should be a module
if message:
bot.twitchapi.set_title(bot.streamer, message)
log_msg = '{0} updated the title to "{1}"'.format(source.username_raw, message)
bot.say(log_msg)
AdminLogManager.add_entry("Title set", source, log_msg)
示例9: add_command
def add_command(bot, source, message, event, args):
"""Dispatch method for creating commands.
Usage: !add command ALIAS [options] RESPONSE
Multiple options available:
--whisper/--no-whisper
--reply/--no-reply
--modonly/--no-modonly
--cd CD
--usercd USERCD
--level LEVEL
--cost COST
"""
if message:
# Make sure we got both an alias and a response
message_parts = message.split()
if len(message_parts) < 2:
bot.whisper(source.username, 'Usage: !add command ALIAS [options] RESPONSE')
return False
options, response = bot.commands.parse_command_arguments(message_parts[1:])
options['added_by'] = source.id
if options is False:
bot.whisper(source.username, 'Invalid command')
return False
alias_str = message_parts[0].replace('!', '').lower()
type = 'say'
if options['whisper'] is True:
type = 'whisper'
elif options['reply'] is True:
type = 'reply'
elif response.startswith('/me') or response.startswith('.me'):
type = 'me'
response = ' '.join(response.split(' ')[1:])
elif options['whisper'] is False or options['reply'] is False:
type = 'say'
action = {
'type': type,
'message': response,
}
command, new_command, alias_matched = bot.commands.create_command(alias_str, action=action, **options)
if new_command is True:
bot.whisper(source.username, 'Added your command (ID: {command.id})'.format(command=command))
log_msg = 'The !{} command has been created'.format(command.command.split('|')[0])
AdminLogManager.add_entry('Command created',
source,
log_msg)
return True
# At least one alias is already in use, notify the user to use !edit command instead
bot.whisper(source.username, 'The alias {} is already in use. To edit that command, use !edit command instead of !add command.'.format(alias_matched))
return False
示例10: add_command
def add_command(bot, source, message, event, args):
"""Dispatch method for creating commands.
Usage: !add command ALIAS [options] RESPONSE
Multiple options available:
--whisper/--no-whisper
--reply/--no-reply
--modonly/--no-modonly
--cd CD
--usercd USERCD
--level LEVEL
--cost COST
"""
if message:
# Make sure we got both an alias and a response
message_parts = message.split()
if len(message_parts) < 2:
bot.whisper(source.username, "Usage: !add command ALIAS [options] RESPONSE")
return False
options, response = bot.commands.parse_command_arguments(message_parts[1:])
options["added_by"] = source.id
if options is False:
bot.whisper(source.username, "Invalid command")
return False
alias_str = message_parts[0].replace("!", "").lower()
type = "say"
if options["whisper"] is True:
type = "whisper"
elif options["reply"] is True:
type = "reply"
elif response.startswith("/me") or response.startswith(".me"):
type = "me"
response = " ".join(response.split(" ")[1:])
elif options["whisper"] is False or options["reply"] is False:
type = "say"
action = {"type": type, "message": response}
command, new_command, alias_matched = bot.commands.create_command(alias_str, action=action, **options)
if new_command is True:
bot.whisper(source.username, "Added your command (ID: {command.id})".format(command=command))
log_msg = "The !{} command has been created".format(command.command.split("|")[0])
AdminLogManager.add_entry("Command created", source, log_msg)
return True
# At least one alias is already in use, notify the user to use !edit command instead
bot.whisper(
source.username,
"The alias {} is already in use. To edit that command, use !edit command instead of !add command.".format(
alias_matched
),
)
return False
示例11: get
def get(self, timer_id, **options):
with DBManager.create_session_scope() as db_session:
timer = db_session.query(Timer).filter_by(id=timer_id).one_or_none()
if timer is None:
return {'error': 'Invalid timer ID'}, 404
AdminLogManager.post('Timer removed', options['user'], timer.name)
db_session.delete(timer)
SocketClientManager.send('timer.remove', {'id': timer.id})
return {'success': 'good job'}
示例12: get
def get(self, banphrase_id, **options):
with DBManager.create_session_scope() as db_session:
banphrase = db_session.query(Banphrase).filter_by(id=banphrase_id).one_or_none()
if banphrase is None:
return {'error': 'Invalid banphrase ID'}, 404
AdminLogManager.post('Banphrase removed', options['user'], banphrase.phrase)
db_session.delete(banphrase)
db_session.delete(banphrase.data)
SocketClientManager.send('banphrase.remove', {'id': banphrase.id})
return {'success': 'good job'}, 200
示例13: add_alias
def add_alias(bot, source, message, event, args):
"""Dispatch method for adding aliases to already-existing commands.
Usage: !add alias EXISTING_ALIAS NEW_ALIAS_1 NEW_ALIAS_2 ...
"""
if message:
message = message.replace("!", "").lower()
# Make sure we got both an existing alias and at least one new alias
message_parts = message.split()
if len(message_parts) < 2:
bot.whisper(source.username, "Usage: !add alias existingalias newalias")
return False
existing_alias = message_parts[0]
new_aliases = re.split("\|| ", " ".join(message_parts[1:]))
added_aliases = []
already_used_aliases = []
if existing_alias not in bot.commands:
bot.whisper(source.username, 'No command called "{0}" found'.format(existing_alias))
return False
command = bot.commands[existing_alias]
for alias in set(new_aliases):
if alias in bot.commands:
already_used_aliases.append(alias)
else:
added_aliases.append(alias)
bot.commands[alias] = command
if len(added_aliases) > 0:
new_aliases = "{}|{}".format(command.command, "|".join(added_aliases))
bot.commands.edit_command(command, command=new_aliases)
bot.whisper(
source.username,
"Successfully added the aliases {0} to {1}".format(", ".join(added_aliases), existing_alias),
)
log_msg = "The aliases {0} has been added to {1}".format(", ".join(added_aliases), existing_alias)
AdminLogManager.add_entry("Alias added", source, log_msg)
if len(already_used_aliases) > 0:
bot.whisper(
source.username,
"The following aliases were already in use: {0}".format(", ".join(already_used_aliases)),
)
else:
bot.whisper(source.username, "Usage: !add alias existingalias newalias")
示例14: permaban
def permaban(bot, source, message, event, args):
if message:
msg_args = message.split(' ')
username = msg_args[0].lower()
user = bot.users[username]
if user.banned:
bot.whisper(source.username, 'User is already permabanned.')
return False
user.banned = True
message = message.lower()
log_msg = '{} has been permabanned'.format(user.username_raw)
bot.whisper(source.username, log_msg)
AdminLogManager.add_entry('Permaban added', source, log_msg)
示例15: add_link_whitelist
def add_link_whitelist(self, **options):
bot = options['bot']
message = options['message']
source = options['source']
parts = message.split(' ')
try:
for link in parts:
self.whitelist_url(link)
AdminLogManager.post('Whitelist link added', source, link)
except:
log.exception('Unhandled exception in add_link')
bot.whisper(source.username, 'Some error occurred white adding your links')
return False
bot.whisper(source.username, 'Successfully added your links')