Update mail.py
This commit is contained in:
parent
c2cc063a78
commit
ddd3cd0888
1 changed files with 46 additions and 20 deletions
|
|
@ -6,7 +6,7 @@ Evennia Contribution - grungies1138 2016
|
||||||
A simple Brandymail style @mail system that uses the Msg class from Evennia Core.
|
A simple Brandymail style @mail system that uses the Msg class from Evennia Core.
|
||||||
|
|
||||||
Installation:
|
Installation:
|
||||||
Import this module into the default Player or Character commandset.
|
import MailCommand from this module into the default Player or Character command set
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from evennia import default_cmds, search_object
|
from evennia import default_cmds, search_object
|
||||||
|
|
@ -14,10 +14,11 @@ from evennia.utils import create, utils, evtable, evform
|
||||||
from evennia.comms.models import Msg
|
from evennia.comms.models import Msg
|
||||||
|
|
||||||
|
|
||||||
HEAD_CHAR = "|015-|n"
|
_HEAD_CHAR = "|015-|n"
|
||||||
SUB_HEAD_CHAR = "-"
|
_SUB_HEAD_CHAR = "-"
|
||||||
|
_WIDTH = 78
|
||||||
|
|
||||||
class MailCommand(default_cmds.MuxCommand):
|
class CmdMail(default_cmds.MuxCommand):
|
||||||
"""
|
"""
|
||||||
Commands that allow either IC or OOC communications
|
Commands that allow either IC or OOC communications
|
||||||
|
|
||||||
|
|
@ -41,13 +42,23 @@ class MailCommand(default_cmds.MuxCommand):
|
||||||
{w@mail/reply <#>=<message>{n
|
{w@mail/reply <#>=<message>{n
|
||||||
- Replies to a message #. Prepends message to the original
|
- Replies to a message #. Prepends message to the original
|
||||||
message text.
|
message text.
|
||||||
|
Switches:
|
||||||
|
delete - deletes a message
|
||||||
|
forward - forward a received message to another object with an optional message attached.
|
||||||
|
reply - Replies to a received message, appending the original message to the bottom.
|
||||||
|
|
||||||
Status Legend:
|
Status Legend:
|
||||||
'{wU{n' = Unread/New message
|
'|wU|n' = Unread/New message
|
||||||
'{wO{n' = Read/Old message
|
'|wO|n' = Read/Old message
|
||||||
'{wR{n' = Replied to
|
'|wR|n' = Replied to
|
||||||
'{wF{n' = Forwarded
|
'|wF|n' = Forwarded
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
@mail 2
|
||||||
|
@mail Griatch=New mail/Hey man, I am sending you a message!
|
||||||
|
@mail/delete 6
|
||||||
|
@mail/forward feend78 Griatch=You guys should read this.
|
||||||
|
@mail/reply 9=Thanks for the info!
|
||||||
"""
|
"""
|
||||||
key = "@mail"
|
key = "@mail"
|
||||||
aliases = ["mail"]
|
aliases = ["mail"]
|
||||||
|
|
@ -131,13 +142,13 @@ class MailCommand(default_cmds.MuxCommand):
|
||||||
|
|
||||||
messageForm = []
|
messageForm = []
|
||||||
if message:
|
if message:
|
||||||
messageForm.append(HEAD_CHAR * 78)
|
messageForm.append(HEAD_CHAR * _WIDTH)
|
||||||
messageForm.append("{wFrom:{n %s" % (message.senders[0].key))
|
messageForm.append("|wFrom:|n %s" % (message.senders[0].key))
|
||||||
messageForm.append("{wSent:{n %s" % message.db_date_created.strftime("%m/%d/%Y %H:%M:%S"))
|
messageForm.append("|wSent:|n %s" % message.db_date_created.strftime("%m/%d/%Y %H:%M:%S"))
|
||||||
messageForm.append("{wSubject:{n %s" % message.header)
|
messageForm.append("|wSubject:|n %s" % message.header)
|
||||||
messageForm.append(SUB_HEAD_CHAR * 78)
|
messageForm.append(SUB_HEAD_CHAR * _WIDTH)
|
||||||
messageForm.append(message.message)
|
messageForm.append(message.message)
|
||||||
messageForm.append(HEAD_CHAR * 78)
|
messageForm.append(HEAD_CHAR * _WIDTH)
|
||||||
self.caller.msg("\n".join(messageForm))
|
self.caller.msg("\n".join(messageForm))
|
||||||
message.tags.remove("u", category="mail")
|
message.tags.remove("u", category="mail")
|
||||||
message.tags.add("o", category="mail")
|
message.tags.add("o", category="mail")
|
||||||
|
|
@ -146,8 +157,8 @@ class MailCommand(default_cmds.MuxCommand):
|
||||||
messages = self.get_all_mail()
|
messages = self.get_all_mail()
|
||||||
|
|
||||||
if messages:
|
if messages:
|
||||||
table = evtable.EvTable("{wID:", "{wFrom:", "{wSubject:", "{wDate:{n", "{wSta:{n",
|
table = evtable.EvTable("|wID:|n", "|wFrom:|n", "|wSubject:|n", "|wDate:|n", "|wSta:|n",
|
||||||
table=None, border="header", header_line_char=SUB_HEAD_CHAR, width=78)
|
table=None, border="header", header_line_char=SUB_HEAD_CHAR, width=_WIDTH)
|
||||||
index = 1
|
index = 1
|
||||||
for message in messages:
|
for message in messages:
|
||||||
table.add_row(index, message.senders[0], message.header,
|
table.add_row(index, message.senders[0], message.header,
|
||||||
|
|
@ -161,19 +172,34 @@ class MailCommand(default_cmds.MuxCommand):
|
||||||
table.reformat_column(3, width=13)
|
table.reformat_column(3, width=13)
|
||||||
table.reformat_column(4, width=7)
|
table.reformat_column(4, width=7)
|
||||||
|
|
||||||
self.caller.msg(HEAD_CHAR * 78)
|
self.caller.msg(HEAD_CHAR * _WIDTH)
|
||||||
self.caller.msg(table)
|
self.caller.msg(table)
|
||||||
self.caller.msg(HEAD_CHAR * 78)
|
self.caller.msg(HEAD_CHAR * _WIDTH)
|
||||||
else:
|
else:
|
||||||
self.caller.msg("Sorry, you don't have any messages. What a pathetic loser!")
|
self.caller.msg("Sorry, you don't have any messages. What a pathetic loser!")
|
||||||
|
|
||||||
def get_all_mail(self):
|
def get_all_mail(self):
|
||||||
|
"""
|
||||||
|
Returns a list of all the messages where the caller is a recipient.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
messages (list): list of Msg objects.
|
||||||
|
"""
|
||||||
mail_messages = Msg.objects.get_by_tag(category="mail")
|
mail_messages = Msg.objects.get_by_tag(category="mail")
|
||||||
messages = []
|
messages = []
|
||||||
messages = [m for m in mail_messages if self.caller.player in m.receivers]
|
messages = [m for m in mail_messages if self.caller.player in m.receivers]
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
def send_mail(self, recipients, subject, message, caller):
|
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 = []
|
recobjs = []
|
||||||
for char in recipients:
|
for char in recipients:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue