User Tools

Site Tools


user:katia:chatlog.py

Why this script?

Did you ever miss conversation messages because you were too bussy in a dungeon, praying or any other activity that puts a lot of messages in your screen? Ok, I know this got solved at newer servers with the critical messages window, but there's still metalforge beeing one of the most active servers and still haven't been updated for that.

So this is my attempt to keep an eye on the conversation, it will only work at servers which do not split Critical messages.

It also conveniently adds the date (when it changes) and a timestamp (for each message).

How does it work?

It keeps in mind that messages related to communication are always colored in a certain way.

So this script for instance logs every message the server tells the client to print in any of this colors: Red (shout), Sky Blue (chat & me), Yellow (tell), bold Black (say, gsay & emotes). It adds the Orange color to see enter/leave messages. And finally it logs deaths, this means any message you get with the string “ killed ” in it (notice the surrounding spaces which filter a few unwanted messages), either if a player got killed, or you killed a monster.

That is the default behaviour. But you can change it.

Lets say you want to log shouts, chat and tell and are not interested in death messages. Then you add as a parameter the color numbers list you are interested. We will avoid the parameter 'deaths' so to avoid loging those. So the command would look like this:

<path to my script>/chatLog.py 3 5 4

If you want to also log deaths you must add:

<path to my script>/chatLog.py 3 5 4 deaths

If any parameters are present, it will only log that for what it's asked. Parameters don't have to be in a particular order, and will be ignored if are not numeric and not equal to 'deaths'. Colors are only available from 0 to 12. Over 12, they are all equivalent to 0. Here's another of my scripts to show you the color numbers available showColors.py.

Nobody's perfect

This script isn't perfect either. Since It's color based, it will log some kind of messages not related to communication.

For instance, since it logs red messages, it will log when you gain or loose a level at some skill or overall (may be good, may be bad, I like it myself :-)).

Since it logs Sky Blue messages, it will log when you gain or loose resistances. EDIT: this got fixed.

Since it logs uncolored messages with the string ' killed ' in it, it will log messages as 'You killed goblin with …' (it may get annoying at some point, but not quite as having the whole bunch of messages telling you hit the monster before killing it).

About the Python version

It works with python 2 (2.6 or 2.7 will be fine). It will NOT run with python 3 or over.

see About python if you need more explanation about it or you never used Python before.

Instructions

Save this code in a new file call it chatLog.py per say.

#!/usr/bin/python2
from crossfire import putline, draw
import sys
from datetime import datetime

logfile = '<filename for chat log>' # '<full path>/chat.log'
try: chatlog = open(logfile, 'a', 0)
except:
    draw(10, "Couldn't open %s for log file, please check path and permissions." % logfile)
    exit(0)

def draw_monitor(colors=['1','3','4','5','6'], deaths=True): #default for player communication/in/out colors
    putline('watch drawinfo')
    do_write=False
    last_date = False
    filter_resists = ('5' in colors)
    while True:
        read = sys.stdin.readline()
        for l in read.split('\n'):
            if l != '':
                timestamp = datetime.now()
                d = datetime.now().strftime('%d-%m-%Y')
                t = datetime.now().strftime('%H:%M:%S')
                if l[:14] == 'watch drawinfo':
                    do_write = (l[15] in colors or (deaths and l[15] == '0' and l[17:].find(' killed ')>0))
                    if do_write and filter_resists and l[15] == '5':
                        do_write = (l[17:36]!=('Your resistance to ')) #filter resistance messages
                    if do_write:
                        if not last_date or last_date != d:
                            last_date = d
                            chatlog.write('%s\n' % d)
                        chatlog.write('[%s] %s\n' % (t,l[17:]))
                elif do_write:
                    if not last_date or last_date != d:
                        last_date = d
                        chatlog.write('%s\n' % d)
                    chatlog.write('[%s] %s\n' % (t,l))
                elif l[:5] == 'watch': do_write = False

if __name__ == '__main__':
    draw(10, 'Chat will be loged to %s' % logfile )
    if len(sys.argv)>1:
        colors=[]
        deaths=False
        for c in sys.argv[1:]:
            if c.isdigit(): colors.append(c)
            elif c=='deaths': deaths = True
        draw_monitor(colors, deaths)
    else: draw_monitor()

Change the value of the variable logfile (at line 6), to wherever you want the chat log to be saved. Use full path please. Make sure you have write access to the directory.

Then give this script execution permission:

chmod +x chatLog.py

You will need to download this file too crossfire.py. It doesn't need execution permissions, but it must be saved in the same directory as the other script.

Run it with:

<path to my script>/chatLog.py

Useful tip

Once you are are running the script you will have the chat loged to a file, so you now would probably like to see the file as it grows continuosly. I use a gnome terminal with a small font and plug it in top of the other windows, size it, and use this command to see the chat:

tail -f <chat log filename>

You are ready now to go praying or identifying huge chests without missing anything of the conversation :-)

Final words

This code is provided as is, use it/modify it at your own risk, share if you like, just keep in mind each server rules and privacy issues ;-)

If you like to call my name/let me know when you re-use it I'll be thankful.

Enjoy!

user/katia/chatlog.py.txt · Last modified: 2012/09/30 18:21 (external edit)