3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
22 require_once INSTALLDIR.'/lib/command.php';
24 class CommandInterpreter
26 function handle_command($user, $text)
30 $text = preg_replace('/\s+/', ' ', trim($text));
31 list($cmd, $arg) = $this->split_arg($text);
33 // We try to support all the same commands as Twitter, see
34 // http://getsatisfaction.com/twitter/topics/what_are_the_twitter_commands
35 // There are a few compatibility commands from earlier versions of
38 $cmd = strtolower($cmd);
40 if (Event::handle('StartIntepretCommand', array($cmd, $arg, $user, &$result))) {
46 $result = new HelpCommand($user);
53 $result = new LoginCommand($user);
58 list($other, $extra) = $this->split_arg($arg);
62 $result = new LoseCommand($user, $other);
72 $result = new SubscribersCommand($user);
79 $result = new SubscriptionsCommand($user);
86 $result = new GroupsCommand($user);
91 list($other, $extra) = $this->split_arg($arg);
95 $result = new OnCommand($user, $other);
98 $result = new OnCommand($user);
103 list($other, $extra) = $this->split_arg($arg);
107 $result = new OffCommand($user, $other);
110 $result = new OffCommand($user);
118 $result = new OffCommand($user);
125 list($other, $extra) = $this->split_arg($arg);
129 $result = new JoinCommand($user, $other);
137 list($other, $extra) = $this->split_arg($arg);
141 $result = new DropCommand($user, $other);
150 list($other, $extra) = $this->split_arg($arg);
154 $result = new SubCommand($user, $other);
163 list($other, $extra) = $this->split_arg($arg);
167 $result = new UnsubCommand($user, $other);
176 list($other, $extra) = $this->split_arg($arg);
180 $result = new GetCommand($user, $other);
188 list($other, $extra) = $this->split_arg($arg);
192 $result = new MessageCommand($user, $other, $extra);
200 list($other, $extra) = $this->split_arg($arg);
204 $result = new ReplyCommand($user, $other, $extra);
214 list($other, $extra) = $this->split_arg($arg);
218 $result = new RepeatCommand($user, $other);
226 list($other, $extra) = $this->split_arg($arg);
230 $result = new WhoisCommand($user, $other);
238 list($other, $extra) = $this->split_arg($arg);
242 $result = new FavCommand($user, $other);
250 list($other, $extra) = $this->split_arg($arg);
254 $result = new NudgeCommand($user, $other);
262 $result = new StatsCommand($user);
269 list($other, $extra) = $this->split_arg($arg);
273 $result = new InviteCommand($user, $other);
283 list($other, $tags) = $this->split_arg($arg);
287 $result = new TagCommand($user, $other, $tags);
296 list($other, $tags) = $this->split_arg($arg);
300 $result = new UntagCommand($user, $other, $tags);
307 list($word, $extra) = $this->split_arg($arg);
310 } else if ($word == 'off') {
311 $result = new TrackOffCommand($user);
313 $result = new TrackCommand($user, $word);
321 list($word, $extra) = $this->split_arg($arg);
324 } else if ($word == 'all') {
325 $result = new TrackOffCommand($user);
327 $result = new UntrackCommand($user, $word);
336 $result = new TrackingCommand($user);
343 Event::handle('EndInterpretCommand', array($cmd, $arg, $user, &$result));
350 * Split arguments without triggering a PHP notice warning
352 function split_arg($text)
354 $pieces = explode(' ', $text, 2);
355 if (count($pieces) == 1) {