sqlite_log.tcl 808 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #
  2. # 22/02/2011
  3. # by horgh
  4. #
  5. # Logs what is said/emoted in set channels in a given sqlite database
  6. #
  7. # Table:
  8. # id
  9. # channel
  10. # type (0 = msg)
  11. # time
  12. # nick
  13. # s (text)
  14. #
  15. package require sqlite3
  16. namespace eval sqlite_log {
  17. variable db_file /home/irc/log.db
  18. variable channels [list #antix #idiotbox]
  19. bind pubm -|- * sqlite_log::pub
  20. }
  21. proc sqlite_log::init {} {
  22. db eval {drop table log}
  23. catch {db eval {create table log(id integer primary key, channel text, type integer, time text, nick text, s text)}} result
  24. }
  25. proc sqlite_log::pub {nick uhost hand chan text} {
  26. if {[lsearch -exact $sqlite_log::channels $chan] == -1} { return }
  27. db eval {INSERT INTO log VALUES(NULL, $chan, 0, datetime('now'), $nick, $text)}
  28. }
  29. sqlite3 db $sqlite_log::db_file
  30. sqlite_log::init
  31. putlog "sqlite_log.tcl loaded"