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
27 function handle_command($user, $text)
31 $text = preg_replace('/\s+/', ' ', trim($text));
32 list($cmd, $arg) = explode(' ', $text, 2);
34 # We try to support all the same commands as Twitter, see
35 # http://getsatisfaction.com/twitter/topics/what_are_the_twitter_commands
36 # There are a few compatibility commands from earlier versions of
39 switch(strtolower($cmd)) {
44 return new HelpCommand($user);
47 list($other, $extra) = explode(' ', $arg, 2);
51 return new OnCommand($user, $other);
54 return new OnCommand($user);
58 list($other, $extra) = explode(' ', $arg, 2);
62 return new OffCommand($user, $other);
65 return new OffCommand($user);
72 return new OffCommand($user);
79 list($other, $extra) = explode(' ', $arg, 2);
83 return new SubCommand($user, $other);
90 list($other, $extra) = explode(' ', $arg, 2);
94 return new UnsubCommand($user, $other);
101 list($other, $extra) = explode(' ', $arg, 2);
105 return new GetCommand($user, $other);
112 list($other, $extra) = explode(' ', $arg, 2);
116 return new MessageCommand($user, $other, $extra);
122 list($other, $extra) = explode(' ', $arg, 2);
126 return new WhoisCommand($user, $other);
132 list($other, $extra) = explode(' ', $arg, 2);
136 return new FavCommand($user, $other);
142 list($other, $extra) = explode(' ', $arg, 2);
146 return new NudgeCommand($user, $other);
152 return new StatsCommand($user);
157 list($other, $extra) = explode(' ', $arg, 2);
161 return new InviteCommand($user, $other);
167 list($word, $extra) = explode(' ', $arg, 2);
170 } else if ($word == 'off') {
171 return new TrackOffCommand($user);
173 return new TrackCommand($user, $word);
179 list($word, $extra) = explode(' ', $arg, 2);
182 } else if ($word == 'all') {
183 return new TrackOffCommand($user);
185 return new UntrackCommand($user, $word);
192 return new TrackingCommand($user);