Adding wildcard_to_regexp() to functions_general and cleaning up some imports.
This commit is contained in:
parent
8335f8b80f
commit
7d78cbcf4b
3 changed files with 24 additions and 5 deletions
|
|
@ -8,7 +8,6 @@ import session_mgr
|
||||||
import functions_general
|
import functions_general
|
||||||
import functions_db
|
import functions_db
|
||||||
import commands_general
|
import commands_general
|
||||||
import commands_unloggedin
|
|
||||||
import ansi
|
import ansi
|
||||||
"""
|
"""
|
||||||
Any command here is prefixed by an '@' sign, usually denoting a
|
Any command here is prefixed by an '@' sign, usually denoting a
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,5 @@
|
||||||
from apps.objects.models import CommChannel
|
from apps.objects.models import CommChannel
|
||||||
import session_mgr
|
import session_mgr
|
||||||
import commands_privileged
|
|
||||||
import commands_general
|
|
||||||
import commands_comsys
|
|
||||||
import commands_unloggedin
|
|
||||||
import ansi
|
import ansi
|
||||||
"""
|
"""
|
||||||
Comsys functions.
|
Comsys functions.
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,30 @@ import commands_unloggedin
|
||||||
General commonly used functions.
|
General commonly used functions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def wildcard_to_regexp(instring):
|
||||||
|
"""
|
||||||
|
Converts a player-supplied string that may have wildcards in it to regular
|
||||||
|
expressions. This is useful for name matching.
|
||||||
|
|
||||||
|
instring: (string) A string that may potentially contain wildcards (* or ?).
|
||||||
|
"""
|
||||||
|
regexp_string = ""
|
||||||
|
|
||||||
|
# If the string starts with an asterisk, we can't impose the beginning of
|
||||||
|
# string (^) limiter.
|
||||||
|
if instring[0] != "*":
|
||||||
|
regexp_string += "^"
|
||||||
|
|
||||||
|
# Replace any occurances of * or ? with the appropriate groups.
|
||||||
|
regexp_string += instring.replace("*","(.*)").replace("?", "(.{1})")
|
||||||
|
|
||||||
|
# If there's an asterisk at the end of the string, we can't impose the
|
||||||
|
# end of string ($) limiter.
|
||||||
|
if instring[-1] != "*":
|
||||||
|
regexp_string += "$"
|
||||||
|
|
||||||
|
return regexp_string
|
||||||
|
|
||||||
def cmd_check_num_args(session, arg_list, min_args, errortext="Missing arguments!"):
|
def cmd_check_num_args(session, arg_list, min_args, errortext="Missing arguments!"):
|
||||||
"""
|
"""
|
||||||
Check a player command's splitted argument list to make sure it contains
|
Check a player command's splitted argument list to make sure it contains
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue