adding ingame chat support from sourcemod through java to python

This commit is contained in:
jenzur 2020-05-05 23:52:01 +02:00
parent bc29b5b97d
commit d13e8cde77
4 changed files with 93 additions and 1 deletions

View File

@ -0,0 +1,42 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package DataLayer;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.dbcp2.BasicDataSource;
import DataLayer.settings;
/**
*
* @author install1
*/
public class DBCPDataSourceAutismo {
private static BasicDataSource ds = new BasicDataSource();
static {
try {
ds.setDriver(new com.mysql.cj.jdbc.Driver());
ds.setUrl(settings.autismo_url);
ds.setUsername(settings.autismo_username);
ds.setPassword(settings.autismo_password);
ds.setMaxTotal(-1);
ds.setMinIdle(5);
ds.setMaxIdle(-1);
ds.setMaxOpenPreparedStatements(100);
} catch (SQLException ex) {
Logger.getLogger(DBCPDataSourceAutismo.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static Connection getConnection() throws SQLException {
return ds.getConnection();
}
private DBCPDataSourceAutismo() {
}
}

View File

@ -105,6 +105,34 @@ public class DataMapper {
return hlStatsMessages;
}
public static String check_autismo_mysql() {
String target = "";
try (Connection l_cCon = DBCPDataSourceAutismo.getConnection()) {
String l_sSQL = "SELECT chatmessage FROM unloze_css_autism_bot.chatting c WHERE c.responsemessage = '' LIMIT 1";
try (PreparedStatement l_pStatement = l_cCon.prepareStatement(l_sSQL)) {
try (ResultSet l_rsSearch = l_pStatement.executeQuery()) {
while (l_rsSearch.next()) {
target = l_rsSearch.getString(1);
}
}
}
} catch (SQLException ex) {
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
}
return target;
}
public static void update_autismo_mysql(String responseMsg, String update_string) {
try (Connection l_cCon = DBCPDataSourceAutismo.getConnection()) {
String l_sSQL = "UPDATE unloze_css_autism_bot.`chatting` SET `responsemessage` = '" + responseMsg + "' WHERE `chatmessage` = '" + update_string + "'";
try (PreparedStatement l_pStatement = l_cCon.prepareStatement(l_sSQL)) {
l_pStatement.execute();
}
} catch (SQLException ex) {
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void CloseConnections(PreparedStatement ps, ResultSet rs, Connection con) {
if (rs != null) {
try {

View File

@ -220,7 +220,7 @@ public class Datahandler {
hlStatsMessages.put(str, hlStatsMessages.size());
}
}
int capacity = 600;
int capacity = 50;
hlStatsMessages.keySet().forEach(str -> {
if (!str.startsWith("!") && MessageResponseHandler.getStr().values().size() < capacity) {
String orElse = strCacheLocal.values().parallelStream().filter(e -> e.equals(str)).findAny().orElse(null);
@ -790,6 +790,18 @@ public class Datahandler {
return stringCache.values().size() - (stringCache.values().size() / 10);
}
public void update_autismo_mysql() {
String update_string = DataMapper.check_autismo_mysql();
if (!update_string.isEmpty()) {
try {
String getResponseMsg = getResponseMsg(update_string);
DataMapper.update_autismo_mysql(getResponseMsg, update_string);
} catch (CustomError ex) {
Logger.getLogger(Datahandler.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
private static class AnnotationCollector<T> implements Consumer<T> {
private static int i = 0;

View File

@ -19,6 +19,8 @@ import FunctionLayer.DoStuff;
import FunctionLayer.PipelineJMWESingleton;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.javacord.api.DiscordApi;
@ -29,6 +31,12 @@ import org.javacord.api.DiscordApiBuilder;
* @author install1
*/
public class DiscordHandler {
public static class update_autismo_ingame_msgs extends TimerTask {
@Override
public void run() {
Datahandler.instance.update_autismo_mysql();
}
}
public static void main(String[] args) {
System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "15");
@ -48,6 +56,8 @@ public class DiscordHandler {
Datahandler.instance.updateStringCache();
String token = "NTI5NzAxNTk5NjAyMjc4NDAx.Dw0vDg.7-aMjVWdQMYPl8qVNyvTCPS5F_A";
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
Timer timer = new Timer();
timer.scheduleAtFixedRate(new update_autismo_ingame_msgs(), 700, 700);
api.addMessageCreateListener(event -> {
if (!FunctionLayer.DoStuff.isOccupied()) {
FunctionLayer.DoStuff.doStuff(event, api);