mirror of
https://github.com/evennia/evennia.git
synced 2026-03-24 16:56:32 +01:00
Added @setcmdalias for creating aliases for commands (l -> look etc). Also moved the hard-coded defaults to settings.py instead.
This commit is contained in:
parent
a286841030
commit
0c29d359f6
6 changed files with 119 additions and 15 deletions
|
|
@ -12,6 +12,8 @@ from src.scripthandler import rebuild_cache
|
|||
from src.cmdtable import GLOBAL_CMD_TABLE
|
||||
from src.helpsys.models import HelpEntry
|
||||
from src.helpsys import helpsystem
|
||||
from src.config.models import CommandAlias
|
||||
from src.config import edit_aliases
|
||||
|
||||
def cmd_reload(command):
|
||||
"""
|
||||
|
|
@ -688,3 +690,59 @@ GLOBAL_CMD_TABLE.add_command("@sethelp", cmd_sethelp,
|
|||
"helpsys.del_help",
|
||||
"helpsys.admin_heelp"),
|
||||
help_category="Admin")
|
||||
|
||||
def cmd_setcmdalias(command):
|
||||
"""
|
||||
@setcmdalias - define shortcuts for commands
|
||||
|
||||
Usage:
|
||||
@setcmdalias[/switch] [command = ] alias
|
||||
|
||||
Switches:
|
||||
list - view all command aliases (default)
|
||||
add - add alias
|
||||
del - remove and existing alias
|
||||
|
||||
This defins a new alias for a common command,
|
||||
for example like letting 'l' work as
|
||||
well as 'look'. When you change an alias you must
|
||||
use @reload/aliases before the alias-change gets
|
||||
recognized.
|
||||
"""
|
||||
source_object = command.source_object
|
||||
args = command.command_argument
|
||||
switches = command.command_switches
|
||||
|
||||
if not args or 'list' in switches:
|
||||
# show all aliases
|
||||
string = "Command aliases defined:"
|
||||
aliases = CommandAlias.objects.all()
|
||||
if not aliases:
|
||||
string = "No command aliases defined."
|
||||
for alias in aliases:
|
||||
string += "\n %s = %s" % (alias.equiv_command, alias.user_input)
|
||||
source_object.emit_to(string)
|
||||
return
|
||||
|
||||
equiv_command = ""
|
||||
user_input = ""
|
||||
# analyze args
|
||||
if '=' in args:
|
||||
equiv_command, user_input = [arg.strip() for arg in args.split("=",1)]
|
||||
else:
|
||||
user_input = args.strip()
|
||||
|
||||
if 'add' in switches:
|
||||
# add alias
|
||||
edit_aliases.add_alias(user_input, equiv_command)
|
||||
source_object.emit_to("Alias %s -> %s added. Now do '@reload/aliases'." % (user_input, equiv_command))
|
||||
return
|
||||
elif 'del' in switches:
|
||||
# delete alias
|
||||
edit_aliases.del_alias(user_input)
|
||||
source_object.emit_to("Removed alias %s (if it existed). Now do '@reload/aliases'." % user_input)
|
||||
else:
|
||||
source_object.emit_to("Usage: @setcmdalias[/switch] [command = ] alias")
|
||||
GLOBAL_CMD_TABLE.add_command("@setcmdalias", cmd_setcmdalias,
|
||||
priv_tuple=("genperms.process_control",),
|
||||
help_category="Admin")
|
||||
|
|
|
|||
27
src/config/edit_aliases.py
Normal file
27
src/config/edit_aliases.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# Support command for editing command aliases
|
||||
#
|
||||
from src.config.models import CommandAlias
|
||||
|
||||
def add_alias(user_input, equiv_command):
|
||||
"""
|
||||
Adds a new alias or replace an old one.
|
||||
"""
|
||||
aquery = CommandAlias.objects.filter(user_input=user_input)
|
||||
if aquery:
|
||||
# overwrite existing alias
|
||||
alias = aquery[0]
|
||||
alias.user_input = user_input
|
||||
alias.equiv_command = equiv_command
|
||||
alias.save()
|
||||
else:
|
||||
# create new alias
|
||||
CommandAlias(user_input=user_input, equiv_command=equiv_command).save()
|
||||
|
||||
def del_alias(alias):
|
||||
"""
|
||||
Delete an alias from the database
|
||||
"""
|
||||
aquery = CommandAlias.objects.filter(user_input=alias)
|
||||
if aquery:
|
||||
aquery[0].delete()
|
||||
|
|
@ -5,4 +5,4 @@ from django.db import models
|
|||
|
||||
class CommandAliasManager(models.Manager):
|
||||
pass
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class CommandAlias(models.Model):
|
|||
class Meta:
|
||||
verbose_name_plural = "Command aliases"
|
||||
ordering = ['user_input']
|
||||
|
||||
|
||||
class ConfigValue(models.Model):
|
||||
"""
|
||||
Experimental new config model.
|
||||
|
|
@ -38,4 +38,4 @@ class ConnectScreen(models.Model):
|
|||
text = models.TextField(help_text="The text for the connect screen. Color codes and substitutions are evaluated.")
|
||||
is_active = models.BooleanField(default=1, help_text="Only active connect screens are placed in the rotation")
|
||||
|
||||
objects = ConnectScreenManager()
|
||||
objects = ConnectScreenManager()
|
||||
|
|
|
|||
|
|
@ -66,6 +66,20 @@ DATABASE_HOST = ''
|
|||
# Empty string defaults to localhost. Not used with sqlite3.
|
||||
DATABASE_PORT = ''
|
||||
|
||||
## Command aliases
|
||||
# These are convenient aliases set up when the game is started
|
||||
# for the very first time. You can add/delete aliases in-game using
|
||||
# the @cmdalias command.
|
||||
COMMAND_ALIASES = {"@desc":"@describe",
|
||||
"@dest":"@destroy", "@nuke":"@destroy",
|
||||
"@tel":"@teleport",
|
||||
"i":"inventory", "inv":"inventory",
|
||||
"l":"look",
|
||||
"ex":"examine",
|
||||
"sa":"say",
|
||||
"emote":"pose",
|
||||
"p":"page" }
|
||||
|
||||
## Permissions
|
||||
## The variables in this section are used by each evennia subsystem to tell which permissions to define.
|
||||
## These variables are called by the respective subsystem ('application' in django lingo) of Evennia. The final
|
||||
|
|
|
|||
|
|
@ -113,19 +113,24 @@ def create_connect_screens():
|
|||
|
||||
def create_aliases():
|
||||
"""
|
||||
Populates the standard aliases.
|
||||
Populates the standard aliases. by reading the COMMAND_ALIASES dict
|
||||
from the settings file.
|
||||
"""
|
||||
CommandAlias(user_input="@desc", equiv_command="@describe").save()
|
||||
CommandAlias(user_input="@dest", equiv_command="@destroy").save()
|
||||
CommandAlias(user_input="@nuke", equiv_command="@destroy").save()
|
||||
CommandAlias(user_input="@tel", equiv_command="@teleport").save()
|
||||
CommandAlias(user_input="i", equiv_command="inventory").save()
|
||||
CommandAlias(user_input="inv", equiv_command="inventory").save()
|
||||
CommandAlias(user_input="l", equiv_command="look").save()
|
||||
CommandAlias(user_input="ex", equiv_command="examine").save()
|
||||
CommandAlias(user_input="sa", equiv_command="say").save()
|
||||
#CommandAlias(user_input="emote", equiv_command="pose").save()
|
||||
CommandAlias(user_input="p", equiv_command="page").save()
|
||||
command_aliases = settings.COMMAND_ALIASES
|
||||
for user_input, equiv_command in command_aliases.items():
|
||||
CommandAlias(user_input=user_input, equiv_command=equiv_command).save()
|
||||
|
||||
## CommandAlias(user_input="@desc", equiv_command="@describe").save()
|
||||
## CommandAlias(user_input="@dest", equiv_command="@destroy").save()
|
||||
## CommandAlias(user_input="@nuke", equiv_command="@destroy").save()
|
||||
## CommandAlias(user_input="@tel", equiv_command="@teleport").save()
|
||||
## CommandAlias(user_input="i", equiv_command="inventory").save()
|
||||
## CommandAlias(user_input="inv", equiv_command="inventory").save()
|
||||
## CommandAlias(user_input="l", equiv_command="look").save()
|
||||
## CommandAlias(user_input="ex", equiv_command="examine").save()
|
||||
## CommandAlias(user_input="sa", equiv_command="say").save()
|
||||
## #CommandAlias(user_input="emote", equiv_command="pose").save()
|
||||
## CommandAlias(user_input="p", equiv_command="page").save()
|
||||
|
||||
def import_help_files():
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue