Posted By

gaunab on 11/13/06


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

willcodeforfood


IRC logger


 / Published in: PHP
 

  1. <?php
  2. // $Id: bot_drupal.module,v 1.2 2006/11/13 03:25:57 morbus Exp $
  3.  
  4. /**
  5.  * Implementation of hook_menu().
  6.  */
  7. function bot_test_menu($may_cache) {
  8. $items = array();
  9.  
  10. if ($may_cache) {
  11. $items[] = array (
  12. 'path' => "bot",
  13. 'type' => MENU_CALLBACK,
  14. 'callback' => 'bot_test_page',
  15. 'access' => 'administer site'
  16. );
  17. }
  18.  
  19. return $items;
  20. }
  21.  
  22. function bot_test_irc_msg_channel($data) {
  23. $mynick = variable_get('bot_nickname');
  24.  
  25. // log it
  26. $query = "INSERT INTO {bot_log} (type, timestamp, channel, nick, message) VALUES ('%s', %d, '%s', '%s', '%s')";
  27. db_query($query, 'irc', time(), $data->channel, $data->nick, $data->message);
  28.  
  29.  
  30. if (preg_match("!^($mynick\:? ?)?botsnack.*!", $data->message))
  31. bot_message($data->channel, "Thanks, ".$data->nick);
  32.  
  33. }
  34.  
  35. function bot_test_page($page = 1) {
  36.  
  37. $perpage = "50";
  38. $from = ($page-1) * $perpage;
  39.  
  40. $rows = array();
  41.  
  42. $result = db_query_range('SELECT * FROM {bot_log} ORDER BY id DESC', $from, $perpage);
  43. while ($current = db_fetch_object($result)) {
  44. $rows[] = array(
  45. $current->channel,
  46. format_date($current->timestamp,"small"),
  47. $current->nick,
  48. $current->message );
  49. }
  50. $header = array(t("Channel"),t("Time"),t("Nick"),t("Message"));
  51.  
  52. return theme_table($header, $rows);
  53. }

Report this snippet  

You need to login to post a comment.