]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/commandinterpreter.php
628f55c2aaf6c24068552bcade0b3ddfa69d9a5c
[quix0rs-gnu-social.git] / lib / commandinterpreter.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, StatusNet, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once INSTALLDIR.'/lib/command.php';
23
24 class CommandInterpreter
25 {
26     function handle_command($user, $text)
27     {
28         # XXX: localise
29
30         $text = preg_replace('/\s+/', ' ', trim($text));
31         list($cmd, $arg) = explode(' ', $text, 2);
32
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
36         # StatusNet
37
38         switch(strtolower($cmd)) {
39          case 'help':
40             if ($arg) {
41                 return null;
42             }
43             return new HelpCommand($user);
44          case 'on':
45             if ($arg) {
46                 list($other, $extra) = explode(' ', $arg, 2);
47                 if ($extra) {
48                     return null;
49                 } else {
50                     return new OnCommand($user, $other);
51                 }
52             } else {
53                 return new OnCommand($user);
54             }
55          case 'off':
56             if ($arg) {
57                 list($other, $extra) = explode(' ', $arg, 2);
58                 if ($extra) {
59                     return null;
60                 } else {
61                     return new OffCommand($user, $other);
62                 }
63             } else {
64                 return new OffCommand($user);
65             }
66          case 'stop':
67          case 'quit':
68             if ($arg) {
69                 return null;
70             } else {
71                 return new OffCommand($user);
72             }
73          case 'follow':
74          case 'sub':
75             if (!$arg) {
76                 return null;
77             }
78             list($other, $extra) = explode(' ', $arg, 2);
79             if ($extra) {
80                 return null;
81             } else {
82                 return new SubCommand($user, $other);
83             }
84          case 'leave':
85          case 'unsub':
86             if (!$arg) {
87                 return null;
88             }
89             list($other, $extra) = explode(' ', $arg, 2);
90             if ($extra) {
91                 return null;
92             } else {
93                 return new UnsubCommand($user, $other);
94             }
95          case 'get':
96          case 'last':
97             if (!$arg) {
98                 return null;
99             }
100             list($other, $extra) = explode(' ', $arg, 2);
101             if ($extra) {
102                 return null;
103             } else {
104                 return new GetCommand($user, $other);
105             }
106          case 'd':
107          case 'dm':
108             if (!$arg) {
109                 return null;
110             }
111             list($other, $extra) = explode(' ', $arg, 2);
112             if (!$extra) {
113                 return null;
114             } else {
115                 return new MessageCommand($user, $other, $extra);
116             }
117          case 'whois':
118             if (!$arg) {
119                 return null;
120             }
121             list($other, $extra) = explode(' ', $arg, 2);
122             if ($extra) {
123                 return null;
124             } else {
125                 return new WhoisCommand($user, $other);
126             }
127          case 'fav':
128             if (!$arg) {
129                 return null;
130             }
131             list($other, $extra) = explode(' ', $arg, 2);
132             if ($extra) {
133                 return null;
134             } else {
135                 return new FavCommand($user, $other);
136             }
137          case 'nudge':
138             if (!$arg) {
139                 return null;
140             }
141             list($other, $extra) = explode(' ', $arg, 2);
142             if ($extra) {
143                 return null;
144             } else {
145                 return new NudgeCommand($user, $other);
146             }
147          case 'stats':
148             if ($arg) {
149                 return null;
150             }
151             return new StatsCommand($user);
152          case 'invite':
153             if (!$arg) {
154                 return null;
155             }
156             list($other, $extra) = explode(' ', $arg, 2);
157             if ($extra) {
158                 return null;
159             } else {
160                 return new InviteCommand($user, $other);
161             }
162          case 'track':
163             if (!$arg) {
164                 return null;
165             }
166             list($word, $extra) = explode(' ', $arg, 2);
167             if ($extra) {
168                 return null;
169             } else if ($word == 'off') {
170                 return new TrackOffCommand($user);
171             } else {
172                 return new TrackCommand($user, $word);
173             }
174          case 'untrack':
175             if (!$arg) {
176                 return null;
177             }
178             list($word, $extra) = explode(' ', $arg, 2);
179             if ($extra) {
180                 return null;
181             } else if ($word == 'all') {
182                 return new TrackOffCommand($user);
183             } else {
184                 return new UntrackCommand($user, $word);
185             }
186          case 'tracks':
187          case 'tracking':
188             if ($arg) {
189                 return null;
190             }
191             return new TrackingCommand($user);
192          default:
193             return false;
194         }
195     }
196 }
197