[Crossfire-wiki] [Crossfire DokuWiki] page added: user:katia:chatlog.py

no-reply_wiki at metalforge.org no-reply_wiki at metalforge.org
Sun Sep 30 08:46:24 CDT 2012


A page in your DokuWiki was added or changed. Here are the details:

Date        : 2012/09/30 08:46
User        : katia
Edit Summary: created

====== 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 [[user:katia: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. 

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. If it's your default python you can change the first line of the script to this:
  #!/usr/bin/python

If you don't know what python version you have installed you can type 'python' at your console and see what it says. It should be something like this:

  Python 2.7.3 (default, Apr 24 2012, 00:06:13) 
  [GCC 4.7.0 20120414 (prerelease)] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> 

Then use Ctrl+d to exit the python console.
So, the second line of that output shows you the version. If it says 3 or over you may have to try the command python2 instead, or may need to install it too.

Anyway, as is, this script will NOT run with python 3 or over.

===== Note about python =====
If you are new to python you should know it's very important to keep indentation to make a python script work properly.

Please make sure it's correctly kept when you copy the contents of my script to your file.

====== 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
      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:
                          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 [[user:eadmund:scripts: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!

IP-Address  : 186.52.69.211
Old Revision: none
New Revision: http://wiki.metalforge.net/doku.php/user:katia:chatlog.py

-- 
This mail was generated by DokuWiki at
http://wiki.metalforge.net/



More information about the crossfire-wiki mailing list