def send_mail(self, recipients, subject, message, caller): """ Function for sending new mail. Also useful for sending notifications from objects or systems. Args: recipients (list): list of Player or character objects to receive the newly created mails. subject (str): The header or subject of the message to be delivered. message (str): The body of the message being sent. caller (obj): The object (or Player or Character) that is sending the message. """ recobjs = [] for char in recipients: if self.caller.player.search(char) is not None: recobjs.append(self.caller.player.search(char)) if recobjs: for recipient in recobjs: recipient.msg("You have received a new @mail from %s" % caller) new_message = create.create_message(self.caller, message, receivers=recipient, header=subject) new_message.tags.add("U", category="mail") caller.msg("You sent your message.") return else: caller.msg("No valid players found. Cannot send message.") return
def func(self): """Destroy objects cleanly.""" caller = self.caller if not self.args: self.msg("Usage: cdestroy <channelname>") return channel = find_channel(caller, self.args) if not channel: self.msg("Could not find channel %s." % self.args) return if not channel.access(caller, "control"): self.msg("You are not allowed to do that.") return channel_key = channel.key message = "%s is being destroyed. Make sure to change your aliases." % channel_key msgobj = create.create_message(caller, message, channel) channel.msg(msgobj) channel.delete() CHANNELHANDLER.update() self.msg("Channel '%s' was destroyed." % channel_key) logger.log_sec( "Channel Deleted: %s (Caller: %s, IP: %s)." % (channel_key, caller, self.session.address) )
def send_mail(self, recipients, subject, message, caller): """ Function for sending new mail. Also useful for sending notifications from objects or systems. Args: recipients (list): list of Account or Character objects to receive the newly created mails. subject (str): The header or subject of the message to be delivered. message (str): The body of the message being sent. caller (obj): The object (or Account or Character) that is sending the message. """ for recipient in recipients: recipient.msg("You have received a new @mail from %s" % caller) new_message = create.create_message(self.caller, message, receivers=recipient, header=subject) new_message.tags.add("new", category="mail") if recipients: caller.msg("You sent your message.") return else: caller.msg("No valid target(s) found. Cannot send message.") return
def func(self): """ Create a new message and send it to channel, using the already formatted input. """ caller = self.caller channelkey, msg = self.args if not msg: caller.msg("Say what?") return channel = ChannelDB.objects.get_channel(channelkey) if not channel: caller.msg("Channel '%s' not found." % channelkey) return if not channel.has_connection(caller): string = "You are not connected to channel '%s'." caller.msg(string % channelkey) return if not channel.access(caller, 'send'): string = "You are not permitted to send to channel '%s'." caller.msg(string % channelkey) return msg = "[%s] %s: %s" % (channel.key, caller.name, msg) msgobj = create.create_message(caller, msg, channels=[channel]) channel.msg(msgobj)
def test_create_msg__simple(self): msg = create.create_message(self.char1, self.msgtext, header="TestHeader") self.assertEqual(msg.message, self.msgtext) self.assertEqual(msg.header, "TestHeader") self.assertEqual(msg.senders, [self.char1])
def test_create_msg__channel(self): chan1 = create.create_channel("DummyChannel1") chan2 = create.create_channel("DummyChannel2") msg = create.create_message(self.char1, self.msgtext, channels=[chan1, chan2], header="TestHeader") self.assertEqual(list(msg.channels), [chan1, chan2])
def test_create_msg__custom(self): locks = "foo:false();bar:true()" tags = ["tag1", "tag2", "tag3"] msg = create.create_message(self.char1, self.msgtext, header="TestHeader", receivers=[self.char1, self.char2], locks=locks, tags=tags) self.assertEqual(msg.receivers, [self.char1, self.char2]) self.assertTrue(all(lock in msg.locks.all() for lock in locks.split(";"))) self.assertEqual(msg.tags.all(), tags)
def func(self): "Destroy objects cleanly." caller = self.caller if not self.args: self.msg("Usage: @cdestroy <channelname>") return channel = find_channel(caller, self.args) if not channel: self.msg("Could not find channel %s." % self.args) return if not channel.access(caller, 'control'): self.msg("You are not allowed to do that.") return channel_key = channel.key message = "%s is being destroyed. Make sure to change your aliases." % channel_key msgobj = create.create_message(caller, message, channel) channel.msg(msgobj) channel.delete() CHANNELHANDLER.update() self.msg("Channel '%s' was destroyed." % channel_key)
def func(self): """Implement function using the Msg methods""" # Since account_caller is set above, this will be an Account. caller = self.caller # get the messages we've sent (not to channels) pages_we_sent = Msg.objects.get_messages_by_sender(caller, exclude_channel_messages=True) # get last messages we've got pages_we_got = Msg.objects.get_messages_by_receiver(caller) if 'last' in self.switches: if pages_we_sent: recv = ",".join(obj.key for obj in pages_we_sent[-1].receivers) self.msg("You last paged |c%s|n: %s" % (recv, pages_we_sent[-1].message)) return else: self.msg("You haven't paged anyone yet.") return if 'list' in self.switches: pages = pages_we_sent + pages_we_got pages.sort(lambda x, y: cmp(x.date_created, y.date_created)) number = 5 if self.args: try: number = int(self.args) except ValueError: self.msg("Usage: pages [number]") return if len(pages) > number: lastpages = pages[-number:] else: lastpages = pages template = "|w%s|n |c%s|n to |c%s|n: %s" lastpages = "\n ".join(template % (utils.datetime_format(page.date_created), ",".join(obj.key for obj in page.senders), "|n,|c ".join([obj.name for obj in page.receivers]), page.message) for page in lastpages) if lastpages: string = "Your latest pages:\n %s" % lastpages else: string = "You haven't paged anyone yet." self.msg(string) return # We are sending. Build a list of targets if not self.lhs: # If there are no targets, then set the targets # to the last person we paged. if pages_we_sent: receivers = pages_we_sent[-1].receivers else: self.msg("Who do you want to page?") return else: receivers = self.lhslist recobjs = [] for receiver in set(receivers): if isinstance(receiver, basestring): pobj = caller.search(receiver) elif hasattr(receiver, 'character'): pobj = receiver else: self.msg("Who do you want to page?") return if pobj: recobjs.append(pobj) if not recobjs: self.msg("No one found to page.") return header = "|wAccount|n |c%s|n |wpages:|n" % caller.key message = self.rhs # Handle supported inline poses parts = InlinePoseHelper.parse(message) parts = InlinePoseHelper.prefix_actor_to_body(parts, caller.key) message = parts['body'] # create the persistent message object create.create_message(caller, message, receivers=recobjs) # Add wrapping punctuation parts = InlinePoseHelper.wrap_body(parts, "'") message = parts['body'] # tell the accounts they got a message. received = [] rstrings = [] for pobj in recobjs: if not pobj.access(caller, 'msg'): rstrings.append("You are not allowed to page %s." % pobj) continue pobj.msg("%s %s" % (header, message)) if hasattr(pobj, 'sessions') and not pobj.sessions.count(): received.append("|C%s|n" % pobj.name) rstrings.append("%s is offline. They will see your message if they list their pages later." % received[-1]) else: received.append("|c%s|n" % pobj.name) if rstrings: self.msg("\n".join(rstrings)) self.msg("You paged %s with: %s" % (", ".join(received), message))
def func(self): """Implement function using the Msg methods""" # Since account_caller is set above, this will be an Account. caller = self.caller # get the messages we've sent (not to channels) pages_we_sent = Msg.objects.get_messages_by_sender( caller, exclude_channel_messages=True) # get last messages we've got pages_we_got = Msg.objects.get_messages_by_receiver(caller) if "last" in self.switches: if pages_we_sent: recv = ",".join(obj.key for obj in pages_we_sent[-1].receivers) self.msg("You last paged |c%s|n:%s" % (recv, pages_we_sent[-1].message)) return else: self.msg("You haven't paged anyone yet.") return if not self.args or not self.rhs: pages = pages_we_sent + pages_we_got pages = sorted(pages, key=lambda page: page.date_created) number = 5 if self.args: try: number = int(self.args) except ValueError: self.msg("Usage: tell [<account> = msg]") return if len(pages) > number: lastpages = pages[-number:] else: lastpages = pages template = "|w%s|n |c%s|n to |c%s|n: %s" lastpages = "\n ".join(template % ( utils.datetime_format(page.date_created), ",".join(obj.key for obj in page.senders), "|n,|c ".join([obj.name for obj in page.receivers]), page.message, ) for page in lastpages) if lastpages: string = "Your latest pages:\n %s" % lastpages else: string = "You haven't paged anyone yet." self.msg(string) return # We are sending. Build a list of targets if not self.lhs: # If there are no targets, then set the targets # to the last person we paged. if pages_we_sent: receivers = pages_we_sent[-1].receivers else: self.msg("Who do you want to page?") return else: receivers = self.lhslist recobjs = [] for receiver in set(receivers): if isinstance(receiver, str): pobj = caller.search(receiver) elif hasattr(receiver, "character"): pobj = receiver else: self.msg("Who do you want to page?") return if pobj: recobjs.append(pobj) if not recobjs: self.msg("Noone found to page.") return header = "|wAccount|n |c%s|n |wpages:|n" % caller.key message = self.rhs # if message begins with a :, we assume it is a 'page-pose' if message.startswith(":"): message = "%s %s" % (caller.key, message.strip(":").strip()) # create the persistent message object create.create_message(caller, message, receivers=recobjs) # tell the accounts they got a message. received = [] rstrings = [] for pobj in recobjs: if not pobj.access(caller, "msg"): rstrings.append("You are not allowed to page %s." % pobj) continue pobj.msg("%s %s" % (header, message)) if hasattr(pobj, "sessions") and not pobj.sessions.count(): received.append("|C%s|n" % pobj.name) rstrings.append( "%s is offline. They will see your message if they list their pages later." % received[-1]) else: received.append("|c%s|n" % pobj.name) if rstrings: self.msg("\n".join(rstrings)) self.msg("You paged %s with: '%s'." % (", ".join(received), message))
def func(self): "Implement function using the Msg methods" # this is a MuxPlayerCommand, which means caller will be a Player. caller = self.caller # get the messages we've sent (not to channels) pages_we_sent = Msg.objects.get_messages_by_sender( caller, exclude_channel_messages=True) # get last messages we've got pages_we_got = Msg.objects.get_messages_by_receiver(caller) if 'last' in self.switches: if pages_we_sent: recv = ",".join(obj.key for obj in pages_we_sent[-1].receivers) self.msg("You last paged {c%s{n:%s" % (recv, pages_we_sent[-1].message)) return else: self.msg("You haven't paged anyone yet.") return if not self.args or not self.rhs: pages = pages_we_sent + pages_we_got pages.sort(lambda x, y: cmp(x.date_sent, y.date_sent)) number = 5 if self.args: try: number = int(self.args) except ValueError: self.msg("Usage: tell [<player> = msg]") return if len(pages) > number: lastpages = pages[-number:] else: lastpages = pages template = "{w%s{n {c%s{n to {c%s{n: %s" lastpages = "\n ".join( template % (utils.datetime_format(page.date_sent), ",".join( obj.key for obj in page.senders), "{n,{c ".join([obj.name for obj in page.receivers]), page.message) for page in lastpages) if lastpages: string = "Your latest pages:\n %s" % lastpages else: string = "You haven't paged anyone yet." self.msg(string) return # We are sending. Build a list of targets if not self.lhs: # If there are no targets, then set the targets # to the last person we paged. if pages_we_sent: receivers = pages_we_sent[-1].receivers else: self.msg("Who do you want to page?") return else: receivers = self.lhslist recobjs = [] for receiver in set(receivers): if isinstance(receiver, basestring): pobj = caller.search(receiver) elif hasattr(receiver, 'character'): pobj = receiver else: self.msg("Who do you want to page?") return if pobj: recobjs.append(pobj) if not recobjs: self.msg("Noone found to page.") return header = "{wPlayer{n {c%s{n {wpages:{n" % caller.key message = self.rhs # if message begins with a :, we assume it is a 'page-pose' if message.startswith(":"): message = "%s %s" % (caller.key, message.strip(':').strip()) # create the persistent message object create.create_message(caller, message, receivers=recobjs) # tell the players they got a message. received = [] rstrings = [] for pobj in recobjs: if not pobj.access(caller, 'msg'): rstrings.append("You are not allowed to page %s." % pobj) continue pobj.msg("%s %s" % (header, message)) if hasattr(pobj, 'sessions') and not pobj.sessions.count(): received.append("{C%s{n" % pobj.name) rstrings.append( "%s is offline. They will see your message if they list their pages later." % received[-1]) else: received.append("{c%s{n" % pobj.name) if rstrings: self.msg("\n".join(rstrings)) self.msg("You paged %s with: '%s'." % (", ".join(received), message))
def func(self): "Implement function using the Msg methods" # Since player_caller is set above, this will be a Player. caller = self.caller # get the messages we've sent (not to channels) pages_we_sent = Msg.objects.get_messages_by_sender(caller, exclude_channel_messages=True) # get last messages we've got pages_we_got = Msg.objects.get_messages_by_receiver(caller) if 'last' in self.switches: if pages_we_sent: recv = ",".join(obj.key for obj in pages_we_sent[-1].receivers) self.msg("You last paged {c%s{n:%s" % (recv, pages_we_sent[-1].message)) return else: self.msg("You haven't paged anyone yet.") return if not self.args or not self.rhs: pages = pages_we_sent + pages_we_got pages.sort(lambda x, y: cmp(x.date_sent, y.date_sent)) number = 5 if self.args: try: number = int(self.args) except ValueError: self.msg("Usage: tell [<player> = msg]") return if len(pages) > number: lastpages = pages[-number:] else: lastpages = pages template = "{w%s{n {c%s{n to {c%s{n: %s" lastpages = "\n ".join(template % (utils.datetime_format(page.date_sent), ",".join(obj.key for obj in page.senders), "{n,{c ".join([obj.name for obj in page.receivers]), page.message) for page in lastpages) if lastpages: string = "Your latest pages:\n %s" % lastpages else: string = "You haven't paged anyone yet." self.msg(string) return # We are sending. Build a list of targets if not self.lhs: # If there are no targets, then set the targets # to the last person we paged. if pages_we_sent: receivers = pages_we_sent[-1].receivers else: self.msg("Who do you want to page?") return else: receivers = self.lhslist recobjs = [] for receiver in set(receivers): if isinstance(receiver, basestring): pobj = caller.search(receiver) elif hasattr(receiver, 'character'): pobj = receiver else: self.msg("Who do you want to page?") return if pobj: recobjs.append(pobj) if not recobjs: self.msg("Noone found to page.") return header = "{wPlayer{n {c%s{n {wpages:{n" % caller.key message = self.rhs # if message begins with a :, we assume it is a 'page-pose' if message.startswith(":"): message = "%s %s" % (caller.key, message.strip(':').strip()) # create the persistent message object create.create_message(caller, message, receivers=recobjs) # tell the players they got a message. received = [] rstrings = [] for pobj in recobjs: if not pobj.access(caller, 'msg'): rstrings.append("You are not allowed to page %s." % pobj) continue pobj.msg("%s %s" % (header, message)) if hasattr(pobj, 'sessions') and not pobj.sessions.count(): received.append("{C%s{n" % pobj.name) rstrings.append("%s is offline. They will see your message if they list their pages later." % received[-1]) else: received.append("{c%s{n" % pobj.name) if rstrings: self.msg("\n".join(rstrings)) self.msg("You paged %s with: '%s'." % (", ".join(received), message))
def func(self): """Implement function using the Msg methods""" char = self.character sent_messages = Msg.objects.get_messages_by_sender(char, exclude_channel_messages=True) recd_messages = Msg.objects.get_messages_by_receiver(char) if 'last' in self.switches: self.mail_check() if sent_messages: recv = ', '.join('%s%s|n' % (obj.STYLE, obj.key) for obj in sent_messages[-1].receivers) self.msg("You last mailed |w%s|n: |w%s" % (recv, sent_messages[-1].message)) else: self.msg("You haven't mailed anyone yet.") self.mail_check() return if 'check' in self.switches: if not self.mail_check(): if not ('silent' in self.switches and 'quiet' in self.switches): self.msg('Your %s mailbox has no new mail.' % char.location.get_display_name(self.character)) if not self.args or not self.rhs: mail = sent_messages + recd_messages mail.sort(lambda x, y: cmp(x.db_date_created, y.db_date_created)) number = 5 if self.args: try: number = int(self.args) except ValueError: self.msg("Usage: mail [<character> = msg]") return if len(mail) > number: mail_last = mail[-number:] else: mail_last = mail template = "|w%s|n |w%s|n to |w%s|n: %s" mail_last = "\n ".join(template % (utils.datetime_format(mail.date_created), ', '.join('%s' % obj.get_display_name(self.character) for obj in mail.senders), ', '.join(['%s' % obj.get_display_name(self.character) for obj in mail.receivers]), mail.message) for mail in mail_last) if mail_last: string = "Your latest letters:\n %s" % mail_last else: string = "You haven't mailed anyone yet." self.msg(string) char.nattributes.remove('new_mail') # Removes the notice. return # Send mode if not self.lhs: if sent_messages: # If no recipients provided, receivers = sent_messages[-1].receivers # default to sending to the last character mailed. else: self.msg("Who do you want to mail?") return else: # Build a list of comma-delimited recipients. receivers = self.lhslist rec_objs = [] received = [] r_strings = [] for receiver in set(receivers): if isinstance(receiver, basestring): c_obj = char.search(receiver, global_search=True, exact=True) elif hasattr(receiver, 'location'): c_obj = receiver else: self.msg("Who do you want to mail?") return if c_obj: if not c_obj.access(char, 'mail'): r_strings.append("You are not able to mail %s." % c_obj) continue rec_objs.append(c_obj) if not rec_objs: self.msg("No one found to mail.") return message = self.rhs.strip() if message.startswith(':'): # Format as pose if message begins with a : message = "%s%s|n %s" % (char.STYLE, char.key, message.strip(':')) create.create_message(char, message, receivers=rec_objs) def letter_delivery(): # c_obj.msg('%s %s' % (header, message)) c_obj.msg('|/A letter has arrived in %s%s|n mailbox for you.|/' % (c_obj.home.STYLE, c_obj.home.key)) for c_obj in rec_objs: # Notify character of mail delivery. received.append('%s%s|n' % (c_obj.STYLE, c_obj.key)) if hasattr(c_obj, 'sessions') and not c_obj.sessions.count(): r_strings.append("|r%s|n is currently asleep, and won't read the letter until later." % received[-1]) c_obj.ndb.new_mail = True else: # Tell the receiving characters about receiving a letter if they are online. utils.delay(20, callback=letter_delivery) if r_strings: self.msg("\n".join(r_strings)) stamp_count = len(rec_objs) stamp_plural = 'a stamp' if stamp_count == 1 else '%i stamps' % stamp_count self.msg('Mail delivery costs %s.' % stamp_plural) char.location.msg_contents('|g%s|n places %s on an envelope and slips it into the %s%s|n mailbox.' % (char.key, stamp_plural, char.location.STYLE, char.location.key)) self.msg("Your letter to %s will be delivered soon. You wrote: %s" % (', '.join(received), message)) self.mail_check()
def func(self): """Implement function using the Msg methods""" # Since player_caller is set above, this will be a Player. caller = self.caller # get the messages we've sent (not to channels) pages_we_sent = Msg.objects.get_messages_by_sender( caller, exclude_channel_messages=True) # get last messages we've got pages_we_got = Msg.objects.get_messages_by_receiver(caller) if 'last' in self.switches: if pages_we_sent: recv = ",".join(obj.key for obj in pages_we_sent[-1].receivers) self.msg("You last paged |c%s|n: %s" % (recv, pages_we_sent[-1].message)) return else: self.msg("You haven't paged anyone anything yet.") return if not self.args or not self.rhs: pages = pages_we_sent + pages_we_got pages.sort(lambda x, y: cmp(x.date_created, y.date_created)) number = 5 if self.args: try: number = int(self.args) except ValueError: self.msg("Usage: page player(s,) = msg") return if len(pages) > number: lastpages = pages[-number:] else: lastpages = pages template = "|w%s|n |c%s|n to |c%s|n: %s" lastpages = "\n ".join( template % (utils.datetime_format(page.date_created), ",".join( obj.key for obj in page.senders), "|n,|c ".join([obj.name for obj in page.receivers]), page.message) for page in lastpages) if lastpages: string = "Your latest pages:\n %s" % lastpages else: string = "You haven't paged anyone anything yet." self.msg(string) return # We are sending. Build a list of targets if not self.lhs: # If there are no targets, then set the targets # to the last person we paged. if pages_we_sent: receivers = pages_we_sent[-1].receivers else: self.msg("Whom do you want to page something to?") return else: receivers = self.lhslist recobjs = [] for receiver in set(receivers): if isinstance(receiver, basestring): pobj = caller.search(receiver) elif hasattr(receiver, 'character'): pobj = receiver else: self.msg("Whom do you want to page something to?") return if pobj: recobjs.append(pobj) if not recobjs: self.msg("No one found to page this to.") return #WHN: Change this to human and undead colord names later on? Currently every name is just yellow on a received tell. header = "|y%s pages you a message:|n \"" % caller.key #WHN: Adding a footer, it's pretty simple. footer = "\"" message = self.rhs # if message begins with a :, we assume it is a 'page-pose' if message.startswith(":"): message = "%s %s" % (caller.key, message.strip(':').strip()) # create the persistent message object create.create_message(caller, message, receivers=recobjs) # tell the players they got a message. received = [] rstrings = [] for pobj in recobjs: if not pobj.access(caller, 'msg'): rstrings.append("You are not allowed to page %s." % pobj) continue #WHN: This is where the message is concatenated together. message = message[0].upper() + message[1:] if not message.endswith(".") and not message.endswith( "!") and not message.endswith("?"): message = message + "." pobj.msg("%s%s%s" % (header, message, footer)) if hasattr(pobj, 'sessions') and not pobj.sessions.count(): received.append("|C%s|n" % pobj.name) rstrings.append( "%s is offline. They will see your message if they list their pages later." % received[-1]) else: received.append("|c%s|n" % pobj.name) if rstrings: self.msg("\n".join(rstrings)) self.msg("|yYou paged %s |ythe following:|n \"%s\"|n" % (", ".join(received), message))
def test_message_create(self): msg = create_message("peewee herman", "heh-heh!", header="mail time!") self.assertTrue(msg) self.assertEqual(str(msg), "peewee herman->: heh-heh!")
def func(self): """Implement function using the Msg methods""" char = self.character sent_messages = Msg.objects.get_messages_by_sender( char, exclude_channel_messages=True) recd_messages = Msg.objects.get_messages_by_receiver(char) if 'last' in self.switches: self.mail_check() if sent_messages: recv = ', '.join('%s%s|n' % (obj.STYLE, obj.key) for obj in sent_messages[-1].receivers) self.msg("You last mailed |w%s|n: |w%s" % (recv, sent_messages[-1].message)) else: self.msg("You haven't mailed anyone yet.") self.mail_check() return if 'check' in self.switches: if not self.mail_check(): if not ('silent' in self.switches and 'quiet' in self.switches): self.msg('Your %s mailbox has no new mail.' % char.location.get_display_name(self.character)) if not self.args or not self.rhs: mail = sent_messages + recd_messages mail.sort(lambda x, y: cmp(x.db_date_created, y.db_date_created)) number = 5 if self.args: try: number = int(self.args) except ValueError: self.msg("Usage: mail [<character> = msg]") return if len(mail) > number: mail_last = mail[-number:] else: mail_last = mail template = "|w%s|n |w%s|n to |w%s|n: %s" mail_last = "\n ".join( template % (utils.datetime_format(mail.date_created), ', '.join( '%s' % obj.get_display_name(self.character) for obj in mail.senders), ', '.join([ '%s' % obj.get_display_name(self.character) for obj in mail.receivers ]), mail.message) for mail in mail_last) if mail_last: string = "Your latest letters:\n %s" % mail_last else: string = "You haven't mailed anyone yet." self.msg(string) char.nattributes.remove('new_mail') # Removes the notice. return # Send mode if not self.lhs: if sent_messages: # If no recipients provided, receivers = sent_messages[ -1].receivers # default to sending to the last character mailed. else: self.msg("Who do you want to mail?") return else: # Build a list of comma-delimited recipients. receivers = self.lhslist rec_objs = [] received = [] r_strings = [] for receiver in set(receivers): if isinstance(receiver, basestring): c_obj = char.search(receiver, global_search=True, exact=True) elif hasattr(receiver, 'location'): c_obj = receiver else: self.msg("Who do you want to mail?") return if c_obj: if not c_obj.access(char, 'mail'): r_strings.append("You are not able to mail %s." % c_obj) continue rec_objs.append(c_obj) if not rec_objs: self.msg("No one found to mail.") return message = self.rhs.strip() if message.startswith( ':'): # Format as pose if message begins with a : message = "%s%s|n %s" % (char.STYLE, char.key, message.strip(':')) create.create_message(char, message, receivers=rec_objs) def letter_delivery(): # c_obj.msg('%s %s' % (header, message)) c_obj.msg('|/A letter has arrived in %s%s|n mailbox for you.|/' % (c_obj.home.STYLE, c_obj.home.key)) for c_obj in rec_objs: # Notify character of mail delivery. received.append('%s%s|n' % (c_obj.STYLE, c_obj.key)) if hasattr(c_obj, 'sessions') and not c_obj.sessions.count(): r_strings.append( "|r%s|n is currently asleep, and won't read the letter until later." % received[-1]) c_obj.ndb.new_mail = True else: # Tell the receiving characters about receiving a letter if they are online. utils.delay(20, callback=letter_delivery) if r_strings: self.msg("\n".join(r_strings)) stamp_count = len(rec_objs) stamp_plural = 'a stamp' if stamp_count == 1 else '%i stamps' % stamp_count self.msg('Mail delivery costs %s.' % stamp_plural) char.location.msg_contents( '|g%s|n places %s on an envelope and slips it into the %s%s|n mailbox.' % (char.key, stamp_plural, char.location.STYLE, char.location.key)) self.msg("Your letter to %s will be delivered soon. You wrote: %s" % (', '.join(received), message)) self.mail_check()