/** * Handle hooks supported bot commands. Note multiple bots may support the same commands, and all respond. It is recommended all bots support the command 'help'. * * @param AUTO_LINK The ID of the chat room * @param string The command used. This is just the chat message, so you can encode and recognise your own parameter scheme if you like. * @return ?string Bot reply (NULL: bot does not handle the command) */ function handle_commands($room_id, $command) { switch ($command) { case 'help': $out = do_lang('CHAT_HELP_BOTMSG'); return do_lang('CHAT_WEBSITE_HELPER_BOT', $out); case 'users_online': // On the site $count = 0; $members = get_online_members(true, NULL, $count); if (is_null($members)) { return do_lang('TOO_MANY_USERS_ONLINE'); } $guests = 0; $site_members = ''; foreach ($members as $member) { if (is_guest($member['the_user']) || is_null($member['cache_username'])) { $guests++; } else { if ($site_members != '') { $site_members .= ', '; } $site_members .= '{{' . $member['cache_username'] . '}}'; } } // In this room $room_members = get_chatters_in_room($room_id); $_room_members = ''; foreach ($room_members as $room_member) { if ($_room_members != '') { $_room_members .= ', '; } $_room_members .= '{{' . $room_member . '}}'; } // Show our complete result $out = do_lang('CHAT_USERSONLINE_BOTMSG', $site_members, $_room_members); return do_lang('CHAT_WEBSITE_HELPER_BOT', $out); case 'time': $out = do_lang('CHAT_TIME_BOTMSG', get_timezoned_date(time(), true, true, true, true)); return do_lang('CHAT_WEBSITE_HELPER_BOT', $out); } return NULL; }
/** * Give ability to reply to any communication. * * @param AUTO_LINK The ID of the chat room * @param string The message used. * @return ?string Bot reply (NULL: bot does not handle the command) */ function reply_to_any_communication($room_id, $string) { $people = get_chatters_in_room($room_id); if (count($people) > 2) { return NULL; } // Don't spam if noone is here if (running_script('shoutbox')) { return NULL; } // Messes up shoutbox $is_im = $GLOBALS['SITE_DB']->query_value('chat_rooms', 'is_im', array('id' => $room_id)); if ($is_im == 1) { return NULL; } $message = preg_replace('#\\[[^\\[\\]]*\\]#U', '', $string); if ($message == '') { return NULL; } return $this->handle_commands($room_id, $message); }
/** * The UI for a chat room. * * @return tempcode The UI */ function chat_room() { require_javascript('javascript_yahoo_2'); require_javascript('javascript_colour_picker'); require_javascript('javascript_posting'); require_css('colour_picker'); $prefs = @$_COOKIE['ocp_chat_prefs']; $prefs = @explode(';', $prefs); //$mode=get_param('mode',''); $room_id = get_param_integer('id', 1); $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=chat&filter=' . strval($room_id); $room_check = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('id', 'is_im', 'allow_list', 'allow_list_groups', 'disallow_list', 'disallow_list_groups', 'room_owner'), array('id' => $room_id), '', 1); if (!array_key_exists(0, $room_check)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } check_chatroom_access($room_check[0]); $posting_name = do_lang_tempcode('SEND_MESSAGE'); $keep = symbol_tempcode('KEEP'); $posting_url = find_script('messages') . '?mode=2&room_id=' . strval($room_id) . $keep->evaluate(); $messages_link = find_script('messages') . '?room_id=' . strval($room_id) . '&zone=' . get_zone_name() . $keep->evaluate(); $comcode_help = build_url(array('page' => 'userguide_comcode'), get_comcode_zone('userguide_comcode')); $chatcode_help = build_url(array('page' => 'userguide_chatcode'), get_comcode_zone('userguide_chatcode')); $buttons = new ocp_tempcode(); $_buttons = array('url', 'thumb', 'email', 'code', 'hide'); if (has_specific_permission(get_member(), 'comcode_dangerous')) { $_buttons[] = 'html'; } foreach ($_buttons as $button) { $buttons->attach(do_template('COMCODE_EDITOR_BUTTON', array('_GUID' => '4fd75edb2d091b1c78a71c653efb18f0', 'DIVIDER' => false, 'FIELD_NAME' => 'post', 'TITLE' => do_lang_tempcode('INPUT_COMCODE_' . $button), 'B' => $button))); } if (!is_guest()) { $_buttons = array('private_message', 'invite'); if (has_specific_permission(get_member(), 'create_private_room')) { $_buttons[] = 'new_room'; } foreach ($_buttons as $button) { $buttons->attach(do_template('CHATCODE_EDITOR_BUTTON', array('_GUID' => 'f1c3ccc2b6f0b68d71b7d256b3817cf3', 'TITLE' => do_lang_tempcode('INPUT_CHATCODE_' . $button), 'B' => $button))); } } $micro_buttons = new ocp_tempcode(); $_micro_buttons = array('b', 'i'); foreach ($_micro_buttons as $button) { $micro_buttons->attach(do_template('COMCODE_EDITOR_MICRO_BUTTON', array('_GUID' => '3ced1e569e0c6feaeadbc09f7f89e7ee', 'FIELD_NAME' => 'post', 'TITLE' => do_lang_tempcode('INPUT_COMCODE_' . $button), 'B' => $button))); } $user_colour = array_key_exists(0, $prefs) && $prefs[0] != '' ? $prefs[0] : get_option('chat_default_post_colour'); $line_contents = array_key_exists(1, $prefs) && $prefs[1] != '' ? $prefs[1] : get_option('chat_default_post_font'); $cs_post_url = build_url(array('page' => '_SELF', 'type' => 'options', 'id' => $room_id), '_SELF'); $yourname = $GLOBALS['FORUM_DRIVER']->get_username(get_member()); if (is_guest()) { $yourname .= '-' . substr(md5(get_ip_address()), 0, 5); } $messages_php = find_script('messages'); $debug = get_param_integer('debug', 0) == 1 ? 'block' : 'none'; $title = get_page_title('ROOM'); if (has_actual_page_access(get_member(), 'cms_chat', NULL, array('chat', strval($room_id)), array('edit_lowrange_content', $room_check[0]['room_owner'] == get_member() ? 'moderate_my_private_rooms' : NULL))) { $link = build_url(array('page' => 'cms_chat', 'type' => 'room', 'id' => $room_id), get_module_zone('cms_chat')); $modlink = hyperlink($link, do_lang_tempcode('CHAT_MOD_PANEL'), true); } else { $modlink = new ocp_tempcode(); } if (has_actual_page_access(get_member(), 'admin_chat')) { // The user is staff, so let him have the admin link $link = build_url(array('page' => 'admin_chat', 'type' => '_ed', 'id' => $room_id), 'adminzone'); $adminlink = hyperlink($link, do_lang_tempcode('EDIT_CHATROOM'), true); } else { $adminlink = new ocp_tempcode(); } $link = build_url(array('page' => '_SELF', 'type' => 'room', 'id' => $room_id), '_SELF'); $refreshlink = hyperlink($link, do_lang_tempcode('CHAT_REFRESH')); $link = build_url(array('page' => '_SELF', 'type' => 'download_logs'), '_SELF'); $downloadlink = hyperlink(build_url(array('page' => '_SELF', 'type' => 'download_logs', 'id' => $room_id), '_SELF'), do_lang_tempcode('CHAT_DOWNLOAD_LOGS'), true); $seteffectslink = hyperlink(build_url(array('page' => '_SELF', 'type' => 'set_effects'), '_SELF'), do_lang_tempcode('CHAT_SET_EFFECTS'), true); $links = array($adminlink, $modlink, $refreshlink, $downloadlink, $seteffectslink); breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('CHAT_LOBBY_END_CHAT')))); return do_template('CHAT_SCREEN', array('_GUID' => '867a0b050c050c81d33482d131783eb0', 'CHATTERS' => get_chatters_in_room_tpl(get_chatters_in_room($room_id)), 'CHAT_SOUND' => get_chat_sound_tpl(), 'ROOM_ID' => strval($room_id), 'DEBUG' => $debug, 'MESSAGES_PHP' => $messages_php, 'TEXT_COLOUR_DEFAULT' => $user_colour, 'FONT_NAME_DEFAULT' => $line_contents, 'OPTIONS_URL' => $cs_post_url, 'COMCODE_HELP' => $comcode_help, 'CHATCODE_HELP' => $chatcode_help, 'ROOM_NAME' => get_chatroom_name(get_param_integer('id', 1)), 'MICRO_BUTTONS' => $micro_buttons, 'BUTTONS' => $buttons, 'YOUR_NAME' => $yourname, 'MESSAGES_LINK' => $messages_link, 'POSTING_URL' => $posting_url, 'SUBMIT_VALUE' => $posting_name, 'INTRODUCTION' => '', 'TITLE' => $title, 'LINKS' => $links)); }
/** * Enter the current member to the chat lobby / Mark them available. */ function enter_chat_lobby() { if (is_guest()) { return; } require_css('chat'); require_lang('chat'); require_javascript('javascript_ajax'); require_javascript('javascript_chat'); require_javascript('javascript_sound'); if (!array_key_exists(get_member(), get_chatters_in_room(NULL)) && !is_invisible()) { $GLOBALS['SITE_DB']->query_insert('chat_active', array('member_id' => get_member(), 'date_and_time' => time(), 'room_id' => NULL)); $GLOBALS['SITE_DB']->query_insert('chat_events', array('e_type_code' => 'BECOME_ACTIVE', 'e_member_id' => get_member(), 'e_room_id' => NULL, 'e_date_and_time' => time())); } }