Skip to content
This repository has been archived by the owner on Jun 22, 2021. It is now read-only.

Commit

Permalink
Merge pull request #32 from Team-Creative-Name/dev
Browse files Browse the repository at this point in the history
Merge Dev Branch and bump version
  • Loading branch information
collectioncard authored Jul 26, 2020
2 parents f353ef2 + 5568eb4 commit ec71222
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 81 deletions.
14 changes: 12 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

plugins {
id 'java'
id 'edu.sc.seis.launch4j' version '2.4.6'
}

group 'com.github.tcn.plexi'
version 'v1.0-beta.6'
version 'v1.0'

sourceCompatibility = 1.8

Expand All @@ -21,7 +23,7 @@ dependencies {
compile 'com.squareup.okhttp3:okhttp:4.2.2'
compile 'com.typesafe:config:1.4.0'
compile 'com.vdurmont:emoji-java:5.1.1'
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.2'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
}

jar {
Expand All @@ -48,3 +50,11 @@ javadoc {
)
}
}

launch4j {
mainClassName = 'com.github.tcn.plexi.Main'

icon = "${projectDir}/src/main/resources/assets/plexiMulti.ico"
}


16 changes: 6 additions & 10 deletions src/main/java/com/github/tcn/plexi/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,20 @@ public class Main {

public static void main(String[] args) {

String logo = " /$$ /$$ \n" +
String logo = " /$$ /$$ \n" +
" | $$ |__/ \n" +
" /$$$$$$ | $$ /$$$$$$ /$$ /$$ /$$ \n" +
" /$$__ $$| $$ /$$__ $$| $$ /$$/| $$ \n" +
" | $$ \\ $$| $$| $$$$$$$$ \\ $$$$/ | $$ \n" +
" | $$ \\ $$| $$| $$$$$$$$ \\ $$$$/ | $$ \n" +
" | $$ | $$| $$| $$_____/ >$$ $$ | $$ \n" +
" | $$$$$$$/| $$| $$$$$$$ /$$/\\ $$| $$ \n" +
" | $$____/ |__/ \\_______/|__/ \\__/|__/ \n" +
" | $$ \n" +
" | $$$$$$$/| $$| $$$$$$$ /$$/\\ $$| $$ \n" +
" | $$____/ |__/ \\_______/|__/ \\__/|__/ \n" +
" | $$ \n" +
" | $$ Created by Team Creative Name \n" +
" |__/";


//check to make sure that we can find the config file - this will fail on first run

//boolean settingsSuccess = false;

//call getInstance in order to ensure that it is loaded
//call getInstance in order to ensure that it is loaded before anything else
Settings.getInstance();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.github.tcn.plexi.ombi.templateClasses.movies.search.MovieSearch;
import com.github.tcn.plexi.ombi.templateClasses.tv.moreInfo.TvInfo;
import com.github.tcn.plexi.ombi.templateClasses.tv.search.TvSearch;
import com.github.tcn.plexi.settingsManager.Settings;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.JDA;

Expand All @@ -14,10 +15,8 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.*;
import java.util.List;
import java.util.Random;

//This class will create the embeds and post them
public class EmbedManager {
Expand Down Expand Up @@ -387,6 +386,9 @@ private String getRandFooter(int max) {
footerPath = getClass().getResource("/assets/footer.plexi").toURI();
} catch (Exception e) {
System.out.println(e.getMessage());
//log that the command was used
Settings.getInstance().getLogger().error("Error while generating a random footer: " + e.getLocalizedMessage());
Settings.getInstance().getLogger().trace(Arrays.toString(e.getStackTrace()));
return "Missing Footer File!";
}

Expand Down
19 changes: 11 additions & 8 deletions src/main/java/com/github/tcn/plexi/discordBot/PlexiBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.jagrosh.jdautilities.commons.waiter.EventWaiter;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PlexiBot {

Expand All @@ -13,7 +15,7 @@ public class PlexiBot {
private static PlexiBot botObj = null;
//reference to plexi object
private JDA botInstance = null;


//lock the constructor
private PlexiBot() {
Expand Down Expand Up @@ -68,16 +70,16 @@ public void startBot() {
botInstance.addEventListener(commandList.build(), waiter);



} catch (Exception e) {
System.out.println("Error: " + e.getLocalizedMessage());
Settings.getInstance().getLogger().warn("Unable to start discord bot: " + e.getLocalizedMessage() );
return;
}
try {
botInstance.awaitReady();
System.out.println("Startup Complete!");
Settings.getInstance().getLogger().info("Startup Complete!");
} catch (InterruptedException e) {
e.printStackTrace();
System.out.println("Error Starting Bot");
Settings.getInstance().getLogger().error("Discord element interrupted while starting. Error: " + e.getLocalizedMessage());
stopBot();
}
//set global botInstance obj to the newly created one
Expand All @@ -91,11 +93,12 @@ public void stopBot() {
botInstance.shutdownNow();
//remove reference to other bot
botInstance = null;
System.out.println("Shutdown Complete");
Settings.getInstance().getLogger().info("Discord Shutdown Complete");
} else {
System.out.println("Error while shutting down: There is no bot running!");
//we cant call the settings file version of the logger bc the settings file is calling this method on startup
Logger plexiLogger = LoggerFactory.getLogger("Plexi");
plexiLogger.error("Unable to shut down discord connection: no bot is currently running");
}

}

public void restartBot() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.github.tcn.plexi.discordBot.commands;

import com.github.tcn.plexi.discordBot.EmbedManager;
import com.github.tcn.plexi.discordBot.PlexiBot;
import com.github.tcn.plexi.ombi.OmbiCallers;
import com.github.tcn.plexi.settingsManager.Settings;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;

Expand All @@ -18,7 +20,9 @@ public GetMissingEpisodes() {
protected void execute(CommandEvent event) {
OmbiCallers ombiCallers = new OmbiCallers();
EmbedManager embedManager = new EmbedManager();

event.reply(embedManager.createMissingEpisodeEmbed(ombiCallers.getMissingEpisodeArray(event.getArgs())).build());

//print command usage to the log
Settings.getInstance().getLogger().info(event.getAuthor().getName() + " has used the getMissing command for ID: " + event.getArgs());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.github.tcn.plexi.ombi.OmbiCallers;
import com.github.tcn.plexi.ombi.templateClasses.movies.moreInfo.MovieInfo;
import com.github.tcn.plexi.ombi.templateClasses.tv.moreInfo.TvInfo;
import com.github.tcn.plexi.settingsManager.Settings;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;

Expand Down Expand Up @@ -34,25 +35,28 @@ protected void execute(CommandEvent event) {
}

if (args[0].toLowerCase().matches("tv|television|telly|tele|t")) {
//log the request in the console
System.out.println("Asked for tv info: " + args[1]);

//retrieve the TvInfo Object
TvInfo newInfo = ombiCaller.ombiTvInfo(args[1]);

//retrieve the EmbedBuilder Object made from the newInfo Object

event.reply(eManager.createTvMoreInfoEmbed(newInfo).build());

//log the command's usage
Settings.getInstance().getLogger().info(event.getAuthor().getName() + " has used the info command for TVDb_ID: " + args[1]);


} else if (args[0].toLowerCase().matches("movie|film|feature|flick|cinematic|cine|movies|films|features|flicks|m")) {

MovieInfo newInfo = ombiCaller.ombiMovieInfo(args[1]);
event.reply(eManager.createMovieMoreInfoEmbed(newInfo).build());

//log the command's usage
Settings.getInstance().getLogger().info(event.getAuthor().getName() + " has used the info command for TMDb_ID: " + args[1]);
} else {
event.reply("Malformed Command! - Please specify `movie` or `tv`");
//log the command's usage
Settings.getInstance().getLogger().info(event.getAuthor().getName() + " has attempted to use the info command but provided invalid information");
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.tcn.plexi.ombi.OmbiCallers;
import com.github.tcn.plexi.ombi.templateClasses.tv.moreInfo.TvInfo;
import com.github.tcn.plexi.settingsManager.Settings;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;

Expand Down Expand Up @@ -30,18 +31,28 @@ protected void execute(CommandEvent event) {
TvInfo tvInfo = caller.ombiTvInfo(args[1]);

event.reply(ombiCallers.requestTv(true, tvInfo));

//log the command's usage
Settings.getInstance().getLogger().info(event.getAuthor().getName() + " has used the request command for TVDb_ID: " + args[1]);
} catch (IllegalArgumentException e) {
event.reply("Error requesting media");
//log the command's failure
Settings.getInstance().getLogger().error("The request failed");
}
} else if (args[0].toLowerCase().matches("movie|film|feature|flick|cinematic|cine|movies|films|features|flicks|m")) {
try {
event.reply(ombiCallers.requestMovie(args[1]));

//log the command's usage
Settings.getInstance().getLogger().info(event.getAuthor().getName() + " has used the request command for TMDb_ID: " + args[1]);
} catch (IllegalArgumentException e) {
event.reply("Error requesting media");
//log the command's failure
Settings.getInstance().getLogger().error("The request failed");
}
} else {
event.getChannel().sendMessage("Malformed Command!").queue();
Settings.getInstance().getLogger().info(event.getAuthor().getName() + " has attempted to use the request command but provided invalid information");
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.tcn.plexi.discordBot.commands;

import com.github.tcn.plexi.discordBot.PlexiBot;
import com.github.tcn.plexi.settingsManager.Settings;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;

Expand All @@ -17,6 +18,9 @@ public RestartCommand() {
@Override
protected void execute(CommandEvent event) {
event.reply("Plexi will be back in 1 second. Please wait.");
//log the command's usage
Settings.getInstance().getLogger().info(event.getAuthor().getName() + " has used the restart command");

PlexiBot.getInstance().restartBot();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.github.tcn.plexi.ombi.templateClasses.movies.search.MovieSearch;
import com.github.tcn.plexi.ombi.templateClasses.tv.search.TvSearch;
import com.github.tcn.plexi.paginators.searchPaginators.SearchPaginator;
import com.github.tcn.plexi.settingsManager.Settings;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.commons.waiter.EventWaiter;
Expand All @@ -27,7 +28,6 @@ public SearchCommand(EventWaiter waiter) {


ePBuilder = new SearchPaginator.Builder()

.setFinalAction(message -> {
try {
message.clearReactions().queue();
Expand All @@ -54,7 +54,7 @@ protected void execute(CommandEvent event) {
OmbiCallers tvSearcher = new OmbiCallers();
EmbedManager embedManager = new EmbedManager();

System.out.println(event.getAuthor().getName() + " has searched for: " + args[1]);
Settings.getInstance().getLogger().info(event.getAuthor().getName() + " has searched for: " + args[1]);
//Retrieve array of TvSearch Objects - each object is a search result
TvSearch[] result = tvSearcher.ombiTvSearch(args[1]);

Expand All @@ -74,13 +74,13 @@ protected void execute(CommandEvent event) {
p.paginate(event.getChannel(), 1);
}


//event.getChannel().sendMessage("Here is the first result: " + result[0].getTitle()).queue();
//log that the command was used
Settings.getInstance().getLogger().info(event.getAuthor().getName() + " has used the search command for the phrase: " + args[1]);
} else if (args[0].toLowerCase().matches("((m(ovie)?|film|feature|flick)s?)|(cine(matic)?)")) {

OmbiCallers moviesearcher = new OmbiCallers();
EmbedManager embedManager = new EmbedManager();
System.out.println(event.getAuthor().getName() + " has searched for " + args[1]);
Settings.getInstance().getLogger().info(event.getAuthor().getName() + " has searched for " + args[1]);

MovieSearch[] result = moviesearcher.ombiMovieSearch(args[1]);

Expand All @@ -99,9 +99,14 @@ protected void execute(CommandEvent event) {
p.paginate(event.getChannel(), 1);
}

//log that the command was used
Settings.getInstance().getLogger().info(event.getAuthor().getName() + " has used the search command for the phrase: " + args[1]);
} else {
event.getChannel().sendMessage("Malformed Command!").queue();
//log that the command was used improperly
Settings.getInstance().getLogger().info(event.getAuthor().getName() + " attempted to use the search command but used malformed arguments");
}

}

private ArrayList<Integer> generateEpisodeIdArray(TvSearch[] tvArray) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.tcn.plexi.discordBot.commands;

import com.github.tcn.plexi.discordBot.PlexiBot;
import com.github.tcn.plexi.settingsManager.Settings;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;

Expand All @@ -17,6 +18,9 @@ public ShutdownCommand() {
protected void execute(CommandEvent event) {
event.reply("Plexi is shutting down.");

//log that the command was used
Settings.getInstance().getLogger().info(event.getAuthor().getName() + " has used the shutdown command");

//turn off plexi
PlexiBot.getInstance().stopBot();
System.exit(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.tcn.plexi.discordBot.EmbedManager;
import com.github.tcn.plexi.discordBot.PlexiBot;
import com.github.tcn.plexi.ombi.OmbiCallers;
import com.github.tcn.plexi.settingsManager.Settings;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;

Expand All @@ -20,5 +21,8 @@ protected void execute(CommandEvent event) {
OmbiCallers caller = new OmbiCallers();
EmbedManager embedManager = new EmbedManager();
event.reply(embedManager.createPingEmbed(PlexiBot.getInstance().getGatewayPing(), PlexiBot.getInstance().getRestPing(), caller.getPingTime()).build());

//print command usage to the log
Settings.getInstance().getLogger().info(event.getAuthor().getName() + " has used the ping command");
}
}
Loading

0 comments on commit ec71222

Please sign in to comment.