Index: bot_twitter/bot_twitter.module =================================================================== RCS file: bot_twitter/bot_twitter.module diff -N bot_twitter/bot_twitter.module --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ bot_twitter/bot_twitter.module 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,75 @@ +".', array('!botname' => variable_get('bot_nickname', 'BOTNAME'))); + } +} + +/** + * Implementation of hook_perm(). + */ +function bot_twitter_perm() { + return array('make twitter bot updates'); +} + +/** + * Listen for conversation directed at, or around, the bot. + * + * @param $data + * The regular $data object prepared by the IRC library. + * @param $from_query + * Boolean; whether this was a queried request. + */ +function bot_twitter_irc_msg_channel($data, $from_query = FALSE) { + $bot_name = variable_get('bot_nickname', 'bot_module'); + $addressed = $from_query ? '' : "\s*${bot_name}[\:,-]\s*"; // bot mentioned? + $to = $from_query ? $data->nick : $data->channel; + + // Check if they're posting a note to Twitter + if (preg_match("/^($addressed)twitter? (.*)$/i", $data->message, $matches)) { + $user = bot_authenticate($data); + if (user_access('make twitter bot updates', $user)) { + module_load_include('inc', 'twitter'); + $twitter_accounts = twitter_get_user_accounts($user->uid); + if (!empty($twitter_accounts)) { + foreach ($twitter_accounts as $screen_name => $account) { + if (!empty($screen_name)) { + $result = twitter_set_status($screen_name, $account['password'], $matches[2]); + if ($result->code == 200) { + bot_message($to, t('!nick: Successfully posted to Twitter as !screen_name.', array('!nick' => $data->nick, '!screen_name' => $screen_name))); + } + else { + bot_message($to, t('!nick: Failed posting to Twitter as !screen_name.', array('!nick' => $data->nick, '!screen_name' => $screen_name))); + } + } + } + } + else { + bot_message($to, t('!nick: You do not have any Twitter accounts setup.', array('!nick' => $data->nick))); + } + } + else { + bot_message($to, t('!nick: You do not have access to post to Twitter.', array('!nick' => $data->nick))); + } + } +} + +/** + * All responses are available via a query. + */ +function bot_twitter_irc_msg_query($data) { + bot_twitter_irc_msg_channel($data, TRUE); +} Index: bot_twitter/bot_twitter.info =================================================================== RCS file: bot_twitter/bot_twitter.info diff -N bot_twitter/bot_twitter.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ bot_twitter/bot_twitter.info 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,7 @@ +; $Id$ +name = Twitter Bot +package = Bot +description = "Allows users to instantly send Twitter updates through IRC." +dependencies[] = bot +dependencies[] = twitter +core = 6.x