def swexclude_cmd(ses, args, input): """ Adds words that should be excluded from speedwalk expansion as well as tells you which words are currently being excluded. If you had swdirs "n", "e", "s", and "w", you might want to create excludes for the words "sense", "news", "sew", ... Which are real words that you most likely don't want to be expanded. examples: #swexclude {end} #swexclude {news} see also: swdir category: commands """ # originally written by Sebastian John excludes = args["exclude"] quiet = args["quiet"] # they typed '#swexclude'--print out all current speedwalking excludes if len(excludes) == 0: data = exported.get_manager("speedwalk").getExcludesInfo(ses) if not data: data = ["swexcl: no speedwalking excludes defined."] exported.write_message("swexcludes:\n" + "\n".join(data), ses) return for exclude in excludes: exported.get_manager("speedwalk").addExclude(ses, exclude) if not quiet: exported.write_message("swexclude: {%s} added." % exclude, ses)
def highlight_cmd(ses, args, input): """ With no arguments, prints all highlights. With one argument, prints all highlights which match the arg. With multiple arguments, creates a highlight. Highlights enable you to colorfully "tag" text that's of interest to you with the given style. Styles available are: styles foreground colors background colors bold black grey b black blink red light red b red reverse green light green b green underline yellow light yellow b yellow blue light blue b blue magenta light magenta b magenta cyan light cyan b cyan white light white b white Highlights handle * at the beginning and end of non-regular expression texts. Highlights will handle regular expression texts as well. See "#help regexp" for more details. Note: blink, underline, and reverse may not be available in all ui's. examples: #highlight {green} {Sven arrives.} #highlight {reverse,green} {Sven arrives.} #highlight {blue} {r[^.*?says:]} which is the same as: #highlight {blue} {*says:} category: commands """ style = args["style"] text = args["text"] quiet = args["quiet"] if not text: data = exported.get_manager("highlight").getInfo(ses, style, 1) if not data: data = ["highlight: no highlights defined."] exported.write_message("highlights:\n" + "\n".join(data), ses) return style = style.lower() stylelist = style.split(",") for mem in stylelist: if mem not in ansi.STYLEMAP: exported.write_error("highlight: '%s' not a valid style.\nCheck out the highglight help file for more information." % mem) return exported.get_manager("highlight").addHighlight(ses, style, text) if not quiet: exported.write_message("highlight: {%s} {%s} added." % (style, text), ses)
def swdir_cmd(ses, args, input): """ This adds speedwalking aliases and tells you the current speedwalking dirs already registered. examples: #swdir {n} {north} #swdir {s} {south} #swdir {e} {east} #swdir {w} {west} #swdir {NE} {northeast} #swdir {l} {look} ... This allows you to string characters together to speedwalk: 4e2sNE which using the above swdirs gets expanded to "east;east;east;east;south;south;northeast" and who wants to type all that? see also: swexclude category: commands """ # originally written by Sebastian John alias = args["alias"] dir = args["dir"] quiet = args["quiet"] # they typed '#swdir dd*' and are looking for matching speedwalking dirs if not dir: data = exported.get_manager("speedwalk").getDirsInfo(ses, alias) if not data: data = ["swdir: no speedwalking dirs defined."] exported.write_message("swdirs:\n" + "\n".join(data), ses) return try: exported.get_manager("speedwalk").addDir(ses, alias, dir) if not quiet: exported.write_message("swdir: {%s} {%s} added." % (alias, dir), ses) except ValueError, e: exported.write_error("swdir: cannot add alias '%s': %s." % (alias, e), ses)
def antisubstitute_cmd(ses, args, input): """ Allows you to create antisubstitutes. For any line that contains an antisubstitute, we won't do substitutions on it. category: commands """ item = args["item"] quiet = args["quiet"] sm = exported.get_manager("substitute") if not item: data = sm.getAntiSubstitutesInfo(ses) if not data: data = ["antisubstitute: no antisubstitutes defined."] exported.write_message("antisubstitutes:\n" + "\n".join(data), ses) return sm.addAntiSubstitute(ses, item) if not quiet: exported.write_message("antisubstitute: {%s} added." % item, ses)
def substitute_cmd(ses, args, input): """ With no arguments, prints all substitutes. With one argument, prints all substitutes which match the argument. Otherwise creates a substitution. Braces are advised around both 'item' and 'substitution'. category: commands """ item = args["item"] substitution = args["substitution"] quiet = args["quiet"] sm = exported.get_manager("substitute") if not substitution: data = sm.getInfo(ses, item) if not data: data = ["substitute: no substitutes defined."] exported.write_message("substitutes:\n" + "\n".join(data), ses) return sm.addSubstitute(ses, item, substitution) if not quiet: exported.write_message("substitute: {%s} {%s} added." % (item, substitution), ses)
def antigag_cmd(ses, args, input): """ Allows you to create antigags. For any line that contains an antigag, we won't do gags on it. category: commands """ item = args["item"] quiet = args["quiet"] gm = exported.get_manager("gag") gd = gm.getGagData(ses) if not item: data = gd.getAntiGagsInfo() if not data: data = ["antigag: no antigags defined."] exported.write_message("antigags\n" + "\n".join(data), ses) return gd.addAntiGag(item) if not quiet: exported.write_message("antigag: {%s} added." % item, ses)
def chr_cmd(ses, args, input): """ Allows you to assign arbitrary characters to variables. For example, if you wanted to assign ASCII char 7 to variable ctrlG you could do: #chr {ctrlG} {7} Since this creates a variable, you should remove the variable with the unvariable command. Note: This won't work if you don't have the variable module loaded. category: commands """ var = args["var"] ascii = args["ascii"] quiet = args["quiet"] vm = exported.get_manager("variable") if not vm: exported.write_error("chr: no variable manager found.") return if ascii < 0 or ascii > 127: exported.write_error("chr: ascii argument out of range of 0 to 127.") return vm.addVariable(ses, var, chr(ascii)) if not quiet: exported.write_message("chr: variable %s added." % var)
def log_cmd(ses, args, input): """ Will start or stop logging to a given filename for that session. Each session can have its own logfile. If USERPREFIX is set, then every line from the user will be prepended with this prefix and immediately written into log file. If USERPREFIX is omitted, then the user input will be attached to mud prompts before logging. category: commands """ logfile = args["logfile"] databuffer = args["databuffer"] stripansi = args["stripansi"] userprefix = args["userprefix"] if not ses.isConnected(): exported.write_error("log: You must have a session to log.", ses) return lm = exported.get_manager("logger") loggerdata = lm.getLogData(ses) if not logfile: exported.write_message(loggerdata.getStatus(), ses) return # handle stopping logging if loggerdata.isLogging() == 1: try: logname = loggerdata._logfile.name loggerdata.closeLogFile() exported.write_message("log: stopped logging to '%s'." % logname, ses) except Exception as e: exported.write_error("log: logfile cannot be closed (%s)." % (e), ses) return # handle starting logging try: if os.sep not in logfile: logfile = config.options["datadir"] + logfile if databuffer: f = open(logfile, "w") buffer = "".join(ses.getDataBuffer()) f.write(buffer) exported.write_message("log: dumped %d lines of databuffer to logfile" % buffer.count("\n"), ses) loggerdata.setLogFile(f, stripansi, userprefix) else: loggerdata.openLogFile(logfile, stripansi, userprefix) if stripansi: stripansimessage = " stripping ansi" else: stripansimessage = "" exported.write_message("log: starting logging to '%s'%s." % (logfile, stripansimessage), ses) except Exception as e: exported.write_error("log: logfile cannot be opened for appending. %s" % (e), ses)
def substitute_cmd(ses, args, input): """ With no arguments, prints all substitutes. With one argument, prints all substitutes which match the argument. Otherwise creates a substitution. Braces are advised around both 'item' and 'substitution'. category: commands """ item = args["item"] substitution = args["substitution"] quiet = args["quiet"] sm = exported.get_manager("substitute") if not substitution: data = sm.getInfo(ses, item) if not data: data = ["substitute: no substitutes defined."] exported.write_message("substitutes:\n" + "\n".join(data), ses) return sm.addSubstitute(ses, item, substitution) if not quiet: exported.write_message( "substitute: {%s} {%s} added." % (item, substitution), ses)
def stop_moving(self): smm = exported.get_manager("sowmud") exits = smm.get_prompt().exits() self._look_room.set_exits(exits) cur = self._current_zone.current_room() looked = self._look_room if not cur.named(): cur.init_from_room(looked) elif cmp(cur, looked) != 0: if not self._position_unknown: self._current_zone = Zone() self._current_zone.current_room().init_from_room(looked) self._position_unknown = True else: exported.write_message( "Looked from unknown position, ended up with yet another different room!" ) else: # Okay, we've looked at the room and it turned out to match # with our expectation, but the position might still be # unknown, so it seems there should be two concepts here # 1. room mismatch -> position unknown # 2. position already unknown -> lets start recording the zone self._position_unknown = False pass self._look_room = None
def unsubstitute_cmd(ses, args, input): """ Allows you to remove substitutes. category: commands """ func = exported.get_manager("substitute").removeSubstitutes modutils.unsomething_helper(args, func, ses, "substitute", "substitutes")
def unswexclude_cmd(ses, args, input): """ Allows you to remove swexcludes. category: commands """ func = exported.get_manager("speedwalk").removeExcludes modutils.unsomething_helper(args, func, ses, "swexclude", "swexcludes")
def unalias_cmd(ses, args, input): """ Allows you to remove aliases. category: commands """ func = exported.get_manager("alias").getAliasData(ses).removeAliases modutils.unsomething_helper(args, func, None, "alias", "aliases")
def unvariable_cmd(ses, args, input): """ Allows you to remove variables. category: commands """ func = exported.get_manager("variable").removeVariables modutils.unsomething_helper(args, func, ses, "variable", "variables")
def unantisubstitute_cmd(ses, args, input): """ Allows you to remove antisubstitutes. category: commands """ func = exported.get_manager("substitute").removeAntiSubstitutes modutils.unsomething_helper(args, func, ses, "antisubstitute", "antisubstitutes")
def deed_cmd(ses, args, input): """ Deeds serve as a kind of notebook - whatever you don't want to forget, store it in a deed. examples:: #deed -- prints all the deeds for that session #deed {$TIMESTAMP Joe healed me} -- adds a new deed to the list #deed 10 -- prints the last 10 deeds Before a deed is stored, variables are expanded--this allows you to use system, global, and session variables in your deeds like $TIMESTAMP which will mark when the deed was created. category: commands """ # original deed_cmd code contributied by Sebastian John if (ses.getName() == "common"): exported.write_error("deed cannot be applied to common session.", ses) return deedtext = args["text"] quiet = args["quiet"] if not deedtext: data = exported.get_manager("deed").getInfo(ses) if data == "": data = "deed: no deeds defined." exported.write_message(data, ses) return if deedtext.isdigit(): data = exported.get_manager("deed").getInfo(ses, deedtext) if data == "": data = "deed: no deeds defined." exported.write_message(data, ses) return exported.get_manager("deed").getDeedData(ses).addDeed(deedtext) if not quiet: exported.write_message("deed: {%s} added." % deedtext, ses)
def bot_status_cmd(ses, args, input): """ Get the status of the bot see also: category: bot """ smm = exported.get_manager("sowmud") smm.status()
def bot_on_cmd(ses, args, input): """ Turn on SowMud bot see also: category: bot """ smm = exported.get_manager("sowmud") smm.turn_on()
def status(self): smm = exported.get_manager("sowmud") if smm.enabled(): exported.write_message( "Current room: {0}, moving {1}, expected room: {2}, position unknown: {3}" .format(self._current_zone.current_room(), self._moving, self._expected_room, self._position_unknown)) else: exported.write_message("Bot disabled")
def map_status_cmd(ses, args, input): """ Display the status of the mapper see also: category: mapper """ smm = exported.get_manager("sowmud") smm.get_world().status()
def unhighlight_cmd(ses, args, input): """ Allows you to remove highlights. examples: #highlight {hello} #highlight {blah*} category: commands """ func = exported.get_manager("highlight").removeHighlights modutils.unsomething_helper(args, func, ses, "highlight", "highlights")
def variable_cmd(ses, args, input): """ Creates a variable for that session of said name with said value. Variables can then pretty much be used anywhere. examples: #variable {hps} {100} #action {HP: %0/%1 } {#variable {hps} {%0}} Variables can later be accessed via the variable character (which defaults to $) and the variable name. In the case of the above, the variable name would be $hps. We also handle braced closures for denoting variables like ${hps}. If you have a variable hps and a variable hpset, you can explicitly specify which one using { }. There are also system variables $HOME, $TIMESTAMP, $LOGTIMESTAMP, and $DATADIR (must be upper-cased) and global variables. To set a global variable which can be used in all sessions, it must be preceded by a _. examples: #variable {_fun} {happy fun ball} #showme $_fun #showme $TIMESTAMP #showme ${TIMESTAMP} category: commands """ var = args["var"] expansion = args["expansion"] quiet = args["quiet"] vm = exported.get_manager("variable") if not expansion: data = vm.getInfo(ses, var) if not data: data = ["variable: no variables defined."] exported.write_message("variables:\n" + "\n".join(data), ses) return try: vm.addVariable(ses, var, expansion) if not quiet: exported.write_message( "variable: {%s}={%s} added." % (var, expansion), ses) except Exception, e: exported.write_error("variable: cannot be set. %s" % e, ses)
def _executeBinding(self, binding): """ Returns the alias for this keybinding.""" ses = exported.get_current_session() action = exported.get_manager("alias").getAlias(ses, binding) if action: self._partk.handleinput(action) return 1 else: # we're commenting this out since it seems to be more annoying # than useful. it's not a good substitute for good documentation # for the tkui. # exported.write_error("%s is currently not bound to anything." % binding) return 0
def mudfilter_moving(self, text): smm = exported.get_manager("sowmud") prompt = smm.get_prompt() ts = prompt.timestamp() if (ts > self._look_room.timestamp()) and (prompt.current()): self.stop_moving() else: if not self._look_room.named(): self._look_room.set_name(text) else: self._look_room.add_desc_line(text)
def action_tags_cmd(ses, args, input): """ Shows all the tags available see also: action, unaction, enable, disable category: commands """ list = exported.get_manager("action").listTags(ses) if list: exported.write_message("\n".join(list)) else: exported.write_message("No tags defined.")
def variable_cmd(ses, args, input): """ Creates a variable for that session of said name with said value. Variables can then pretty much be used anywhere. examples: #variable {hps} {100} #action {HP: %0/%1 } {#variable {hps} {%0}} Variables can later be accessed via the variable character (which defaults to $) and the variable name. In the case of the above, the variable name would be $hps. We also handle braced closures for denoting variables like ${hps}. If you have a variable hps and a variable hpset, you can explicitly specify which one using { }. There are also system variables $HOME, $TIMESTAMP, $LOGTIMESTAMP, and $DATADIR (must be upper-cased) and global variables. To set a global variable which can be used in all sessions, it must be preceded by a _. examples: #variable {_fun} {happy fun ball} #showme $_fun #showme $TIMESTAMP #showme ${TIMESTAMP} category: commands """ var = args["var"] expansion = args["expansion"] quiet = args["quiet"] vm = exported.get_manager("variable") if not expansion: data = vm.getInfo(ses, var) if not data: data = ["variable: no variables defined."] exported.write_message("variables:\n" + "\n".join(data), ses) return try: vm.addVariable(ses, var, expansion) if not quiet: exported.write_message("variable: {%s}={%s} added." % (var, expansion), ses) except Exception, e: exported.write_error("variable: cannot be set. %s" % e, ses)
def ungag_cmd(ses, args, input): """ Allows you to remove gags. category: commands """ str = args["str"] quiet = args["quiet"] gm = exported.get_manager("gag") gd = gm.getGagData(ses) func = gd.removeGags modutils.unsomething_helper(args, func, None, "gag", "gags")
def alias_cmd(ses, args, input): """ With no arguments, prints all aliases. With one argument, prints all aliases which match the arg. With multiple arguments, creates an alias. You can use pattern variables which look like % and a number. %0 will be all the arguments passed in. Ranges can be used by using python colon-syntax, specifying a half-open slice of the input items, so %0:3 is the alias name, first, and second arguments of the input. Negative numbers count back from the end of the list. So %-1 is the last item in the list, %:-1 is everything but the last item in the list. examples: #alias {k*} - prints out aliases that start with k #alias {k} {kill %1} - builds a new alias #alias {gg} {put %1: in chest} - builds a new alias category: commands """ name = args["alias"] command = args["expansion"] quiet = args["quiet"] am = exported.get_manager("alias") ad = am.getAliasData(ses) # they typed '#alias' or '#alias x' so we print the relevant aliases if not command: data = ad.getInfo(name) if not data: data = ["alias: no aliases defined."] exported.write_message("aliases:\n" + "\n".join(data), ses) return # they're creating an alias try: ad.addAlias(name, command) except ValueError as e: exported.write_error("alias: %s" % e, ses) if not quiet: exported.write_message("alias: {%s} {%s} added." % (name, command), ses)
def action_enable_cmd(ses, args, input): """ Enables actions with given tag. By default, all the tags are enabled. see also: action, unaction, disable, atags category: commands """ tag = args["tag"] am = exported.get_manager("action") ad = am.getActionData(ses) ad.enable(tag) if not args["quiet"]: exported.write_message("Enabling actions tagged as {%s}" % tag)
def unaction_cmd(ses, args, input): """ Removes action(s) from the manager. examples: #unaction {missed you.} #unaction missed* #unaction tag={indoor} see also: action, enable, disable, atags category: commands """ am = exported.get_manager("action") ad = am.getActionData(ses) func = lambda x: ad.removeActions(x, args["tag"]) modutils.unsomething_helper(args, func, None, "action", "actions")
def alias_cmd(ses, args, input): """ With no arguments, prints all aliases. With one argument, prints all aliases which match the arg. With multiple arguments, creates an alias. You can use pattern variables which look like % and a number. %0 will be all the arguments passed in. Ranges can be used by using python colon-syntax, specifying a half-open slice of the input items, so %0:3 is the alias name, first, and second arguments of the input. Negative numbers count back from the end of the list. So %-1 is the last item in the list, %:-1 is everything but the last item in the list. examples: #alias {k*} - prints out aliases that start with k #alias {k} {kill %1} - builds a new alias #alias {gg} {put %1: in chest} - builds a new alias category: commands """ name = args["alias"] command = args["expansion"] quiet = args["quiet"] am = exported.get_manager("alias") ad = am.getAliasData(ses) # they typed '#alias' or '#alias x' so we print the relevant aliases if not command: data = ad.getInfo(name) if not data: data = ["alias: no aliases defined."] exported.write_message("aliases:\n" + "\n".join(data), ses) return # they're creating an alias try: ad.addAlias(name, command) except ValueError, e: exported.write_error("alias: %s" % e, ses)
def _tickfunc(ses): """ Handles executing the command or displaying a message to the user. @param ses: the Session instance @type ses: Session """ am = exported.get_manager("alias") if am: tickaction = am.getAlias(ses, "TICK!!!") if not tickaction: tickaction = am.getAlias(ses, "TICK") if tickaction: event.InputEvent(tickaction, internal=1, ses=ses).enqueue() else: exported.write_message("TICK!!!")
def action_disable_cmd(ses, args, input): """ Temporarily disables all the actions with given tag, so their triggers won't trigger any actions (well, this desciption is a bit obscure, but I've tried my best :) see also: action, unaction, enable, atags category: commands """ tag = args["tag"] am = exported.get_manager("action") ad = am.getActionData(ses) ad.disable(tag) if not args["quiet"]: exported.write_message("Disabling actions tagged as {%s}" % tag)
def gag_cmd(ses, args, input): """ With no arguments, prints out all gags. With arguments, creates a gag. Incoming lines from the mud which contain gagged text will be removed and not shown on the ui. Gags get converted to regular expressions. Feel free to use regular expression matching syntax as you see fit. As with all commands, braces get stripped off and each complete argument creates a gag. examples: #gag {has missed you.} <-- will prevent any incoming line with "has missed you" to be shown. #gag missed <-- will gag lines with "missed" in them. #gag {r[sven.*?dealt]i} <-- will gag anything that matches the regexp "sven.*?dealt" and ignore case. category: commands """ gaggedtext = args["text"] quiet = args["quiet"] gm = exported.get_manager("gag") gd = gm.getGagData(ses) if not gaggedtext: data = gd.getInfo() if not data: data = ["gag: no gags defined."] exported.write_message("gags\n" + "\n".join(data), ses) return gd.addGag(gaggedtext) if not quiet: exported.write_message("gag: {%s} added." % gaggedtext, ses)
def _tickwarnfunc(ses, warnlen): """ Handles executing the command or displaying a message to the user. @param ses: the Session instance @type ses: Session @param warnlen: the warning length @type warnlen: int """ am = exported.get_manager("alias") if am: tickaction = am.getAlias(ses, "TICKWARN!!!") if not tickaction: tickaction = am.getAlias(ses, "TICKWARN") if tickaction: event.InputEvent(tickaction, internal=1, ses=ses).enqueue() else: exported.write_message("ticker: %d seconds to tick!" % warnlen)
def math_cmd(ses, args, input): """ Implements the #math command which allows you to manipulate variables above and beyond setting them. examples: #math {hps} {$hps + 5} category: commands """ var = args["var"] ops = args["operation"] quiet = args["quiet"] try: rvalue = eval(ops) varman = exported.get_manager("variable") if varman: varman.addVariable(ses,var, str(rvalue)) if not quiet: exported.write_message("math: %s = %s = %s." % (var, ops, str(rvalue)), ses) except Exception, e: exported.write_error("math: exception: %s\n%s" % (ops, e), ses)
def log_cmd(ses, args, input): """ Will start or stop logging to a given filename for that session. Each session can have its own logfile. If USERPREFIX is set, then every line from the user will be prepended with this prefix and immediately written into log file. If USERPREFIX is omitted, then the user input will be attached to mud prompts before logging. category: commands """ logfile = args["logfile"] databuffer = args["databuffer"] stripansi = args["stripansi"] userprefix = args["userprefix"] if not ses.isConnected(): exported.write_error("log: You must have a session to log.", ses) return lm = exported.get_manager("logger") loggerdata = lm.getLogData(ses) if not logfile: exported.write_message(loggerdata.getStatus(), ses) return # handle stopping logging if loggerdata.isLogging() == 1: try: logname = loggerdata._logfile.name loggerdata.closeLogFile() exported.write_message("log: stopped logging to '%s'." % logname, ses) except Exception, e: exported.write_error("log: logfile cannot be closed (%s)." % (e), ses) return
def action_cmd(ses, args, input): """ With no trigger, no action and no tag, prints all actions. With no trigger and no action, prints all actions with given tag. With a trigger and no action, prints actions that match the trigger statement. With a trigger and an action, creates an action. When data from the mud matches the trigger clause, the response will be executed. Trigger clauses can use anchors (^ and $) to anchor the text to the beginning and end of the line respectively. Triggers can also contain Lyntin pattern-variables which start with a % sign and have digits: %0, %1, %10... When Lyntin sees a pattern-variable in an action trigger, it tries to match any pattern against it, and saves any match it finds so you can use it in the response. See below for examples. Note: As a note, actions are matched via regular expressions. %1 gets translated to (.+?) and %_1 gets translated to (\S+?). The special variable "%a" means "the whole matched line". We handle regular expressions with a special r[ ... ] syntax. If you put an "i" or "I" after the ], then we'll ignorecase as well. The onetime argument can be set to true to have the action remove itself automatically after it is triggered. examples: #action {^You are hungry} {get bread bag;eat bread} #action {%0 gives you %5} {say thanks for the %5, %0!} #action {r[^%_1 tells\\s+you %2$]} {say %1 just told me %2} #action {r[sven dealt .+? to %1$]i} {say i just killed %1!} see also: unaction, enable, disable, atags category: commands """ trigger = args["trigger"] action = args["action"] color = args["color"] priority = args["priority"] onetime = args["onetime"] quiet = args["quiet"] tag = args["tag"] am = exported.get_manager("action") ad = am.getActionData(ses) # they typed '#action'--print out all the current actions if not action: data = ad.getInfo(trigger, tag) if not data: data = ["action: no actions defined."] message = "actions" if tag: message += " with tag={%s}" % tag data += ad.getDisabledInfo(tag) exported.write_message(message + "\n" + "\n".join(data), ses) return try: ad.addAction(trigger, action, color, priority, onetime, tag) if not quiet: exported.write_message("action: {%s} {%s} color={%d} priority={%d} tag={%s} added." % (trigger, action, color, priority, str(tag)), ses) except: exported.write_traceback("action: exception thrown.", ses)