Update lexicon-player cli commands
This commit is contained in:
parent
afb49a86db
commit
8b069132a9
|
@ -6,7 +6,7 @@ from amanuensis.cli.helpers import (
|
||||||
add_argument, no_argument, requires_lexicon, requires_user, alias,
|
add_argument, no_argument, requires_lexicon, requires_user, alias,
|
||||||
config_get, config_set, CONFIG_GET_ROOT_VALUE)
|
config_get, config_set, CONFIG_GET_ROOT_VALUE)
|
||||||
from amanuensis.config import RootConfigDirectoryContext
|
from amanuensis.config import RootConfigDirectoryContext
|
||||||
from amanuensis.models import LexiconModel
|
from amanuensis.models import LexiconModel, UserModel
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -130,6 +130,7 @@ def command_config(args):
|
||||||
# Player/character commands
|
# Player/character commands
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
@alias('lpa')
|
@alias('lpa')
|
||||||
@requires_lexicon
|
@requires_lexicon
|
||||||
@requires_user
|
@requires_user
|
||||||
|
@ -137,22 +138,24 @@ def command_player_add(args):
|
||||||
"""
|
"""
|
||||||
Add a player to a lexicon
|
Add a player to a lexicon
|
||||||
"""
|
"""
|
||||||
|
lexicon: LexiconModel = args.lexicon
|
||||||
|
user: UserModel = args.user
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from amanuensis.config import logger
|
from amanuensis.lexicon import add_player_to_lexicon
|
||||||
from amanuensis.lexicon.manage import add_player
|
|
||||||
|
|
||||||
# Verify arguments
|
# Verify arguments
|
||||||
if args.user.in_lexicon(args.lexicon):
|
if user.uid in lexicon.cfg.join.joined:
|
||||||
logger.error('"{0.username}" is already a player in "{1.name}"'.format(
|
logger.error(f'"{user.cfg.username}" is already a player '
|
||||||
args.user, args.lexicon))
|
f'in "{lexicon.cfg.name}"')
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
# Perform command
|
# Perform command
|
||||||
add_player(args.lexicon, args.user)
|
add_player_to_lexicon(user, lexicon)
|
||||||
|
|
||||||
# Output
|
# Output
|
||||||
logger.info('Added user "{0.username}" to lexicon "{1.name}"'.format(
|
logger.info(f'Added user "{user.cfg.username}" to '
|
||||||
args.user, args.lexicon))
|
f'lexicon "{lexicon.cfg.name}"')
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
@ -166,26 +169,26 @@ def command_player_remove(args):
|
||||||
Removing a player dissociates them from any characters
|
Removing a player dissociates them from any characters
|
||||||
they control but does not delete any character data.
|
they control but does not delete any character data.
|
||||||
"""
|
"""
|
||||||
# Module imports
|
raise NotImplementedError()
|
||||||
from amanuensis.config import logger
|
# # Module imports
|
||||||
from amanuensis.lexicon.manage import remove_player
|
# from amanuensis.lexicon.manage import remove_player
|
||||||
|
|
||||||
# Verify arguments
|
# # Verify arguments
|
||||||
if not args.user.in_lexicon(args.lexicon):
|
# if not args.user.in_lexicon(args.lexicon):
|
||||||
logger.error('"{0.username}" is not a player in lexicon "{1.name}"'
|
# logger.error('"{0.username}" is not a player in lexicon "{1.name}"'
|
||||||
''.format(args.user, args.lexicon))
|
# ''.format(args.user, args.lexicon))
|
||||||
return -1
|
# return -1
|
||||||
if args.user.id == args.lexicon.editor:
|
# if args.user.id == args.lexicon.editor:
|
||||||
logger.error("Can't remove the editor of a lexicon")
|
# logger.error("Can't remove the editor of a lexicon")
|
||||||
return -1
|
# return -1
|
||||||
|
|
||||||
# Perform command
|
# # Perform command
|
||||||
remove_player(args.lexicon, args.user)
|
# remove_player(args.lexicon, args.user)
|
||||||
|
|
||||||
# Output
|
# # Output
|
||||||
logger.info('Removed "{0.username}" from lexicon "{1.name}"'.format(
|
# logger.info('Removed "{0.username}" from lexicon "{1.name}"'.format(
|
||||||
args.user, args.lexicon))
|
# args.user, args.lexicon))
|
||||||
return 0
|
# return 0
|
||||||
|
|
||||||
|
|
||||||
@alias('lpl')
|
@alias('lpl')
|
||||||
|
@ -194,19 +197,19 @@ def command_player_list(args):
|
||||||
"""
|
"""
|
||||||
List all players in a lexicon
|
List all players in a lexicon
|
||||||
"""
|
"""
|
||||||
import json
|
raise NotImplementedError()
|
||||||
# Module imports
|
# import json
|
||||||
from amanuensis.config import logger
|
# # Module imports
|
||||||
from amanuensis.user import UserModel
|
# from amanuensis.user import UserModel
|
||||||
|
|
||||||
# Perform command
|
# # Perform command
|
||||||
players = list(map(
|
# players = list(map(
|
||||||
lambda uid: UserModel.by(uid=uid).username,
|
# lambda uid: UserModel.by(uid=uid).username,
|
||||||
args.lexicon.join.joined))
|
# args.lexicon.join.joined))
|
||||||
|
|
||||||
# Output
|
# # Output
|
||||||
print(json.dumps(players, indent=2))
|
# print(json.dumps(players, indent=2))
|
||||||
return 0
|
# return 0
|
||||||
|
|
||||||
|
|
||||||
@alias('lcc')
|
@alias('lcc')
|
||||||
|
@ -220,7 +223,6 @@ def command_char_create(args):
|
||||||
The specified player will be set as the character's player.
|
The specified player will be set as the character's player.
|
||||||
"""
|
"""
|
||||||
# Module imports
|
# Module imports
|
||||||
from amanuensis.config import logger
|
|
||||||
from amanuensis.lexicon import LexiconModel
|
from amanuensis.lexicon import LexiconModel
|
||||||
from amanuensis.lexicon.manage import add_character
|
from amanuensis.lexicon.manage import add_character
|
||||||
from amanuensis.user import UserModel
|
from amanuensis.user import UserModel
|
||||||
|
@ -251,7 +253,6 @@ def command_char_delete(args):
|
||||||
they have contributed rather than deleting it.
|
they have contributed rather than deleting it.
|
||||||
"""
|
"""
|
||||||
# Module imports
|
# Module imports
|
||||||
from amanuensis.config import logger
|
|
||||||
from amanuensis.lexicon import LexiconModel
|
from amanuensis.lexicon import LexiconModel
|
||||||
from amanuensis.lexicon.manage import delete_character
|
from amanuensis.lexicon.manage import delete_character
|
||||||
|
|
||||||
|
@ -274,7 +275,6 @@ def command_char_list(args):
|
||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
# Module imports
|
# Module imports
|
||||||
from amanuensis.config import logger
|
|
||||||
from amanuensis.lexicon import LexiconModel
|
from amanuensis.lexicon import LexiconModel
|
||||||
|
|
||||||
# Verify arguments
|
# Verify arguments
|
||||||
|
|
|
@ -9,7 +9,7 @@ from amanuensis.models import LexiconModel, UserModel
|
||||||
def player_can_join_lexicon(
|
def player_can_join_lexicon(
|
||||||
player: UserModel,
|
player: UserModel,
|
||||||
lexicon: LexiconModel,
|
lexicon: LexiconModel,
|
||||||
password: str = None):
|
password: str = None) -> bool:
|
||||||
"""
|
"""
|
||||||
Checks whether the given player can join a lexicon
|
Checks whether the given player can join a lexicon
|
||||||
"""
|
"""
|
||||||
|
@ -36,7 +36,7 @@ def player_can_join_lexicon(
|
||||||
|
|
||||||
def add_player_to_lexicon(
|
def add_player_to_lexicon(
|
||||||
player: UserModel,
|
player: UserModel,
|
||||||
lexicon: LexiconModel):
|
lexicon: LexiconModel) -> None:
|
||||||
"""
|
"""
|
||||||
Unconditionally adds a player to a lexicon
|
Unconditionally adds a player to a lexicon
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue