Added more functionality to page command (resolving and going beyond issue102). Cleaned up the output of sevreral commands as well as added a few more useful functions in src/utils/utils.py.

This commit is contained in:
Griatch 2010-09-04 17:21:26 +00:00
parent 60851ade11
commit cfbb249d96
8 changed files with 122 additions and 61 deletions

View file

@ -4,7 +4,7 @@ Comsys command module.
from src.comms.models import Channel, Msg, ChannelConnection
from game.gamesrc.commands.default.muxcommand import MuxCommand
from src.utils import create
from src.utils import create, utils
from src.permissions.permissions import has_perm
@ -712,9 +712,10 @@ class CmdPage(MuxCommand):
Usage:
page[/switches] [<player>,<player>,... = <message>]
tell ''
page/list <number>
Switch:
list - show your last 10 tells/pages.
list - show your last <number> of tells/pages.
Send a message to target user (if online). If no
argument is given, you will instead see who was the last
@ -733,30 +734,44 @@ class CmdPage(MuxCommand):
caller = self.caller
player = caller.player
# get the last messages we sent
messages = list(Msg.objects.get_messages_by_sender(player))
pages = [msg for msg in messages
if msg.receivers]
if pages:
lastpage = pages[-1]
# get the messages we've sent
messages_we_sent = list(Msg.objects.get_messages_by_sender(player))
pages_we_sent = [msg for msg in messages_we_sent
if msg.receivers]
# get last messages we've got
pages_we_got = list(Msg.objects.get_messages_by_receiver(player))
print "we sent:", pages_we_sent
print "we_got:", pages_we_got
if 'list' in self.switches:
if len(messages) > 10:
lastpages = messages[-10:]
pages = pages_we_sent + pages_we_got
pages.sort(lambda x,y: cmp(x.date_sent, y.date_sent))
number = 10
if self.args:
try:
number = int(self.args)
except ValueError:
pass
if len(pages) > number:
lastpages = pages[-number:]
else:
lastpages = messages
lastpages = "\n ".join(["{w%s{n to {c%s{n: %s" % (page.date_sent,
"{n,{c ".join([obj.name for obj in page.receivers]),
lastpages = pages
lastpages = "\n ".join(["{w%s{n {c%s{n to {c%s{n: %s" % (utils.datetime_format(page.date_sent),
page.sender.name,
"{n,{c ".join([obj.name for obj in page.receivers]),
page.message)
for page in pages])
for page in lastpages])
caller.msg("Your latest pages:\n %s" % lastpages )
return
if not self.args or not self.rhs:
if pages:
if pages_we_sent:
string = "You last paged {c%s{n." % (", ".join([obj.name
for obj in lastpage.receivers]))
for obj in pages_we_sent[-1].receivers]))
caller.msg(string)
return
else:
@ -764,29 +779,49 @@ class CmdPage(MuxCommand):
caller.msg(string)
return
# Build a list of targets
# 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 they paged.
receivers = lastpage.receivers
if pages_we_sent:
receivers = pages_we_sent[-1].receivers
else:
caller.msg("Who do you want to page?")
return
else:
receivers = self.lhslist
recobjs = []
for receiver in set(receivers):
pobj = caller.search("*%s" % (receiver.lstrip('*')), global_search=True)
if not pobj:
return
if isinstance(receiver, basestring):
pobj = caller.search("*%s" % (receiver.lstrip('*')), global_search=True)
if not pobj:
return
elif hasattr(receiver, 'character'):
pobj = receiver.character
else:
caller.msg("Who do you want to page?")
return
recobjs.append(pobj)
if not recobjs:
caller.msg("No players matching your target were found.")
return
header = "{wPlayer{n {c%s{n {wpages:{n" % caller.key
message = self.rhs
# create the persistent message object
msg = create.create_message(player, message,
receivers=recobjs)
receivers=recobjs)
# tell the players they got a message.
received = []
for pobj in recobjs:
pobj.msg("%s %s" % (header, message))
target_names = "{n,{c ".join([pobj.name for pobj in recobjs])
caller.msg("You paged {c%s{n with: '%s'." % (target_names, message))
if not pobj.has_player:
received.append("{C%s{n" % pobj.name)
caller.msg("%s is offline. They will see your message if they list their pages later." % received[-1])
else:
received.append("{c%s{n" % pobj.name)
received = ", ".join(received)
caller.msg("You paged %s with: '%s'." % (received, message))

View file

@ -2,7 +2,7 @@
Commands that are generally staff-oriented that show information regarding
the server instance.
"""
import os
import os, datetime
import django, twisted
from django.contrib.auth.models import User
from src.objects.models import ObjectDB
@ -52,26 +52,22 @@ class CmdTime(MuxCommand):
def func(self):
"Show times."
string2 = "\nCurrent server uptime:\n %i yrs, %i months, "
string2 += "%i weeks, %i days, %i hours, %i minutes and %i secs."
string2 = string2 % gametime.uptime(format=True)
string1 = "\nCurrent server uptime: "
string1 += "{w%s{n" % (utils.time_format(gametime.uptime(format=False), 2))
string3 = "\nTotal running time (gametime x %g):" % (1.0/gametime.TIMEFACTOR)
string3 += "\n %i yrs, %i months, %i weeks, %i days, "
string3 += "%i hours, %i minutes and %i secs."
string3 = string3 % gametime.runtime(format=True)
#print "runtime:", gametime.runtime()
string1 = "\nTotal game time (realtime x %g):" % (gametime.TIMEFACTOR)
string1 += "\n %i yrs, %i months, %i weeks, %i days, "
string1 += "%i hours, %i minutes and %i secs."
string1 = string1 % (gametime.gametime(format=True))
#print "gametime:", gametime.gametime()
string4 = ""
string2 = "\nTotal server running time: "
string2 += "{w%s{n" % (utils.time_format(gametime.runtime(format=False), 2))
string3 = "\nTotal in-game time (realtime x %g): " % (gametime.TIMEFACTOR)
string3 += "{w%s{n" % (utils.time_format(gametime.gametime(format=False), 2))
string4 = "\nServer time stamp: {w%s{n" % (str(datetime.datetime.now()))
string5 = ""
if not utils.host_os_is('nt'):
# os.getloadavg() is not available on Windows.
loadavg = os.getloadavg()
string4 = "\n Server load (1 min) : %g%%" % (100 * loadavg[0])
string = "%s%s%s%s" % (string2, string3, string1, string4)
string5 += "\nServer load (per minute): {w%g%%{n" % (100 * loadavg[0])
string = "%s%s%s%s%s" % (string1, string2, string3, string4, string5)
self.caller.msg(string)
class CmdList(MuxCommand):

View file

@ -303,7 +303,7 @@ class CmdBoot(MuxCommand):
pobj = caller.search("*%s" % args, global_search=True)
if not pobj:
return
pobj = pobj[0]
pobj = pobj
if pobj.has_player:
if not has_perm(caller, pobj, 'can_boot'):
string = "You don't have the permission to boot %s."

View file

@ -102,7 +102,6 @@ class CmdConnect(MuxCommand):
#print "character:", character, character.scripts.all(), character.cmdset.current
character.execute_cmd('look')
class CmdCreate(MuxCommand):
"""
Create a new account.
@ -291,7 +290,7 @@ To login to the system, you need to do one of the following:
> connect anna@myemail.com tuK3221mP
This should log you in. Run 'help' again once you're logged in
to get more aid. Welcome to Evennia!
to get more aid. Hope you enjoy your stay!
You can use the 'look' command if you want to see the connect screen again.
"""

View file

@ -76,7 +76,7 @@ class MsgManager(models.Manager):
if not receiver:
return None
return [msg for msg in self.all()
if receiver in msg.recivers
if receiver in msg.receivers
and receiver not in msg.hide_from_receivers]
def get_messages_by_channel(self, channel):

View file

@ -208,8 +208,7 @@ class Msg(SharedMemoryModel):
#@property
def date_sent_get(self):
"Getter. Allows for value = self.date_sent"
date = self.db_date_sent
return str(date).rsplit('.',1)[0]
return self.db_date_sent
#@date_sent.setter
def date_sent_set(self, value):
"Setter. Allows for self.date_sent = value"

View file

@ -32,8 +32,8 @@ REAL_MIN = 60.0 # seconds per minute in real world
# e.g. when defining events. The words month, week and year can
# of course mean whatever units of time are used in the game.
TICK = REAL_TICK / TIMEFACTOR
MIN = REAL_MIN / TIMEFACTOR
TICK = REAL_TICK * TIMEFACTOR
MIN = REAL_MIN * TIMEFACTOR
HOUR = MIN * settings.TIME_MIN_PER_HOUR
DAY = HOUR * settings.TIME_HOUR_PER_DAY
WEEK = DAY * settings.TIME_DAY_PER_WEEK

View file

@ -6,8 +6,10 @@ be of use when designing your own game.
"""
import os
import textwrap
import datetime
from django.conf import settings
def is_iter(iterable):
"""
Checks if an object behaves iterably. However,
@ -85,9 +87,9 @@ def time_format(seconds, style=0):
# We'll just use integer math, no need for decimal precision.
seconds = int(seconds)
days = seconds / 86400
days = seconds / 86400
seconds -= days * 86400
hours = seconds / 3600
hours = seconds / 3600
seconds -= hours * 3600
minutes = seconds / 60
seconds -= minutes * 60
@ -117,20 +119,50 @@ def time_format(seconds, style=0):
elif style is 2:
"""
Full-detailed, long-winded format.
Full-detailed, long-winded format. We ignore seconds.
"""
days_str = hours_str = minutes_str = ''
days_str = hours_str = minutes_str = seconds_str = ''
if days > 0:
days_str = '%i days, ' % (days,)
if days == 1:
days_str = '%i day, ' % days
else:
days_str = '%i days, ' % days
if days or hours > 0:
hours_str = '%i hours, ' % (hours,)
if hours == 1:
hours_str = '%i hour, ' % hours
else:
hours_str = '%i hours, ' % hours
if hours or minutes > 0:
minutes_str = '%i minutes, ' % (minutes,)
seconds_str = '%i seconds' % (seconds,)
retval = '%s%s%s%s' % (days_str, hours_str, minutes_str, seconds_str,)
if minutes == 1:
minutes_str = '%i minute ' % minutes
else:
minutes_str = '%i minutes ' % minutes
retval = '%s%s%s' % (days_str, hours_str, minutes_str)
return retval
def datetime_format(dtobj):
"""
Takes a datetime object instance (e.g. from django's DateTimeField)
and returns a string.
"""
year, month, day = dtobj.year, dtobj.date, dtobj.day
hour, minute, second = dtobj.hour, dtobj.minute, dtobj.second
now = datetime.datetime.now()
if year < now.year:
# another year
timestring = str(dtobj.date())
elif dtobj.date() < now.date():
# another date, same year
timestring = "%02i-%02i" % (day, month)
elif hour < now.hour - 1:
# same day, more than 1 hour ago
timestring = "%02i:%02i" % (hour, minute)
else:
# same day, less than 1 hour ago
timestring = "%02i:%02i:%02i" % (hour, minute, second)
return timestring
def host_os_is(osname):
"""
Check to see if the host OS matches the query.