3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, 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('LACONICA')) { exit(1); }
22 require_once(INSTALLDIR.'/classes/Command.php');
24 class CommandInterpreter {
26 function handle_command($user, $text) {
29 $text = preg_replace('/\s+/', ' ', trim($text));
30 list($cmd, $arg) = explode(' ', $text, 2);
32 # We try to support all the same commands as Twitter, see
33 # http://getsatisfaction.com/twitter/topics/what_are_the_twitter_commands
34 # There are a few compatibility commands from earlier versions of
37 switch(strtolower($cmd)) {
42 return new HelpCommand($user);
45 list($other, $extra) = explode(' ', $arg, 2);
49 return new OnCommand($user, $other);
52 return new OnCommand($user);
56 list($other, $extra) = explode(' ', $arg, 2);
60 return new OffCommand($user, $other);
63 return new OffCommand($user);
70 return new OffCommand($user);
77 list($other, $extra) = explode(' ', $arg, 2);
81 return new SubCommand($user, $other);
88 list($other, $extra) = explode(' ', $arg, 2);
92 return new UnsubCommand($user, $other);
99 list($other, $extra) = explode(' ', $arg, 2);
103 return new GetCommand($user, $other);
110 list($other, $extra) = explode(' ', $arg, 2);
114 return new MessageCommand($user, $other, $extra);
120 list($other, $extra) = explode(' ', $arg, 2);
124 return new WhoisCommand($user, $other);
130 list($other, $extra) = explode(' ', $arg, 2);
134 return new FavCommand($user, $other);
140 list($other, $extra) = explode(' ', $arg, 2);
144 return new NudgeCommand($user, $other);
150 return new StatsCommand($user);
155 list($other, $extra) = explode(' ', $arg, 2);
159 return new InviteCommand($user, $other);
165 list($word, $extra) = explode(' ', $arg, 2);
168 } else if ($word == 'off') {
169 return new TrackOffCommand($user);
171 return new TrackCommand($user, $word);
177 list($word, $extra) = explode(' ', $arg, 2);
180 } else if ($word == 'all') {
181 return new TrackOffCommand($user);
183 return new UntrackCommand($user, $word);
190 return new TrackingCommand($user);