thankyou
Donate to the B3 fund!

"even a small donation helps!"
Donate with PayPal!
Most of the plugins here are made by B3 users and the authors may not visit frequently. If you need support for plugins or if questions remain unanswered, you will have to contact the author directly. Read the full Support Disclaimer here

NOTE: Do not attach plugins to your forumtopics! Attachements are periodically removed by maintenance tasks. Upload your plugins to our Downloads section instead!

Author Topic: chatlogger plugin  (Read 83072 times)

Offline Courgette

  • Senior Dev.
  • Hero Member
  • *
  • Posts: 4883
    • Github repository
Re: chatlogger plugin v0.1.1
« Reply #30 on: September 13, 2008, 01:56:43 PM »
new release v0.1.1
 - in config, the hour defined for the purge is now understood in the timezone defined in the main B3 config file (before, was understood as UTC time)
 - fix mistake in log text
see first message for new download link

Offline |FaLLeN| Op-X

  • Full Member
  • ***
  • Posts: 97
    • |FaLLeN| Clan
Re: chatlogger plugin v0.1.1
« Reply #31 on: December 06, 2008, 07:46:04 AM »
will there be a release for a search box for chatlog?
Say I want to look for a specific word like "recruiting"
« Last Edit: December 06, 2008, 02:18:22 PM by |FaLLeN| Op-X »

xfire=specialopx
www.fallenclan.com

Offline Courgette

  • Senior Dev.
  • Hero Member
  • *
  • Posts: 4883
    • Github repository
Re: chatlogger plugin v0.1.1
« Reply #32 on: December 06, 2008, 02:17:27 PM »
you mean a search box in Echelon...
Not from me, but feel free to hack and propose a patch

Offline |FaLLeN| Op-X

  • Full Member
  • ***
  • Posts: 97
    • |FaLLeN| Clan
Re: chatlogger plugin v0.1.1
« Reply #33 on: December 06, 2008, 02:18:50 PM »
yep for echelon

xfire=specialopx
www.fallenclan.com

Offline Bakes

  • B3 Contrib/Support
  • Hero Member
  • *
  • Posts: 1226
Re: chatlogger plugin v0.1.1
« Reply #34 on: December 14, 2008, 01:03:43 PM »
A feature request, when two players are feuding they tend to tk each other a lot. Is there any way chatlogger could expand, and optionally add lines for tks?
it would be really useful.

Offline eire.32

  • Echelon v2. Dev.
  • Former Dev. (senate)
  • Full Member
  • *****
  • Posts: 114
    • e32designs.com
Re: chatlogger plugin v0.1.1
« Reply #35 on: December 19, 2008, 10:22:24 PM »
I'm having some trouble trying to install this plugin. I put the files in the right place and then made it pirority 1 so that it would work in conjuction with the censor plugin. I'm running this on CoD4 with linux, using the cod4 parser.

Quote
081219 15:28:04 CRITICAL Error loading plugin: No module named chatlogger
File "/usr/lib/python2.4/site-packages/b3-1.1.2d_r103-py2.4.egg/b3/parser.py", line 316, in loadPlugins
pluginModule = self.pluginImport(p)
File "/usr/lib/python2.4/site-packages/b3-1.1.2d_r103-py2.4.egg/b3/parser.py", line 338, in pluginImport
fp, pathname, description = imp.find_module(name, [self.config.getpath('plugins', 'external_dir')])
ImportError: No module named chatlogger

sry about the tiny info I remembered about the log, but got any ideas?
Eire.32
« Last Edit: December 19, 2008, 11:18:06 PM by eire.32 »
Eire.32

Offline Courgette

  • Senior Dev.
  • Hero Member
  • *
  • Posts: 4883
    • Github repository
Re: chatlogger plugin v0.1.1
« Reply #36 on: December 19, 2008, 11:28:46 PM »
obviously b3 cannot find the files in the right place... double check your config

Offline eire.32

  • Echelon v2. Dev.
  • Former Dev. (senate)
  • Full Member
  • *****
  • Posts: 114
    • e32designs.com
Re: chatlogger plugin v0.1.1
« Reply #37 on: December 21, 2008, 05:00:54 PM »
Yup the person who ftp'ed the files missed by about 3folders ^^

On a separate issue, I have all three of my CoD4 servers connected up to the same database, but I want them all to use chat logger on all of them. My problem is the chat would all end up in the same table/echelon page so...... if I create a different table (named "chatlog2" and 'chatlog3' for example) for each server and then if I change the line in the .py file
Quote
class ChatData(object):
  #default name of the table for this data object
  _table = 'chatlog'
  plugin = None
to equal
Quote
_table='chatlog2'
  is that the only line i need to change to make sure that each server reproduces a different table?


On the echelon matter if i change the line,
Quote
$query_rs_chats = sprintf("SELECT * FROM chatlog2 ORDER BY %s %s", $xlorderby_rs_chats,$xlorder_rs_chats);
In the echelon coding will I be able to view each server's chat logs on a diffferent page from a different table? Sorry if this seems a bit random or crazy. I don't have anywhere to test my idea so my threoy could protiential kill my server's mysql echelon and land me in some serious crap. Thanks for the help.
Eire.32
« Last Edit: December 21, 2008, 05:03:35 PM by eire.32 »
Eire.32

Offline Courgette

  • Senior Dev.
  • Hero Member
  • *
  • Posts: 4883
    • Github repository
Re: chatlogger plugin v0.1.1
« Reply #38 on: December 21, 2008, 08:52:45 PM »
hum... never though of that situation

Your solution won't work that easy as the same code (.py file) is used by each instances of the bot.
You have to hack the code a different way to read the table name from the config file.

quick and dirty untested code :
Quote
_db_table = None
...
# in onloadconfig
try:
   _db_table = self.config.get('database', 'db_table')
except:
   _db_table = 'chatlog'
   self.debug('Using default value (%s) for db_table', _db_table)

...
q = "DELETE FROM %s WHERE msg_time < %i"%(self._db_table, self.console.time() - (self._max_age_in_days*24*60*60))

...
if event.type == b3.events.EVT_CLIENT_SAY:
   chat = ChatData(self, event)
   chat._table = self._db_table
   chat.save()
if event.type == b3.events.EVT_CLIENT_TEAM_SAY:
   chat = TeamChatData(self, event)
   chat._table = self._db_table
   chat.save()
if event.type == b3.events.EVT_CLIENT_PRIVATE_SAY:
   chat = PrivateChatData(self, event)
   chat._table = self._db_table
   chat.save()

Quote
<configuration plugin="chatlogger">
  <settings name="database">
    <set name="db_table">chatlog2</set>
  </settings>

  <settings name="purge">
    <!-- how long (in days) do you want the history to be kept for.
      0 : keep chat log history for ever (default value)
      You can use the following syntax as well
      3d : purge all chat older than 3 days
      2w : two weeks
      6m : six month
      1y : one year
    -->
    <set name="max_age">0</set>

    <!-- The purge action takes place once a day at the time define below.
    Default time is midnight -->
    <set name="hour">0</set><!-- between 0 and 23 -->
    <set name="min">0</set><!-- between 0 and 59 -->

  </settings>
</configuration>
« Last Edit: December 21, 2008, 08:58:02 PM by Courgette »

Offline eire.32

  • Echelon v2. Dev.
  • Former Dev. (senate)
  • Full Member
  • *****
  • Posts: 114
    • e32designs.com
Re: chatlogger plugin v0.1.1
« Reply #39 on: December 21, 2008, 09:09:18 PM »
Thanks very much. your fix is definately more professional than my 1 charater fix. So with this change all I need is one .py file and 3.xml files right? (I run everything off the same folder)
Thanks.
Eire.32
« Last Edit: December 21, 2008, 09:44:55 PM by eire.32 »
Eire.32

Offline Courgette

  • Senior Dev.
  • Hero Member
  • *
  • Posts: 4883
    • Github repository
Re: chatlogger plugin v0.1.1
« Reply #40 on: December 21, 2008, 10:59:01 PM »
that's it, and also you gonna have to hack through echelon. send a patch once you got it working

Offline eire.32

  • Echelon v2. Dev.
  • Former Dev. (senate)
  • Full Member
  • *****
  • Posts: 114
    • e32designs.com
Re: chatlogger plugin v0.1.1
« Reply #41 on: December 22, 2008, 03:44:14 PM »
One small problem, this is the error I get is....
Code: [Select]
081222 14:35:38	VERBOSE	Queueing event Say test1
081222 14:35:38 VERBOSE Parsing Event: Client Name Change: ClantagPlugin
081222 14:35:38 VERBOSE Parsing Event: Say: ChatloggerPlugin
081222 14:35:38 DEBUG ChatloggerPlugin: ALL, 2, =(eGO)= Eire.32, test1
081222 14:35:38 DEBUG ChatloggerPlugin: query: INSERT INTO None (msg_time, msg_type, client_id, client_name, client_team, msg) VALUES (1229956538, "ALL", 2, "=(eGO)= Eire.32", 3, "test1")
081222 14:35:38 ERROR Query failed - <class '_mysql_exceptions.ProgrammingError'>: (1146, "Table 'b3.none' doesn't exist")
081222 14:35:38 ERROR handler ChatloggerPlugin could not handle event Say: AttributeError: 'NoneType' object has no attribute
'rowcount' [('C:\\usr\\local\\games\\B3s\\b3\\parser.py', 483, 'handleEvents', 'hfunc.parseEvent(event)'), ('C:\\usr\\local\\games\\B3s\\b3
\\plugin.py', 130, 'parseEvent', 'self.onEvent(event)'), ('b3\\extplugins\\chatlogger.py', 148, 'onEvent', 'chat.save()'), ('b3\\extplugins
\\chatlogger.py', 199, 'save', 'if (cursor.rowcount > 0):')]
081222 14:35:38 VERBOSE Parsing Event: Say: SpamcontrolPlugin
081222 14:35:38 VERBOSE Parsing Event: Say: AdminPlugin

I'm using, this .py file.
Code: [Select]
__version__ = '0.1.1'
__author__  = 'Courgette'

import b3, time, threading, re
from b3 import clients
import b3.events
import b3.plugin
import b3.cron
import datetime, string
from b3 import functions

#--------------------------------------------------------------------------------------------------
class ChatloggerPlugin(b3.plugin.Plugin):
  _cronTab = None
  _max_age_in_days = None
  _hours = None
  _minutes = None
  _db_table = None
 
 
  def onLoadConfig(self):
    # remove eventual existing crontab
    if self._cronTab:
      self.console.cron - self._cronTab

# in onloadconfig
    try:
      _db_table = self.config.get('database', 'db_table')
    except:
      _db_table = 'chatlog'
      self.debug('Using default value (%s) for db_table', _db_table)
     
    try:
      max_age = self.config.get('purge', 'max_age')
    except:
      days = 0
      self.debug('Using default value (%s) for max_age', days)
     
    # convert max age string to days. (max age can be written as : 2d for 'two days', etc)
    try:
      if max_age[-1:] == 'd':
        days = int(max_age[:-1])
      elif max_age[-1:] == 'w':
        days = int(max_age[:-1]) * 7
      elif max_age[-1:] == 'm':
        days = int(max_age[:-1]) * 30
      elif max_age[-1:] == 'y':
        days = int(max_age[:-1]) * 365
      else:
        days = int(max_age)
    except ValueError:
      self.error("Could not convert %s to a valid number of days."%max_age)
      days = 0
   
    self.debug('max age : %s => %s days'%(max_age, days))
   
    # force max age to be at least one day
    if days != 0 and days < 1:
      self._max_age_in_days = 1
    else:
      self._max_age_in_days = days

   
    try:
      self._hours = self.config.getint('purge', 'hour')
      if self._hours < 0:
        self._hours = 0
      elif self._hours > 23:
        self._hours = 23
    except:
      self._hours = 0
      self.debug('Using default value (%s) for hours', self._hours)
     
    try:
      self._minutes = self.config.getint('purge', 'min')
      if self._minutes < 0:
        self._minutes = 0
      elif self._minutes > 59:
        self._minutes = 59
    except:
      self._minutes = 0
      self.debug('Using default value (%s) for minutes', self._minutes)
   
    if self._max_age_in_days != 0:
      # Get time_zone from main B3 config
      tzName = self.console.config.get('b3', 'time_zone').upper()
      tzOffest = b3.timezones.timezones[tzName]
      hoursGMT = (self._hours - tzOffest)%24
      self.debug("%02d:%02d %s => %02d:%02d UTC" % (self._hours, self._minutes, tzName, hoursGMT, self._minutes))
      self.info('everyday at %2d:%2d %s, chat messages older than %s days will be deleted'%(self._hours, self._minutes, tzName, self._max_age_in_days))
      self._cronTab = b3.cron.PluginCronTab(self, self.purge, 0, self._minutes, hoursGMT, '*', '*', '*')
      self.console.cron + self._cronTab
    else:
      self.info("chat log messages are kept forever")
 
  def startup(self):
    """\
    Initialize plugin settings
    """
   
    # listen for client events
    self.registerEvent(b3.events.EVT_CLIENT_SAY)
    self.registerEvent(b3.events.EVT_CLIENT_TEAM_SAY)
    self.registerEvent(b3.events.EVT_CLIENT_PRIVATE_SAY)


   

  def onEvent(self, event):
    """\
    Handle intercepted events
    """
    if not event.client or event.client.cid == None or len(event.data) <= 0:
      return
   
    if event.type == b3.events.EVT_CLIENT_SAY:
      chat = ChatData(self, event)
      chat._table = self._db_table
      chat.save()
    if event.type == b3.events.EVT_CLIENT_TEAM_SAY:
      chat = TeamChatData(self, event)
      chat._table = self._db_table
      chat.save()
    if event.type == b3.events.EVT_CLIENT_PRIVATE_SAY:
      chat = PrivateChatData(self, event)
      chat._table = self._db_table
      chat.save()
 
  def purge(self):
    if not self._max_age_in_days or self._max_age_in_days == 0:
      self.warning('max_age is invalid [%s]'%self._max_age_in_days)
      return False
     
    self.info('purge of chat messages older than %s days ...'%self._max_age_in_days)
    q = "DELETE FROM %s WHERE msg_time < %i"%(self._db_table, self.console.time() - (self._max_age_in_days*24*60*60))
    self.debug(q)
    cursor = self.console.storage.query(q)
    #self.debug('cursor : %s'%cursor)
   
   
class ChatData(object):
  #default name of the table for this data object
  _table = 'chatlog'
  plugin = None
 
  #fields of the table
  msg_type = 'ALL' # ALL, TEAM or PM
  client_id = None
  client_name = None
  client_team = None
  msg = None
 
  def __init__(self, plugin, event):
    self.plugin = plugin
    self.client_id = event.client.id
    self.client_name = event.client.name
    self.client_team = event.client.team
    self.msg = event.data
   
  def _insertquery(self):
    return "INSERT INTO %s (msg_time, msg_type, client_id, client_name, client_team, msg) VALUES (%s, \"%s\", %s, \"%s\", %s, \"%s\")" % (self._table, self.plugin.console.time(), self.msg_type, self.client_id, self.client_name.replace('\\','\\\\').replace('"','\\"'), self.client_team, self.msg.replace('\\','\\\\').replace('"','\\"'))

  def save(self):
    self.plugin.debug("%s, %s, %s, %s"% (self.msg_type, self.client_id, self.client_name, self.msg))
   
    q = self._insertquery()
    self.plugin.debug("query: %s" % q)
   
    cursor = self.plugin.console.storage.query(q)
    if (cursor.rowcount > 0):
      self.plugin.debug("rowcount: %s, id:%s" % (cursor.rowcount, cursor.lastrowid))
    else:
      self.plugin.warn("inserting chat failed")
     
     
   
class TeamChatData(ChatData):
  msg_type = 'TEAM'
 
  def __init__(self, plugin, event):
    ChatData.__init__(self, plugin, event)
 
 
 
 
class PrivateChatData(ChatData):
  msg_type = 'PM'
 
  target_id = None
  target_name = None
  target_team = None
 
  def __init__(self, plugin, event):
    ChatData.__init__(self, plugin, event)
    self.target_id = event.target.id
    self.target_name = event.target.name
    self.target_team = event.target.team
   
  def _insertquery(self):
    return "INSERT INTO %s (msg_time, msg_type, client_id, client_name, client_team, msg, target_id, target_name, target_team) VALUES (%s, \"%s\", %s, \"%s\", %s, \"%s\", %s, \"%s\", %s)" % (self._table, self.plugin.console.time(), self.msg_type, self.client_id, self.client_name.replace('\\','\\\\').replace('"','\\"'), self.client_team, self.msg.replace('\\','\\\\').replace('"','\\"'), self.target_id, self.target_name.replace('\\','\\\\').replace('"','\\"'), self.target_team)

And the .xml file,
Code: [Select]
<configuration plugin="chatlogger">
  <settings name="database">
    <set name="db_table">chatlog2</set>
  </settings>
  <settings name="purge">
    <!-- how long (in days) do you want the history to be kept for.
      0 : keep chat log history for ever (default value)
      You can use the following syntax as well
      3d : purge all chat older than 3 days
      2w : two weeks
      6m : six month
      1y : one year
    -->
    <set name="max_age">0</set>

    <!-- The purge action takes place once a day at the time define below.
    Default time is midnight -->
    <set name="hour">0</set><!-- between 0 and 23 -->
    <set name="min">0</set><!-- between 0 and 59 -->
  </settings>
</configuration>

There is a table in my b3 database called chatlog2, but as you can see from the log, b3 is trying to send the info to a table called none. I tired a few other changes for the line.
Quote
  _db_table = None
But I just seemed to go backwards.
Eire.32
 
Eire.32

Offline Courgette

  • Senior Dev.
  • Hero Member
  • *
  • Posts: 4883
    • Github repository
Re: chatlogger plugin v0.1.1
« Reply #42 on: December 22, 2008, 03:47:02 PM »
try :
Quote
   try:
      self._db_table = self.config.get('database', 'db_table')
    except:
      self._db_table = 'chatlog'
      self.debug('Using default value (%s) for db_table', self._db_table)


Offline eire.32

  • Echelon v2. Dev.
  • Former Dev. (senate)
  • Full Member
  • *****
  • Posts: 114
    • e32designs.com
Re: chatlogger plugin v0.1.1
« Reply #43 on: December 22, 2008, 06:23:13 PM »
That works prefectly.
Eire.32
Eire.32

Offline Courgette

  • Senior Dev.
  • Hero Member
  • *
  • Posts: 4883
    • Github repository
Re: chatlogger plugin v0.2.0
« Reply #44 on: December 22, 2008, 11:37:29 PM »
new release v0.2.0

allows to use a customized table name for storing the log to database.
Thanks to Eire.32 for is work/tests :)

 


Rate this page +1 at Google Search