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