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) = self::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('StartInterpretCommand', array($cmd, $arg, $user, &$result))) {
46 $result = new HelpCommand($user);
53 $result = new LoginCommand($user);
58 list($other, $extra) = self::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) = self::split_arg($arg);
95 $result = new OnCommand($user, $other);
98 $result = new OnCommand($user);
103 list($other, $extra) = self::split_arg($arg);
107 $result = new OffCommand($user, $other);
110 $result = new OffCommand($user);
118 $result = new OffCommand($user);
125 list($other, $extra) = self::split_arg($arg);
129 $result = new JoinCommand($user, $other);
137 list($other, $extra) = self::split_arg($arg);
141 $result = new DropCommand($user, $other);
150 list($other, $extra) = self::split_arg($arg);
154 $result = new SubCommand($user, $other);
163 list($other, $extra) = self::split_arg($arg);
167 $result = new UnsubCommand($user, $other);
176 list($other, $extra) = self::split_arg($arg);
180 $result = new GetCommand($user, $other);
188 list($other, $extra) = self::split_arg($arg);
192 $result = new ReplyCommand($user, $other, $extra);
202 list($other, $extra) = self::split_arg($arg);
206 $result = new RepeatCommand($user, $other);
214 list($other, $extra) = self::split_arg($arg);
218 $result = new WhoisCommand($user, $other);
226 list($other, $extra) = self::split_arg($arg);
230 $result = new NudgeCommand($user, $other);
238 $result = new StatsCommand($user);
245 list($other, $extra) = self::split_arg($arg);
249 $result = new InviteCommand($user, $other);
259 list($other, $tags) = self::split_arg($arg);
263 $result = new TagCommand($user, $other, $tags);
272 list($other, $tags) = self::split_arg($arg);
276 $result = new UntagCommand($user, $other, $tags);
283 list($word, $extra) = self::split_arg($arg);
286 } else if ($word == 'off') {
287 $result = new TrackOffCommand($user);
289 $result = new TrackCommand($user, $word);
297 list($word, $extra) = self::split_arg($arg);
300 } else if ($word == 'all') {
301 $result = new TrackOffCommand($user);
303 $result = new UntrackCommand($user, $word);
312 $result = new TrackingCommand($user);
319 Event::handle('EndInterpretCommand', array($cmd, $arg, $user, &$result));
326 * Split arguments without triggering a PHP notice warning
328 static function split_arg($text)
330 $pieces = explode(' ', $text, 2);
331 if (count($pieces) == 1) {