· 7 years ago · Dec 21, 2018, 02:18 AM
1this is my error from the actual evennia client:
2Traceback (most recent call last):
3 File "/home/amil/realMUSH/evennia/evennia/commands/cmdsethandler.py", line 174, in import_cmdset
4 module = import_module(modpath, package="evennia")
5 File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
6 __import__(name)
7 File "./commands/default_cmdsets.py", line 37, in <module>
8 from commands.command import CmdMakeGM
9 File "./commands/command.py", line 372
10 else:
11 ^
12SyntaxError: invalid syntax
13
14SyntaxError encountered when loading cmdset 'commands.default_cmdsets.SessionCmdSet'.
15(Traceback was logged 18-12-21 02:15:00)
16
17Error encountered for cmdset at path 'commands.default_cmdsets.SessionCmdSet'.
18Replacing with fallback 'evennia.commands.default.cmdset_session.SessionCmdSet'.
19 ... Server restarted.
20
21this is my command.py:
22"""
23Commands
24
25Commands describe the input the account can do to the game.
26
27"""
28
29from evennia import Command as BaseCommand
30from evennia import default_cmds
31
32
33class Command(BaseCommand):
34 """
35 Inherit from this if you want to create your own command styles
36 from scratch. Note that Evennia's default commands inherits from
37 MuxCommand instead.
38
39 Note that the class's `__doc__` string (this text) is
40 used by Evennia to create the automatic help entry for
41 the command, so make sure to document consistently here.
42
43 Each Command implements the following methods, called
44 in this order (only func() is actually required):
45 - at_pre_cmd(): If this returns True, execution is aborted.
46 - parse(): Should perform any extra parsing needed on self.args
47 and store the result on self.
48 - func(): Performs the actual work.
49 - at_post_cmd(): Extra actions, often things done after
50 every command, like prompts.
51
52 """
53 pass
54
55# -------------------------------------------------------------
56#
57# The default commands inherit from
58#
59# evennia.commands.default.muxcommand.MuxCommand.
60#
61# If you want to make sweeping changes to default commands you can
62# uncomment this copy of the MuxCommand parent and add
63#
64# COMMAND_DEFAULT_CLASS = "commands.command.MuxCommand"
65#
66# to your settings file. Be warned that the default commands expect
67# the functionality implemented in the parse() method, so be
68# careful with what you change.
69#
70# -------------------------------------------------------------
71
72# from evennia.utils import utils
73#
74#
75# class MuxCommand(Command):
76# """
77# This sets up the basis for a MUX command. The idea
78# is that most other Mux-related commands should just
79# inherit from this and don't have to implement much
80# parsing of their own unless they do something particularly
81# advanced.
82#
83# Note that the class's __doc__ string (this text) is
84# used by Evennia to create the automatic help entry for
85# the command, so make sure to document consistently here.
86# """
87# def has_perm(self, srcobj):
88# """
89# This is called by the cmdhandler to determine
90# if srcobj is allowed to execute this command.
91# We just show it here for completeness - we
92# are satisfied using the default check in Command.
93# """
94# return super(MuxCommand, self).has_perm(srcobj)
95#
96# def at_pre_cmd(self):
97# """
98# This hook is called before self.parse() on all commands
99# """
100# pass
101#
102# def at_post_cmd(self):
103# """
104# This hook is called after the command has finished executing
105# (after self.func()).
106# """
107# pass
108#
109# def parse(self):
110# """
111# This method is called by the cmdhandler once the command name
112# has been identified. It creates a new set of member variables
113# that can be later accessed from self.func() (see below)
114#
115# The following variables are available for our use when entering this
116# method (from the command definition, and assigned on the fly by the
117# cmdhandler):
118# self.key - the name of this command ('look')
119# self.aliases - the aliases of this cmd ('l')
120# self.permissions - permission string for this command
121# self.help_category - overall category of command
122#
123# self.caller - the object calling this command
124# self.cmdstring - the actual command name used to call this
125# (this allows you to know which alias was used,
126# for example)
127# self.args - the raw input; everything following self.cmdstring.
128# self.cmdset - the cmdset from which this command was picked. Not
129# often used (useful for commands like 'help' or to
130# list all available commands etc)
131# self.obj - the object on which this command was defined. It is often
132# the same as self.caller.
133#
134# A MUX command has the following possible syntax:
135#
136# name[ with several words][/switch[/switch..]] arg1[,arg2,...] [[=|,] arg[,..]]
137#
138# The 'name[ with several words]' part is already dealt with by the
139# cmdhandler at this point, and stored in self.cmdname (we don't use
140# it here). The rest of the command is stored in self.args, which can
141# start with the switch indicator /.
142#
143# This parser breaks self.args into its constituents and stores them in the
144# following variables:
145# self.switches = [list of /switches (without the /)]
146# self.raw = This is the raw argument input, including switches
147# self.args = This is re-defined to be everything *except* the switches
148# self.lhs = Everything to the left of = (lhs:'left-hand side'). If
149# no = is found, this is identical to self.args.
150# self.rhs: Everything to the right of = (rhs:'right-hand side').
151# If no '=' is found, this is None.
152# self.lhslist - [self.lhs split into a list by comma]
153# self.rhslist - [list of self.rhs split into a list by comma]
154# self.arglist = [list of space-separated args (stripped, including '=' if it exists)]
155#
156# All args and list members are stripped of excess whitespace around the
157# strings, but case is preserved.
158# """
159# raw = self.args
160# args = raw.strip()
161#
162# # split out switches
163# switches = []
164# if args and len(args) > 1 and args[0] == "/":
165# # we have a switch, or a set of switches. These end with a space.
166# switches = args[1:].split(None, 1)
167# if len(switches) > 1:
168# switches, args = switches
169# switches = switches.split('/')
170# else:
171# args = ""
172# switches = switches[0].split('/')
173# arglist = [arg.strip() for arg in args.split()]
174#
175# # check for arg1, arg2, ... = argA, argB, ... constructs
176# lhs, rhs = args, None
177# lhslist, rhslist = [arg.strip() for arg in args.split(',')], []
178# if args and '=' in args:
179# lhs, rhs = [arg.strip() for arg in args.split('=', 1)]
180# lhslist = [arg.strip() for arg in lhs.split(',')]
181# rhslist = [arg.strip() for arg in rhs.split(',')]
182#
183# # save to object properties:
184# self.raw = raw
185# self.switches = switches
186# self.args = args.strip()
187# self.arglist = arglist
188# self.lhs = lhs
189# self.lhslist = lhslist
190# self.rhs = rhs
191# self.rhslist = rhslist
192#
193# # if the class has the account_caller property set on itself, we make
194# # sure that self.caller is always the account if possible. We also create
195# # a special property "character" for the puppeted object, if any. This
196# # is convenient for commands defined on the Account only.
197# if hasattr(self, "account_caller") and self.account_caller:
198# if utils.inherits_from(self.caller, "evennia.objects.objects.DefaultObject"):
199# # caller is an Object/Character
200# self.character = self.caller
201# self.caller = self.caller.account
202# elif utils.inherits_from(self.caller, "evennia.accounts.accounts.DefaultAccount"):
203# # caller was already an Account
204# self.character = self.caller.get_puppet(self.session)
205# else:
206# self.character = None
207import evennia
208
209class CmdMakeGM(default_cmds.MuxCommand):
210 """
211 Change an account's GM status
212
213 Usage:
214 @gm <account>
215 @ungm <account>
216
217 """
218 key = "@gm"
219 aliases = "@ungm"
220 locks = "cmd:perm(Developers)"
221 help_category = "RP"
222
223 def func(self):
224 "Implement the command"
225 caller = self.caller
226
227 if not self.args:
228 caller.msg("Usage: @gm account or @ungm account")
229 return
230
231 accountlist = evennia.search_account(self.args) # returns a list
232 if not accountlist:
233 caller.msg("Could not find account '%s'" % self.args)
234 return
235 elif len(accountlist) > 1:
236 caller.msg("Multiple matches for '%s': %s" % (self.args, accountlist))
237 return
238 else:
239 account = accountlist[0]
240
241 if self.cmdstring == "@gm":
242 # turn someone into a GM
243 if account.permissions.get("Admins"):
244 caller.msg("Account %s is already a GM." % account)
245 else:
246 account.permissions.add("Admins")
247 caller.msg("Account %s is now a GM." % account)
248 account.msg("You are now a GM (changed by %s)." % caller)
249 account.character.db.is_gm = True
250 else:
251 # @ungm was entered - revoke GM status from someone
252 if not account.permissions.get("Admins"):
253 caller.msg("Account %s is not a GM." % account)
254 else:
255 account.permissions.remove("Admins")
256 caller.msg("Account %s is no longer a GM." % account)
257 account.msg("You are no longer a GM (changed by %s)." % caller)
258 del account.character.db.is_gm
259ALLOWED_ATTRS = ("str", "con", "dex", "int", "wis", "cha")
260ALLOWED_FIELDNAMES = ALLOWED_ATTRS + \
261 ("name", "advantages", "disadvantages")
262
263def _validate_fieldname(caller, fieldname):
264 "Helper function to validate field names."
265 if fieldname not in ALLOWED_FIELDNAMES:
266 err = "Allowed field names: %s" % (", ".join(ALLOWED_FIELDNAMES))
267 caller.msg(err)
268 return False
269 if fieldname in ALLOWED_ATTRS and not value.isdigit():
270 caller.msg("%s must receive a number." % fieldname)
271 return False
272 return True
273
274class CmdSheet(MuxCommand):
275 """
276 Edit a field on the character sheet
277
278 Usage:
279 @sheet field value
280
281 Examples:
282 @sheet name Ulrik the Warrior
283 @sheet dex 12
284 @sheet advantages Super strength, Night vision
285
286 If given without arguments, will view the current character sheet.
287
288 Allowed field names are:
289 name,
290 str, con, dex, int, wis, cha,
291 advantages, disadvantages
292
293 """
294
295 key = "@sheet"
296 aliases = "@editsheet"
297 locks = "cmd: perm(Players)"
298 help_category = "RP"
299
300 def func(self):
301 caller = self.caller
302 if not self.args or len(self.args) < 2:
303 # not enough arguments. Display the sheet
304 if sheet:
305 caller.msg(unicode(caller.db.charsheet))
306 else:
307 caller.msg("You have no character sheet.")
308 return
309
310 # if caller.db.sheet_locked:
311 caller.msg("Your character sheet is locked.")
312 return
313
314 # split input by whitespace, once
315 fieldname, value = self.args.split(None, 1)
316 fieldname = fieldname.lower() # ignore case
317
318 if not _validate_fieldnames(caller, fieldname):
319 return
320 if fieldname == "name":
321 self.key = value
322 else:
323 caller.chardata[fieldname] = value
324 caller.update_charsheet()
325 caller.msg("%s was set to %s." % (fieldname, value))
326class CmdGMsheet(MuxCommand):
327 """
328 GM-modification of char sheets
329
330 Usage:
331 @gmsheet character [= fieldname value]
332
333 Switches:
334 lock - lock the character sheet so the account
335 can no longer edit it (GM's still can)
336 unlock - unlock character sheet for Account
337 editing.
338
339 Examples:
340 @gmsheet Tom
341 @gmsheet Anna = str 12
342 @gmsheet/lock Tom
343
344 """
345 key = "@gmsheet"
346 locks = "cmd: perm(Admins)"
347 help_category = "RP"
348
349 def func(self):
350 caller = self.caller
351 if not self.args:
352 caller.msg("Usage: @gmsheet character [= fieldname value]).")
353 if self.rhs:
354 # rhs (right-hand-side) is set only if a '='
355 # was given.
356 if len(self.rhs) < 2:
357 caller.msg("You must specify both a fieldname and value.")
358 return
359 fieldname, value = self.rhs.split(None, 1)
360 fieldname = fieldname.lower()
361 if not _validate_fieldname(caller, fieldname):
362 return
363 charname = self.lhs
364 else:
365 # no '=', so we must be aiming to look at a charsheet
366 fieldname, value = None, None
367 charname = self.args.strip()
368
369 character = caller.search(charname, global_search=True)
370 if not character:
371 return
372
373 if "lock" in self.switches:
374 if character.db.sheet_locked:
375 caller.msg("The character sheet is already locked.")
376 else:
377 character.db.sheet_locked = True
378 caller.msg("%s can no longer edit their character sheet." % character.key)
379 elif "unlock" in self.switches:
380 if not character.db.sheet_locked:
381 caller.msg("The character sheet is already unlocked.")
382 else:
383 character.db.sheet_locked = False
384 caller.msg("%s can now edit their character sheet." % character.key)
385
386 if fieldname:
387 if fieldname == "name":
388 character.key = value
389 else:
390 character.db.chardata[fieldname] = value
391 character.update_charsheet()
392 caller.msg("You set %s's %s to %s." % (character.key, fieldname, value)
393 else:
394 # just display
395 caller.msg(unicode(character.db.charsheet))
396
397this is my characters.py:
398"""
399Characters
400
401Characters are (by default) Objects setup to be puppeted by Accounts.
402They are what you "see" in game. The Character class in this module
403is setup to be the "default" character type created by the default
404creation commands.
405
406"""
407from evennia import DefaultCharacter
408from evennia.utils import evform, evtable
409
410
411class Character(DefaultCharacter):
412 """
413 The Character defaults to reimplementing some of base Object's hook methods with the
414 following functionality:
415
416 at_basetype_setup - always assigns the DefaultCmdSet to this object type
417 (important!)sets locks so character cannot be picked up
418 and its commands only be called by itself, not anyone else.
419 (to change things, use at_object_creation() instead).
420 at_after_move(source_location) - Launches the "look" command after every move.
421 at_post_unpuppet(account) - when Account disconnects from the Character, we
422 store the current location in the pre_logout_location Attribute and
423 move it to a None-location so the "unpuppeted" character
424 object does not need to stay on grid. Echoes "Account has disconnected"
425 to the room.
426 at_pre_puppet - Just before Account re-connects, retrieves the character's
427 pre_logout_location Attribute and move it back on the grid.
428 at_post_puppet - Echoes "AccountName has entered the game" to the room.
429
430 """
431 def get_display_name(self, looker, **kwargs):
432 """
433 This method customizes how character names are displayed. We assume
434 only permissions of types "Developers" and "Admins" require
435 special attention.
436 """
437 name = self.key
438 selfaccount = self.account # will be None if we are not puppeted
439 lookaccount = looker.account # - " -
440
441 if selfaccount and selfaccount.db.is_gm:
442 # A GM. Show name as name(GM)
443 name = "%s(GM)" % name
444
445 if lookaccount and \
446 (lookaccount.permissions.get("Developers") or lookaccount.db.is_gm):
447 # Developers/GMs see name(#dbref) or name(GM)(#dbref)
448 return "%s(#%s)" % (name, self.id)
449 else:
450 return name
451
452 pass
453 def at_object_creation(self):
454 "called only once, when object is first created"
455 # we will use this to stop account from changing sheet
456 self.db.sheet_locked = False
457 # we store these so we can build these on demand
458 self.db.chardata = {"str": 0,
459 "con": 0,
460 "dex": 0,
461 "int": 0,
462 "wis": 0,
463 "cha": 0,
464 "advantages": "",
465 "disadvantages": ""}
466 self.db.charsheet = evform.EvForm("world/charsheetform.py")
467 self.update_charsheet()
468
469 def update_charsheet(self):
470 """
471 Call this to update the sheet after any of the ingoing data
472 has changed.
473 """
474 sheet = self.db.charsheet
475 data = self.db.chardata
476 table = evtable.EvTable("Attr", "Value",
477 table = [
478 ["STR", "CON", "DEX", "INT", "WIS", "CHA"],
479 [data["str"], data["con"], data["dex"],
480 data["int"], data["wis"], data["cha"]]],
481 align='r', border="incols")
482 self.db.charsheet = sheet.map(tables={"2": table},
483 cells={"1":self.key,
484 "3":data["advantages"],
485 "4":data["disadvantages"]})
486
487this is my default_cmdsets.py:
488"""
489Command sets
490
491All commands in the game must be grouped in a cmdset. A given command
492can be part of any number of cmdsets and cmdsets can be added/removed
493and merged onto entities at runtime.
494
495To create new commands to populate the cmdset, see
496`commands/command.py`.
497
498This module wraps the default command sets of Evennia; overloads them
499to add/remove commands from the default lineup. You can create your
500own cmdsets by inheriting from them or directly from `evennia.CmdSet`.
501
502"""
503
504from evennia import default_cmds
505
506
507class CharacterCmdSet(default_cmds.CharacterCmdSet):
508 """
509 The `CharacterCmdSet` contains general in-game commands like `look`,
510 `get`, etc available on in-game Character objects. It is merged with
511 the `AccountCmdSet` when an Account puppets a Character.
512 """
513 key = "DefaultCharacter"
514
515 def at_cmdset_creation(self):
516 """
517 Populates the cmdset
518 """
519 super(CharacterCmdSet, self).at_cmdset_creation()
520 #
521 # any commands you add below will overload the default ones.
522 #
523
524from commands.command import CmdMakeGM
525from commands.command import CmdSheet
526from commands.command import CmdGMsheet
527import contrib.dice.CmdDice
528
529class AccountCmdSet(default_cmds.AccountCmdSet):
530 """
531 This is the cmdset available to the Account at all times. It is
532 combined with the `CharacterCmdSet` when the Account puppets a
533 Character. It holds game-account-specific commands, channel
534 commands, etc.
535 """
536 key = "DefaultAccount"
537
538 def at_cmdset_creation(self):
539 """
540 Populates the cmdset
541 """
542 super(AccountCmdSet, self).at_cmdset_creation()
543 #
544 # any commands you add below will overload the default ones.
545 #
546 self.add(CmdMakeGM())
547 self.add(CmdSheet())
548 self.add(CmdGMsheet())
549 self.add(CmdDice())
550
551
552class UnloggedinCmdSet(default_cmds.UnloggedinCmdSet):
553 """
554 Command set available to the Session before being logged in. This
555 holds commands like creating a new account, logging in, etc.
556 """
557 key = "DefaultUnloggedin"
558
559 def at_cmdset_creation(self):
560 """
561 Populates the cmdset
562 """
563 super(UnloggedinCmdSet, self).at_cmdset_creation()
564 #
565 # any commands you add below will overload the default ones.
566 #
567
568
569class SessionCmdSet(default_cmds.SessionCmdSet):
570 """
571 This cmdset is made available on Session level once logged in. It
572 is empty by default.
573 """
574 key = "DefaultSession"
575
576 def at_cmdset_creation(self):
577 """
578 This is the only method defined in a cmdset, called during
579 its creation. It should populate the set with command instances.
580
581 As and example we just add the empty base `Command` object.
582 It prints some info.
583 """
584 super(SessionCmdSet, self).at_cmdset_creation()
585 #
586 # any commands you add below will overload the default ones.
587 #