-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
781 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>me.mrdoc</groupId> | ||
<artifactId>Twitch_TOPCheersTotal</artifactId> | ||
<version>1.0.0</version> | ||
|
||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>2.4.3</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>2.3</version> | ||
<executions> | ||
<execution> | ||
<id>stuff</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<outputDirectory>${basedir}/production</outputDirectory> | ||
<shadedArtifactAttached>true</shadedArtifactAttached> | ||
<shadedClassifierName>launcher</shadedClassifierName> | ||
<transformers> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<manifestEntries> | ||
<Main-Class>me.mrdoc.twitchtopcheers.Core</Main-Class> | ||
<Class-Path>.</Class-Path> | ||
</manifestEntries> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>2.6</version> | ||
<executions> | ||
<execution> | ||
<id>copy-resources</id> | ||
<phase>validate</phase> | ||
<goals> | ||
<goal>copy-resources</goal> | ||
</goals> | ||
<configuration> | ||
<outputDirectory>${basedir}/production</outputDirectory> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<includes> | ||
<include>**/config.yml</include> | ||
</includes> | ||
</resource> | ||
<!-- <resource> | ||
<directory>src/main/resources/examples</directory> | ||
</resource> --> | ||
</resources> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<repositories> | ||
<repository> | ||
<id>sonatype-nexus-snapshots</id> | ||
<name>Sonatype Nexus Snapshots</name> | ||
<url>https://oss.sonatype.org/content/repositories/snapshots</url> | ||
<releases> | ||
<enabled>false</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</repository> | ||
<repository> | ||
<id>Sonatype-public</id> | ||
<name>SnakeYAML repository</name> | ||
<url>http://oss.sonatype.org/content/groups/public/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<!-- Framework to BOT IRC --> | ||
<dependency> | ||
<groupId>org.pircbotx</groupId> | ||
<artifactId>pircbotx</artifactId> | ||
<version>2.2-SNAPSHOT</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc --> | ||
<dependency> | ||
<groupId>org.xerial</groupId> | ||
<artifactId>sqlite-jdbc</artifactId> | ||
<version>3.19.3</version> | ||
</dependency> | ||
<!-- YML --> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.dataformat</groupId> | ||
<artifactId>jackson-dataformat-yaml</artifactId> | ||
<version>2.3.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.2.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>3.4</version> | ||
</dependency> | ||
<!-- Console Color --> | ||
<dependency> | ||
<groupId>com.diogonunes</groupId> | ||
<artifactId>JCDP</artifactId> | ||
<version>2.0.3.1</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package me.mrdoc.twitchtopcheers; | ||
|
||
import me.mrdoc.twitchtopcheers.bot.TwitchBOT; | ||
import me.mrdoc.twitchtopcheers.classes.Cheering; | ||
import me.mrdoc.twitchtopcheers.db.SQLiteSystem; | ||
import me.mrdoc.twitchtopcheers.managers.ConfigManager; | ||
import me.mrdoc.twitchtopcheers.managers.DBCheerManagent; | ||
import me.mrdoc.twitchtopcheers.managers.FileCheerManagent; | ||
import me.mrdoc.twitchtopcheers.utils.PrintConsole; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Created on 19-07-2017 for twitchtopcheers. | ||
* | ||
* @author Doc | ||
*/ | ||
public class Core { | ||
|
||
public static TwitchBOT jaideBOTInstance; | ||
|
||
public static final ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(); | ||
|
||
public static void main(String[] args) throws IOException { | ||
PrintConsole.sendStatus("Iniciando sistema..."); | ||
|
||
loadConfig(); | ||
loadFileTop(); | ||
loadDB(); | ||
|
||
Scanner scanner = new Scanner(System.in); | ||
PrintConsole.sendInfo("Antes de iniciar el BOT y el trackeo, debe escribir (Y/N) si desea o no reiniciar el TOP en el sistema"); | ||
String response = scanner.nextLine(); | ||
|
||
if(!response.equalsIgnoreCase("y") && !response.equalsIgnoreCase("n")) { | ||
PrintConsole.sendError("Ha ingresado una respuesta que no se esperaba (ud no lee)."); | ||
System.exit(0); | ||
} | ||
|
||
if(response.equalsIgnoreCase("y")) { | ||
PrintConsole.sendInfo("Borrando registros de TOP"); | ||
DBCheerManagent.purgeTable(); | ||
} | ||
|
||
//testALL(); | ||
|
||
loadBOT(); | ||
|
||
Core.exec.schedule(() -> { | ||
PrintConsole.sendInfo("Sistema operando. trackeando mensajes en busca de cheers."); | ||
}, 5, TimeUnit.SECONDS); | ||
|
||
} | ||
|
||
private static void testALL() { | ||
DBCheerManagent.addCheer("test",200); | ||
DBCheerManagent.addCheer("test2",800); | ||
DBCheerManagent.addCheer("test3",100); | ||
|
||
ArrayList<Cheering> cheers = DBCheerManagent.getTOPCheers(1); | ||
|
||
PrintConsole.sendInfo("CANTIDAD TOP: " + cheers.size()); | ||
|
||
if(!cheers.isEmpty()) { | ||
PrintConsole.sendInfo(cheers.get(0).getUsername() + " " + cheers.get(0).getTotalCheers()); | ||
} | ||
|
||
FileCheerManagent.setTOP(DBCheerManagent.getTOPCheers(1).get(0)); | ||
|
||
//FileCheerManagent.setTOP(DBCheerManagent.getTOPCheers(1).get(0)); | ||
} | ||
|
||
private static void loadConfig() { | ||
//Cargamos archivo de TOP | ||
PrintConsole.sendInfo("Iniciando carga del modulo de configuracion"); | ||
ConfigManager.loadConfig(); | ||
PrintConsole.sendInfo("Modulo cargado"); | ||
} | ||
|
||
private static void loadFileTop() { | ||
//Cargamos archivo de TOP | ||
PrintConsole.sendInfo("Iniciando carga del modulo de registro de TOP en top.txt"); | ||
FileCheerManagent.loadFileCheerManagent(); | ||
PrintConsole.sendInfo("Modulo cargado"); | ||
} | ||
|
||
private static void loadDB() { | ||
//Cargamos DB | ||
PrintConsole.sendInfo("Iniciando carga del modulo de registro de datos en DB"); | ||
SQLiteSystem.run(); | ||
PrintConsole.sendInfo("Modulo cargado"); | ||
} | ||
|
||
private static void loadBOT() { | ||
//Cargamos BOT | ||
PrintConsole.sendInfo("Iniciando carga del modulo de trackeo usando BOT_IRC"); | ||
jaideBOTInstance = new TwitchBOT(); | ||
PrintConsole.sendInfo("Modulo cargado"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package me.mrdoc.twitchtopcheers.bot; | ||
|
||
import me.mrdoc.twitchtopcheers.Core; | ||
import me.mrdoc.twitchtopcheers.bot.listener.ManageCheerListener; | ||
import me.mrdoc.twitchtopcheers.managers.ConfigManager; | ||
import me.mrdoc.twitchtopcheers.utils.PrintConsole; | ||
import org.pircbotx.Configuration; | ||
import org.pircbotx.PircBotX; | ||
import org.pircbotx.cap.EnableCapHandler; | ||
import org.pircbotx.exception.IrcException; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
import java.util.ArrayList; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Created on 19-07-2017 for twitchtopcheers. | ||
* | ||
* @author Doc | ||
*/ | ||
public class TwitchBOT { | ||
|
||
private PircBotX botInstance; | ||
|
||
private ArrayList<String> messages = new ArrayList<String>(); | ||
|
||
public TwitchBOT() { | ||
botInstance = new PircBotX(generateConfiguration().buildConfiguration()); | ||
PrintConsole.sendInfo("Cargando modulo de mensajes del BOT (Este sistema no esta operando correctamente)"); | ||
processMessages(); | ||
PrintConsole.sendInfo("Iniciando BOT"); | ||
startSystem(); | ||
} | ||
|
||
private void processMessages() { | ||
Core.exec.scheduleAtFixedRate(() -> { | ||
if(Core.jaideBOTInstance.getBOTInstance().isConnected()) { | ||
if(!messages.isEmpty()) { | ||
PrintConsole.sendInfo("Se enviaran " + messages.size() + " mensajes via BOT."); | ||
for(String message : messages) { | ||
botInstance.send().message(ConfigManager.getConfig().getChannel_config().get("channel_name"),"RUNNING"); | ||
messages.remove(message); | ||
} | ||
} else { | ||
PrintConsole.sendInfo("No hay mensajes pendientes de ser enviados por el BOT"); | ||
} | ||
} else { | ||
PrintConsole.sendError("El BOT esta desconectado y no puede enviar mensajes"); | ||
} | ||
}, 10, 5, TimeUnit.SECONDS); | ||
} | ||
|
||
private void startSystem() { | ||
try { | ||
botInstance.startBot(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} catch (IrcException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private Configuration.Builder generateConfiguration() { | ||
return new Configuration.Builder() | ||
|
||
.setEncoding(Charset.forName("UTF-8")) //Support UTF-8 | ||
|
||
.setAutoNickChange(false) //Twitch doesn't support multiple users | ||
.setOnJoinWhoEnabled(false) //Twitch doesn't support WHO command | ||
|
||
.setCapEnabled(true) | ||
.addCapHandler(new EnableCapHandler("twitch.tv/membership")) //Twitch by default doesn't send JOIN, PART, and NAMES unless you request it, see https://github.com/justintv/Twitch-API/blob/master/IRC.md#membership | ||
.addCapHandler(new EnableCapHandler("twitch.tv/tags")) | ||
.addCapHandler(new EnableCapHandler("twitch.tv/commands")) | ||
|
||
|
||
.addServer("irc.twitch.tv") | ||
|
||
.setName(ConfigManager.getConfig().getChannel_config().get("bot_username")) //Your twitch.tv username | ||
.setServerPassword(ConfigManager.getConfig().getChannel_config().get("bot_token")) //Your oauth password from http://twitchapps.com/tmi | ||
.addAutoJoinChannel(ConfigManager.getConfig().getChannel_config().get("channel_name")) | ||
|
||
.addListener(new ManageCheerListener()) | ||
|
||
; | ||
} | ||
|
||
public void sendMessage(String message) { | ||
messages.add(message); | ||
PrintConsole.sendInfo("Se ha cargado un mensaje para ser enviado por el BOT"); | ||
} | ||
|
||
public PircBotX getBOTInstance() { | ||
return botInstance; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/me/mrdoc/twitchtopcheers/bot/listener/ManageCheerListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package me.mrdoc.twitchtopcheers.bot.listener; | ||
|
||
import me.mrdoc.twitchtopcheers.classes.Cheering; | ||
import me.mrdoc.twitchtopcheers.managers.DBCheerManagent; | ||
import me.mrdoc.twitchtopcheers.managers.FileCheerManagent; | ||
import me.mrdoc.twitchtopcheers.utils.PrintConsole; | ||
import org.pircbotx.hooks.ListenerAdapter; | ||
import org.pircbotx.hooks.events.MessageEvent; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* Created on 19-07-2017 for twitchtopcheers. | ||
* | ||
* @author Doc | ||
*/ | ||
public class ManageCheerListener extends ListenerAdapter { | ||
|
||
@Override | ||
public void onMessage(MessageEvent event) { | ||
for(String tag : event.getV3Tags().keySet()) { | ||
if(tag.contains("bits")) { | ||
System.out.println("==========================================]"); | ||
PrintConsole.sendInfo("Se detecto un mensaje con TAG de cheers, enviando a evento custom."); | ||
onCheerEvent(event); | ||
} | ||
} | ||
} | ||
|
||
private void onCheerEvent(MessageEvent event) { | ||
PrintConsole.sendInfo("El usuario " + event.getUser().getNick() + " envio " + event.getV3Tags().get("bits") + " cheers."); | ||
int cheerInMsg = Integer.parseInt(event.getV3Tags().get("bits")); //Obtengo cantidad de bits | ||
DBCheerManagent.addCheer(event.getUser().getNick(),cheerInMsg); | ||
|
||
//Recargamos TOP | ||
ArrayList<Cheering> cheersTOP = DBCheerManagent.getTOPCheers(1); | ||
|
||
FileCheerManagent.setTOP(cheersTOP.get(0)); | ||
} | ||
|
||
} |
Oops, something went wrong.