diff options
author | Craig Andrews <candrews@integralblue.com> | 2009-10-27 22:30:21 -0400 |
---|---|---|
committer | Craig Andrews <candrews@integralblue.com> | 2009-10-27 22:30:21 -0400 |
commit | da16dc05a81e2fcc1ed89fe16717f2652265f23a (patch) | |
tree | 0bb8bdeed85dda9a6ce6c12972db24668771ff65 /lib | |
parent | 7b30e3c00f9fea529ee71a9783006956960ca5e2 (diff) |
Added a new "reply" command
Diffstat (limited to 'lib')
-rw-r--r-- | lib/command.php | 71 | ||||
-rw-r--r-- | lib/commandinterpreter.php | 11 |
2 files changed, 80 insertions, 2 deletions
diff --git a/lib/command.php b/lib/command.php index 6ece01b96..d7ae11361 100644 --- a/lib/command.php +++ b/lib/command.php @@ -125,7 +125,7 @@ class FavCommand extends Command function execute($channel) { if(substr($this->other,0,1)=='#'){ - //replying to a specific notice_id + //favoriting a specific notice_id $notice = Notice::staticGet(substr($this->other,1)); if (!$notice) { @@ -134,7 +134,7 @@ class FavCommand extends Command } $recipient = $notice->getProfile(); }else{ - //replying to a given user's last notice + //favoriting a given user's last notice $recipient = common_relative_profile($this->user, common_canonical_nickname($this->other)); @@ -359,6 +359,71 @@ class MessageCommand extends Command } } +class ReplyCommand extends Command +{ + var $other = null; + var $text = null; + function __construct($user, $other, $text) + { + parent::__construct($user); + $this->other = $other; + $this->text = $text; + } + + function execute($channel) + { + if(substr($this->other,0,1)=='#'){ + //replying to a specific notice_id + + $notice = Notice::staticGet(substr($this->other,1)); + if (!$notice) { + $channel->error($this->user, _('Notice with that id does not exist')); + return; + } + $recipient = $notice->getProfile(); + }else{ + //replying to a given user's last notice + + $recipient = + common_relative_profile($this->user, common_canonical_nickname($this->other)); + + if (!$recipient) { + $channel->error($this->user, _('No such user.')); + return; + } + $notice = $recipient->getCurrentNotice(); + if (!$notice) { + $channel->error($this->user, _('User has no last notice')); + return; + } + } + + $len = mb_strlen($this->text); + + if ($len == 0) { + $channel->error($this->user, _('No content!')); + return; + } + + $this->text = common_shorten_links($this->text); + + if (Notice::contentTooLong($this->text)) { + $channel->error($this->user, sprintf(_('Notice too long - maximum is %d characters, you sent %d'), + Notice::maxContent(), mb_strlen($this->text))); + return; + } + + $notice = Notice::saveNew($this->user->id, $this->text, $channel->source(), 1, + $notice->id); + if ($notice) { + $channel->output($this->user, sprintf(_('Reply to %s sent'), $recipient->nickname)); + } else { + $channel->error($this->user, _('Error saving notice.')); + } + common_broadcast_notice($notice); + } +} + class GetCommand extends Command { @@ -510,6 +575,8 @@ class HelpCommand extends Command "whois <nickname> - get profile info on user\n". "fav <nickname> - add user's last notice as a 'fave'\n". "fav #<notice_id> - add notice with the given id as a 'fave'\n". + "reply #<notice_id> - reply to notice with a given id\n". + "reply <nickname> - reply to the last notice from user\n". "join <group> - join group\n". "drop <group> - leave group\n". "stats - get your stats\n". diff --git a/lib/commandinterpreter.php b/lib/commandinterpreter.php index 60fc4c3c4..b921a17cc 100644 --- a/lib/commandinterpreter.php +++ b/lib/commandinterpreter.php @@ -134,6 +134,17 @@ class CommandInterpreter } else { return new MessageCommand($user, $other, $extra); } + case 'r': + case 'reply': + if (!$arg) { + return null; + } + list($other, $extra) = $this->split_arg($arg); + if (!$extra) { + return null; + } else { + return new ReplyCommand($user, $other, $extra); + } case 'whois': if (!$arg) { return null; |