1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-22 21:40:08 +00:00

Read out available commands

This commit is contained in:
Tim Düsterhus 2013-06-01 14:37:18 +02:00
parent 9bb3a337a7
commit 9d637efa15
3 changed files with 27 additions and 2 deletions

View File

@ -180,7 +180,7 @@ The the word the caret is in will be passed to `autocomplete` and replaced if a
if beforeComplete is '' and toComplete.substring(0, 1) is '/' if beforeComplete is '' and toComplete.substring(0, 1) is '/'
regex = new RegExp "^#{WCF.String.escapeRegExp toComplete.substring 1}", "i" regex = new RegExp "^#{WCF.String.escapeRegExp toComplete.substring 1}", "i"
# TODO: Proper command list # TODO: Proper command list
commands = (command for command in [ 'gmute', 'gban', 'ban', 'mute', 'whisper', 'where', 'info' ] when regex.test command) commands = (command for command in v.config.installedCommands when regex.test command)
toComplete = '/' + commands[autocomplete.offset++ % commands.length] + ' ' if commands.length isnt 0 toComplete = '/' + commands[autocomplete.offset++ % commands.length] + ' ' if commands.length isnt 0
else else

View File

@ -50,6 +50,13 @@ class ChatPage extends \wcf\page\AbstractPage {
*/ */
public $rooms = array(); public $rooms = array();
/**
* List of installed commands.
*
* @var array<string>
*/
public $commands = array();
/** /**
* List of smilies in the default category. * List of smilies in the default category.
* *
@ -81,6 +88,7 @@ public function assignVariables() {
'room' => $this->room, 'room' => $this->room,
'roomID' => $this->roomID, 'roomID' => $this->roomID,
'rooms' => $this->rooms, 'rooms' => $this->rooms,
'commands' => $this->commands,
'defaultSmilies' => $this->defaultSmilies, 'defaultSmilies' => $this->defaultSmilies,
'smileyCategories' => $this->smileyCategories, 'smileyCategories' => $this->smileyCategories,
'sidebarCollapsed' => \wcf\system\user\collapsible\content\UserCollapsibleContentHandler::getInstance()->isCollapsed('com.woltlab.wcf.collapsibleSidebar', 'be.bastelstu.chat.ChatPage'), 'sidebarCollapsed' => \wcf\system\user\collapsible\content\UserCollapsibleContentHandler::getInstance()->isCollapsed('com.woltlab.wcf.collapsibleSidebar', 'be.bastelstu.chat.ChatPage'),
@ -95,6 +103,7 @@ public function readData() {
parent::readData(); parent::readData();
$this->readRoom(); $this->readRoom();
$this->readCommands();
// get default smilies // get default smilies
if (MODULE_SMILEY) { if (MODULE_SMILEY) {
@ -124,6 +133,21 @@ public function readParameters() {
if (isset($_REQUEST['id'])) $this->roomID = (int) $_REQUEST['id']; if (isset($_REQUEST['id'])) $this->roomID = (int) $_REQUEST['id'];
} }
/**
* Reads installed commands.
*/
public function readCommands() {
$regex = new \wcf\system\Regex('Command.class.php$');
$directory = \wcf\utilDirectoryUtil::getInstance(CHAT_DIR.'lib/system/command/commands/', false);
$files = $directory->getFiles(SORT_ASC, $regex);
foreach ($files as $file) {
$command = $regex->replace(basename($file), '');
if ($command == 'Plain') continue;
$this->commands[] = \wcf\util\StringUtil::toLowerCase($command);
}
}
/** /**
* Reads room data. * Reads room data.
*/ */

View File

@ -33,7 +33,8 @@
{$roomID}, {$roomID},
{ {
reloadTime: {@CHAT_RELOADTIME}, reloadTime: {@CHAT_RELOADTIME},
messageURL: '{link application="chat" controller="NewMessages"}{/link}' messageURL: '{link application="chat" controller="NewMessages"}{/link}',
installedCommands: [ {implode from=$commands item='command'}'{$command|encodeJS}'{/implode} ]
}, },
new WCF.Template('{literal}{if $newMessageCount}({#$newMessageCount}) {/if}{$title} - {/literal}{"chat.general.title"|language|encodeJS} - {PAGE_TITLE|language|encodeJS}'), new WCF.Template('{literal}{if $newMessageCount}({#$newMessageCount}) {/if}{$title} - {/literal}{"chat.general.title"|language|encodeJS} - {PAGE_TITLE|language|encodeJS}'),
new WCF.Template('{@$messageTemplate|encodeJS}'), new WCF.Template('{@$messageTemplate|encodeJS}'),