hooks for commands

This commit is contained in:
Evan Prodromou 2011-02-03 17:04:16 -05:00
parent a002d57736
commit 21feac3bea
2 changed files with 273 additions and 227 deletions

View File

@ -1069,3 +1069,16 @@ StartGroupSave: After initializing but before saving a group
EndGroupSave: After saving a group, aliases, and first member EndGroupSave: After saving a group, aliases, and first member
- $group: group that was saved - $group: group that was saved
StartInterpretCommand: Before running a command
- $cmd: First word in the string, 'foo' in 'foo argument'
- $arg: Argument, if any, like 'argument' in 'foo argument'
- $user: User who issued the command
- &$result: Resulting command; you can set this!
EndInterpretCommand: Before running a command
- $cmd: First word in the string, 'foo' in 'foo argument'
- $arg: Argument, if any, like 'argument' in 'foo argument'
- $user: User who issued the command
- $result: Resulting command

View File

@ -25,252 +25,285 @@ class CommandInterpreter
{ {
function handle_command($user, $text) function handle_command($user, $text)
{ {
# XXX: localise // XXX: localise
$text = preg_replace('/\s+/', ' ', trim($text)); $text = preg_replace('/\s+/', ' ', trim($text));
list($cmd, $arg) = $this->split_arg($text); list($cmd, $arg) = $this->split_arg($text);
# We try to support all the same commands as Twitter, see // We try to support all the same commands as Twitter, see
# http://getsatisfaction.com/twitter/topics/what_are_the_twitter_commands // http://getsatisfaction.com/twitter/topics/what_are_the_twitter_commands
# There are a few compatibility commands from earlier versions of // There are a few compatibility commands from earlier versions of
# StatusNet // StatusNet
if (Event::handle('StartIntepretCommand', array($cmd, $arg, $user, &$result))) {
switch(strtolower($cmd)) { switch(strtolower($cmd)) {
case 'help': case 'help':
if ($arg) { if ($arg) {
return null; $result = null;
} }
return new HelpCommand($user); $result = new HelpCommand($user);
break;
case 'login': case 'login':
if ($arg) { if ($arg) {
return null; $result = null;
} else { } else {
return new LoginCommand($user); $result = new LoginCommand($user);
} }
break;
case 'lose': case 'lose':
if ($arg) { if ($arg) {
list($other, $extra) = $this->split_arg($arg); list($other, $extra) = $this->split_arg($arg);
if ($extra) { if ($extra) {
return null; $result = null;
} else { } else {
return new LoseCommand($user, $other); $result = new LoseCommand($user, $other);
} }
} else { } else {
return null; $result = null;
} }
break;
case 'subscribers': case 'subscribers':
if ($arg) { if ($arg) {
return null; $result = null;
} else { } else {
return new SubscribersCommand($user); $result = new SubscribersCommand($user);
} }
break;
case 'subscriptions': case 'subscriptions':
if ($arg) { if ($arg) {
return null; $result = null;
} else { } else {
return new SubscriptionsCommand($user); $result = new SubscriptionsCommand($user);
} }
break;
case 'groups': case 'groups':
if ($arg) { if ($arg) {
return null; $result = null;
} else { } else {
return new GroupsCommand($user); $result = new GroupsCommand($user);
} }
break;
case 'on': case 'on':
if ($arg) { if ($arg) {
list($other, $extra) = $this->split_arg($arg); list($other, $extra) = $this->split_arg($arg);
if ($extra) { if ($extra) {
return null; $result = null;
} else { } else {
return new OnCommand($user, $other); $result = new OnCommand($user, $other);
} }
} else { } else {
return new OnCommand($user); $result = new OnCommand($user);
} }
break;
case 'off': case 'off':
if ($arg) { if ($arg) {
list($other, $extra) = $this->split_arg($arg); list($other, $extra) = $this->split_arg($arg);
if ($extra) { if ($extra) {
return null; $result = null;
} else { } else {
return new OffCommand($user, $other); $result = new OffCommand($user, $other);
} }
} else { } else {
return new OffCommand($user); $result = new OffCommand($user);
} }
break;
case 'stop': case 'stop':
case 'quit': case 'quit':
if ($arg) { if ($arg) {
return null; $result = null;
} else { } else {
return new OffCommand($user); $result = new OffCommand($user);
} }
break;
case 'join': case 'join':
if (!$arg) { if (!$arg) {
return null; $result = null;
} }
list($other, $extra) = $this->split_arg($arg); list($other, $extra) = $this->split_arg($arg);
if ($extra) { if ($extra) {
return null; $result = null;
} else { } else {
return new JoinCommand($user, $other); $result = new JoinCommand($user, $other);
} }
break;
case 'drop': case 'drop':
if (!$arg) { if (!$arg) {
return null; $result = null;
} }
list($other, $extra) = $this->split_arg($arg); list($other, $extra) = $this->split_arg($arg);
if ($extra) { if ($extra) {
return null; $result = null;
} else { } else {
return new DropCommand($user, $other); $result = new DropCommand($user, $other);
} }
break;
case 'follow': case 'follow':
case 'sub': case 'sub':
if (!$arg) { if (!$arg) {
return null; $result = null;
} }
list($other, $extra) = $this->split_arg($arg); list($other, $extra) = $this->split_arg($arg);
if ($extra) { if ($extra) {
return null; $result = null;
} else { } else {
return new SubCommand($user, $other); $result = new SubCommand($user, $other);
} }
break;
case 'leave': case 'leave':
case 'unsub': case 'unsub':
if (!$arg) { if (!$arg) {
return null; $result = null;
} }
list($other, $extra) = $this->split_arg($arg); list($other, $extra) = $this->split_arg($arg);
if ($extra) { if ($extra) {
return null; $result = null;
} else { } else {
return new UnsubCommand($user, $other); $result = new UnsubCommand($user, $other);
} }
break;
case 'get': case 'get':
case 'last': case 'last':
if (!$arg) { if (!$arg) {
return null; $result = null;
} }
list($other, $extra) = $this->split_arg($arg); list($other, $extra) = $this->split_arg($arg);
if ($extra) { if ($extra) {
return null; $result = null;
} else { } else {
return new GetCommand($user, $other); $result = new GetCommand($user, $other);
} }
break;
case 'd': case 'd':
case 'dm': case 'dm':
if (!$arg) { if (!$arg) {
return null; $result = null;
} }
list($other, $extra) = $this->split_arg($arg); list($other, $extra) = $this->split_arg($arg);
if (!$extra) { if (!$extra) {
return null; $result = null;
} else { } else {
return new MessageCommand($user, $other, $extra); $result = new MessageCommand($user, $other, $extra);
} }
break;
case 'r': case 'r':
case 'reply': case 'reply':
if (!$arg) { if (!$arg) {
return null; $result = null;
} }
list($other, $extra) = $this->split_arg($arg); list($other, $extra) = $this->split_arg($arg);
if (!$extra) { if (!$extra) {
return null; $result = null;
} else { } else {
return new ReplyCommand($user, $other, $extra); $result = new ReplyCommand($user, $other, $extra);
} }
break;
case 'repeat': case 'repeat':
case 'rp': case 'rp':
case 'rt': case 'rt':
case 'rd': case 'rd':
if (!$arg) { if (!$arg) {
return null; $result = null;
} }
list($other, $extra) = $this->split_arg($arg); list($other, $extra) = $this->split_arg($arg);
if ($extra) { if ($extra) {
return null; $result = null;
} else { } else {
return new RepeatCommand($user, $other); $result = new RepeatCommand($user, $other);
} }
break;
case 'whois': case 'whois':
if (!$arg) { if (!$arg) {
return null; $result = null;
} }
list($other, $extra) = $this->split_arg($arg); list($other, $extra) = $this->split_arg($arg);
if ($extra) { if ($extra) {
return null; $result = null;
} else { } else {
return new WhoisCommand($user, $other); $result = new WhoisCommand($user, $other);
} }
break;
case 'fav': case 'fav':
if (!$arg) { if (!$arg) {
return null; $result = null;
} }
list($other, $extra) = $this->split_arg($arg); list($other, $extra) = $this->split_arg($arg);
if ($extra) { if ($extra) {
return null; $result = null;
} else { } else {
return new FavCommand($user, $other); $result = new FavCommand($user, $other);
} }
break;
case 'nudge': case 'nudge':
if (!$arg) { if (!$arg) {
return null; $result = null;
} }
list($other, $extra) = $this->split_arg($arg); list($other, $extra) = $this->split_arg($arg);
if ($extra) { if ($extra) {
return null; $result = null;
} else { } else {
return new NudgeCommand($user, $other); $result = new NudgeCommand($user, $other);
} }
break;
case 'stats': case 'stats':
if ($arg) { if ($arg) {
return null; $result = null;
} }
return new StatsCommand($user); $result = new StatsCommand($user);
break;
case 'invite': case 'invite':
if (!$arg) { if (!$arg) {
return null; $result = null;
} }
list($other, $extra) = $this->split_arg($arg); list($other, $extra) = $this->split_arg($arg);
if ($extra) { if ($extra) {
return null; $result = null;
} else { } else {
return new InviteCommand($user, $other); $result = new InviteCommand($user, $other);
} }
break;
case 'track': case 'track':
if (!$arg) { if (!$arg) {
return null; $result = null;
} }
list($word, $extra) = $this->split_arg($arg); list($word, $extra) = $this->split_arg($arg);
if ($extra) { if ($extra) {
return null; $result = null;
} else if ($word == 'off') { } else if ($word == 'off') {
return new TrackOffCommand($user); $result = new TrackOffCommand($user);
} else { } else {
return new TrackCommand($user, $word); $result = new TrackCommand($user, $word);
} }
break;
case 'untrack': case 'untrack':
if (!$arg) { if (!$arg) {
return null; $result = null;
} }
list($word, $extra) = $this->split_arg($arg); list($word, $extra) = $this->split_arg($arg);
if ($extra) { if ($extra) {
return null; $result = null;
} else if ($word == 'all') { } else if ($word == 'all') {
return new TrackOffCommand($user); $result = new TrackOffCommand($user);
} else { } else {
return new UntrackCommand($user, $word); $result = new UntrackCommand($user, $word);
} }
break;
case 'tracks': case 'tracks':
case 'tracking': case 'tracking':
if ($arg) { if ($arg) {
return null; $result = null;
} }
return new TrackingCommand($user); $result = new TrackingCommand($user);
break;
default: default:
return false; $result = false;
} }
Event::handle('EndInterpretCommand', array($cmd, $arg, $user, $result));
}
return $result;
} }
/** /**