detection of user profiles. Also included detecting if a stream is online. Planned Twitch Follower Features: Follower Notification System: - Provide a Unique Follower Notification first time user Follows. - User ID is added to Database to prevent Duplicate Follow entries. - Display Logo + Current Display Name of User - Display scrolling Bio. - Play Sound (Probably Glaceon) - "Thanks for Follow" - Detect users that follow while offline. Announce them next time stream is online. (Store 'last announced user' ID, try to find next stream.) Get User-Specific Emotes, Download specific sub emotes.dev
parent
9251d09aa7
commit
8488c798c6
@ -1,11 +1,12 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
||||||
<classpath> |
<classpath> |
||||||
<classpathentry kind="src" path="src"/> |
<classpathentry kind="src" path="src"/> |
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> |
||||||
<classpathentry kind="lib" path="D:/Downloads/commons-io-2.5.jar"> |
<classpathentry exported="true" kind="lib" path="D:/Downloads/commons-io-2.5.jar"> |
||||||
<attributes> |
<attributes> |
||||||
<attribute name="javadoc_location" value="jar:file:/D:/Data/commons-io-2.5-javadoc.jar!/"/> |
<attribute name="javadoc_location" value="jar:file:/D:/Data/commons-io-2.5-javadoc.jar!/"/> |
||||||
</attributes> |
</attributes> |
||||||
</classpathentry> |
</classpathentry> |
||||||
|
<classpathentry exported="true" kind="lib" path="D:/Downloads/twitch-api-wrapper-0.3-jar-with-dependencies.jar"/> |
||||||
<classpathentry kind="output" path="bin"/> |
<classpathentry kind="output" path="bin"/> |
||||||
</classpath> |
</classpath> |
||||||
|
@ -1,11 +1,11 @@ |
|||||||
eclipse.preferences.version=1 |
eclipse.preferences.version=1 |
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
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.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.lineNumber=generate |
||||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate |
org.eclipse.jdt.core.compiler.debug.localVariable=generate |
||||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate |
org.eclipse.jdt.core.compiler.debug.sourceFile=generate |
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
||||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=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 |
||||||
|
@ -0,0 +1,2 @@ |
|||||||
|
/commons-io-2.5.jar |
||||||
|
/twitch-api-wrapper-0.3-jar-with-dependencies.jar |
Binary file not shown.
@ -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<ChannelFollow> 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<ChannelFollow> 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); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue