diff --git a/.classpath b/.classpath
index fcd4204..2119f89 100644
--- a/.classpath
+++ b/.classpath
@@ -1,11 +1,12 @@
-
-
+
+
+
diff --git a/.externalToolBuilders/Makejar.launch b/.externalToolBuilders/Makejar.launch
index 1d6d52a..2137ab8 100644
--- a/.externalToolBuilders/Makejar.launch
+++ b/.externalToolBuilders/Makejar.launch
@@ -3,6 +3,12 @@
+
+
+
+
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
index 838bd9d..bb35fa0 100644
--- a/.settings/org.eclipse.jdt.core.prefs
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -1,11 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.7
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/README.md b/README.md
index c638d91..4685b77 100644
--- a/README.md
+++ b/README.md
@@ -2,4 +2,6 @@
You will need to download the commons-io library from the Apache Commons Library website. Download page found here: https://commons.apache.org/proper/commons-io/
-Include it as an External Jar and you should be good to go.
+You will also need the Java Twitch API Wrapper library if you are planning to use the Twitch module functionality. Download page found here: https://github.com/urgrue/Java-Twitch-Api-Wrapper/releases/tag/0.3
+
+Include both as an External Jar and you should be good to go.
diff --git a/lib/.gitignore b/lib/.gitignore
new file mode 100644
index 0000000..93813ca
--- /dev/null
+++ b/lib/.gitignore
@@ -0,0 +1,2 @@
+/commons-io-2.5.jar
+/twitch-api-wrapper-0.3-jar-with-dependencies.jar
diff --git a/projectBuilder.xml b/projectBuilder.xml
index 362bfe3..2be4de0 100644
--- a/projectBuilder.xml
+++ b/projectBuilder.xml
@@ -14,6 +14,7 @@
+
diff --git a/sigIRCv2.jar b/sigIRCv2.jar
index 54544cf..8fe24ff 100644
Binary files a/sigIRCv2.jar and b/sigIRCv2.jar differ
diff --git a/src/sig/Module.java b/src/sig/Module.java
index 23fcf39..3f0ca7d 100644
--- a/src/sig/Module.java
+++ b/src/sig/Module.java
@@ -21,6 +21,7 @@ public class Module {
protected boolean enabled;
protected String name;
public static BufferedImage IMG_DRAGBAR;
+ public static boolean inDragZone=false;
final protected int titleHeight;
@@ -73,9 +74,21 @@ public class Module {
protected void moduleRun() {
dragWindow();
+ modifyCursor();
run();
}
+ private void modifyCursor() {
+ int cursortype = sigIRC.panel.getCursor().getType();
+ if (inDragZone &&
+ cursortype!=Cursor.MOVE_CURSOR) {
+ sigIRC.panel.setCursor(new Cursor(Cursor.MOVE_CURSOR));
+ } else
+ if (!inDragZone && cursortype!=Cursor.DEFAULT_CURSOR) {
+ sigIRC.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
+ }
+ }
+
private void dragWindow() {
if (dragging) {
sigIRC.panel.repaint(getDrawBounds().getBounds());
@@ -88,11 +101,13 @@ public class Module {
ModuleDragEvent(oldX,oldY,mouseX,mouseY);
}
if (inDragBounds(sigIRC.panel.lastMouseX,sigIRC.panel.lastMouseY)) {
- sigIRC.panel.setCursor(new Cursor(Cursor.MOVE_CURSOR));
- } else
+ inDragZone=true;
+ //System.out.println("In Drag Zone for Module "+name);
+ //sigIRC.panel.setCursor(new Cursor(Cursor.MOVE_CURSOR));
+ } /*else
if (sigIRC.panel.getCursor().getType()==Cursor.MOVE_CURSOR) {
sigIRC.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
- }
+ }*/
}
public void run() {
diff --git a/src/sig/UpdateEvent.java b/src/sig/UpdateEvent.java
index 3eec234..a589a02 100644
--- a/src/sig/UpdateEvent.java
+++ b/src/sig/UpdateEvent.java
@@ -91,6 +91,7 @@ public class UpdateEvent implements ActionListener{
cs.decreaseCooldown(1);
}
}
+ Module.inDragZone=false;
for (Module m : sigIRC.modules) {
m.moduleRun();
}
diff --git a/src/sig/modules/TwitchModule.java b/src/sig/modules/TwitchModule.java
new file mode 100644
index 0000000..e6f8b15
--- /dev/null
+++ b/src/sig/modules/TwitchModule.java
@@ -0,0 +1,212 @@
+package sig.modules;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.geom.Rectangle2D;
+import java.io.File;
+import java.io.IOException;
+import java.text.DateFormat;
+
+import com.mb3364.twitch.api.Twitch;
+import com.mb3364.twitch.api.handlers.ChannelFollowsResponseHandler;
+import com.mb3364.twitch.api.handlers.StreamResponseHandler;
+import com.mb3364.twitch.api.models.ChannelFollow;
+import com.mb3364.twitch.api.models.Stream;
+
+import sig.Module;
+import sig.sigIRC;
+import sig.utils.DrawUtils;
+import sig.utils.FileUtils;
+import sig.utils.TextUtils;
+
+public class TwitchModule extends Module{
+ public String console="Twitch module goes here.";
+ Twitch manager = new Twitch();
+ final static String USERDIR = sigIRC.BASEDIR+"sigIRC/users/";
+ final static String FOLLOWERQUEUEFILE = USERDIR+"followers.txt";
+ public static boolean streamOnline = false;
+
+ public TwitchModule(Rectangle2D bounds, String moduleName) {
+ this(bounds,moduleName,true);
+ }
+
+ public TwitchModule(Rectangle2D bounds, String moduleName, boolean enabled) {
+ super(bounds, moduleName, enabled);
+ Initialize();
+ }
+
+ private void Initialize() {
+ boolean firstTime = false;
+ firstTime = CreateUserFolder();
+ if (firstTime) {
+ CreateFollowerQueueLog();
+ }
+ manager.setClientId("o4c2x0l3e82scgar4hpxg6m5dfjbem");
+ getFollowers(firstTime);
+ /*manager.streams().get("theduckishot", new StreamResponseHandler() {
+
+ @Override
+ public void onFailure(Throwable arg0) {
+ }
+
+ @Override
+ public void onFailure(int arg0, String arg1, String arg2) {
+ System.out.println(arg0+","+arg1+","+arg2);
+ }
+
+ @Override
+ public void onSuccess(Stream arg0) {
+ //System.out.println("Stream data is available! "+arg0);
+ if (arg0==null) {
+ System.out.println("Stream is offline.");
+ } else {
+ System.out.println("Stream is online.");
+ }
+ }
+
+ });*/
+ /*manager.channels().getFollows(TextUtils.getActualChannelName(), new ChannelFollowsResponseHandler() {
+ @Override
+ public void onSuccess(int total, java.util.List follows) {
+ //System.out.println("Successfully found followers for channel "+sigIRC.channel+". Total: "+total);
+ //console = "Last Follower: "+follows.get(0).getUser().getDisplayName();
+ follows.get(0).
+ }
+
+ @Override
+ public void onFailure(Throwable arg0) {
+ }
+
+ @Override
+ public void onFailure(int arg0, String arg1, String arg2) {
+ System.out.println(arg0+","+arg1+","+arg2);
+ }
+ }
+ );*/
+ }
+
+ private void CreateFollowerQueueLog() {
+ String dir = FOLLOWERQUEUEFILE;
+ File filer = new File(dir);
+ if (!filer.exists()) {
+ try {
+ filer.createNewFile();
+ System.out.println("Follower Queue Log does not exist. Creating in "+USERDIR+".");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private void getFollowers(boolean firstTime) {
+ //isStreamOnline();
+ manager.channels().getFollows(TextUtils.getActualChannelName(), new ChannelFollowsResponseHandler() {
+ @Override
+ public void onSuccess(int total, java.util.List follows) {
+ //System.out.println("Successfully found followers for channel "+sigIRC.channel+". Total: "+total);
+ //console = "Last Follower: "+follows.get(0).getUser().getDisplayName();
+ for (ChannelFollow f : follows) {
+ addFollower(f,isStreamOnline(),firstTime);
+ }
+ }
+
+ @Override
+ public void onFailure(Throwable arg0) {
+ }
+
+ @Override
+ public void onFailure(int arg0, String arg1, String arg2) {
+ System.out.println(arg0+","+arg1+","+arg2);
+ }
+ }
+ );
+ if (isStreamOnline()) {ClearFollowerAnnouncerQueue();}
+ }
+
+ private void ClearFollowerAnnouncerQueue() {
+ // TODO Read the file and announce everybody in that queue.
+
+ }
+
+ private boolean isStreamOnline() {
+ manager.streams().get(TextUtils.getActualChannelName(), new StreamResponseHandler() {
+
+ @Override
+ public void onFailure(Throwable arg0) {
+ TwitchModule.streamOnline=false;
+ }
+
+ @Override
+ public void onFailure(int arg0, String arg1, String arg2) {
+ System.out.println(arg0+","+arg1+","+arg2);
+ TwitchModule.streamOnline=false;
+ }
+
+ @Override
+ public void onSuccess(Stream arg0) {
+ //System.out.println("Stream data is available! "+arg0);
+ if (arg0==null) {
+ //System.out.println("Stream is offline.");
+ TwitchModule.streamOnline=false;
+ } else {
+ TwitchModule.streamOnline=true;
+ }
+ }
+
+ });
+ //return TwitchModule.streamOnline;
+ return false;
+ }
+
+ protected void addFollower(ChannelFollow f, boolean streamOnline, boolean silent) {
+ String filename = USERDIR+f.getUser().getId();
+ File userProfile = new File(filename);
+ if (!silent) { //If we got in here, this isn't the initial follower setup, so we are good to go with announcing these followers.
+ if (!streamOnline) {
+ //Save their ID to a queue.
+ FileUtils.logToFile(Long.toString(f.getUser().getId()), FOLLOWERQUEUEFILE);
+ } else {
+ //Announce it now.
+ AnnounceFollower(f);
+ }
+ }
+ CreateUserProfile(f, filename, userProfile);
+ }
+
+ private void CreateUserProfile(ChannelFollow f, String filename, File userProfile) {
+ if (!userProfile.exists()) {
+ try {
+ userProfile.createNewFile();
+ FileUtils.logToFile(DateFormat.getDateInstance().format(f.getCreatedAt()), filename);
+ FileUtils.logToFile(f.getUser().getBio(), filename);
+ FileUtils.logToFile(f.getUser().getDisplayName(), filename);
+ FileUtils.logToFile(f.getUser().getLogo(), filename);
+ FileUtils.logToFile(f.getUser().getName(), filename);
+ FileUtils.logToFile(f.getUser().getType(), filename);
+ FileUtils.logToFile(DateFormat.getDateInstance().format(f.getUser().getUpdatedAt()), filename);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private void AnnounceFollower(ChannelFollow f) {
+ System.out.println("Thanks for following "+f.getUser().getDisplayName()+"!");
+ }
+
+ private boolean CreateUserFolder() {
+ File userDir = new File(USERDIR);
+ if (!userDir.exists()) {
+ userDir.mkdir();
+ System.out.println("Could not find Twitch User directory. Creating in "+USERDIR+".");
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public void draw(Graphics g){
+ super.draw(g);
+ DrawUtils.drawText(g, bounds.getX(), bounds.getY()+24, Color.RED, console);
+ }
+}
diff --git a/src/sig/sigIRC.java b/src/sig/sigIRC.java
index f74c95e..be91c78 100644
--- a/src/sig/sigIRC.java
+++ b/src/sig/sigIRC.java
@@ -7,6 +7,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import sig.modules.TouhouMotherModule;
+import sig.modules.TwitchModule;
import sig.utils.FileUtils;
import java.awt.Color;
@@ -30,9 +31,7 @@ import java.util.Calendar;
import java.util.List;
import javax.imageio.ImageIO;
-import javax.swing.JColorChooser;
import javax.swing.JFrame;
-import javax.swing.JPanel;
public class sigIRC{
public static MyPanel panel = null;
@@ -52,7 +51,7 @@ public class sigIRC{
static ConfigFile config;
static String server;
static String nickname;
- static String channel;
+ public static String channel;
public static boolean authenticated=false;
public static int lastPlayedDing=0;
final public static int DINGTIMER=150;
@@ -74,6 +73,7 @@ public class sigIRC{
static String usernameFont="GillSansMTStd-Book";
static String touhoumotherConsoleFont="Agency FB Bold";
static boolean touhoumothermodule_enabled=true;
+ static boolean twitchmodule_enabled=true;
static boolean downloadsComplete=false;
static boolean hardwareAcceleration=true;
static boolean playedoAuthSoundOnce=false;
@@ -100,6 +100,7 @@ public class sigIRC{
usernameFont = config.getProperty("usernameFont","Gill Sans");
touhoumotherConsoleFont = config.getProperty("touhoumotherConsoleFont","Agency FB Bold");
touhoumothermodule_enabled = config.getBoolean("Module_touhoumother_Enabled",true);
+ twitchmodule_enabled = config.getBoolean("Module_twitch_Enabled",true);
hardwareAcceleration = config.getBoolean("hardware_acceleration",true);
DownloadAllRequiredDependencies();
@@ -166,6 +167,12 @@ public class sigIRC{
"Touhou Mother"
));
}
+ if (twitchmodule_enabled) {
+ modules.add(new TwitchModule(
+ new Rectangle(320,panel.getHeight()/2,panel.getWidth()-320,96),
+ "Twitch"
+ ));
+ }
}
private static void InitializeCustomSounds() {
diff --git a/src/sig/utils/TextUtils.java b/src/sig/utils/TextUtils.java
index 12b4bff..5188d50 100644
--- a/src/sig/utils/TextUtils.java
+++ b/src/sig/utils/TextUtils.java
@@ -69,4 +69,8 @@ public class TextUtils {
}
return sb.toString();
}
+
+ public static String getActualChannelName() {
+ return sigIRC.channel.replaceFirst("#", "");
+ }
}