|
@@ -28,39 +28,19 @@ import java.io.FileNotFoundException;
|
|
|
import java.io.FileReader;
|
|
|
import java.io.IOException;
|
|
|
|
|
|
-import java.net.InetAddress;
|
|
|
-import java.net.UnknownHostException;
|
|
|
-
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.Properties;
|
|
|
import java.util.TreeMap;
|
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
import javax.net.ssl.SSLSocketFactory;
|
|
|
|
|
|
-import javax.jmdns.JmDNS;
|
|
|
-import javax.jmdns.ServiceEvent;
|
|
|
-import javax.jmdns.ServiceInfo;
|
|
|
-import javax.jmdns.ServiceListener;
|
|
|
-
|
|
|
-import com.google.anymote.common.AnymoteFactory;
|
|
|
-import com.google.anymote.common.ErrorListener;
|
|
|
-
|
|
|
-import com.google.anymote.device.DeviceAdapter;
|
|
|
-import com.google.anymote.device.MessageReceiver;
|
|
|
-
|
|
|
-import org.apache.oro.text.GlobCompiler;
|
|
|
-
|
|
|
import org.jibble.pircbot.Colors;
|
|
|
import org.jibble.pircbot.IrcException;
|
|
|
-import org.jibble.pircbot.PircBot;
|
|
|
-import org.jibble.pircbot.User;
|
|
|
|
|
|
-public class BigScreenBot extends PircBot
|
|
|
+public class BigScreenBot extends Bot
|
|
|
{
|
|
|
private static final String SETTINGS = "bigscreenbot.properties";
|
|
|
private static final int CHANNEL = 0x1;
|
|
@@ -69,39 +49,6 @@ public class BigScreenBot extends PircBot
|
|
|
|
|
|
private static enum Action { RECONNECT, RESTART, QUIT }
|
|
|
|
|
|
- private static class Settings extends Properties
|
|
|
- {
|
|
|
- public boolean getBooleanProperty(String key, boolean defaultValue)
|
|
|
- {
|
|
|
- String value = getProperty(key);
|
|
|
-
|
|
|
- if (value != null)
|
|
|
- return Boolean.parseBoolean(value);
|
|
|
- else
|
|
|
- return defaultValue;
|
|
|
- }
|
|
|
-
|
|
|
- public int getIntegerProperty(String key, int defaultValue)
|
|
|
- {
|
|
|
- String value = getProperty(key);
|
|
|
-
|
|
|
- if (value != null)
|
|
|
- return Integer.parseInt(value);
|
|
|
- else
|
|
|
- return defaultValue;
|
|
|
- }
|
|
|
-
|
|
|
- public List<String> getListProperty(String key)
|
|
|
- {
|
|
|
- String value = getProperty(key);
|
|
|
-
|
|
|
- if (value != null)
|
|
|
- return Arrays.asList(value.split("\\s"));
|
|
|
- else
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private abstract class Command
|
|
|
{
|
|
|
private boolean admin;
|
|
@@ -149,17 +96,53 @@ public class BigScreenBot extends PircBot
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private Settings settings;
|
|
|
+ private Settings settings = new Settings();
|
|
|
+ private Remote remote;
|
|
|
private List<Pattern> admins = new ArrayList<Pattern>();
|
|
|
private Map<String, Command> commands = new TreeMap<String, Command>();
|
|
|
private Action action = Action.RECONNECT;
|
|
|
- private JmDNS mdns;
|
|
|
|
|
|
- private BigScreenBot(Settings settings)
|
|
|
+ private BigScreenBot()
|
|
|
{
|
|
|
super();
|
|
|
|
|
|
- this.settings = settings;
|
|
|
+ FileReader reader = null;
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ reader = new FileReader(SETTINGS);
|
|
|
+
|
|
|
+ settings.load(reader);
|
|
|
+ }
|
|
|
+ catch (FileNotFoundException exception)
|
|
|
+ {
|
|
|
+ error(exception, 1);
|
|
|
+ }
|
|
|
+ catch (IOException exception)
|
|
|
+ {
|
|
|
+ error(exception, 1);
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ if (reader != null)
|
|
|
+ try
|
|
|
+ {
|
|
|
+ reader.close();
|
|
|
+ }
|
|
|
+ catch (IOException exception)
|
|
|
+ {
|
|
|
+ error(exception, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ remote = new Remote(settings);
|
|
|
+ }
|
|
|
+ catch (IOException exception)
|
|
|
+ {
|
|
|
+ error(exception, 1);
|
|
|
+ }
|
|
|
|
|
|
setAutoNickChange(true);
|
|
|
setFinger("Big Screen Bot");
|
|
@@ -177,9 +160,9 @@ public class BigScreenBot extends PircBot
|
|
|
setVerbose(settings.getBooleanProperty("verbose", false));
|
|
|
|
|
|
for (String admin : settings.getListProperty("admins"))
|
|
|
- admins.add(Pattern.compile(GlobCompiler.globToPerl5(admin.toCharArray(), GlobCompiler.DEFAULT_MASK), Pattern.CASE_INSENSITIVE));
|
|
|
+ admins.add(compileNickMask(admin));
|
|
|
|
|
|
- commands.put("fling", new Command(false, BOTH, "url [device]", "fling url to a Google TV device")
|
|
|
+ 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)
|
|
@@ -228,18 +211,43 @@ public class BigScreenBot extends PircBot
|
|
|
commands.put("pair", new Command(true, PRIVATE, "[device [code]]", "pair with 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)
|
|
|
{
|
|
|
- /*JmDNS dns = JmDNS.create(InetAddress.getByName(settings.getProperty("interface")));
|
|
|
+ String[] arguments = argument.split("\\s", 2);
|
|
|
|
|
|
- for (ServiceInfo info : dns.list("_anymote._tcp.local."))
|
|
|
+ if (arguments.length == 1)
|
|
|
+ if (arguments[0].isEmpty())
|
|
|
+ new Thread()
|
|
|
+ {
|
|
|
+ @Override
|
|
|
+ public void run()
|
|
|
+ {
|
|
|
+ List<String> devices;
|
|
|
+
|
|
|
+ synchronized (remote)
|
|
|
+ {
|
|
|
+ devices = remote.listDevices();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (devices.isEmpty())
|
|
|
+ {
|
|
|
+ sendMessage(channel, sender, "there are no devices to pair with");
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ sendMessage(channel, sender, Colors.BOLD + "devices" + Colors.NORMAL);
|
|
|
+
|
|
|
+ for (String device : devices)
|
|
|
+ sendMessage(channel, sender, device);
|
|
|
+ }
|
|
|
+ }.start();
|
|
|
+ else
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- System.out.println(info.getName());
|
|
|
- System.out.println(info.getInetAddresses()[0]);
|
|
|
- System.out.println(info.getPort());
|
|
|
}
|
|
|
-
|
|
|
- dns.close();*/
|
|
|
}
|
|
|
});
|
|
|
commands.put("quit", new Command(true, PRIVATE, "[message]", "quit and do not come back")
|
|
@@ -432,49 +440,9 @@ public class BigScreenBot extends PircBot
|
|
|
commands.get("help").execute(channel, sender, admin, command);
|
|
|
}
|
|
|
|
|
|
- private boolean isNickInChannels(String nick)
|
|
|
- {
|
|
|
- for (String channel : getChannels())
|
|
|
- for (User user : getUsers(channel))
|
|
|
- if (user.equals(nick))
|
|
|
- return true;
|
|
|
-
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
public static void main(String[] args)
|
|
|
{
|
|
|
- Settings settings = new Settings();
|
|
|
- FileReader reader = null;
|
|
|
-
|
|
|
- try
|
|
|
- {
|
|
|
- reader = new FileReader(SETTINGS);
|
|
|
-
|
|
|
- settings.load(reader);
|
|
|
- }
|
|
|
- catch (FileNotFoundException exception)
|
|
|
- {
|
|
|
- error(exception, 1);
|
|
|
- }
|
|
|
- catch (IOException exception)
|
|
|
- {
|
|
|
- error(exception, 1);
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
- if (reader != null)
|
|
|
- try
|
|
|
- {
|
|
|
- reader.close();
|
|
|
- }
|
|
|
- catch (IOException exception)
|
|
|
- {
|
|
|
- error(exception, 1);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- new BigScreenBot(settings);
|
|
|
+ new BigScreenBot();
|
|
|
}
|
|
|
|
|
|
private static void error(Exception exception)
|
|
@@ -488,33 +456,6 @@ public class BigScreenBot extends PircBot
|
|
|
|
|
|
System.exit(code);
|
|
|
}
|
|
|
-
|
|
|
- private static boolean matchNickMasks(String sender, String login, String hostname, List<Pattern> masks)
|
|
|
- {
|
|
|
- String nick = sender + "!" + login + "@" + hostname;
|
|
|
-
|
|
|
- for (Pattern mask : masks)
|
|
|
- if (mask.matcher(nick).matches())
|
|
|
- return true;
|
|
|
-
|
|
|
- try
|
|
|
- {
|
|
|
- InetAddress address = InetAddress.getByName(hostname);
|
|
|
- String name = address.getCanonicalHostName();
|
|
|
-
|
|
|
- if (!name.equalsIgnoreCase(hostname))
|
|
|
- {
|
|
|
- nick = sender + "!" + login + "@" + name;
|
|
|
-
|
|
|
- for (Pattern mask : masks)
|
|
|
- if (mask.matcher(nick).matches())
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- catch (UnknownHostException exception) {}
|
|
|
-
|
|
|
- return false;
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
// vim: expandtab
|