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 switch(strtolower($cmd)) {
43 return new HelpCommand($user);
48 return new SubscribersCommand($user);
54 return new SubscriptionsCommand($user);
60 return new GroupsCommand($user);
64 list($other, $extra) = $this->split_arg($arg);
68 return new OnCommand($user, $other);
71 return new OnCommand($user);
75 list($other, $extra) = $this->split_arg($arg);
79 return new OffCommand($user, $other);
82 return new OffCommand($user);
89 return new OffCommand($user);
95 list($other, $extra) = $this->split_arg($arg);
99 return new JoinCommand($user, $other);
105 list($other, $extra) = $this->split_arg($arg);
109 return new DropCommand($user, $other);
116 list($other, $extra) = $this->split_arg($arg);
120 return new SubCommand($user, $other);
127 list($other, $extra) = $this->split_arg($arg);
131 return new UnsubCommand($user, $other);
138 list($other, $extra) = $this->split_arg($arg);
142 return new GetCommand($user, $other);
149 list($other, $extra) = $this->split_arg($arg);
153 return new MessageCommand($user, $other, $extra);
160 list($other, $extra) = $this->split_arg($arg);
164 return new ReplyCommand($user, $other, $extra);
170 list($other, $extra) = $this->split_arg($arg);
174 return new WhoisCommand($user, $other);
180 list($other, $extra) = $this->split_arg($arg);
184 return new FavCommand($user, $other);
190 list($other, $extra) = $this->split_arg($arg);
194 return new NudgeCommand($user, $other);
200 return new StatsCommand($user);
205 list($other, $extra) = $this->split_arg($arg);
209 return new InviteCommand($user, $other);
215 list($word, $extra) = $this->split_arg($arg);
218 } else if ($word == 'off') {
219 return new TrackOffCommand($user);
221 return new TrackCommand($user, $word);
227 list($word, $extra) = $this->split_arg($arg);
230 } else if ($word == 'all') {
231 return new TrackOffCommand($user);
233 return new UntrackCommand($user, $word);
240 return new TrackingCommand($user);
247 * Split arguments without triggering a PHP notice warning
249 function split_arg($text)
251 $pieces = explode(' ', $text, 2);
252 if (count($pieces) == 1) {