Skip to content

Commit 734f26a

Browse files
committed
Release 1.0.0
1 parent 3442932 commit 734f26a

File tree

12 files changed

+781
-0
lines changed

12 files changed

+781
-0
lines changed

pom.xml

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>me.mrdoc</groupId>
8+
<artifactId>Twitch_TOPCheersTotal</artifactId>
9+
<version>1.0.0</version>
10+
11+
<properties>
12+
<maven.compiler.source>1.8</maven.compiler.source>
13+
<maven.compiler.target>1.8</maven.compiler.target>
14+
</properties>
15+
16+
<build>
17+
<plugins>
18+
<plugin>
19+
<groupId>org.apache.maven.plugins</groupId>
20+
<artifactId>maven-resources-plugin</artifactId>
21+
<version>2.4.3</version>
22+
</plugin>
23+
<plugin>
24+
<groupId>org.apache.maven.plugins</groupId>
25+
<artifactId>maven-shade-plugin</artifactId>
26+
<version>2.3</version>
27+
<executions>
28+
<execution>
29+
<id>stuff</id>
30+
<phase>package</phase>
31+
<goals>
32+
<goal>shade</goal>
33+
</goals>
34+
<configuration>
35+
<outputDirectory>${basedir}/production</outputDirectory>
36+
<shadedArtifactAttached>true</shadedArtifactAttached>
37+
<shadedClassifierName>launcher</shadedClassifierName>
38+
<transformers>
39+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
40+
<manifestEntries>
41+
<Main-Class>me.mrdoc.twitchtopcheers.Core</Main-Class>
42+
<Class-Path>.</Class-Path>
43+
</manifestEntries>
44+
</transformer>
45+
</transformers>
46+
</configuration>
47+
</execution>
48+
</executions>
49+
</plugin>
50+
<plugin>
51+
<artifactId>maven-resources-plugin</artifactId>
52+
<version>2.6</version>
53+
<executions>
54+
<execution>
55+
<id>copy-resources</id>
56+
<phase>validate</phase>
57+
<goals>
58+
<goal>copy-resources</goal>
59+
</goals>
60+
<configuration>
61+
<outputDirectory>${basedir}/production</outputDirectory>
62+
<resources>
63+
<resource>
64+
<directory>src/main/resources</directory>
65+
<includes>
66+
<include>**/config.yml</include>
67+
</includes>
68+
</resource>
69+
<!-- <resource>
70+
<directory>src/main/resources/examples</directory>
71+
</resource> -->
72+
</resources>
73+
</configuration>
74+
</execution>
75+
</executions>
76+
</plugin>
77+
</plugins>
78+
</build>
79+
80+
<repositories>
81+
<repository>
82+
<id>sonatype-nexus-snapshots</id>
83+
<name>Sonatype Nexus Snapshots</name>
84+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
85+
<releases>
86+
<enabled>false</enabled>
87+
</releases>
88+
<snapshots>
89+
<enabled>true</enabled>
90+
</snapshots>
91+
</repository>
92+
<repository>
93+
<id>Sonatype-public</id>
94+
<name>SnakeYAML repository</name>
95+
<url>http://oss.sonatype.org/content/groups/public/</url>
96+
</repository>
97+
</repositories>
98+
99+
<dependencies>
100+
<!-- Framework to BOT IRC -->
101+
<dependency>
102+
<groupId>org.pircbotx</groupId>
103+
<artifactId>pircbotx</artifactId>
104+
<version>2.2-SNAPSHOT</version>
105+
</dependency>
106+
<!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc -->
107+
<dependency>
108+
<groupId>org.xerial</groupId>
109+
<artifactId>sqlite-jdbc</artifactId>
110+
<version>3.19.3</version>
111+
</dependency>
112+
<!-- YML -->
113+
<dependency>
114+
<groupId>com.fasterxml.jackson.dataformat</groupId>
115+
<artifactId>jackson-dataformat-yaml</artifactId>
116+
<version>2.3.0</version>
117+
</dependency>
118+
<dependency>
119+
<groupId>com.fasterxml.jackson.core</groupId>
120+
<artifactId>jackson-databind</artifactId>
121+
<version>2.2.3</version>
122+
</dependency>
123+
<dependency>
124+
<groupId>org.apache.commons</groupId>
125+
<artifactId>commons-lang3</artifactId>
126+
<version>3.4</version>
127+
</dependency>
128+
<!-- Console Color -->
129+
<dependency>
130+
<groupId>com.diogonunes</groupId>
131+
<artifactId>JCDP</artifactId>
132+
<version>2.0.3.1</version>
133+
</dependency>
134+
</dependencies>
135+
136+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package me.mrdoc.twitchtopcheers;
2+
3+
import me.mrdoc.twitchtopcheers.bot.TwitchBOT;
4+
import me.mrdoc.twitchtopcheers.classes.Cheering;
5+
import me.mrdoc.twitchtopcheers.db.SQLiteSystem;
6+
import me.mrdoc.twitchtopcheers.managers.ConfigManager;
7+
import me.mrdoc.twitchtopcheers.managers.DBCheerManagent;
8+
import me.mrdoc.twitchtopcheers.managers.FileCheerManagent;
9+
import me.mrdoc.twitchtopcheers.utils.PrintConsole;
10+
11+
import java.io.IOException;
12+
import java.util.ArrayList;
13+
import java.util.Scanner;
14+
import java.util.concurrent.Executors;
15+
import java.util.concurrent.ScheduledExecutorService;
16+
import java.util.concurrent.TimeUnit;
17+
18+
/**
19+
* Created on 19-07-2017 for twitchtopcheers.
20+
*
21+
* @author Doc
22+
*/
23+
public class Core {
24+
25+
public static TwitchBOT jaideBOTInstance;
26+
27+
public static final ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
28+
29+
public static void main(String[] args) throws IOException {
30+
PrintConsole.sendStatus("Iniciando sistema...");
31+
32+
loadConfig();
33+
loadFileTop();
34+
loadDB();
35+
36+
Scanner scanner = new Scanner(System.in);
37+
PrintConsole.sendInfo("Antes de iniciar el BOT y el trackeo, debe escribir (Y/N) si desea o no reiniciar el TOP en el sistema");
38+
String response = scanner.nextLine();
39+
40+
if(!response.equalsIgnoreCase("y") && !response.equalsIgnoreCase("n")) {
41+
PrintConsole.sendError("Ha ingresado una respuesta que no se esperaba (ud no lee).");
42+
System.exit(0);
43+
}
44+
45+
if(response.equalsIgnoreCase("y")) {
46+
PrintConsole.sendInfo("Borrando registros de TOP");
47+
DBCheerManagent.purgeTable();
48+
}
49+
50+
//testALL();
51+
52+
loadBOT();
53+
54+
Core.exec.schedule(() -> {
55+
PrintConsole.sendInfo("Sistema operando. trackeando mensajes en busca de cheers.");
56+
}, 5, TimeUnit.SECONDS);
57+
58+
}
59+
60+
private static void testALL() {
61+
DBCheerManagent.addCheer("test",200);
62+
DBCheerManagent.addCheer("test2",800);
63+
DBCheerManagent.addCheer("test3",100);
64+
65+
ArrayList<Cheering> cheers = DBCheerManagent.getTOPCheers(1);
66+
67+
PrintConsole.sendInfo("CANTIDAD TOP: " + cheers.size());
68+
69+
if(!cheers.isEmpty()) {
70+
PrintConsole.sendInfo(cheers.get(0).getUsername() + " " + cheers.get(0).getTotalCheers());
71+
}
72+
73+
FileCheerManagent.setTOP(DBCheerManagent.getTOPCheers(1).get(0));
74+
75+
//FileCheerManagent.setTOP(DBCheerManagent.getTOPCheers(1).get(0));
76+
}
77+
78+
private static void loadConfig() {
79+
//Cargamos archivo de TOP
80+
PrintConsole.sendInfo("Iniciando carga del modulo de configuracion");
81+
ConfigManager.loadConfig();
82+
PrintConsole.sendInfo("Modulo cargado");
83+
}
84+
85+
private static void loadFileTop() {
86+
//Cargamos archivo de TOP
87+
PrintConsole.sendInfo("Iniciando carga del modulo de registro de TOP en top.txt");
88+
FileCheerManagent.loadFileCheerManagent();
89+
PrintConsole.sendInfo("Modulo cargado");
90+
}
91+
92+
private static void loadDB() {
93+
//Cargamos DB
94+
PrintConsole.sendInfo("Iniciando carga del modulo de registro de datos en DB");
95+
SQLiteSystem.run();
96+
PrintConsole.sendInfo("Modulo cargado");
97+
}
98+
99+
private static void loadBOT() {
100+
//Cargamos BOT
101+
PrintConsole.sendInfo("Iniciando carga del modulo de trackeo usando BOT_IRC");
102+
jaideBOTInstance = new TwitchBOT();
103+
PrintConsole.sendInfo("Modulo cargado");
104+
}
105+
106+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package me.mrdoc.twitchtopcheers.bot;
2+
3+
import me.mrdoc.twitchtopcheers.Core;
4+
import me.mrdoc.twitchtopcheers.bot.listener.ManageCheerListener;
5+
import me.mrdoc.twitchtopcheers.managers.ConfigManager;
6+
import me.mrdoc.twitchtopcheers.utils.PrintConsole;
7+
import org.pircbotx.Configuration;
8+
import org.pircbotx.PircBotX;
9+
import org.pircbotx.cap.EnableCapHandler;
10+
import org.pircbotx.exception.IrcException;
11+
12+
import java.io.IOException;
13+
import java.nio.charset.Charset;
14+
import java.util.ArrayList;
15+
import java.util.concurrent.TimeUnit;
16+
17+
/**
18+
* Created on 19-07-2017 for twitchtopcheers.
19+
*
20+
* @author Doc
21+
*/
22+
public class TwitchBOT {
23+
24+
private PircBotX botInstance;
25+
26+
private ArrayList<String> messages = new ArrayList<String>();
27+
28+
public TwitchBOT() {
29+
botInstance = new PircBotX(generateConfiguration().buildConfiguration());
30+
PrintConsole.sendInfo("Cargando modulo de mensajes del BOT (Este sistema no esta operando correctamente)");
31+
processMessages();
32+
PrintConsole.sendInfo("Iniciando BOT");
33+
startSystem();
34+
}
35+
36+
private void processMessages() {
37+
Core.exec.scheduleAtFixedRate(() -> {
38+
if(Core.jaideBOTInstance.getBOTInstance().isConnected()) {
39+
if(!messages.isEmpty()) {
40+
PrintConsole.sendInfo("Se enviaran " + messages.size() + " mensajes via BOT.");
41+
for(String message : messages) {
42+
botInstance.send().message(ConfigManager.getConfig().getChannel_config().get("channel_name"),"RUNNING");
43+
messages.remove(message);
44+
}
45+
} else {
46+
PrintConsole.sendInfo("No hay mensajes pendientes de ser enviados por el BOT");
47+
}
48+
} else {
49+
PrintConsole.sendError("El BOT esta desconectado y no puede enviar mensajes");
50+
}
51+
}, 10, 5, TimeUnit.SECONDS);
52+
}
53+
54+
private void startSystem() {
55+
try {
56+
botInstance.startBot();
57+
} catch (IOException e) {
58+
e.printStackTrace();
59+
} catch (IrcException e) {
60+
e.printStackTrace();
61+
}
62+
}
63+
64+
private Configuration.Builder generateConfiguration() {
65+
return new Configuration.Builder()
66+
67+
.setEncoding(Charset.forName("UTF-8")) //Support UTF-8
68+
69+
.setAutoNickChange(false) //Twitch doesn't support multiple users
70+
.setOnJoinWhoEnabled(false) //Twitch doesn't support WHO command
71+
72+
.setCapEnabled(true)
73+
.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
74+
.addCapHandler(new EnableCapHandler("twitch.tv/tags"))
75+
.addCapHandler(new EnableCapHandler("twitch.tv/commands"))
76+
77+
78+
.addServer("irc.twitch.tv")
79+
80+
.setName(ConfigManager.getConfig().getChannel_config().get("bot_username")) //Your twitch.tv username
81+
.setServerPassword(ConfigManager.getConfig().getChannel_config().get("bot_token")) //Your oauth password from http://twitchapps.com/tmi
82+
.addAutoJoinChannel(ConfigManager.getConfig().getChannel_config().get("channel_name"))
83+
84+
.addListener(new ManageCheerListener())
85+
86+
;
87+
}
88+
89+
public void sendMessage(String message) {
90+
messages.add(message);
91+
PrintConsole.sendInfo("Se ha cargado un mensaje para ser enviado por el BOT");
92+
}
93+
94+
public PircBotX getBOTInstance() {
95+
return botInstance;
96+
}
97+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package me.mrdoc.twitchtopcheers.bot.listener;
2+
3+
import me.mrdoc.twitchtopcheers.classes.Cheering;
4+
import me.mrdoc.twitchtopcheers.managers.DBCheerManagent;
5+
import me.mrdoc.twitchtopcheers.managers.FileCheerManagent;
6+
import me.mrdoc.twitchtopcheers.utils.PrintConsole;
7+
import org.pircbotx.hooks.ListenerAdapter;
8+
import org.pircbotx.hooks.events.MessageEvent;
9+
10+
import java.util.ArrayList;
11+
12+
/**
13+
* Created on 19-07-2017 for twitchtopcheers.
14+
*
15+
* @author Doc
16+
*/
17+
public class ManageCheerListener extends ListenerAdapter {
18+
19+
@Override
20+
public void onMessage(MessageEvent event) {
21+
for(String tag : event.getV3Tags().keySet()) {
22+
if(tag.contains("bits")) {
23+
System.out.println("==========================================]");
24+
PrintConsole.sendInfo("Se detecto un mensaje con TAG de cheers, enviando a evento custom.");
25+
onCheerEvent(event);
26+
}
27+
}
28+
}
29+
30+
private void onCheerEvent(MessageEvent event) {
31+
PrintConsole.sendInfo("El usuario " + event.getUser().getNick() + " envio " + event.getV3Tags().get("bits") + " cheers.");
32+
int cheerInMsg = Integer.parseInt(event.getV3Tags().get("bits")); //Obtengo cantidad de bits
33+
DBCheerManagent.addCheer(event.getUser().getNick(),cheerInMsg);
34+
35+
//Recargamos TOP
36+
ArrayList<Cheering> cheersTOP = DBCheerManagent.getTOPCheers(1);
37+
38+
FileCheerManagent.setTOP(cheersTOP.get(0));
39+
}
40+
41+
}

0 commit comments

Comments
 (0)