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 //favoriting 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 //favoriting 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 ReplyCommand extends Command
366 function __construct($user, $other, $text)
368 parent::__construct($user);
369 $this->other = $other;
373 function execute($channel)
375 if(substr($this->other,0,1)=='#'){
376 //replying to a specific notice_id
378 $notice = Notice::staticGet(substr($this->other,1));
380 $channel->error($this->user, _('Notice with that id does not exist'));
383 $recipient = $notice->getProfile();
385 //replying to a given user's last notice
388 common_relative_profile($this->user, common_canonical_nickname($this->other));
391 $channel->error($this->user, _('No such user.'));
394 $notice = $recipient->getCurrentNotice();
396 $channel->error($this->user, _('User has no last notice'));
401 $len = mb_strlen($this->text);
404 $channel->error($this->user, _('No content!'));
408 $this->text = common_shorten_links($this->text);
410 if (Notice::contentTooLong($this->text)) {
411 $channel->error($this->user, sprintf(_('Notice too long - maximum is %d characters, you sent %d'),
412 Notice::maxContent(), mb_strlen($this->text)));
416 $notice = Notice::saveNew($this->user->id, $this->text, $channel->source(), 1,
419 $channel->output($this->user, sprintf(_('Reply to %s sent'), $recipient->nickname));
421 $channel->error($this->user, _('Error saving notice.'));
423 common_broadcast_notice($notice);
427 class GetCommand extends Command
432 function __construct($user, $other)
434 parent::__construct($user);
435 $this->other = $other;
438 function execute($channel)
440 $target_nickname = common_canonical_nickname($this->other);
443 common_relative_profile($this->user, $target_nickname);
446 $channel->error($this->user, _('No such user.'));
449 $notice = $target->getCurrentNotice();
451 $channel->error($this->user, _('User has no last notice'));
454 $notice_content = $notice->content;
456 $channel->output($this->user, $target_nickname . ": " . $notice_content);
460 class SubCommand extends Command
465 function __construct($user, $other)
467 parent::__construct($user);
468 $this->other = $other;
471 function execute($channel)
475 $channel->error($this->user, _('Specify the name of the user to subscribe to'));
479 $result = subs_subscribe_user($this->user, $this->other);
481 if ($result == 'true') {
482 $channel->output($this->user, sprintf(_('Subscribed to %s'), $this->other));
484 $channel->error($this->user, $result);
489 class UnsubCommand extends Command
494 function __construct($user, $other)
496 parent::__construct($user);
497 $this->other = $other;
500 function execute($channel)
503 $channel->error($this->user, _('Specify the name of the user to unsubscribe from'));
507 $result=subs_unsubscribe_user($this->user, $this->other);
510 $channel->output($this->user, sprintf(_('Unsubscribed from %s'), $this->other));
512 $channel->error($this->user, $result);
517 class OffCommand extends Command
520 function __construct($user, $other=null)
522 parent::__construct($user);
523 $this->other = $other;
525 function execute($channel)
528 $channel->error($this->user, _("Command not yet implemented."));
530 if ($channel->off($this->user)) {
531 $channel->output($this->user, _('Notification off.'));
533 $channel->error($this->user, _('Can\'t turn off notification.'));
539 class OnCommand extends Command
542 function __construct($user, $other=null)
544 parent::__construct($user);
545 $this->other = $other;
548 function execute($channel)
551 $channel->error($this->user, _("Command not yet implemented."));
553 if ($channel->on($this->user)) {
554 $channel->output($this->user, _('Notification on.'));
556 $channel->error($this->user, _('Can\'t turn on notification.'));
562 class HelpCommand extends Command
564 function execute($channel)
566 $channel->output($this->user,
568 "on - turn on notifications\n".
569 "off - turn off notifications\n".
570 "help - show this help\n".
571 "follow <nickname> - subscribe to user\n".
572 "leave <nickname> - unsubscribe from user\n".
573 "d <nickname> <text> - direct message to user\n".
574 "get <nickname> - get last notice from user\n".
575 "whois <nickname> - get profile info on user\n".
576 "fav <nickname> - add user's last notice as a 'fave'\n".
577 "fav #<notice_id> - add notice with the given id as a 'fave'\n".
578 "reply #<notice_id> - reply to notice with a given id\n".
579 "reply <nickname> - reply to the last notice from user\n".
580 "join <group> - join group\n".
581 "drop <group> - leave group\n".
582 "stats - get your stats\n".
583 "stop - same as 'off'\n".
584 "quit - same as 'off'\n".
585 "sub <nickname> - same as 'follow'\n".
586 "unsub <nickname> - same as 'leave'\n".
587 "last <nickname> - same as 'get'\n".
588 "on <nickname> - not yet implemented.\n".
589 "off <nickname> - not yet implemented.\n".
590 "nudge <nickname> - not yet implemented.\n".
591 "invite <phone number> - not yet implemented.\n".
592 "track <word> - not yet implemented.\n".
593 "untrack <word> - not yet implemented.\n".
594 "track off - not yet implemented.\n".
595 "untrack all - not yet implemented.\n".
596 "tracks - not yet implemented.\n".
597 "tracking - not yet implemented.\n"));