Browse Source

Fleshed out how things will work with the Google TV.

Douglas William Thrift 13 years ago
parent
commit
be484a95f4

+ 71 - 1
src/net/douglasthrift/bigscreenbot/BigScreenBot.java

@@ -26,6 +26,9 @@ package net.douglasthrift.bigscreenbot;
 
 import java.io.IOException;
 
+import java.net.MalformedURLException;
+import java.net.URL;
+
 import java.security.GeneralSecurityException;
 
 import java.util.ArrayList;
@@ -183,8 +186,59 @@ public class BigScreenBot extends Bot
         commands.put("googletv", new Command(false, BOTH, "url [device]", "fling url to a Google TV device")
         {
             @Override
-            public void execute(String channel, String sender, boolean admin, String argument)
+            public void execute(final String channel, final String sender, boolean admin, String argument)
             {
+                final String[] arguments = StringUtils.split(argument, null, 2);
+
+                if (arguments.length == 0)
+                {
+                    help(channel, sender, admin, "googletv");
+
+                    return;
+                }
+
+                try
+                {
+                    if (!new URL(arguments[0]).getProtocol().matches("^https?$"))
+                    {
+                        invalidURL(channel, sender, arguments[0]);
+
+                        return;
+                    }
+                }
+                catch (MalformedURLException exception)
+                {
+                    invalidURL(channel, sender, arguments[0]);
+
+                    return;
+                }
+
+                if (arguments.length == 2)
+                    sendMessage(channel, sender, String.format("flinging URL (\"%1$s\") to device (\"%2$s\")...", arguments[0], arguments[1]));
+                else
+                    sendMessage(channel, sender, String.format("flinging URL (\"%1$s\") to device(s)...", arguments[0]));
+
+                new Thread()
+                {
+                    @Override
+                    public void run()
+                    {
+                        synchronized (remote)
+                        {
+                            if (arguments.length == 2)
+                                remote.fling(arguments[1], arguments[0]);
+                            else
+                                remote.fling(arguments[0]);
+                        }
+
+                        sendMessage(channel, sender, String.format("flung URL (\"%1$s\") to device(s)", arguments[0]));
+                    }
+                }.start();
+            }
+
+            private void invalidURL(String channel, String sender, String url)
+            {
+                sendMessage(channel, sender, String.format("invalid URL (\"%1$s\")", url));
             }
         });
         commands.put("help", new Command(false, PRIVATE, "[command]", "show this help message")
@@ -321,6 +375,8 @@ public class BigScreenBot extends Bot
                                     error(channel, sender, exception);
                                 }
                             }
+
+                            sendMessage(channel, sender, String.format("enter the code from the device (\"%1$s\") to finish pairing", arguments[0]));
                         }
                     }.start();
 
@@ -337,6 +393,8 @@ public class BigScreenBot extends Bot
                             {
                                 remote.finishPairDevice(arguments[0], arguments[1]);
                             }
+
+                            sendMessage(channel, sender, String.format("paired with device (\"%1$s\")", arguments[0]));
                         }
                     }.start();
                 }
@@ -544,6 +602,18 @@ public class BigScreenBot extends Bot
 
         if (arguments.length != 0)
         {
+            if (channel == null)
+                try
+                {
+                    if (new URL(arguments[0]).getProtocol().matches("^https?$"))
+                    {
+                        commands.get("googletv").execute(channel, sender, admin, StringUtils.join(arguments, ' '));
+
+                        return;
+                    }
+                }
+                catch (MalformedURLException exception) {}
+
             argument = arguments[0].toLowerCase();
 
             if (argument.startsWith("!"))

+ 8 - 0
src/net/douglasthrift/bigscreenbot/Remote.java

@@ -91,6 +91,14 @@ public class Remote
     {
     }
 
+    public void fling(String url)
+    {
+    }
+
+    public void fling(String device, String url)
+    {
+    }
+
     @Override
     protected void finalize() throws IOException
     {