Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
Merge pull request #5 from sfi-region9/email
Browse files Browse the repository at this point in the history
Switched to email
  • Loading branch information
vanilla-extracts authored Apr 4, 2020
2 parents 71eb1c2 + 3341c69 commit d6ad753
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 47 deletions.
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@
<version>3.1.0</version>
</dependency>

<dependency>
<groupId>org.simplejavamail</groupId>
<artifactId>simple-java-mail</artifactId>
<version>5.3.0</version>

<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.github.messenger4j</groupId>
<artifactId>messenger4j</artifactId>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/fr/charlotte/arsreloaded/AutoSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public void run() {
} catch (InterruptedException e) {
e.printStackTrace();
}
AutomaticReportServer.sendMessage(AutomaticReportServer.ADMIN_ID, "I'm still here");
System.out.println("Launching Automatic Launching Verification");
if (isTimeToSent()) {
System.out.println("Time is now :D !");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.apache.commons.lang3.StringUtils;
import org.pf4j.JarPluginManager;
import org.pf4j.PluginManager;
import org.simplejavamail.email.EmailBuilder;
import org.simplejavamail.mailer.Mailer;

import java.io.File;
import java.sql.SQLException;
Expand All @@ -44,9 +46,11 @@ public class AutomaticReportServer {
public static String ARS_VERSION = "v2.0";

public static String ADMIN_ID = "";
public static String ADMIN_MAIL = "";
private static String TOKEN = "";
private static String ACCESS_TOKEN = "";
private static String SECRET = "";
private static String ARSMAIL = "";

public static HashMap<String, ReportProcessing> processingHashMap = new HashMap<>();
public static HashMap<String, ProcessAllReports> processing = new HashMap<>();
Expand All @@ -56,6 +60,8 @@ public class AutomaticReportServer {
public static SimpleDateFormat DATE_M = new SimpleDateFormat("MM");
public static SimpleDateFormat DATE_Y = new SimpleDateFormat("YYYY");

private static Mailer mailer;


private final static Gson GSON = new Gson();

Expand Down Expand Up @@ -84,14 +90,18 @@ private static void loadConfig() {
SECRET = config.getSecretKey();
ADMIN_ID = config.getAdminID();
TOKEN = config.getVerifyToken();
ARSMAIL = config.getMailUser();
ADMIN_MAIL = config.getAdminMail();

arsDatabase = config.setupMainDatabase();
userDatabase = config.setupUserDatabase();

wrapper = new DatabaseWrapper(arsDatabase);
wrapperD = new DatabaseUserWrapper(userDatabase);
mailer = config.buildMailer();
}


private static void loadPlugins() throws SQLException {
processingHashMap.clear();
File file = new File("plugins/");
Expand Down Expand Up @@ -173,7 +183,7 @@ private static void setupRootRoute() {
if (request.queryParams().isEmpty())
return "Invalid";
String sentToken = request.queryParams("hub.verify_token");
if(sentToken == null)
if (sentToken == null)
return "Invalid";
if (sentToken.equalsIgnoreCase(TOKEN))
return request.queryParams("hub.challenge");
Expand Down Expand Up @@ -294,6 +304,10 @@ private static void setupRoutes() {
get("/hello", (request, response) -> "Hello World");
}

public static void sendCompletedMail(String subject, String message, String recipientName, String recipientAdress) {
mailer.sendMail(EmailBuilder.startingBlank().from("ARS Mail Sender", ARSMAIL).to(recipientName, recipientAdress).withSubject(subject).withPlainText(message).buildEmail());
}


/**
* Simple method to parse commands sent by messenger to the server
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/fr/charlotte/arsreloaded/commands/AboutCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ public AboutCommand() {
}


public static void main(String[] args) throws IOException {
System.getenv().keySet().stream().filter(s -> s.contains("EPSILON_VERSION")).forEach(System.out::println);

for(String s : System.getenv().keySet()){
if(s.contains("EPSILON_VERSION")){
System.out.println(s);
}
}

}



@Override
public void onCommand(String senderID, String text, String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public PingCommand() {
@Override
public void onCommand(String senderID, String text, String[] args) {
System.out.println("Ping Command received from " + senderID);
AutomaticReportServer.sendMessage(senderID, "Pong !!, Version " + AutomaticReportServer.ARS_VERSION + ", Developed by LCDR Charlotte THOMAS");
AutomaticReportServer.sendMessage(senderID, "Pong !!, Version " + AutomaticReportServer.ARS_VERSION + ", Developed by CMDR Charlotte THOMAS");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@ public SubscribeCommand() {

@Override
public void onCommand(String senderID, String text, String[] args) {
if (args.length < 2) {
if (args.length < 4) {
sendMessage(senderID, "Usage : !subscribe" + this.args());
return;
}
String scc;
String name;
String region;
if (args.length == 3) {
String mail;
if (args.length == 4) {
scc = args[0];
name = args[2];
name = args[3];
region = args[1];
mail = args[2];
} else {
scc = args[0];
region = args[1];
String[] names = Arrays.copyOfRange(args, 2, args.length);
mail = args[2];
String[] names = Arrays.copyOfRange(args, 3, args.length);
name = StringUtils.join(names, "_");
}
int re;
Expand All @@ -46,10 +49,10 @@ public void onCommand(String senderID, String text, String[] args) {
return;
}
try {
boolean result = getWrapper().addWaiting(senderID, name, scc, re);
boolean result = getWrapper().addWaiting(senderID, name, scc, re, mail);
if (result) {
sendMessage(senderID, "Your vessel is successfully registered in the database !");
sendMessage(ADMIN_ID, "You have a new pending registry from " + scc + " for the vessel " + name);
sendCompletedMail("New Pending Vessel in ARS", "You have a new pending vessel in ARS!", "Administrator", ADMIN_MAIL);
} else {
sendMessage(senderID, "Your vessel already exist in the database !");
}
Expand All @@ -66,6 +69,6 @@ public String usage() {

@Override
public String args() {
return " [scc] [region] [vesselname]";
return " [scc] [region] [mail] [vesselname]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ private void deny(String senderID, String[] args) {
sendMessage(senderID, "An error occured");
return;
}
boolean success = false;
String success = "false";
try {
success = getWrapper().deletePending(vesselID);
} catch (SQLException e) {
e.printStackTrace();
}
if (success) {
if (!(success.equalsIgnoreCase("false"))) {
sendMessage(senderID, "You denied the subscribe of " + coID + " CO of the " + vesselID);
sendMessage(coID, "Your pending subscribe was denied by the administrator :(");
sendCompletedMail("ARS", "We're sorry your pending subscribe has been denied by the administrator, contact them via email", "CO", success);
}
}

Expand All @@ -66,18 +67,20 @@ private void accept(String senderID, String[] args) {
try {
coID = getWrapper().getPendingCoId(vesselID);
} catch (SQLException | VesselNotFoundException e) {
e.printStackTrace();
sendMessage(senderID, "An error occured");
return;
}
boolean success = false;
String success = "";
try {
success = getWrapper().switchPending(vesselID);
} catch (SQLException e) {
e.printStackTrace();
}
if (success) {
if (!(success.equalsIgnoreCase("false"))) {
sendMessage(senderID, "You accepted the subscribe of " + coID + " CO of the " + vesselID);
sendMessage(coID, "Your pending subscribe was accepted by the administrator !");
sendCompletedMail("ARS", "Your pending subscribe was accepted by the administrator !", "CO", success);
}
}

Expand Down
27 changes: 26 additions & 1 deletion src/main/java/fr/charlotte/arsreloaded/configuration/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.google.gson.Gson;
import fr.charlotte.arsreloaded.databases.Database;
import org.apache.commons.lang3.StringUtils;
import org.simplejavamail.mailer.Mailer;
import org.simplejavamail.mailer.MailerBuilder;
import org.simplejavamail.mailer.config.TransportStrategy;

import java.io.BufferedReader;
import java.io.InputStream;
Expand All @@ -20,9 +23,14 @@ public class Config {
private String dbUser;
private String dbUserName;
private String dbPassword;
private String smtpHost;
private String mailUser;
private String mailPassword;
private String adminMail;
private int mailPort;


public Config(String accessToken, String adminID, String secretKey, String dbHost, String dbName, String dbUser, String dbUserName, String dbPassword, String verifyToken) {
public Config(String accessToken, String adminID, String secretKey, String dbHost, String dbName, String dbUser, String dbUserName, String dbPassword, String verifyToken, String smtpHost, String mailUser, String mailPassword, int mailPort, String adminMail) {
this.accessToken = accessToken;
this.adminID = adminID;
this.secretKey = secretKey;
Expand All @@ -32,6 +40,15 @@ public Config(String accessToken, String adminID, String secretKey, String dbHos
this.dbUserName = dbUserName;
this.dbPassword = dbPassword;
this.verifyToken = verifyToken;
this.mailPassword = mailPassword;
this.mailUser = mailUser;
this.mailPort = mailPort;
this.smtpHost = smtpHost;
this.adminMail = adminMail;
}

public String getAdminMail() {
return adminMail;
}

public Database setupMainDatabase() {
Expand All @@ -54,6 +71,14 @@ public String getSecretKey() {
return secretKey;
}

public Mailer buildMailer(){
return MailerBuilder.withSMTPServer(smtpHost, mailPort, mailUser, mailPassword).withTransportStrategy(TransportStrategy.SMTP_TLS).buildMailer();
}

public String getMailUser() {
return mailUser;
}

public String getVerifyToken() {
return verifyToken;
}
Expand Down
Loading

0 comments on commit d6ad753

Please sign in to comment.