adding ingame chat support from sourcemod through java to python
This commit is contained in:
parent
bc29b5b97d
commit
d13e8cde77
@ -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() {
|
||||||
|
}
|
||||||
|
}
|
@ -105,6 +105,34 @@ public class DataMapper {
|
|||||||
return hlStatsMessages;
|
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) {
|
public static void CloseConnections(PreparedStatement ps, ResultSet rs, Connection con) {
|
||||||
if (rs != null) {
|
if (rs != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -220,7 +220,7 @@ public class Datahandler {
|
|||||||
hlStatsMessages.put(str, hlStatsMessages.size());
|
hlStatsMessages.put(str, hlStatsMessages.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int capacity = 600;
|
int capacity = 50;
|
||||||
hlStatsMessages.keySet().forEach(str -> {
|
hlStatsMessages.keySet().forEach(str -> {
|
||||||
if (!str.startsWith("!") && MessageResponseHandler.getStr().values().size() < capacity) {
|
if (!str.startsWith("!") && MessageResponseHandler.getStr().values().size() < capacity) {
|
||||||
String orElse = strCacheLocal.values().parallelStream().filter(e -> e.equals(str)).findAny().orElse(null);
|
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);
|
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 class AnnotationCollector<T> implements Consumer<T> {
|
||||||
|
|
||||||
private static int i = 0;
|
private static int i = 0;
|
||||||
|
@ -19,6 +19,8 @@ import FunctionLayer.DoStuff;
|
|||||||
import FunctionLayer.PipelineJMWESingleton;
|
import FunctionLayer.PipelineJMWESingleton;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.javacord.api.DiscordApi;
|
import org.javacord.api.DiscordApi;
|
||||||
@ -29,6 +31,12 @@ import org.javacord.api.DiscordApiBuilder;
|
|||||||
* @author install1
|
* @author install1
|
||||||
*/
|
*/
|
||||||
public class DiscordHandler {
|
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) {
|
public static void main(String[] args) {
|
||||||
System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "15");
|
System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "15");
|
||||||
@ -48,6 +56,8 @@ public class DiscordHandler {
|
|||||||
Datahandler.instance.updateStringCache();
|
Datahandler.instance.updateStringCache();
|
||||||
String token = "NTI5NzAxNTk5NjAyMjc4NDAx.Dw0vDg.7-aMjVWdQMYPl8qVNyvTCPS5F_A";
|
String token = "NTI5NzAxNTk5NjAyMjc4NDAx.Dw0vDg.7-aMjVWdQMYPl8qVNyvTCPS5F_A";
|
||||||
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
|
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
|
||||||
|
Timer timer = new Timer();
|
||||||
|
timer.scheduleAtFixedRate(new update_autismo_ingame_msgs(), 700, 700);
|
||||||
api.addMessageCreateListener(event -> {
|
api.addMessageCreateListener(event -> {
|
||||||
if (!FunctionLayer.DoStuff.isOccupied()) {
|
if (!FunctionLayer.DoStuff.isOccupied()) {
|
||||||
FunctionLayer.DoStuff.doStuff(event, api);
|
FunctionLayer.DoStuff.doStuff(event, api);
|
||||||
|
Loading…
Reference in New Issue
Block a user