irssibot.modules
Class Logger

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--irssibot.modules.AbstractModule
              |
              +--irssibot.modules.Logger
All Implemented Interfaces:
java.lang.Runnable

public class Logger
extends AbstractModule

MySQL logging module.

MySQL clauses to initialize the database is as follows. The tables need to be named like this:

quote table: networkname_channelname_quote
nick table: networkname_nick
alias table: networkname_alias

Networkname is the symbolic name given to a network in the bot's configuration file. It is the name returned by ServerConnection.getInstanceData().getNetwork()

Therefore you need one quote table per channel, and one nick table and alias table per network.

NOTE: you do not need to create any of the tables, this module will automatically create them for you. The SQL code is just supplied here to show the structure of the tables to help the development of 3rd party applications on top of the logging system.


 DROP DATABASE IF EXISTS ircstats;
 
 CREATE DATABASE ircstats;
 
 CONNECT ircstats;
 
 DROP TABLE IF EXISTS networkname_alias;
 
 CREATE TABLE networkname_alias
 (
     alias_id INT( 11 )     NOT NULL AUTO_INCREMENT,
     name     VARCHAR( 32 ) NOT NULL,
     PRIMARY KEY ( alias_id ),
     UNIQUE      ( name ),
     INDEX       ( name )
 );
 
 DROP TABLE IF EXISTS networkname_nick;
 
 CREATE TABLE networkname_nick
 (
     nick_id  INT( 11 ) NOT NULL AUTO_INCREMENT,
     name     VARCHAR( 32 ) NOT NULL,
     alias_id INT( 11 ) NOT NULL,
     status   enum(' ','D','U'),
     PRIMARY KEY ( nick_id ),
     UNIQUE      ( name ),
     INDEX       ( name ),
     INDEX ( alias_id )
 );
 
 DROP TABLE IF EXISTS networkname_channelname_quote;
 
 CREATE TABLE networkname_channelname_quote
 (
     nick_id   INT( 11 )  NOT NULL,
     quoteline MEDIUMTEXT NOT NULL,
     created   DATETIME   NOT NULL,
     INDEX ( nick_id )
 );

 

Version:
$Name: $ $Revision: 1.17 $
Author:
Matti Dahlbom

Field Summary
private  boolean autoNickJoin
          Indicates whether to automatically connect nicks on NICK change.
private  boolean autoQuote
          Indicates whether to automatically quote people on on channel JOINs
private  ServerConnection caller
           
private  boolean changed
          Whether the state of the module has changed and needs saving.
private  java.sql.Connection connection
          Database connection
private  Core core
          Reference to bot core
private  java.lang.String dbName
          Name of database descriptor to use.
private static java.text.SimpleDateFormat defaultDateFormat
          Default dateformat
private  Host host
           
private static java.lang.String moduleInfo
          Module info
private  java.text.SimpleDateFormat sdf
          Dateformat to use for displaying quotes
private  java.lang.String source
           
 
Fields inherited from class irssibot.modules.AbstractModule
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Logger()
          Default constructor
 
Method Summary
private  void closeConnection()
          Disconnects from the database.
private  void commandAdd(Host host, User invoker, java.lang.String[] args, Channel channel)
          Add command
private  void commandEdit(Host host, User invoker, java.lang.String[] args, Channel channel)
          Edit command
private  void commandLast(Host host, User invoker, java.lang.String[] args, Channel channel)
          Last command.
private  void commandList(Host host, User invoker, java.lang.String[] args, Channel channel)
          List command
private  void commandQuote(Host host, User invoker, java.lang.String[] args, Channel channel)
          Quote command.
private  boolean createAliasTable(java.lang.String tableName)
           
private  boolean createNickTable(java.lang.String tableName)
           
private  boolean createQuoteTable(java.lang.String tableName)
           
private  void deleteFromAliasTable(java.lang.String nick, java.lang.String aliasTableName)
          Deletes an entry from alias table.
 void doJoin(IrcMessage message)
          Handles JOINs
private  void doNick(IrcMessage message)
          Handles NICK changes :porkkanaz!^asd@dreamland.tky.hut.fi NICK :testink
private  void doPrivmsg(IrcMessage message)
          Handles PRIVMSGs.
private  int getAliasIdFromAliasTable(java.lang.String nick, java.lang.String aliasTableName)
          Get alias_id corresponding to a certain name in alias table.
private  int getAliasIdFromNickTable(java.lang.String nick, java.lang.String nickTableName)
          Get alias_id corresponding to a certain name in nick table.
 java.lang.String getModuleInfo()
          Returns a module info string.
private  int getNickId(java.lang.String nick, java.lang.String nickTableName)
           
private  int getNumAliases(int aliasId, java.lang.String nickTableName)
          Get number of alias nicks for an alias_id
private  int getNumNicks(java.lang.String nickTableName)
          Return the number of nicks in nick table
private  int getNumQuotes(java.lang.String nick, java.lang.String nickTableName, java.lang.String aliasTableName, java.lang.String quoteTableName)
          Counts number of quotelines for given nickId, or if none given (nick == null), get number of all quotes.
 java.util.Properties getState()
          Returns module state.
private  void insertIntoNickTable(int aliasId, java.lang.String nick, java.lang.String nickTableName)
          Inserts a new entry in nick table
private  void joinNicks(java.lang.String nick1, java.lang.String nick2, java.lang.String nickTableName, java.lang.String aliasTableName, boolean insert)
          Joins two nicks (nick1 to nick2) together by their alias_id's: Gets alias_id from nick2 and sets nick1's alias_id to the value.
private  void log(Host host, Channel channel, java.lang.String msg)
          Insert quote into log
 boolean onLoad(java.util.Properties state, Core core)
          Called upon loading the module.
 void onUnload()
          Called upon unloading the module.
private  void processCmdMsg(Host host, java.lang.String cmd, Channel channel, java.lang.String[] args)
          Process command message.
protected  void processMessage(IrcMessage message, ServerConnection serverConnection)
          Processes incoming IrcMessages from a ServerConnection.
private  boolean setAliasId(java.lang.String nick, int aliasId, java.lang.String nickTableName)
          Sets the alias_id for given entry in nick table
private  java.lang.String strip(java.lang.String input)
          Returns a string with non-alphanumerics removed from the input.
private  void write(java.lang.String message)
          Sends message to source (channel/user)
 
Methods inherited from class irssibot.modules.AbstractModule
addMessage, killModule, run
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

moduleInfo

private static final java.lang.String moduleInfo
Module info

See Also:
Constant Field Values

defaultDateFormat

private static final java.text.SimpleDateFormat defaultDateFormat
Default dateformat


sdf

private java.text.SimpleDateFormat sdf
Dateformat to use for displaying quotes


dbName

private java.lang.String dbName
Name of database descriptor to use.

See Also:
Core.getDatabaseConnection(String)

autoQuote

private boolean autoQuote
Indicates whether to automatically quote people on on channel JOINs


autoNickJoin

private boolean autoNickJoin
Indicates whether to automatically connect nicks on NICK change.


changed

private boolean changed
Whether the state of the module has changed and needs saving.


host

private Host host

source

private java.lang.String source

caller

private ServerConnection caller

connection

private java.sql.Connection connection
Database connection


core

private Core core
Reference to bot core

Constructor Detail

Logger

public Logger()
Default constructor

Method Detail

getState

public java.util.Properties getState()
Returns module state.

Overrides:
getState in class AbstractModule
Returns:
module state or null if state has not changed.

getModuleInfo

public java.lang.String getModuleInfo()
Returns a module info string.

Specified by:
getModuleInfo in class AbstractModule
Returns:
module info string

closeConnection

private void closeConnection()
Disconnects from the database.


onLoad

public boolean onLoad(java.util.Properties state,
                      Core core)
Called upon loading the module. Inits the module and connects to the configured database.

Overrides:
onLoad in class AbstractModule
Parameters:
state - initial state for the module
core - refenrece to bot core
Returns:
true if ok, false if error. modules returning false from onLoad() will be unloaded immediately.
See Also:
Core

onUnload

public void onUnload()
Called upon unloading the module.

Overrides:
onUnload in class AbstractModule

strip

private java.lang.String strip(java.lang.String input)
Returns a string with non-alphanumerics removed from the input.

Parameters:
input - the input String
Returns:
String with non-alphanumerics removed

createQuoteTable

private boolean createQuoteTable(java.lang.String tableName)

createNickTable

private boolean createNickTable(java.lang.String tableName)

createAliasTable

private boolean createAliasTable(java.lang.String tableName)

getNumAliases

private int getNumAliases(int aliasId,
                          java.lang.String nickTableName)
Get number of alias nicks for an alias_id

Parameters:
aliasId -
nickTableName - per-network name of nick table
Returns:
number of alias nicks

getNickId

private int getNickId(java.lang.String nick,
                      java.lang.String nickTableName)

getAliasIdFromAliasTable

private int getAliasIdFromAliasTable(java.lang.String nick,
                                     java.lang.String aliasTableName)
Get alias_id corresponding to a certain name in alias table.

Parameters:
nick - Nick whose alias id to look for
aliasTableName - per-network name for alias table
Returns:
alias_id for nick, or -1 if not found.

insertIntoNickTable

private void insertIntoNickTable(int aliasId,
                                 java.lang.String nick,
                                 java.lang.String nickTableName)
Inserts a new entry in nick table

Parameters:
aliasId - alias_id to assign to nick entry
nick - nick (name) to insert
nickTableName - per-network name of nick table

getAliasIdFromNickTable

private int getAliasIdFromNickTable(java.lang.String nick,
                                    java.lang.String nickTableName)
Get alias_id corresponding to a certain name in nick table.

Parameters:
nick - Nick whose alias id to look for
nickTableName - per-network name for nick table
Returns:
alias_id for nick, or -1 if not found.

log

private void log(Host host,
                 Channel channel,
                 java.lang.String msg)
Insert quote into log

Parameters:
host - Host of nick saying the message
channel - channel on which the message was said
msg - the said message

getNumQuotes

private int getNumQuotes(java.lang.String nick,
                         java.lang.String nickTableName,
                         java.lang.String aliasTableName,
                         java.lang.String quoteTableName)
Counts number of quotelines for given nickId, or if none given (nick == null), get number of all quotes.

Parameters:
nick - nick in nick table or null if getting count for all quotelines in database.
nickTableName - name of nick table
aliasTableName - name alias table
quoteTableName - name of quote table
Returns:
number of quotes for given nick or all nicks or -1 on error

setAliasId

private boolean setAliasId(java.lang.String nick,
                           int aliasId,
                           java.lang.String nickTableName)
Sets the alias_id for given entry in nick table

Parameters:
nick - name entry in nick table
aliasId - new value for alias_id
nickTableName - per-network name for nick table
Returns:
true on success. false if no entry for given nick.

deleteFromAliasTable

private void deleteFromAliasTable(java.lang.String nick,
                                  java.lang.String aliasTableName)
Deletes an entry from alias table.

Parameters:
nick - indicates the entry to be deleted.
aliasTableName - per-network name of alias table

getNumNicks

private int getNumNicks(java.lang.String nickTableName)
Return the number of nicks in nick table


joinNicks

private void joinNicks(java.lang.String nick1,
                       java.lang.String nick2,
                       java.lang.String nickTableName,
                       java.lang.String aliasTableName,
                       boolean insert)
Joins two nicks (nick1 to nick2) together by their alias_id's:

Parameters:
nick1 - nick to assign new alias_id to
nick2 - nick to acquire the alias_id from
nickTableName - per-network name of nick table
aliasTableName - per-network name of alias table
insert - indicates whether to INSERT nick1 into nick table if it does not exists there. this is used with autoNickJoining on NICK changes.

commandQuote

private void commandQuote(Host host,
                          User invoker,
                          java.lang.String[] args,
                          Channel channel)
Quote command. Displays a random quote from log.

Parameters:
host - host of invoker
invoker - invoking User
args - arguments of command
channel - target channel

commandLast

private void commandLast(Host host,
                         User invoker,
                         java.lang.String[] args,
                         Channel channel)
Last command. Displays N last quotelines said by given nick.

Parameters:
host - host of invoker
invoker - invoking User
args - arguments of command
channel - target channel

commandEdit

private void commandEdit(Host host,
                         User invoker,
                         java.lang.String[] args,
                         Channel channel)
Edit command

Parameters:
host - host of invoker
invoker - invoking User
args - arguments of command
channel - target channel

commandAdd

private void commandAdd(Host host,
                        User invoker,
                        java.lang.String[] args,
                        Channel channel)
Add command

Parameters:
host - host of invoker
invoker - invoking User
args - arguments of command
channel - target channel

commandList

private void commandList(Host host,
                         User invoker,
                         java.lang.String[] args,
                         Channel channel)
List command

Parameters:
host - host of invoker
invoker - invoking User
args - arguments of command
channel - target channel

processCmdMsg

private void processCmdMsg(Host host,
                           java.lang.String cmd,
                           Channel channel,
                           java.lang.String[] args)
Process command message. assuming valid channel argument.

Parameters:
channel - valid channel name

doNick

private void doNick(IrcMessage message)
Handles NICK changes :porkkanaz!^asd@dreamland.tky.hut.fi NICK :testink

Parameters:
message - NICK IrcMessage to process

doPrivmsg

private void doPrivmsg(IrcMessage message)
Handles PRIVMSGs.

Parameters:
message - PRIVMSG IrcMessage to process

doJoin

public void doJoin(IrcMessage message)
Handles JOINs

Parameters:
message - the JOIN IrcMessage

processMessage

protected void processMessage(IrcMessage message,
                              ServerConnection serverConnection)
Processes incoming IrcMessages from a ServerConnection.

Specified by:
processMessage in class AbstractModule
Parameters:
message - IrcMessage to process
serverConnection - invoking ServerConnection

write

private void write(java.lang.String message)
Sends message to source (channel/user)

Parameters:
message - message to send


IrssiBot (c) 2000-2002 Matti Dahlbom