Touch up lexicon-player-*
This commit is contained in:
parent
0fd744537c
commit
9e53e1bb61
|
@ -48,7 +48,6 @@ def command_delete(args):
|
||||||
"""
|
"""
|
||||||
# Module imports
|
# Module imports
|
||||||
from amanuensis.config import logger
|
from amanuensis.config import logger
|
||||||
from amanuensis.lexicon import LexiconModel
|
|
||||||
from amanuensis.lexicon.manage import delete_lexicon
|
from amanuensis.lexicon.manage import delete_lexicon
|
||||||
|
|
||||||
# Perform command
|
# Perform command
|
||||||
|
@ -116,34 +115,32 @@ def command_config(args):
|
||||||
#
|
#
|
||||||
|
|
||||||
@requires_lexicon
|
@requires_lexicon
|
||||||
# @requires_username
|
@requires_user
|
||||||
def command_player_add(args):
|
def command_player_add(args):
|
||||||
"""
|
"""
|
||||||
Add a player to a lexicon
|
Add a player to a lexicon
|
||||||
"""
|
"""
|
||||||
# Module imports
|
# Module imports
|
||||||
from amanuensis.config import logger
|
from amanuensis.config import logger
|
||||||
from amanuensis.lexicon import LexiconModel
|
|
||||||
from amanuensis.lexicon.manage import add_player
|
from amanuensis.lexicon.manage import add_player
|
||||||
from amanuensis.user import UserModel
|
|
||||||
|
|
||||||
# Verify arguments
|
# Verify arguments
|
||||||
u = UserModel.by(name=args.username)
|
if args.user.id in args.lexicon.join.joined:
|
||||||
if u is None:
|
logger.error('"{0.username}" is already a player in "{1.name}"'.format(
|
||||||
logger.error("Could not find user '{}'".format(args.username))
|
args.user, args.lexicon))
|
||||||
return -1
|
|
||||||
lex = LexiconModel.by(name=args.lexicon)
|
|
||||||
if lex is None:
|
|
||||||
logger.error("Could not find lexicon '{}'".format(args.lexicon))
|
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
# Internal call
|
# Perform command
|
||||||
add_player(lex, u)
|
add_player(lex, u)
|
||||||
|
|
||||||
|
# Output
|
||||||
|
logger.info('Added user "{0.username}" to lexicon "{1.name}"'.format(
|
||||||
|
args.user, ags.lexicon))
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@requires_lexicon
|
@requires_lexicon
|
||||||
# @requires_username
|
@requires_user
|
||||||
def command_player_remove(args):
|
def command_player_remove(args):
|
||||||
"""
|
"""
|
||||||
Remove a player from a lexicon
|
Remove a player from a lexicon
|
||||||
|
@ -153,25 +150,23 @@ def command_player_remove(args):
|
||||||
"""
|
"""
|
||||||
# Module imports
|
# Module imports
|
||||||
from amanuensis.config import logger
|
from amanuensis.config import logger
|
||||||
from amanuensis.lexicon import LexiconModel
|
|
||||||
from amanuensis.lexicon.manage import remove_player
|
from amanuensis.lexicon.manage import remove_player
|
||||||
from amanuensis.user import UserModel
|
|
||||||
|
|
||||||
# Verify arguments
|
# Verify arguments
|
||||||
u = UserModel.by(name=args.username)
|
if args.user.id not in args.lexicon.join.joined:
|
||||||
if u is None:
|
logger.error('"{0.username}" is not a player in lexicon "{1.name}"'
|
||||||
logger.error("Could not find user '{}'".format(args.username))
|
''.format(args.user, args.lexicon))
|
||||||
return -1
|
return -1
|
||||||
lex = LexiconModel.by(name=args.lexicon)
|
if args.user.id == args.lexicon.editor:
|
||||||
if lex is None:
|
|
||||||
logger.error("Could not find lexicon '{}'".format(args.lexicon))
|
|
||||||
return -1
|
|
||||||
if lex.editor == u.id:
|
|
||||||
logger.error("Can't remove the editor of a lexicon")
|
logger.error("Can't remove the editor of a lexicon")
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
# Internal call
|
# Perform command
|
||||||
remove_player(lex, u)
|
remove_player(lex, u)
|
||||||
|
|
||||||
|
# Output
|
||||||
|
logger.info('Removed "{0.username}" from lexicon "{1.name}"'.format(
|
||||||
|
args.user, args.lexicon))
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
@ -183,21 +178,14 @@ def command_player_list(args):
|
||||||
import json
|
import json
|
||||||
# Module imports
|
# Module imports
|
||||||
from amanuensis.config import logger
|
from amanuensis.config import logger
|
||||||
from amanuensis.lexicon import LexiconModel
|
|
||||||
from amanuensis.user import UserModel
|
from amanuensis.user import UserModel
|
||||||
|
|
||||||
# Verify arguments
|
# Perform command
|
||||||
lex = LexiconModel.by(name=args.lexicon)
|
players = list(map(
|
||||||
if lex is None:
|
lambda uid: UserModel.by(uid=uid).username,
|
||||||
logger.error("Could not find lexicon '{}'".format(args.lexicon))
|
args.lexicon.join.joined))
|
||||||
return -1
|
|
||||||
|
|
||||||
# Internal call
|
|
||||||
players = []
|
|
||||||
for uid in lex.join.joined:
|
|
||||||
u = UserModel.by(uid=uid)
|
|
||||||
players.append(u.username)
|
|
||||||
|
|
||||||
|
# Output
|
||||||
print(json.dumps(players, indent=2))
|
print(json.dumps(players, indent=2))
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@ -257,6 +245,7 @@ def command_char_delete(args):
|
||||||
delete_character(lex, args.charname)
|
delete_character(lex, args.charname)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@requires_lexicon
|
@requires_lexicon
|
||||||
def command_char_list(args):
|
def command_char_list(args):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue