def func(self): """Run the say command""" char = self.character here = char.location if char else None account = self.account opt = self.switches args = self.args.strip() if not (here and char): if args: account.execute_cmd('pub %s' % args) else: account.msg('Usage: say <message> to speak on public channel.') return if not args: account.execute_cmd("help say") return if 'verb' in opt: char.attributes.add('say-verb', args) here.msg_contents(text=('{char} warms up vocally with "%s|n"' % escape_braces(args), {'type': 'pose', 'action': True}), from_obj=char, mapping=dict(char=char)) return if 'quote' in opt: if len(args) > 2: char.quote = args # Not yet implemented. return else: speech = args verb = char.attributes.get('say-verb') if char.attributes.has('say-verb') else 'says' if 'ooc' in opt: here.msg_contents(text=('[OOC] {char} says, "|w%s|n"' % escape_braces(speech), {'type': 'say', 'ooc': True}), from_obj=char, mapping=dict(char=char)) if here.has_account: here.msg(text=('[OOC] %s says, "|w%s|n"' % (char.get_display_name(here), escape_braces(speech)), {'type': 'say', 'ooc': True}), from_obj=char) else: here.msg_contents(text=('{char} %s, "|w%s|n"' % (escape_braces(verb), escape_braces(speech)), {'type': 'say'}), from_obj=char, mapping=dict(char=char)) if here.has_account: here.msg(text=('From inside you, %s %s, "|w%s|n"' % (char.get_display_name(here), escape_braces(verb), escape_braces(speech)), {'type': 'say'}), from_obj=char)
def func(self): """Run the ooc command""" char = self.character account = self.account here = char.location args = self.args.strip() if not args: account.execute_cmd('help ooc') return elif args[0] == '"' or args[0] == "'": account.execute_cmd('say/o ' + args[1:]) elif args[0] == ':' or args[0] == ';': account.execute_cmd('pose/o %s' % args[1:]) else: here.msg_contents(text=('[OOC {char}] %s' % escape_braces(args), {'type': 'ooc', 'ooc': True}), from_obj=char, mapping=dict(char=char)) if here.has_account: here.msg(text=('[OOC %s] %s' % (char.get_display_name(here), escape_braces(args)), {'type': 'ooc', 'ooc': True}), from_obj=char)
def get(self): """Implements the attempt to get this object.""" too_heavy, too_large = self.s.get_limit() < self.o.get_mass(), False pose = self.s.ndb.pose if self.s == self.o: self.s.msg("%sYou|n can't get yourself." % self.s.STYLE) elif self.o.location == self.s: self.s.msg("%sYou|n already have %s." % (self.s.STYLE, self.o.get_display_name(self.s))) elif too_heavy: self.s.msg("%sYou|n can't lift %s; it is too heavy." % (self.s.STYLE, self.o.get_display_name(self.s))) elif too_large: self.s.msg("%sYou|n can lift %s, but it is too large to carry." % (self.s.STYLE, self.o.get_display_name(self.s))) elif self.o.move_to(self.s, quiet=True): self.s.location.msg_contents('%s|g%s|n gets {it}.' % (escape_braces(pose), self.s.key), from_obj=self.s, mapping=dict(it=self.o)) self.o.at_get(self.s) # calling hook method
def func(self): """Basic pose, power pose, room posing - all in one""" cmd = self.cmdstring opt = self.switches args = unicode(self.args).strip() lhs, rhs = self.lhs, self.rhs sess = self.session char = self.character account = self.account here = char.location if char else None power = True if cmd in ('ppose', 'pp', 'p:') else False raw_pose = rhs if rhs and cmd == 'do' or power else args raw_pose = substitute_objects(raw_pose, char) non_space_chars = ['®', '©', '°', '·', '~', '@', '-', "'", '’', ',', ';', ':', '.', '?', '!', '…'] magnet = True if raw_pose and raw_pose[0] in non_space_chars or cmd == ";" else False doing = True if 'do' in cmd or 'rp' in cmd else False pose = ('' if magnet else '|_') + (ansi.strip_ansi(raw_pose) if doing else raw_pose) # ---- Setting Room poses as a doing message ---------- if doing: # Pose will have no markup when posing on the room, to minimize shenanigans. target = char # Initially assume the setting character is the target. if not args and 'reset' not in opt: has_pose = char.db.messages and char.db.messages.get('pose') if has_pose: # If target has poses set, display them to the setter. char.msg("Current pose reads: '%s'" % target.get_display_name(char, pose=True)) default_pose = target.db.messages and target.db.messages.get('pose_default') or None if default_pose: char.msg('Default pose is \'%s%s\'' % (char.get_display_name(char), default_pose)) else: char.msg('Default pose not set.') else: char.msg('No pose has been set.|/Usage: rp <pose-text> OR pose <obj> = <pose-text>') return if len(pose) > 60: # Pose length in characters, not counting the poser's name. char.msg('Your pose is too long.') return if rhs: # pose something else other than self. target = char.search(lhs) # Search for a reference to the target. if not target: return if pose: self.set_doing(char, pose, target) # Try to set the pose of the target. else: # pose self. target = char if 'reset' in opt: # Clears current temp doing, reverts it to default. pose = target.db.messages and target.db.messages.get('pose_default', '') if not target.db.messages: target.db.messages = {} target.db.messages['pose'] = pose elif 'default' in opt: # Sets doing pose default. self.set_doing(char, pose, target, True) # True means "set default", not temp doing. char.msg("Default pose is now: '%s%s'" % (target.get_display_name(char), pose)) return # Nothing more to do. Default never poses to room, just sets doing message. elif not rhs: self.set_doing(char, pose) # Setting temp doing message on the setter... if args and not ('silent' in opt or 'quiet' in opt) and char is target: # Allow set without posing # FIXME: Do not execute the pose if not permitted to room pose it. account.execute_cmd(';%s' % pose, session=sess) # pose to the room like a normal pose would. # return # Having executed the pose in a different way, work in this command instance is done. char.msg("Pose now set to: '%s'" % target.get_display_name(char, pose=True)) # Display name with pose. else: # ---- Action pose, not static Room Pose. --------------------- if '|/' in pose: pose = pose.split('|/', 1)[0] if 'magnet' in opt: char.msg("Pose magnet glyphs are %s." % non_space_chars) if not (here and char): if args: account.execute_cmd('pub :%s' % pose, session=sess) else: self.msg('Usage: pose <message> to pose to public channel.') return if args: if power and self.rhs and 'o' not in self.switches: char.ndb.power_pose = pose account.execute_cmd(self.rhs, session=sess) else: ooc = 'ooc' in self.switches prepend_ooc = '[OOC] ' if ooc else '' here.msg_contents(('%s{char}%s' % (prepend_ooc, escape_braces(pose)), {'type': 'pose', 'ooc': ooc}), from_obj=char, mapping=dict(char=char)) else: account.execute_cmd('help pose', session=sess)
def func(self): """Run the spoof command""" char = self.character here = char.location opt = self.switches args = self.args to_self = 'self' in opt or not here if not args: self.account.execute_cmd('help spoof') return # Optionally strip any markup /or/ just escape it, stripped = ansi.strip_ansi(args) spoof = stripped if 'strip' in opt else args.replace('|', '||') if 'indent' in opt: indent = 20 if self.rhs: args = self.lhs.strip() indent = re.sub("[^0123456789]", '', self.rhs) or 20 indent = int(indent) if to_self: char.msg(' ' * indent + args.rstrip()) else: here.msg_contents(text=(' ' * indent + escape_braces(args.rstrip()), {'type': 'spoof'})) elif 'right' in opt or 'center' in opt or 'news' in opt: if self.rhs is not None: # Equals sign exists. parameters = '' if not self.rhs else self.rhs.split() args = self.lhs.strip() if len(parameters) > 1: if len(parameters) == 2: outside, inside = self.rhs.split() else: outside, inside = [parameters[0], parameters[1]] outside = re.sub("[^0123456789]", '', outside) or 0 inside = re.sub("[^0123456789]", '', inside) or 0 outside, inside = [int(max(outside, inside)), int(min(outside, inside))] else: outside, inside = [72, 20] else: outside, inside = [72, min(int(self.rhs or 72), 20)] block = 'r' if 'right' in opt else 'f' block = 'c' if 'center' in opt else block for text in justify(args, width=outside, align=block, indent=inside).split('\n'): if to_self: char.msg(text.rstrip()) else: here.msg_contents(text=(escape_braces(text.rstrip()), {'type': 'spoof'})) else: if 'strip' in opt: # Optionally strip any markup or escape it, if to_self: char.msg(spoof.rstrip(), options={'raw': True}) else: here.msg_contents(text=(escape_braces(spoof.rstrip()), {'type': 'spoof'}), options={'raw': True}) elif 'dot' in opt: # Leave leading spacing intact, remove leading dot. spoof = args.lstrip('.') if to_self: char.msg(spoof.rstrip(), options={'raw': True}) else: here.msg_contents(text=(escape_braces(spoof.rstrip()), {'type': 'spoof'}), options={'raw': True}) else: if to_self: char.msg(args.rstrip()) else: here.msg_contents(text=(escape_braces(spoof.rstrip()), {'type': 'spoof'}))
def func(self): """Basic pose, power pose, room posing - all in one""" cmd = self.cmdstring opt = self.switches args = unicode(self.args).strip() lhs, rhs = self.lhs, self.rhs char = self.character account = self.account here = char.location if char else None power = True if self.cmdstring == 'ppose' or self.cmdstring == 'pp' or self.cmdstring == 'p:' else False def parse_pose(text): return_text = [] for each in text.split(): match = None new_each = each word_end = '' if each.startswith('/'): # A possible substitution to test if each.endswith('/'): # Skip this one, it's /italic/ return_text.append(new_each) continue search_word = each[1:] if search_word.startswith('/'): # Skip this one, it's being escaped new_each = each[1:] else: # Marked for substitution, try to find a match if "'" in each: # Test for possessive or contraction: 's (apostrophe before end of grouping) pass if each[-1] in ".,!?": search_word, word_end = search_word[:-1], each[-1] match = char.search(search_word, quiet=True) return_text.append(new_each if not match else (match[0].get_display_name(char) + word_end)) return ' '.join(return_text) raw_pose = rhs if rhs and power else args raw_pose = parse_pose(raw_pose) non_space_chars = ['®', '©', '°', '·', '~', '@', '-', "'", '’', ',', ';', ':', '.', '?', '!', '…'] magnet = True if raw_pose and raw_pose[0] in non_space_chars or cmd == ";" else False doing = True if 'do' in cmd or 'rp' in cmd else False pose = ('' if magnet else '|_') + (ansi.strip_ansi(raw_pose) if doing else raw_pose) # ---- Setting Room poses as a doing message ---------- if doing: # Pose will have no markup when posing on the room, to minimize shenanigans. target = char # Initially assume the setting character is the target. if not args and 'reset' not in opt: has_pose = char.db.messages and char.db.messages.get('pose') if has_pose: # If target has poses set, display them to the setter. char.msg("Current pose reads: '%s'" % target.get_display_name(char, pose=True)) default_pose = target.db.messages and target.db.messages.get('pose_default') or None if default_pose: char.msg('Default pose is \'%s%s\'' % (char.get_display_name(char), default_pose)) else: char.msg('Default pose not set.') else: char.msg('No pose has been set.|/Usage: rp <pose-text> OR pose <obj> = <pose-text>') return if len(pose) > 60: # Pose length in characters, not counting the poser's name. char.msg('Your pose is too long.') return if rhs: # pose something else other than self. target = char.search(lhs) # Search for a reference to the target. if not target: return if pose: self.set_doing(char, pose, target) # Try to set the pose of the target. else: # pose self. target = char if 'reset' in opt: # Clears current temp doing, reverts it to default. pose = target.db.messages and target.db.messages.get('pose_default', '') if not target.db.messages: target.db.messages = {} target.db.messages['pose'] = pose elif 'default' in opt: # Sets doing pose default. self.set_doing(char, pose, target, True) # True means "set default", not temp doing. char.msg("Default pose is now: '%s%s'" % (target.get_display_name(char), pose)) return # Nothing more to do. Default never poses to room, just sets doing message. elif not rhs: self.set_doing(char, pose) # Setting temp doing message on the setter... if args and not ('silent' in opt or 'quiet' in opt) and char is target: # Allow set without posing account.execute_cmd(';%s' % pose) # pose to the room like a normal pose would. char.msg("Pose now set to: '%s'" % target.get_display_name(char, pose=True)) # Display name with pose. else: # ---- Action pose, not static Room Pose. --------------------- if '|/' in pose: pose = pose.split('|/', 1)[0] if 'magnet' in opt: char.msg("Pose magnet glyphs are %s." % non_space_chars) if not (here and char): if args: account.execute_cmd('pub :%s' % pose) else: account.msg('Usage: pose <message> to pose to public channel.') return if args: if power and self.rhs and 'o' not in self.switches: char.ndb.power_pose = pose account.execute_cmd(self.rhs) else: ooc = 'ooc' in self.switches prepend_ooc = '[OOC] ' if ooc else '' here.msg_contents(('%s{char}%s' % (prepend_ooc, escape_braces(pose)), {'type': 'pose', 'ooc': ooc}), from_obj=char, mapping=dict(char=char)) else: account.execute_cmd('help pose')
def func(self): """Run the spoof command""" char = self.character cmd = self.cmdstring here = char.location opt = self.switches args = self.args to_self = 'self' in opt or not here if not args: self.account.execute_cmd('help spoof', session=self.session) return # Optionally strip any markup /or/ just escape it, stripped = ansi.strip_ansi(args) spoof = stripped if 'strip' in opt else args.replace('|', '||') if 'indent' in opt: indent = 20 if self.rhs: args = self.lhs.strip() indent = re.sub("[^0123456789]", '', self.rhs) or 20 indent = int(indent) if to_self: char.msg(' ' * indent + args.rstrip()) else: here.msg_contents(text=(' ' * indent + escape_braces(args.rstrip()), {'type': 'spoof'})) elif 'right' in opt or 'center' in opt or 'news' in opt: # Use Justify if self.rhs is not None: # Equals sign exists. parameters = '' if not self.rhs else self.rhs.split() args = self.lhs.strip() if len(parameters) > 1: if len(parameters) == 2: outside, inside = self.rhs.split() else: outside, inside = [parameters[0], parameters[1]] outside = re.sub("[^0123456789]", '', outside) or 0 inside = re.sub("[^0123456789]", '', inside) or 0 outside, inside = [int(max(outside, inside)), int(min(outside, inside))] else: outside, inside = [72, 20] else: outside, inside = [72, min(int(self.rhs or 72), 20)] block = 'l' if 'right' in opt: block = 'r' elif 'center' in opt: block = 'c' elif 'news' in opt: block = 'f' for text in justify(args, width=outside, align=block, indent=inside).split('\n'): if to_self: char.msg(text.rstrip()) else: here.msg_contents(text=(escape_braces(text.rstrip()), {'type': 'spoof'})) else: if 'strip' in opt: # Optionally strip any markup or escape it, if to_self: char.msg(spoof.rstrip(), options={'raw': True}) else: here.msg_contents(text=(escape_braces(spoof.rstrip()), {'type': 'spoof'}), options={'raw': True}) elif '.' in cmd: # Leave leading spacing intact by using self.raw and not stripping left whitespace # Adding <pre> and </pre> to all output in case one of the viewers is using webclient spoof = self.raw.rstrip() if to_self: char.msg(('<code>' + spoof + '</code>', {'type': 'spoof'}), options={'raw': True}) else: here.msg_contents(text=('<code>' + spoof + '</code>', {'type': 'spoof'}), options={'raw': True}) else: if to_self: char.msg(args.rstrip()) else: here.msg_contents(text=(escape_braces(spoof.rstrip()), {'type': 'spoof'}))