notifier
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?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>
|
||||
@@ -0,0 +1,70 @@
|
||||
<?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>
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* 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.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;
|
||||
private final Stopwatch stopwatch;
|
||||
|
||||
public DataMapper() {
|
||||
this.stopwatch = Stopwatch.createStarted();
|
||||
this.soEventContentCache = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
}
|
||||
|
||||
public List<StringObject> getAllMapValues() {
|
||||
List<StringObject> MapColoumns = new ArrayList(soEventContentCache.values());
|
||||
return MapColoumns;
|
||||
}
|
||||
|
||||
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 void checkUpdateTime() {
|
||||
new Thread(() -> {
|
||||
if (stopwatch.elapsed(TimeUnit.SECONDS) >= EXPIRE_TIME_IN_SECONDS) {
|
||||
try {
|
||||
soEventContentCache.clear();
|
||||
called = false;
|
||||
initialization();
|
||||
stopwatch.reset();
|
||||
} catch (SQLException | IOException | CustomError ex) {
|
||||
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.
@@ -0,0 +1,68 @@
|
||||
<?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>[email protected]</email>
|
||||
<url>https://github.com/BtoBastian</url>
|
||||
<timezone>Europe/Berlin</timezone>
|
||||
</developer>
|
||||
</developers>
|
||||
<contributors>
|
||||
<contributor>
|
||||
<name>Björn Kautler</name>
|
||||
<email>[email protected]</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:[email protected]: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.
@@ -0,0 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Fri Jan 04 22:18:34 CET 2019
|
||||
version=1.0
|
||||
groupId=com.mycompany
|
||||
artifactId=EventNotfierDiscordBot
|
||||
Reference in New Issue
Block a user