Made channels log to a log file by default. Added a default /history switch to the channel commands (for viewing past entries) and implemented a very efficient tail_log_file function to scan the log and display it.
This commit is contained in:
parent
d00ff9ae32
commit
5583a8d758
3 changed files with 124 additions and 54 deletions
|
|
@ -27,6 +27,7 @@ from builtins import object
|
|||
|
||||
from evennia.comms.models import ChannelDB
|
||||
from evennia.commands import cmdset, command
|
||||
from evennia.utils.logger import tail_log_file
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
|
@ -34,11 +35,21 @@ class ChannelCommand(command.Command):
|
|||
"""
|
||||
{channelkey} channel
|
||||
|
||||
{channeldesc}
|
||||
|
||||
Usage:
|
||||
{lower_channelkey} <message>
|
||||
{lower_channelkey} history <num>[-<num>]
|
||||
{lower_channelkey}/history [start]
|
||||
|
||||
Switch:
|
||||
history: View the 20 last messages, optionally
|
||||
beginning <start> messages from the end.
|
||||
|
||||
Example:
|
||||
{lower_channelkey} Hello World!
|
||||
{lower_channelkey}/history
|
||||
{lower_channelkey}/history 30
|
||||
|
||||
{channeldesc}
|
||||
"""
|
||||
# this flag is what identifies this cmd as a channel cmd
|
||||
# and branches off to the system send-to-channel command
|
||||
|
|
@ -54,6 +65,13 @@ class ChannelCommand(command.Command):
|
|||
"""
|
||||
# cmdhandler sends channame:msg here.
|
||||
channelname, msg = self.args.split(":", 1)
|
||||
self.history_start = None
|
||||
if msg.startswith("/history"):
|
||||
arg = msg[8:]
|
||||
try:
|
||||
self.history_start = int(arg) if arg else 0
|
||||
except ValueError:
|
||||
pass
|
||||
self.args = (channelname.strip(), msg.strip())
|
||||
|
||||
def func(self):
|
||||
|
|
@ -79,7 +97,13 @@ class ChannelCommand(command.Command):
|
|||
string = _("You are not permitted to send to channel '%s'.")
|
||||
self.msg(string % channelkey)
|
||||
return
|
||||
channel.msg(msg, senders=self.caller, online=True)
|
||||
if self.history_start is not None:
|
||||
# Try to view history
|
||||
log_file = channel.attributes.get("log_file", default="channel_%s.log" % channel.key)
|
||||
self.msg("".join(line.split("[-]", 1)[1] if "[-]" in line else line
|
||||
for line in tail_log_file(log_file, self.history_start, 20)))
|
||||
else:
|
||||
channel.msg(msg, senders=self.caller, online=True)
|
||||
|
||||
def get_extra_info(self, caller, **kwargs):
|
||||
"""
|
||||
|
|
@ -175,7 +199,7 @@ class ChannelHandler(object):
|
|||
locks="cmd:all();%s" % channel.locks,
|
||||
help_category="Channel names",
|
||||
obj=channel,
|
||||
arg_regex=r"\s.*?",
|
||||
arg_regex=r"\s.*?|/history.*?",
|
||||
is_channel=True)
|
||||
# format the help entry
|
||||
key = channel.key
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue