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/channel.php');
29 function __construct($user=null)
34 function execute($channel)
40 class UnimplementedCommand extends Command
42 function execute($channel)
44 $channel->error($this->user, _("Sorry, this command is not yet implemented."));
48 class TrackingCommand extends UnimplementedCommand
52 class TrackOffCommand extends UnimplementedCommand
56 class TrackCommand extends UnimplementedCommand
59 function __construct($user, $word)
61 parent::__construct($user);
66 class UntrackCommand extends UnimplementedCommand
69 function __construct($user, $word)
71 parent::__construct($user);
76 class NudgeCommand extends UnimplementedCommand
79 function __construct($user, $other)
81 parent::__construct($user);
82 $this->other = $other;
86 class InviteCommand extends UnimplementedCommand
89 function __construct($user, $other)
91 parent::__construct($user);
92 $this->other = $other;
96 class StatsCommand extends Command
98 function execute($channel)
100 $profile = $this->user->getProfile();
102 $subs_count = $profile->subscriptionCount();
103 $subbed_count = $profile->subscriberCount();
104 $notice_count = $profile->noticeCount();
106 $channel->output($this->user, sprintf(_("Subscriptions: %1\$s\n".
107 "Subscribers: %2\$s\n".
115 class FavCommand extends Command
119 function __construct($user, $other)
121 parent::__construct($user);
122 $this->other = $other;
125 function execute($channel)
127 if(substr($this->other,0,1)=='#'){
128 //replying to a specific notice_id
130 $notice = Notice::staticGet(substr($this->other,1));
132 $channel->error($this->user, _('Notice with that id does not exist'));
135 $recipient = $notice->getProfile();
137 //replying to a given user's last notice
140 common_relative_profile($this->user, common_canonical_nickname($this->other));
143 $channel->error($this->user, _('No such user.'));
146 $notice = $recipient->getCurrentNotice();
148 $channel->error($this->user, _('User has no last notice'));
153 $fave = Fave::addNew($this->user, $notice);
156 $channel->error($this->user, _('Could not create favorite.'));
160 $other = User::staticGet('id', $recipient->id);
162 if ($other && $other->id != $user->id) {
163 if ($other->email && $other->emailnotifyfav) {
164 mail_notify_fave($other, $this->user, $notice);
168 $this->user->blowFavesCache();
170 $channel->output($this->user, _('Notice marked as fave.'));
174 class JoinCommand extends Command
178 function __construct($user, $other)
180 parent::__construct($user);
181 $this->other = $other;
184 function execute($channel)
187 $nickname = common_canonical_nickname($this->other);
188 $group = User_group::staticGet('nickname', $nickname);
192 $channel->error($cur, _('No such group.'));
196 if ($cur->isMember($group)) {
197 $channel->error($cur, _('You are already a member of that group'));
200 if (Group_block::isBlocked($group, $cur->getProfile())) {
201 $channel->error($cur, _('You have been blocked from that group by the admin.'));
205 $member = new Group_member();
207 $member->group_id = $group->id;
208 $member->profile_id = $cur->id;
209 $member->created = common_sql_now();
211 $result = $member->insert();
213 common_log_db_error($member, 'INSERT', __FILE__);
214 $channel->error($cur, sprintf(_('Could not join user %s to group %s'),
215 $cur->nickname, $group->nickname));
219 $channel->output($cur, sprintf(_('%s joined group %s'),
225 class DropCommand extends Command
229 function __construct($user, $other)
231 parent::__construct($user);
232 $this->other = $other;
235 function execute($channel)
238 $nickname = common_canonical_nickname($this->other);
239 $group = User_group::staticGet('nickname', $nickname);
243 $channel->error($cur, _('No such group.'));
247 if (!$cur->isMember($group)) {
248 $channel->error($cur, _('You are not a member of that group.'));
252 $member = new Group_member();
254 $member->group_id = $group->id;
255 $member->profile_id = $cur->id;
257 if (!$member->find(true)) {
258 $channel->error($cur,_('Could not find membership record.'));
261 $result = $member->delete();
263 common_log_db_error($member, 'INSERT', __FILE__);
264 $channel->error($cur, sprintf(_('Could not remove user %s to group %s'),
265 $cur->nickname, $group->nickname));
269 $channel->output($cur, sprintf(_('%s left group %s'),
276 class WhoisCommand extends Command
279 function __construct($user, $other)
281 parent::__construct($user);
282 $this->other = $other;
285 function execute($channel)
288 common_relative_profile($this->user, common_canonical_nickname($this->other));
291 $channel->error($this->user, _('No such user.'));
295 $whois = sprintf(_("%1\$s (%2\$s)"), $recipient->nickname,
296 $recipient->profileurl);
297 if ($recipient->fullname) {
298 $whois .= "\n" . sprintf(_('Fullname: %s'), $recipient->fullname);
300 if ($recipient->location) {
301 $whois .= "\n" . sprintf(_('Location: %s'), $recipient->location);
303 if ($recipient->homepage) {
304 $whois .= "\n" . sprintf(_('Homepage: %s'), $recipient->homepage);
306 if ($recipient->bio) {
307 $whois .= "\n" . sprintf(_('About: %s'), $recipient->bio);
309 $channel->output($this->user, $whois);
313 class MessageCommand extends Command
317 function __construct($user, $other, $text)
319 parent::__construct($user);
320 $this->other = $other;
324 function execute($channel)
326 $other = User::staticGet('nickname', common_canonical_nickname($this->other));
328 $len = mb_strlen($this->text);
331 $channel->error($this->user, _('No content!'));
335 $this->text = common_shorten_links($this->text);
337 if (Message::contentTooLong($this->text)) {
338 $channel->error($this->user, sprintf(_('Message too long - maximum is %d characters, you sent %d'),
339 Message::maxContent(), mb_strlen($this->text)));
344 $channel->error($this->user, _('No such user.'));
346 } else if (!$this->user->mutuallySubscribed($other)) {
347 $channel->error($this->user, _('You can\'t send a message to this user.'));
349 } else if ($this->user->id == $other->id) {
350 $channel->error($this->user, _('Don\'t send a message to yourself; just say it to yourself quietly instead.'));
353 $message = Message::saveNew($this->user->id, $other->id, $this->text, $channel->source());
355 $channel->output($this->user, sprintf(_('Direct message to %s sent'), $this->other));
357 $channel->error($this->user, _('Error sending direct message.'));
362 class GetCommand extends Command
367 function __construct($user, $other)
369 parent::__construct($user);
370 $this->other = $other;
373 function execute($channel)
375 $target_nickname = common_canonical_nickname($this->other);
378 common_relative_profile($this->user, $target_nickname);
381 $channel->error($this->user, _('No such user.'));
384 $notice = $target->getCurrentNotice();
386 $channel->error($this->user, _('User has no last notice'));
389 $notice_content = $notice->content;
391 $channel->output($this->user, $target_nickname . ": " . $notice_content);
395 class SubCommand extends Command
400 function __construct($user, $other)
402 parent::__construct($user);
403 $this->other = $other;
406 function execute($channel)
410 $channel->error($this->user, _('Specify the name of the user to subscribe to'));
414 $result = subs_subscribe_user($this->user, $this->other);
416 if ($result == 'true') {
417 $channel->output($this->user, sprintf(_('Subscribed to %s'), $this->other));
419 $channel->error($this->user, $result);
424 class UnsubCommand extends Command
429 function __construct($user, $other)
431 parent::__construct($user);
432 $this->other = $other;
435 function execute($channel)
438 $channel->error($this->user, _('Specify the name of the user to unsubscribe from'));
442 $result=subs_unsubscribe_user($this->user, $this->other);
445 $channel->output($this->user, sprintf(_('Unsubscribed from %s'), $this->other));
447 $channel->error($this->user, $result);
452 class OffCommand extends Command
455 function __construct($user, $other=null)
457 parent::__construct($user);
458 $this->other = $other;
460 function execute($channel)
463 $channel->error($this->user, _("Command not yet implemented."));
465 if ($channel->off($this->user)) {
466 $channel->output($this->user, _('Notification off.'));
468 $channel->error($this->user, _('Can\'t turn off notification.'));
474 class OnCommand extends Command
477 function __construct($user, $other=null)
479 parent::__construct($user);
480 $this->other = $other;
483 function execute($channel)
486 $channel->error($this->user, _("Command not yet implemented."));
488 if ($channel->on($this->user)) {
489 $channel->output($this->user, _('Notification on.'));
491 $channel->error($this->user, _('Can\'t turn on notification.'));
497 class HelpCommand extends Command
499 function execute($channel)
501 $channel->output($this->user,
503 "on - turn on notifications\n".
504 "off - turn off notifications\n".
505 "help - show this help\n".
506 "follow <nickname> - subscribe to user\n".
507 "leave <nickname> - unsubscribe from user\n".
508 "d <nickname> <text> - direct message to user\n".
509 "get <nickname> - get last notice from user\n".
510 "whois <nickname> - get profile info on user\n".
511 "fav <nickname> - add user's last notice as a 'fave'\n".
512 "fav #<notice_id> - add notice with the given id as a 'fave'\n".
513 "join <group> - join group\n".
514 "drop <group> - leave group\n".
515 "stats - get your stats\n".
516 "stop - same as 'off'\n".
517 "quit - same as 'off'\n".
518 "sub <nickname> - same as 'follow'\n".
519 "unsub <nickname> - same as 'leave'\n".
520 "last <nickname> - same as 'get'\n".
521 "on <nickname> - not yet implemented.\n".
522 "off <nickname> - not yet implemented.\n".
523 "nudge <nickname> - not yet implemented.\n".
524 "invite <phone number> - not yet implemented.\n".
525 "track <word> - not yet implemented.\n".
526 "untrack <word> - not yet implemented.\n".
527 "track off - not yet implemented.\n".
528 "untrack all - not yet implemented.\n".
529 "tracks - not yet implemented.\n".
530 "tracking - not yet implemented.\n"));