removed obsolete event notifier
This commit is contained in:
parent
7bdfb1b288
commit
e4712524d2
@ -1,49 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<actions>
|
||||
<action>
|
||||
<actionName>run</actionName>
|
||||
<packagings>
|
||||
<packaging>jar</packaging>
|
||||
</packagings>
|
||||
<goals>
|
||||
<goal>process-classes</goal>
|
||||
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
|
||||
</goals>
|
||||
<properties>
|
||||
<exec.args>-classpath %classpath FunctionLayer.Bottest</exec.args>
|
||||
<exec.executable>java</exec.executable>
|
||||
<exec.workingdir>E:\java8\Projects\EventNotfierDiscordBot</exec.workingdir>
|
||||
</properties>
|
||||
</action>
|
||||
<action>
|
||||
<actionName>debug</actionName>
|
||||
<packagings>
|
||||
<packaging>jar</packaging>
|
||||
</packagings>
|
||||
<goals>
|
||||
<goal>process-classes</goal>
|
||||
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
|
||||
</goals>
|
||||
<properties>
|
||||
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath FunctionLayer.Bottest</exec.args>
|
||||
<exec.executable>java</exec.executable>
|
||||
<jpda.listen>true</jpda.listen>
|
||||
<exec.workingdir>E:\java8\Projects\EventNotfierDiscordBot</exec.workingdir>
|
||||
</properties>
|
||||
</action>
|
||||
<action>
|
||||
<actionName>profile</actionName>
|
||||
<packagings>
|
||||
<packaging>jar</packaging>
|
||||
</packagings>
|
||||
<goals>
|
||||
<goal>process-classes</goal>
|
||||
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
|
||||
</goals>
|
||||
<properties>
|
||||
<exec.args>-classpath %classpath FunctionLayer.Bottest</exec.args>
|
||||
<exec.executable>java</exec.executable>
|
||||
<exec.workingdir>E:\java8\Projects\EventNotfierDiscordBot</exec.workingdir>
|
||||
</properties>
|
||||
</action>
|
||||
</actions>
|
@ -1,70 +0,0 @@
|
||||
<?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>com.mycompany</groupId>
|
||||
<artifactId>EventNotfierDiscordBot</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.javacord</groupId>
|
||||
<artifactId>javacord</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-dbcp2</artifactId>
|
||||
<version>2.5.0</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>26.0-jre</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<mainClass>FunctionLayer.Bottest</mainClass>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>install</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>lib/</classpathPrefix>
|
||||
<mainClass>${mainClass}</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class DBCPDataSource {
|
||||
private static BasicDataSource ds = new BasicDataSource();
|
||||
static {
|
||||
try {
|
||||
ds.setDriver(new com.mysql.cj.jdbc.Driver());
|
||||
ds.setUrl("jdbc:mysql://151.80.230.149:3306/eventscss?useLegacyDatetimeCode=false&serverTimezone=UTC");
|
||||
//ds.setUrl("jdbc:mysql://localhost:3306/eventcss?useLegacyDatetimeCode=false&serverTimezone=UTC");
|
||||
ds.setUsername("eventscss");
|
||||
ds.setPassword("sdbhb2h34b2hbhbdfwbfwhber234");
|
||||
ds.setMaxTotal(-1);
|
||||
ds.setMinIdle(5);
|
||||
ds.setMaxIdle(-1);
|
||||
ds.setMaxOpenPreparedStatements(100);
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DBCPDataSource.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getConnection() throws SQLException {
|
||||
return ds.getConnection();
|
||||
}
|
||||
|
||||
private DBCPDataSource() {
|
||||
}
|
||||
|
||||
}
|
@ -1,208 +0,0 @@
|
||||
/*
|
||||
* 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 FunctionLayer.CustomError;
|
||||
import FunctionLayer.StringObject;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import java.beans.PropertyVetoException;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class DataMapper {
|
||||
|
||||
public static final long EXPIRE_TIME_IN_SECONDS = TimeUnit.SECONDS.convert(15, TimeUnit.MINUTES);
|
||||
public static DataMapper instance = new DataMapper();
|
||||
private volatile boolean called;
|
||||
private final ConcurrentMap<Integer, StringObject> soEventContentCache;
|
||||
|
||||
public DataMapper() {
|
||||
this.soEventContentCache = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
}
|
||||
|
||||
public List<StringObject> getAllMapValues() {
|
||||
List<StringObject> MapColoumns = new ArrayList(soEventContentCache.values());
|
||||
return MapColoumns;
|
||||
}
|
||||
|
||||
public void insertIntoDBEventContent(ConcurrentMap<Integer, String> EventContentMap) {
|
||||
String SQL_Delete = "delete from Maps";
|
||||
String l_sSQL = "INSERT INTO `EventContent` (`title`,`Rewards`,`Leaders`,`datum`,`hours`) VALUES (?, ?, ?, ?, ?)";
|
||||
String l_SQLMaps = "INSERT INTO `Maps` (`MapNames`) VALUES (?)";
|
||||
List<String> maps = new ArrayList();
|
||||
try (Connection l_cCon = DBCPDataSource.getConnection()) {
|
||||
try (PreparedStatement s = l_cCon.prepareStatement(SQL_Delete)) {
|
||||
s.executeUpdate();
|
||||
}
|
||||
SQL_Delete = "delete from EventContent";
|
||||
try (PreparedStatement s = l_cCon.prepareStatement(SQL_Delete)) {
|
||||
s.executeUpdate();
|
||||
}
|
||||
try (PreparedStatement s = l_cCon.prepareStatement(l_sSQL)) {
|
||||
int i = 1;
|
||||
for (String str : EventContentMap.values()) {
|
||||
if (i < 6) {
|
||||
//System.out.println("str: " + str + "\n");
|
||||
s.setString(i, str);
|
||||
i++;
|
||||
} else {
|
||||
maps.add(str);
|
||||
}
|
||||
}
|
||||
s.executeUpdate();
|
||||
}
|
||||
try (PreparedStatement s = l_cCon.prepareStatement(l_SQLMaps)) {
|
||||
for (String strMap : maps) {
|
||||
if (!maps.isEmpty()) {
|
||||
s.setString(1, strMap);
|
||||
s.addBatch();
|
||||
}
|
||||
}
|
||||
s.executeBatch();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
called = false;
|
||||
}
|
||||
|
||||
private Map<Integer, StringObject> getCache() throws SQLException, IOException, CustomError {
|
||||
List<StringObject> stro;
|
||||
stro = GetEventContentFromDBTable();
|
||||
LinkedHashMap<Integer, StringObject> LHM = new LinkedHashMap();
|
||||
for (int i = 0; i < stro.size(); i++) {
|
||||
LHM.put(i, stro.get(i));
|
||||
}
|
||||
return LHM;
|
||||
}
|
||||
|
||||
public synchronized void initialization() throws SQLException, IOException, CustomError {
|
||||
if (called == false) {
|
||||
soEventContentCache.putAll(getCache());
|
||||
for (int i = 0; i < soEventContentCache.size(); i++) {
|
||||
soEventContentCache.get(i).setEventContent(modifyEventContent(soEventContentCache.get(i).getEventContent(), i));
|
||||
}
|
||||
called = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static String modifyEventContent(String str, int i) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
switch (i) {
|
||||
case 0: {
|
||||
sb.append(str);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
str = str.trim();
|
||||
sb.append(str);
|
||||
sb.insert(0, "Rewards: ");
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
sb.append(str);
|
||||
sb.insert(0, "Leaders: ");
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
sb.append(str);
|
||||
sb.insert(0, "Date: ");
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
sb.append(str);
|
||||
sb.insert(0, "Hour: ");
|
||||
sb.append("GMT +1");
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
sb.append(str);
|
||||
sb.insert(0, "Map: ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static List<StringObject> GetEventContentFromDBTable() throws CustomError {
|
||||
/*
|
||||
0 = title
|
||||
1 = rewards
|
||||
2 = leaders
|
||||
3 = datum
|
||||
4 = hours
|
||||
5 = maps
|
||||
*/
|
||||
List<StringObject> str = new ArrayList();
|
||||
Connection l_cCon = null;
|
||||
PreparedStatement l_pStatement = null;
|
||||
ResultSet l_rsSearch = null;
|
||||
try {
|
||||
l_cCon = DBCPDataSource.getConnection();
|
||||
String l_sSQL = "SELECT * FROM `EventContent`";
|
||||
l_pStatement = l_cCon.prepareStatement(l_sSQL);
|
||||
l_rsSearch = l_pStatement.executeQuery();
|
||||
l_rsSearch.next();
|
||||
for (int i = 1; i < 6; i++) {
|
||||
StringObject so = new StringObject(l_rsSearch.getString(i));
|
||||
str.add(so);
|
||||
}
|
||||
l_sSQL = "SELECT * FROM `Maps`";
|
||||
l_pStatement = l_cCon.prepareStatement(l_sSQL);
|
||||
l_rsSearch = l_pStatement.executeQuery();
|
||||
while (l_rsSearch.next()) {
|
||||
StringObject so = new StringObject(l_rsSearch.getString(1));
|
||||
str.add(so);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
throw new CustomError("failed in DataMapper " + ex.getMessage());
|
||||
} finally {
|
||||
CloseConnections(l_pStatement, l_rsSearch, l_cCon);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static void CloseConnections(PreparedStatement ps, ResultSet rs, Connection con) {
|
||||
if (rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
if (ps != null) {
|
||||
try {
|
||||
ps.close();
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
if (con != null) {
|
||||
try {
|
||||
con.close();
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* 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 FunctionLayer;
|
||||
//https://github.com/Javacord/Javacord
|
||||
//https://discordapp.com/developers/applications/
|
||||
//https://docs.javacord.org/api/v/3.0.1/org/javacord/api/DiscordApi.html
|
||||
//https://stackoverflow.com/questions/17654213/how-do-i-create-a-netbeans-style-jar-with-all-dependencies-in-a-lib-folder
|
||||
//ps ax | grep EventNotfierDiscordBot-1.0
|
||||
//kill $pid (number)
|
||||
/*
|
||||
screen -d -m -S nonRoot java -jar /home/sourcemodextensionstest/EventNotfierDiscordBot/EventNotfierDiscordBot-1.0.jar
|
||||
screen -ls (number1)
|
||||
screen -X -S (number1) quit
|
||||
*/
|
||||
|
||||
import DataLayer.DataMapper;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.javacord.api.DiscordApi;
|
||||
import org.javacord.api.DiscordApiBuilder;
|
||||
import org.javacord.api.event.message.MessageCreateEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class Bottest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Insert your bot's token here
|
||||
String token = "NTI5MDIyODgwOTU3MDcxMzk5.Dwqy6w.sgbRejEzZOLdTqyqzDmktSTBDpM";
|
||||
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
|
||||
api.addMessageCreateListener((MessageCreateEvent event) -> {
|
||||
DataMapper.instance.checkUpdateTime();
|
||||
if (event.getMessageContent().equalsIgnoreCase("!event")) {
|
||||
try {
|
||||
event.getChannel().sendMessage("Event Information: ");
|
||||
DataMapper.instance.initialization();
|
||||
List<StringObject> EventContent = DataMapper.instance.getAllMapValues();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < EventContent.size(); i++) {
|
||||
sb.append(EventContent.get(i).getEventContent()).append("\n");
|
||||
}
|
||||
event.getChannel().sendMessage(sb.toString());
|
||||
} catch (SQLException | IOException | CustomError ex) {
|
||||
Logger.getLogger(Bottest.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package FunctionLayer;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class CustomError extends Exception {
|
||||
|
||||
public CustomError(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
@ -1,179 +0,0 @@
|
||||
/*
|
||||
* 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 FunctionLayer;
|
||||
//ps ax | grep EventNotfierDiscordBot-1.0
|
||||
//kill $pid (number)
|
||||
/*
|
||||
screen -d -m -S nonRoot java -jar /home/sourcemodextensionstest/EventNotfierDiscordBot/EventNotfierDiscordBot-1.0.jar
|
||||
screen -ls (number1)
|
||||
screen -X -S (number1) quit
|
||||
nohup screen -d -m -S nonroot java -jar /home/sourcemodextensionstest/EventNotfierDiscordBot/EventNotfierDiscordBot-1.0.jar
|
||||
*/
|
||||
|
||||
import DataLayer.DataMapper;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.URL;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
import static jdk.nashorn.internal.objects.NativeRegExp.source;
|
||||
import org.javacord.api.DiscordApi;
|
||||
import org.javacord.api.DiscordApiBuilder;
|
||||
import org.javacord.api.event.message.MessageCreateEvent;
|
||||
import org.jsoup.Jsoup;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class EventNotifier {
|
||||
|
||||
//public static EventNotifier instance = new EventNotifier();
|
||||
public static final long EXPIRE_TIME_IN_SECONDS = TimeUnit.SECONDS.convert(15, TimeUnit.MINUTES);
|
||||
private static Stopwatch stopwatch = Stopwatch.createUnstarted();
|
||||
private static String eventURL = "https://unloze.com/forums/events.76/";
|
||||
|
||||
private static void checkIfNewEventThread() {
|
||||
try {
|
||||
URL url = new URL(eventURL);
|
||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||
String inputLine;
|
||||
StringBuffer content = new StringBuffer();
|
||||
int firstEventForZEFinder = 0;
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
content.append(inputLine).append("\n");
|
||||
if (inputLine.contains(">Event #") && inputLine.contains("data-previewUrl=\"") && firstEventForZEFinder == 0) {
|
||||
//System.out.println("inputLine: " + inputLine);
|
||||
boolean find = Pattern.compile(Pattern.quote("nomination"), Pattern.CASE_INSENSITIVE).matcher(inputLine).find();
|
||||
if (!find) {
|
||||
find = Pattern.compile(Pattern.quote("poll"), Pattern.CASE_INSENSITIVE).matcher(inputLine).find();
|
||||
if (!find) {
|
||||
int diff = content.length() - inputLine.length();
|
||||
firstEventForZEFinder = diff > 0 ? diff : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
String str = content.toString();
|
||||
String hRef = "data-previewUrl=\"";
|
||||
str = str.substring(firstEventForZEFinder);
|
||||
//System.out.println("str post firstEventForZEFinder: " + str);
|
||||
str = str.substring(0, str.indexOf(">Event #"));
|
||||
str = str.trim();
|
||||
str = str.substring(str.indexOf(hRef), str.lastIndexOf("/preview\""));
|
||||
str = str.replace(hRef, "");
|
||||
String urlFirstEvent = "https://unloze.com/" + str;
|
||||
System.out.println("urlFirstEvent: " + urlFirstEvent);
|
||||
url = new URL(urlFirstEvent);
|
||||
con = (HttpURLConnection) url.openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||
content = new StringBuffer();
|
||||
String title = "";
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
content.append(inputLine).append("\n");
|
||||
if (inputLine.contains("Server :")) {
|
||||
int diff = content.length() - inputLine.length();
|
||||
firstEventForZEFinder = diff > 0 ? diff : 0;
|
||||
}
|
||||
if (inputLine.contains("<title>Event #")) {
|
||||
title = inputLine;
|
||||
}
|
||||
if (inputLine.contains("Prize :")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
str = content.toString();
|
||||
str = str.substring(firstEventForZEFinder);
|
||||
//System.out.println("str pre thread check: " + str);
|
||||
ConcurrentMap<Integer, String> eventContentMap = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
String html2text = html2text(str);
|
||||
//System.out.println("html2text: " + html2text);
|
||||
title = html2text(title);
|
||||
title = title.substring(0, title.length() - 8);
|
||||
// System.out.println("title: " + title);
|
||||
eventContentMap.put(eventContentMap.size(), title);
|
||||
String rewards = html2text.substring(html2text.indexOf("Prize :") + 7);
|
||||
// System.out.println("rewards: " + rewards);
|
||||
eventContentMap.put(eventContentMap.size(), rewards);
|
||||
String leaders = html2text.substring(html2text.indexOf("Leader :") + 7, html2text.indexOf("Prize :"));
|
||||
eventContentMap.put(eventContentMap.size(), leaders);
|
||||
String date = html2text.substring(html2text.indexOf("Date :") + 6, html2text.indexOf("Time :"));
|
||||
eventContentMap.put(eventContentMap.size(), date);
|
||||
String Time = html2text.substring(html2text.indexOf("Time :") + 6, html2text.indexOf("Leader :"));
|
||||
eventContentMap.put(eventContentMap.size(), Time);
|
||||
String maps = html2text.substring(html2text.indexOf("Maps : -") + 6, html2text.indexOf("Date :"));
|
||||
if (maps.contains("CS:S Zombie Escape Server IP")){
|
||||
maps = maps.substring(maps.indexOf("Map :") + 5);
|
||||
}
|
||||
maps = maps.trim();
|
||||
System.out.println("maps: " + maps);
|
||||
if (!maps.contains("-")) {
|
||||
eventContentMap.put(eventContentMap.size(), maps);
|
||||
} else {
|
||||
String[] split = maps.split("-");
|
||||
for (String strsplit : split) {
|
||||
eventContentMap.put(eventContentMap.size(), strsplit);
|
||||
}
|
||||
}
|
||||
//System.out.println("pre insertIntoDBEventContent");
|
||||
DataMapper.instance.insertIntoDBEventContent(eventContentMap);
|
||||
con.disconnect();
|
||||
in.close();
|
||||
} catch (MalformedURLException | ProtocolException ex) {
|
||||
Logger.getLogger(EventNotifier.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(EventNotifier.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static String html2text(String html) {
|
||||
return Jsoup.parse(html).text();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String token = "NTI5MDIyODgwOTU3MDcxMzk5.Dwqy6w.sgbRejEzZOLdTqyqzDmktSTBDpM";
|
||||
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
|
||||
api.addMessageCreateListener((MessageCreateEvent event) -> {
|
||||
if (stopwatch.elapsed(TimeUnit.SECONDS) >= EXPIRE_TIME_IN_SECONDS || !stopwatch.isRunning()) {
|
||||
if (!stopwatch.isRunning()) {
|
||||
stopwatch.start();
|
||||
} else {
|
||||
stopwatch.reset();
|
||||
}
|
||||
checkIfNewEventThread();
|
||||
}
|
||||
if (event.getMessageContent().equalsIgnoreCase("!event")) {
|
||||
try {
|
||||
DataMapper.instance.initialization();
|
||||
List<StringObject> EventContent = DataMapper.instance.getAllMapValues();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Event Information: \n");
|
||||
for (StringObject SO : EventContent) {
|
||||
sb.append(SO.getEventContent()).append("\n");
|
||||
}
|
||||
event.getChannel().sendMessage(sb.toString());
|
||||
} catch (SQLException | IOException | CustomError ex) {
|
||||
Logger.getLogger(EventNotifier.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
/*
|
||||
* 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 FunctionLayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class StringObject {
|
||||
String EventContent;
|
||||
|
||||
public String getEventContent() {
|
||||
return EventContent;
|
||||
}
|
||||
|
||||
public void setEventContent(String EventContent) {
|
||||
this.EventContent = EventContent;
|
||||
}
|
||||
|
||||
public StringObject(String EventContent) {
|
||||
this.EventContent = EventContent;
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,68 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.javacord</groupId>
|
||||
<artifactId>javacord</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>Javacord</name>
|
||||
<description>An easy to use multithreaded library for creating Discord bots in Java</description>
|
||||
<url>https://www.javacord.org</url>
|
||||
<inceptionYear>2015</inceptionYear>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
<comments>A business-friendly OSS license</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>BtoBastian</id>
|
||||
<name>Bastian Oppermann</name>
|
||||
<email>bastianoppermann1997@gmail.com</email>
|
||||
<url>https://github.com/BtoBastian</url>
|
||||
<timezone>Europe/Berlin</timezone>
|
||||
</developer>
|
||||
</developers>
|
||||
<contributors>
|
||||
<contributor>
|
||||
<name>Björn Kautler</name>
|
||||
<email>Bjoern@Kautler.net</email>
|
||||
<url>https://github.com/Vampire</url>
|
||||
<timezone>Europe/Berlin</timezone>
|
||||
</contributor>
|
||||
</contributors>
|
||||
<scm>
|
||||
<connection>scm:git:https://github.com/Javacord/Javacord.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:Javacord/Javacord.git</developerConnection>
|
||||
<url>https://github.com/Javacord/Javacord</url>
|
||||
</scm>
|
||||
<issueManagement>
|
||||
<system>GitHub</system>
|
||||
<url>https://github.com/Javacord/Javacord/issues</url>
|
||||
</issueManagement>
|
||||
<ciManagement>
|
||||
<system>TeamCity</system>
|
||||
<url>https://ci.javacord.org/project.html?projectId=Javacord&guest=1</url>
|
||||
</ciManagement>
|
||||
<distributionManagement>
|
||||
<downloadUrl>https://github.com/Javacord/Javacord/releases</downloadUrl>
|
||||
</distributionManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.javacord</groupId>
|
||||
<artifactId>javacord-api</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.javacord</groupId>
|
||||
<artifactId>javacord-core</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,5 +0,0 @@
|
||||
#Generated by Maven
|
||||
#Fri Jan 04 22:18:34 CET 2019
|
||||
version=1.0
|
||||
groupId=com.mycompany
|
||||
artifactId=EventNotfierDiscordBot
|
@ -1,97 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|ARM">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>ARM</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|ARM">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>ARM</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|ARM64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>ARM64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|ARM64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>ARM64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x86">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x86</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x86">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x86</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{3ecf1ab2-fbd0-43c8-beb9-11ff8bb66aa2}</ProjectGuid>
|
||||
<Keyword>Linux</Keyword>
|
||||
<RootNamespace>Eventnotifier_v2</RootNamespace>
|
||||
<MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion>
|
||||
<ApplicationType>Linux</ApplicationType>
|
||||
<ApplicationTypeRevision>1.0</ApplicationTypeRevision>
|
||||
<TargetLinuxPlatform>Generic</TargetLinuxPlatform>
|
||||
<LinuxProjectType>{D51BCBC9-82E9-4017-911E-C93873C4EA2B}</LinuxProjectType>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="Configuration">
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'" Label="Configuration">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'" Label="Configuration">
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<RemoteRootDir>/home/sourcemodextensionstest</RemoteRootDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="Configuration">
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings" />
|
||||
<ImportGroup Label="Shared" />
|
||||
<ImportGroup Label="PropertySheets" />
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<IncludePath>/home/sourcemodextensionstest/EventNotifier/boost_1_69_0;/home/sourcemodextensionstest/EventNotifier/includes/mysql;/home/sourcemodextensionstest/EventNotifier/includes/jdbc;/home/sourcemodextensionstest/EventNotifier/curl-7.62.0/include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>/home/sourcemodextensionstest/EventNotifier/boost_1_69_0/libs;/home/sourcemodextensionstest/EventNotifier/curl-7.62.0/lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
</ItemGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>/home/sourcemodextensionstest/EventNotifier/boost_1_69_0;/home/sourcemodextensionstest/EventNotifier/includes/jdbc;/home/sourcemodextensionstest/EventNotifier/includes/mysql;/home/sourcemodextensionstest/EventNotifier/curl-7.62.0/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>-lmysqlcppconn;-lcurl;$(StlAdditionalDependencies);%(Link.AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets" />
|
||||
</Project>
|
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<RemoteTarget>-1386263875;104.248.40.216 (username=, port=22, authentication=Password)</RemoteTarget>
|
||||
</PropertyGroup>
|
||||
</Project>
|
@ -1,286 +0,0 @@
|
||||
#include <algorithm>
|
||||
#include <string.h>
|
||||
#include <cstdio>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include <cppconn/driver.h>
|
||||
#include <cppconn/exception.h>
|
||||
#include <cppconn/resultset.h>
|
||||
#include <cppconn/statement.h>
|
||||
#include "mysql_connection.h"
|
||||
#include "mysql_driver.h"
|
||||
#include <curl/curl.h>
|
||||
/*
|
||||
g++ -v -x c -E -
|
||||
-lmysqlcppconn
|
||||
https://stackoverflow.com/questions/34057798/how-does-one-set-up-the-visual-studio-code-compiler-debugger-to-gcc
|
||||
https://docs.microsoft.com/en-us/cpp/linux/deploy-run-and-debug-your-linux-project?view=vs-2017
|
||||
*/
|
||||
|
||||
using namespace std;
|
||||
string data;
|
||||
string mapnames[10];
|
||||
string EventContent[5];
|
||||
string pattern[10];
|
||||
int SelectMysqlEventCount(sql::Connection *con)
|
||||
{
|
||||
sql::Statement *stmt;
|
||||
sql::ResultSet *res;
|
||||
int EventCount = 0;
|
||||
try {
|
||||
stmt = con->createStatement();
|
||||
res = stmt->executeQuery("SELECT * FROM `EventCount`");
|
||||
if (res->next()) {
|
||||
cout << res->getInt(1) << endl;
|
||||
EventCount = res->getInt(1);
|
||||
}
|
||||
}
|
||||
catch (sql::SQLException &e) {
|
||||
cout << "# ERR: SQLException in " << __FILE__;
|
||||
cout << "# ERR: " << e.what();
|
||||
cout << " (MySQL error code: " << e.getErrorCode();
|
||||
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
|
||||
}
|
||||
delete stmt;
|
||||
delete res;
|
||||
//cout << endl;
|
||||
return EventCount;
|
||||
}
|
||||
|
||||
size_t writeCallback(char* buf, size_t size, size_t nmemb, void* up)
|
||||
{
|
||||
for (std::size_t c = 0; c < size*nmemb; c++)
|
||||
{
|
||||
data.push_back(buf[c]);
|
||||
}
|
||||
return size * nmemb; //tell curl how many bytes we handled
|
||||
}
|
||||
|
||||
|
||||
string printreturn(std::string::size_type urlstringend, std::string const &s)
|
||||
{
|
||||
string strreturn("");
|
||||
if (urlstringend == std::string::npos) {
|
||||
strreturn = "not found sdbhabd2342d";
|
||||
}
|
||||
else
|
||||
{
|
||||
strreturn = s.substr(0, urlstringend);
|
||||
}
|
||||
return strreturn;
|
||||
}
|
||||
|
||||
void removeSubstrs(string& s, string& p) {
|
||||
string::size_type n = p.length();
|
||||
for (string::size_type i = s.find(p);
|
||||
i != string::npos;
|
||||
i = s.find(p))
|
||||
s.erase(i, n);
|
||||
}
|
||||
|
||||
void ReadForumSubSectionEvent()
|
||||
{
|
||||
int index;
|
||||
CURL* curl;
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
curl = curl_easy_init();
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://unloze.com/forums/events.76/");
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallback);
|
||||
//curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); //tell curl to output its progress
|
||||
curl_easy_perform(curl);
|
||||
//check by taking the first from the top of the page, thats always the newest in order
|
||||
//the needed context is always close, instead of taking the full size we only take the needed portion distance
|
||||
std::string::size_type urlstringend;
|
||||
urlstringend = data.find("preview\">Event #");
|
||||
std::string sdeli = ("data-previewUrl=\"");
|
||||
string strf = printreturn(urlstringend, data);
|
||||
size_t pos = 0;
|
||||
if ((pos = strf.find(sdeli)) != std::string::npos) {
|
||||
strf.erase(0, pos + sdeli.length());
|
||||
}
|
||||
data.clear();
|
||||
strf.insert(0, "https://unloze.com/");
|
||||
//https://unloze.com/threads/event-54n74-15-b4ck.1324 is returned here for example
|
||||
std::cout << "strf.c_str(): " << strf.c_str() << "\n";
|
||||
curl_easy_setopt(curl, CURLOPT_URL, strf.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallback);
|
||||
curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
curl_global_cleanup();
|
||||
//assumes only ze event threads contain "CS:S Zombie Escape"
|
||||
//mapnames collects maps specified to event
|
||||
urlstringend = data.find("CS:S Zombie Escape");
|
||||
strf = printreturn(urlstringend, data);
|
||||
if (strf.find("not found sdbhabd2342d") == std::string::npos)
|
||||
{
|
||||
urlstringend = data.find("Prize :");
|
||||
strf = printreturn(urlstringend, data);
|
||||
sdeli = ("<a href=\"http://fastdl.unloze.com/css_ze/maps/");
|
||||
pos = 0;
|
||||
while ((pos = strf.find(sdeli)) != std::string::npos && index < 10)
|
||||
{
|
||||
strf.erase(0, pos + sdeli.length());
|
||||
mapnames[index] = strf.substr(0, strf.find(".bsp.bz2"));
|
||||
std::cout << "mapnames[index]: " << mapnames[index] << "\n";
|
||||
index++;
|
||||
}
|
||||
//EventContent 0 = title
|
||||
urlstringend = data.find("| UNLOZE</title>");
|
||||
strf = printreturn(urlstringend, data);
|
||||
sdeli = ("<title>");
|
||||
pos = 0;
|
||||
if ((pos = strf.find(sdeli)) != std::string::npos)
|
||||
{
|
||||
strf.erase(0, pos + sdeli.length());
|
||||
EventContent[0] = strf;
|
||||
}
|
||||
//EventContent 1 = rewards
|
||||
urlstringend = data.find("<div class=\"messageTextEndMarker\"> </div>");
|
||||
strf = printreturn(urlstringend, data);
|
||||
sdeli = ("Prize :");
|
||||
pos = 0;
|
||||
index = 0;
|
||||
if ((pos = strf.find(sdeli)) != std::string::npos)
|
||||
{
|
||||
strf.erase(0, pos + sdeli.length());
|
||||
size_t index1 = 0;
|
||||
pattern[0] = "</span>";
|
||||
pattern[1] = "<br/>";
|
||||
pattern[2] = "<b>";
|
||||
pattern[3] = "</b>";
|
||||
string teststr = strf;
|
||||
while (!!pattern[index].size())
|
||||
{
|
||||
removeSubstrs(teststr, pattern[index]);
|
||||
index++;
|
||||
}
|
||||
//std::cout << "teststr: " << "\n" << teststr << "\n";
|
||||
strf = teststr;
|
||||
EventContent[1] = strf;
|
||||
}
|
||||
//EventContent 2 = leader
|
||||
urlstringend = data.find("Prize :");
|
||||
strf = printreturn(urlstringend, data);
|
||||
sdeli = ("Leader :</span>");
|
||||
pos = 0;
|
||||
if ((pos = strf.find(sdeli)) != std::string::npos)
|
||||
{
|
||||
strf.erase(0, pos + sdeli.length());
|
||||
//std::cout << "reached eventcontent2 strf: " << strf << "\n";
|
||||
EventContent[2] = strf.substr(0, strf.find("<"));
|
||||
}
|
||||
//EventContent 3 = date
|
||||
urlstringend = data.find("\">Time :");
|
||||
strf = printreturn(urlstringend, data);
|
||||
sdeli = ("Date :</span>");
|
||||
pos = 0;
|
||||
if ((pos = strf.find(sdeli)) != std::string::npos)
|
||||
{
|
||||
strf.erase(0, pos + sdeli.length());
|
||||
EventContent[3] = strf.substr(0, strf.find("<"));
|
||||
}
|
||||
//EventContent[4] = hours
|
||||
urlstringend = data.find("Leader :");
|
||||
strf = printreturn(urlstringend, data);
|
||||
sdeli = ("Time :</span>");
|
||||
pos = 0;
|
||||
if ((pos = strf.find(sdeli)) != std::string::npos)
|
||||
{
|
||||
strf.erase(0, pos + sdeli.length());
|
||||
strf = strf.substr(0, strf.find("pm GMT+1"));
|
||||
}
|
||||
sdeli = ("//");
|
||||
pos = 0;
|
||||
if ((pos = strf.find(sdeli)) != std::string::npos)
|
||||
{
|
||||
strf.erase(0, pos + sdeli.length());
|
||||
EventContent[4] = strf;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Not found" << "\n" << "data value: " << data << "\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MYSQLUpdateEventMaps(sql::Connection *con)
|
||||
{
|
||||
sql::Statement *stmt;
|
||||
try {
|
||||
stmt = con->createStatement();
|
||||
stmt->executeUpdate("delete from Maps");
|
||||
int index;
|
||||
while (!!mapnames[index].size())
|
||||
{
|
||||
stmt->executeUpdate("INSERT INTO `Maps` (`MapNames`) VALUES (\"" + mapnames[index] + "\")");
|
||||
index++;
|
||||
}
|
||||
}
|
||||
catch (sql::SQLException &e) {
|
||||
cout << "# ERR: SQLException in " << __FILE__;
|
||||
cout << "# ERR: " << e.what();
|
||||
cout << " (MySQL error code: " << e.getErrorCode();
|
||||
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
|
||||
}
|
||||
delete stmt;
|
||||
}
|
||||
|
||||
void MYSQLUpdateEventContent(sql::Connection *con)
|
||||
{
|
||||
sql::Statement *stmt;
|
||||
try {
|
||||
stmt = con->createStatement();
|
||||
stmt->executeUpdate("UPDATE `EventContent` SET `title`=\"" + EventContent[0] +"\",`Rewards`=\"" + EventContent[1]
|
||||
+ "\",`Leaders`=\"" + EventContent[2] + "\",`datum`=\"" + EventContent[3] + "\",`hours`=\"" + EventContent[4] + "\"");
|
||||
}catch (sql::SQLException &e) {
|
||||
cout << "# ERR: SQLException in " << __FILE__;
|
||||
cout << "# ERR: " << e.what();
|
||||
cout << " (MySQL error code: " << e.getErrorCode();
|
||||
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
|
||||
}
|
||||
delete stmt;
|
||||
}
|
||||
|
||||
bool CloseDBConnection(sql::Connection *con)
|
||||
{
|
||||
try
|
||||
{
|
||||
con->close();
|
||||
delete con;
|
||||
return true;
|
||||
}
|
||||
catch (sql::SQLException &e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
sql::mysql::MySQL_Driver *driver;
|
||||
sql::Connection *con;
|
||||
driver = sql::mysql::get_driver_instance();
|
||||
con = driver->connect("tcp://151.80.230.149:3306", "eventscss", "sdbhb2h34b2hbhbdfwbfwhber234");
|
||||
con->setSchema("eventscss");
|
||||
try {
|
||||
//Eventcount = SelectMysqlEventCount(con);
|
||||
ReadForumSubSectionEvent();
|
||||
MYSQLUpdateEventMaps(con);
|
||||
MYSQLUpdateEventContent(con);
|
||||
CloseDBConnection(con);
|
||||
}
|
||||
catch (sql::SQLException &e) {
|
||||
cout << "# ERR: SQLException in " << __FILE__;
|
||||
cout << "# ERR: " << e.what();
|
||||
cout << " (MySQL error code: " << e.getErrorCode();
|
||||
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
|
||||
}
|
||||
cout << "EventContent[0]: " << EventContent[0] << endl;
|
||||
cout << "EventContent[1]: " << EventContent[1] << endl;
|
||||
cout << "EventContent[2]: " << EventContent[2] << endl;
|
||||
cout << "EventContent[3]: " << EventContent[3] << endl;
|
||||
cout << "EventContent[4]: " << EventContent[4] << endl;
|
||||
return 0;
|
||||
}
|
@ -1,296 +0,0 @@
|
||||
#pragma semicolon 1
|
||||
#define DEBUG
|
||||
#define PLUGIN_AUTHOR "jenz"
|
||||
#define PLUGIN_VERSION "1.00"
|
||||
#define g_dIndex 65
|
||||
#define g_dLength 256
|
||||
#include <sourcemod>
|
||||
#include <sdktools>
|
||||
#include <system2>
|
||||
#pragma newdecls required
|
||||
//64 maps in one event cuz ofc
|
||||
char g_cEventMaps[g_dIndex][g_dLength];
|
||||
char g_cEventContent[g_dLength][g_dLength];
|
||||
int g_iIndexCounter;
|
||||
Database g_dDatabase;
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "schedule announcer",
|
||||
author = PLUGIN_AUTHOR,
|
||||
description = "informs players when next event takes place",
|
||||
version = PLUGIN_VERSION,
|
||||
url = "www.unloze.com"
|
||||
};
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnPluginStart()
|
||||
{
|
||||
RegConsoleCmd("sm_event", Cmd_EventNotifier);
|
||||
RegConsoleCmd("sm_events", Cmd_EventNotifier);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Action Cmd_EventNotifier(int client, any args)
|
||||
{
|
||||
EventNotifierMenu(client);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnMapStart()
|
||||
{
|
||||
SQL_StartConnection();
|
||||
SQL_CreateDBIFNotExist();
|
||||
EventInfo();
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
static void EventNotifierMenu(int client)
|
||||
{
|
||||
Menu EventMenu = new Menu(MenuHandler1);
|
||||
char l_cEventTimeleft[g_dLength][1];
|
||||
EventMenu.SetTitle("UNLOZE Event Information");
|
||||
CalculateTimeToNextEvent(g_cEventContent[3], g_cEventContent[4], l_cEventTimeleft[0], sizeof(l_cEventTimeleft));
|
||||
// 0 event title
|
||||
EventMenu.AddItem("", g_cEventContent[0], ITEMDRAW_DISABLED);
|
||||
for (int i = 0; i < g_iIndexCounter; i++)
|
||||
{
|
||||
if (StrContains(g_cEventMaps[i], "Map:", false) == -1)
|
||||
{
|
||||
Format(g_cEventMaps[i], sizeof(g_cEventMaps), "Map: %s", g_cEventMaps[i]);
|
||||
}
|
||||
EventMenu.AddItem("", g_cEventMaps[i], ITEMDRAW_DISABLED);
|
||||
}
|
||||
// 1 rewards
|
||||
if (StrContains(g_cEventContent[1], "Rewards:", false) == -1)
|
||||
{
|
||||
TrimString(g_cEventContent[1]);
|
||||
Format(g_cEventContent[1], sizeof(g_cEventContent), "Rewards: %s", g_cEventContent[1]);
|
||||
}
|
||||
EventMenu.AddItem("", g_cEventContent[1], ITEMDRAW_DISABLED);
|
||||
// 2 leaders
|
||||
if (StrContains(g_cEventContent[2], "Leaders:", false) == -1)
|
||||
{
|
||||
Format(g_cEventContent[2], sizeof(g_cEventContent), "Leaders: %s", g_cEventContent[2]);
|
||||
}
|
||||
EventMenu.AddItem("", g_cEventContent[2], ITEMDRAW_DISABLED);
|
||||
// 3 timeleft
|
||||
if (StrContains(l_cEventTimeleft[0], "Timeleft:", false) == -1)
|
||||
{
|
||||
Format(l_cEventTimeleft[0], sizeof(l_cEventTimeleft), "Timeleft: %s", l_cEventTimeleft[0]);
|
||||
}
|
||||
EventMenu.AddItem("", l_cEventTimeleft[0], ITEMDRAW_DISABLED);
|
||||
EventMenu.ExitButton = true;
|
||||
EventMenu.ExitBackButton = true;
|
||||
EventMenu.Display(client, 0);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public int MenuHandler1(Menu menu, MenuAction action, int param1, int param2)
|
||||
{
|
||||
if (action == MenuAction_End)
|
||||
{
|
||||
delete menu;
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void CalculateTimeToNextEvent(char[] content, char[] content1, char[]str, int maxsize)
|
||||
{
|
||||
//content = 24/11/2018
|
||||
//content1 = : 6
|
||||
char sPart[2][526];
|
||||
char sYear[24];
|
||||
char sMonth[24];
|
||||
char sDay[24];
|
||||
char sHour[24];
|
||||
char sMinute[24];
|
||||
int i_Year;
|
||||
int i_Month;
|
||||
int i_Day;
|
||||
int i_Hour;
|
||||
int i_Minute;
|
||||
int year;
|
||||
int months;
|
||||
int days;
|
||||
int l_hours;
|
||||
int minutes;
|
||||
FormatTime(sYear, sizeof(sYear), "%Y");
|
||||
FormatTime(sMonth, sizeof(sMonth), "%m");
|
||||
FormatTime(sDay, sizeof(sDay), "%d");
|
||||
FormatTime(sHour, sizeof(sHour), "%H");
|
||||
FormatTime(sMinute, sizeof(sMinute), "%M");
|
||||
TrimString(content);
|
||||
TrimString(content1);
|
||||
ExplodeString(content, "/", sPart, 2, maxsize);
|
||||
i_Day = StringToInt(sDay);
|
||||
days = StringToInt(sPart[0]);
|
||||
i_Month = StringToInt(sMonth);
|
||||
ExplodeString(sPart[1], "/", sPart, 2, maxsize);
|
||||
months = StringToInt(sPart[0]);
|
||||
i_Hour = StringToInt(sHour);
|
||||
l_hours = StringToInt(content1);
|
||||
char sPart1[3][526];
|
||||
ExplodeString(content, "/", sPart1, 3, maxsize);
|
||||
year = StringToInt(sPart1[2]);
|
||||
i_Year = StringToInt(sYear);
|
||||
i_Minute = StringToInt(sMinute);
|
||||
if (days >= i_Day || months > i_Month || year > i_Year)
|
||||
{
|
||||
if (i_Year <= year)
|
||||
{
|
||||
if (year > i_Year)
|
||||
{
|
||||
i_Month = 1;
|
||||
}
|
||||
if (days >= i_Day)
|
||||
{
|
||||
days -= i_Day;
|
||||
}
|
||||
else if (i_Month == 1 || i_Month == 3 || i_Month == 5 || i_Month == 7 || i_Month == 8 || i_Month == 10 || i_Month == 12)
|
||||
{
|
||||
days += (31 - i_Day);
|
||||
}
|
||||
else if (i_Month == 2)
|
||||
{
|
||||
days += (28 - i_Day);
|
||||
}
|
||||
else
|
||||
{
|
||||
days += (30 - i_Day);
|
||||
}
|
||||
//from 12 to 24 or from 7 to 19 etc etc
|
||||
l_hours += 12;
|
||||
if (i_Hour > l_hours)
|
||||
{
|
||||
days -= 1;
|
||||
l_hours = 24 - (i_Hour - l_hours);
|
||||
//PrintToChatAll("if statement l_hours: %i", l_hours);
|
||||
}
|
||||
else
|
||||
{
|
||||
l_hours -= i_Hour;
|
||||
//PrintToChatAll("else statement: l_hours: %i", l_hours);
|
||||
}
|
||||
if (l_hours != 0)
|
||||
{
|
||||
l_hours -= 1;
|
||||
}
|
||||
minutes = 60 - i_Minute;
|
||||
Format(str, maxsize, "Taking Place in: %i Days, %i hours, %i Minutes", days, l_hours, minutes);
|
||||
}
|
||||
else
|
||||
{
|
||||
Format(str, maxsize, "EVENT OVER");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Format(str, maxsize, "EVENT OVER");
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void EventInfo()
|
||||
{
|
||||
MYSQLGetEventContent();
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void MYSQLGetEventContent()
|
||||
{
|
||||
MYSQLGetContent();
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void MYSQLGetContent()
|
||||
{
|
||||
char sQuery[g_dLength];
|
||||
Format(sQuery, sizeof(sQuery), "SELECT * FROM `EventContent`");
|
||||
SQL_TQuery(g_dDatabase, TqueryThreadCallback, sQuery);
|
||||
Format(sQuery, sizeof(sQuery), "SELECT * FROM `Maps`");
|
||||
SQL_TQuery(g_dDatabase, TqueryThreadCallbackmaps, sQuery);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void TqueryThreadCallback(Handle db, Handle rs, const char[] error, any data)
|
||||
{
|
||||
if (SQL_GetRowCount(rs) > 0 && SQL_FetchRow(rs))
|
||||
{
|
||||
// 0 event title
|
||||
SQL_FetchString(rs, 0, g_cEventContent[0], sizeof(g_cEventContent));
|
||||
// 1 rewards
|
||||
SQL_FetchString(rs, 1, g_cEventContent[1], sizeof(g_cEventContent));
|
||||
// 2 leaders
|
||||
SQL_FetchString(rs, 2, g_cEventContent[2], sizeof(g_cEventContent));
|
||||
// 3 timeleft (24/11/2018)
|
||||
SQL_FetchString(rs, 3, g_cEventContent[3], sizeof(g_cEventContent));
|
||||
//4 timeleft = : 5 pm GMT+0 // 6 pm GMT+1 // 7 pm GMT+2
|
||||
SQL_FetchString(rs, 4, g_cEventContent[4], sizeof(g_cEventContent));
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void TqueryThreadCallbackmaps(Handle owner, Handle rs, const char[] error, any data)
|
||||
{
|
||||
g_iIndexCounter = 0;
|
||||
if (SQL_GetRowCount(rs) > 0 && SQL_FetchRow(rs))
|
||||
{
|
||||
g_iIndexCounter++;
|
||||
int index;
|
||||
SQL_FetchString(rs, 0, g_cEventMaps[index], sizeof(g_cEventMaps));
|
||||
index++;
|
||||
while (SQL_FetchRow(rs))
|
||||
{
|
||||
SQL_FetchString(rs, 0, g_cEventMaps[index], sizeof(g_cEventMaps));
|
||||
index++;
|
||||
g_iIndexCounter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void SQL_StartConnection()
|
||||
{
|
||||
char error[g_dLength];
|
||||
if (SQL_CheckConfig("eventscss"))
|
||||
g_dDatabase = SQL_Connect("eventscss", true, error, sizeof(error));
|
||||
if (g_dDatabase == null)
|
||||
{
|
||||
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to MYSQL-DB!");
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void SQL_CreateDBIFNotExist()
|
||||
{
|
||||
char sQuery[g_dLength];
|
||||
Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `eventscss`.`EventContent` (`title` VARCHAR(256) NOT NULL, `Rewards` VARCHAR(256) NULL, `Leaders` VARCHAR(256) NULL, `datum` VARCHAR(128) NULL, `hours` VARCHAR(128) NULL, PRIMARY KEY (`title`)) ENGINE = InnoDB;");
|
||||
SQL_FastQuery(g_dDatabase, sQuery);
|
||||
Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `eventscss`.`Maps` (`MapNames` VARCHAR(45) NOT NULL, PRIMARY KEY (`MapNames`)) ENGINE = InnoDB;");
|
||||
SQL_FastQuery(g_dDatabase, sQuery);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
stock bool IsValidClient(int client)
|
||||
{
|
||||
if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
Loading…
Reference in New Issue
Block a user