Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. def func(self):
  2.  
  3. # Validate the switch.
  4. if self.switches:
  5. # This command only accepts
  6. # one switch so we're only going to consider the first switch that was
  7. # passed.
  8.  
  9. # is the tolower necessary? is startswith case sensitive?
  10. first = self.switches[0].lower() or ''
  11.  
  12. # Try to match the passed switch against the list of allowed switches.
  13. switch = filter(lambda x: x.startswith(first), self.switchtab)
  14.  
  15. # If switch is None, then there were no matches.
  16. if not switch:
  17. self.caller.msg("Unknown switch, bro! Try one of %s." % utils.itemize(self.switchtab, prep="and"))
  18. return
  19. elif len(switch) > 1:
  20. # If the length of switch (a list) is > 1 then more than one switch was matched.
  21. self.caller.msg("Sorry bro, '%s' matches multiple switches: %s. Please be more specific." % (first, utils.itemize(switch)))
  22. return
  23. # There was precisely one match.
  24. switch = switch[0]
  25. else:
  26. # No switch was passed so default to /list.
  27. switch = 'list'
  28.  
  29. if _DEBUG:
  30. self.caller.msg("DEBUG: switch=%s" % switch)
  31.  
  32. # All switches except for LIST require permission checks.
  33. if switch <> 'list':
  34. if not self.access(self.caller, "control") or not self.access(self.caller, "edit"):
  35. self.caller.msg("Sorry bro, you don't have permission to modify that room.")
  36. return
  37.  
  38. # Lookup the name of the handler.
  39. method = getattr(self, "do_%s" % switch)
  40.  
  41. if _DEBUG:
  42. self.caller.msg("DEBUG: handler=%s" % method.__name__)
  43.  
  44. # Call the handler. No need to pass any args here since they'll be accessible in self.args.
  45. if method and callable(method):
  46. # Call the do_x method. This does the actual work.
  47. method()
  48. else:
  49. 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