Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def func(self):
- # Validate the switch.
- if self.switches:
- # This command only accepts
- # one switch so we're only going to consider the first switch that was
- # passed.
- # is the tolower necessary? is startswith case sensitive?
- first = self.switches[0].lower() or ''
- # Try to match the passed switch against the list of allowed switches.
- switch = filter(lambda x: x.startswith(first), self.switchtab)
- # If switch is None, then there were no matches.
- if not switch:
- self.caller.msg("Unknown switch, bro! Try one of %s." % utils.itemize(self.switchtab, prep="and"))
- return
- elif len(switch) > 1:
- # If the length of switch (a list) is > 1 then more than one switch was matched.
- self.caller.msg("Sorry bro, '%s' matches multiple switches: %s. Please be more specific." % (first, utils.itemize(switch)))
- return
- # There was precisely one match.
- switch = switch[0]
- else:
- # No switch was passed so default to /list.
- switch = 'list'
- if _DEBUG:
- self.caller.msg("DEBUG: switch=%s" % switch)
- # All switches except for LIST require permission checks.
- if switch <> 'list':
- if not self.access(self.caller, "control") or not self.access(self.caller, "edit"):
- self.caller.msg("Sorry bro, you don't have permission to modify that room.")
- return
- # Lookup the name of the handler.
- method = getattr(self, "do_%s" % switch)
- if _DEBUG:
- self.caller.msg("DEBUG: handler=%s" % method.__name__)
- # Call the handler. No need to pass any args here since they'll be accessible in self.args.
- if method and callable(method):
- # Call the do_x method. This does the actual work.
- method()
- else:
- self.caller.msg("Sorry bro, there's no handler defined for the '%s' switch." % switch)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement