Index: bot_aggregator/bot_aggregator.info
===================================================================
RCS file: bot_aggregator/bot_aggregator.info
diff -N bot_aggregator/bot_aggregator.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ bot_aggregator/bot_aggregator.info	4 Aug 2008 00:40:37 -0000
@@ -0,0 +1,7 @@
+; $Id$
+name = Bot Aggregator
+package = Bot
+dependencies[] = bot
+dependencies[] = aggregator
+description = Print the results of aggregator feeds to the IRC channel(s) of your choice.
+core = 6.x
\ No newline at end of file
Index: bot_aggregator/bot_aggregator.module
===================================================================
RCS file: bot_aggregator/bot_aggregator.module
diff -N bot_aggregator/bot_aggregator.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ bot_aggregator/bot_aggregator.module	4 Aug 2008 00:37:52 -0000
@@ -0,0 +1,71 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_help().
+ */
+function bot_aggregator_help($path, $arg) {
+  if ($path == 'irc:features') {
+    return array('Aggregator', 'Refresh');
+  }
+  if ($path == 'irc:features#aggregator') {
+    $channels = variable_get('bot_aggregator_channels', array());
+    foreach ($channels as $key => $channel) {
+      $channels[$key] = substr($channel, 1);
+    }
+    $channel_list = implode(', ', $channels);
+    return t('The aggregator feature reads from aggregated feeds and then spits the results back to the @channels channel.', array('@channels' => $channel_list));
+  }
+}
+
+/**
+ * Implementation of hook_menu().
+ */
+function bot_aggregator_menu() {
+  $items = array();
+
+  $items['admin/settings/bot/aggregator'] = array(
+    'title' => 'Bot aggregator',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('bot_aggregator_settings_form'),
+    'access arguments'  => array('administer bot'),
+    'file' => 'bot_aggregator.pages.inc',
+  );
+
+  return $items;
+}
+
+/**
+ * Implementation of hook_irc_bot_cron().
+ */
+function bot_aggregator_irc_bot_cron() {
+  static $last_checked;
+  if (!isset($last_checked)) {
+    $last_checked = time();
+  }
+  $categories = variable_get('bot_aggregator_categories', array());
+  if (empty($categories)) {
+    $feeds = db_query('SELECT * FROM {aggregator_feed}');
+  }
+  else {
+    $feeds = db_query('SELECT af.* FROM {aggregator_feed} af INNER JOIN {aggregator_category_feed} acf ON af.fid = acf.fid WHERE acf.cid IN (' . db_placeholders($categories) . ')', $categories);
+  }
+  while ($feed = db_fetch_array($feeds)) {
+    aggregator_refresh($feed);
+  }
+  if (empty($categories)) {
+    $result = db_query('SELECT title, link, author FROM {aggregator_item} WHERE timestamp > %d ORDER BY timestamp ASC', $last_checked);
+  }
+  else {
+    $placeholders = $categories;
+    array_unshift($placeholders, $last_checked);
+    $result = db_query('SELECT ai.title, ai.link, ai.author FROM {aggregator_item} ai INNER JOIN {aggregator_category_item} aci ON ai.iid = aci.iid WHERE timestamp > %d AND aci.cid IN (' . db_placeholders($categories) . ') ORDER BY ai.timestamp ASC', $placeholders);
+  }
+  while ($item = db_fetch_array($result)) {
+    $item = array_map('strip_tags', $item);
+    foreach (variable_get('bot_aggregator_channels', array()) as $channel) {
+      $channel = substr($channel, 1);
+      bot_message($channel, t('!title by !author - !link', array('!title' => $item['title'], '!author' => $item['author'], '!link' => $item['link'])));
+    }
+  }
+}
\ No newline at end of file
Index: bot_aggregator/bot_aggregator.pages.inc
===================================================================
RCS file: bot_aggregator/bot_aggregator.pages.inc
diff -N bot_aggregator/bot_aggregator.pages.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ bot_aggregator/bot_aggregator.pages.inc	4 Aug 2008 00:30:16 -0000
@@ -0,0 +1,42 @@
+<?php
+// $Id$
+
+/**
+ * FAPI callback for the administration settings page.
+ */
+function bot_aggregator_settings_form() {
+  $form = array();
+
+  $channels = preg_split('/\s*,\s*/', variable_get('bot_channels', '#test'));
+  $options = array();
+  foreach ($channels as $channel) {
+    list($channel) = explode(' ', $channel);
+    // If the option key starts with #, as many IRC channel names do, it would
+    // be ignored. So we escape it with \.
+    $options['\\'. check_plain($channel)] = $channel;
+  }
+
+  $form['bot_aggregator_channels'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Channels'),
+    '#description' => t('Choose the channels in which new aggregated items should be displayed.'),
+    '#options' => $options,
+    '#default_value' => variable_get('bot_aggregator_channels', array()),
+  );
+
+  $result = db_query('SELECT cid, title FROM {aggregator_category}');
+  $options = array();
+  while ($category = db_fetch_array($result)) {
+    $options[$category['cid']] = $category['title'];
+  }
+
+  $form['bot_aggregator_categories'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Categories'),
+    '#description' => t('Choose the aggregator categories to be displayed. If none are selected, all will be displayed.'),
+    '#options' => $options,
+    '#default_value' => variable_get('bot_aggregator_categories', array()),
+  );
+
+  return system_settings_form($form);
+}
\ No newline at end of file
