]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/commandinterpreter.php
Merge branch '1.0.x' into schema-x
[quix0rs-gnu-social.git] / lib / commandinterpreter.php
index 6e4340e5dcac05529218c6246b2aff02e35a62fa..c288c2e5f0ec66d5d781b067417bbed6931eae3f 100644 (file)
@@ -28,7 +28,7 @@ class CommandInterpreter
         # XXX: localise
 
         $text = preg_replace('/\s+/', ' ', trim($text));
-        list($cmd, $arg) = explode(' ', $text, 2);
+        list($cmd, $arg) = $this->split_arg($text);
 
         # We try to support all the same commands as Twitter, see
         # http://getsatisfaction.com/twitter/topics/what_are_the_twitter_commands
@@ -41,9 +41,44 @@ class CommandInterpreter
                 return null;
             }
             return new HelpCommand($user);
+         case 'login':
+            if ($arg) {
+                return null;
+            } else {
+                return new LoginCommand($user);
+            }
+         case 'lose':
+            if ($arg) {
+                list($other, $extra) = $this->split_arg($arg);
+                if ($extra) {
+                    return null;
+                } else {
+                    return new LoseCommand($user, $other);
+                }
+            } else {
+              return null;
+            }
+         case 'subscribers':
+            if ($arg) {
+                return null;
+            } else {
+                return new SubscribersCommand($user);
+            }
+         case 'subscriptions':
+            if ($arg) {
+                return null;
+            } else {
+                return new SubscriptionsCommand($user);
+            }
+         case 'groups':
+            if ($arg) {
+                return null;
+            } else {
+                return new GroupsCommand($user);
+            }
          case 'on':
             if ($arg) {
-                list($other, $extra) = explode(' ', $arg, 2);
+                list($other, $extra) = $this->split_arg($arg);
                 if ($extra) {
                     return null;
                 } else {
@@ -54,7 +89,7 @@ class CommandInterpreter
             }
          case 'off':
             if ($arg) {
-                list($other, $extra) = explode(' ', $arg, 2);
+                list($other, $extra) = $this->split_arg($arg);
                 if ($extra) {
                     return null;
                 } else {
@@ -74,7 +109,7 @@ class CommandInterpreter
              if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else {
@@ -84,7 +119,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else {
@@ -95,7 +130,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else {
@@ -106,7 +141,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else {
@@ -117,7 +152,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else {
@@ -128,17 +163,41 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if (!$extra) {
                 return null;
             } 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 'repeat':
+         case 'rp':
+         case 'rt':
+         case 'rd':
+            if (!$arg) {
+                return null;
+            }
+            list($other, $extra) = $this->split_arg($arg);
+            if ($extra) {
+                return null;
+            } else {
+                return new RepeatCommand($user, $other);
+            }
          case 'whois':
             if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else {
@@ -148,7 +207,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else {
@@ -158,7 +217,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else {
@@ -173,7 +232,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else {
@@ -183,7 +242,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($word, $extra) = explode(' ', $arg, 2);
+            list($word, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else if ($word == 'off') {
@@ -195,7 +254,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($word, $extra) = explode(' ', $arg, 2);
+            list($word, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else if ($word == 'all') {
@@ -213,5 +272,16 @@ class CommandInterpreter
             return false;
         }
     }
-}
 
+    /**
+     * Split arguments without triggering a PHP notice warning
+     */
+    function split_arg($text)
+    {
+        $pieces = explode(' ', $text, 2);
+        if (count($pieces) == 1) {
+            $pieces[] = null;
+        }
+        return $pieces;
+    }
+}