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 #34 from Team-Creative-Name/dev
Browse files Browse the repository at this point in the history
all good
  • Loading branch information
collectioncard committed Oct 5, 2020
2 parents 0984dcf + d3b03f1 commit 0bfe740
Show file tree
Hide file tree
Showing 30 changed files with 2,201 additions and 260 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group 'com.github.tcn.plexi'
version 'v1.0'
version 'v1.1'

sourceCompatibility = 1.8

Expand All @@ -19,7 +19,7 @@ dependencies {
compile group: 'junit', name: 'junit', version: '4.12'
compile 'com.google.code.gson:gson:2.8.6'
compile 'com.jagrosh:jda-utilities:3.0.4'
compile 'net.dv8tion:JDA:4.1.1_166'
compile 'net.dv8tion:JDA:4.2.0_208'
compile 'com.squareup.okhttp3:okhttp:4.2.2'
compile 'com.typesafe:config:1.4.0'
compile 'com.vdurmont:emoji-java:5.1.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ <h2 title="Class MovieRequest" class="title">Class MovieRequest</h2>
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>com.github.tcn.plexi.ombi.templateClasses.requests.movie.MovieRequest</li>
<li>com.github.tcn.plexi.ombi.templateClasses.movies.requestResponse.MovieRequest</li>
</ul>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ <h2 title="Class RequestEpisode" class="title">Class RequestEpisode</h2>
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>com.github.tcn.plexi.ombi.templateClasses.requests.tv.jsonTemplate.RequestEpisode</li>
<li>com.github.tcn.plexi.ombi.templateClasses.tv.requestTemplate.RequestEpisode</li>
</ul>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ <h2 title="Class Season" class="title">Class Season</h2>
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>com.github.tcn.plexi.ombi.templateClasses.requests.tv.jsonTemplate.Season</li>
<li>com.github.tcn.plexi.ombi.templateClasses.tv.requestTemplate.Season</li>
</ul>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ <h2 title="Class TvRequestTemplate" class="title">Class TvRequestTemplate</h2>
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>com.github.tcn.plexi.ombi.templateClasses.requests.tv.jsonTemplate.TvRequestTemplate</li>
<li>com.github.tcn.plexi.ombi.templateClasses.tv.requestTemplate.TvRequestTemplate</li>
</ul>
</li>
</ul>
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/github/tcn/plexi/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public class Main {

public static void main(String[] args) {

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


String logo = " /$$ /$$ \n" +
" | $$ |__/ \n" +
" /$$$$$$ | $$ /$$$$$$ /$$ /$$ /$$ \n" +
Expand All @@ -19,11 +23,10 @@ public static void main(String[] args) {
" | $$____/ |__/ \\_______/|__/ \\__/|__/ \n" +
" | $$ \n" +
" | $$ Created by Team Creative Name \n" +
" |__/";
" |__/ Version " + Settings.getInstance().getVersionNumber();



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


SwingUtilities.invokeLater(() -> {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/github/tcn/plexi/discordBot/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ public void commandList(EventWaiter waiter) {
this.addCommand(new ShutdownCommand());
this.addCommand(new RestartCommand());
this.addCommand(new getPingCommand());
this.addCommand(new ViewRequestsCommand(waiter));
this.addCommand(new UpcomingCommand(waiter));
}
}
111 changes: 111 additions & 0 deletions src/main/java/com/github/tcn/plexi/discordBot/EmbedManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import com.github.tcn.plexi.ombi.OmbiCallers;
import com.github.tcn.plexi.ombi.templateClasses.movies.moreInfo.MovieInfo;
import com.github.tcn.plexi.ombi.templateClasses.movies.requestList.MovieRequestList;
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.requestTemplate.TvRequestTemplate;
import com.github.tcn.plexi.ombi.templateClasses.tv.search.TvSearch;
import com.github.tcn.plexi.ombi.templateClasses.tv.tvLite.TvLite;
import com.github.tcn.plexi.ombi.templateClasses.tv.tvRequests.TvRequestList;
import com.github.tcn.plexi.settingsManager.Settings;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.JDA;
Expand Down Expand Up @@ -285,6 +289,113 @@ public EmbedBuilder getTvInfoEmbed(int id) {
return createTvMoreInfoEmbed(caller.ombiTvInfo(String.valueOf(id)));
}

public EmbedBuilder getMovieRequestListEmbed(MovieRequestList[] movieRequestArray, int pageNum){
EmbedBuilder eb = new EmbedBuilder();
eb.setColor(new Color(0x00Ae86));
eb.setTitle("Requested Movies");
eb.setFooter("Page " + (pageNum + 1));
int numOfItems = 10 * (pageNum + 1); //sets the number of items per page

if(pageNum == (int)Math.floor(movieRequestArray.length / 10.0) ){ //last page in array
numOfItems = movieRequestArray.length;
}

//generate the string required for the embed description
String descString = "";
for(int i = pageNum * 10; i < numOfItems ; i++){ //<--- this line
descString += movieRequestArray[i].getTitle() + "\n";
}

eb.setDescription(descString);
return eb;
}

public ArrayList<EmbedBuilder> getMovieRequestListArray(MovieRequestList[] movieRequestArray){
//first determine the number of pages that we will need to present with 10 movies per page
int numOfPages = (int)Math.ceil(movieRequestArray.length / 10.0) ;


//create the embed array
ArrayList<EmbedBuilder> newArray = new ArrayList<>();

for(int i = 0; i < numOfPages; i++){
newArray.add(getMovieRequestListEmbed(movieRequestArray, i));
}

//return newArray
return newArray;
}

public ArrayList<EmbedBuilder> getUnfilledMovieRequestListArray(MovieRequestList[] movieRequestArray){
//run through the movie array and strip it of available movies
ArrayList<MovieRequestList> tempMovieArray = new ArrayList<>();

for (int i = 0; i < movieRequestArray.length; i++){
if (!movieRequestArray[i].getAvailable()) {
tempMovieArray.add(movieRequestArray[i]);
}
}

MovieRequestList[] fixedMovieArray = tempMovieArray.toArray(new MovieRequestList[tempMovieArray.size()]);

return getMovieRequestListArray(fixedMovieArray);
}

public EmbedBuilder getTvRequestListEmbed(TvRequestList[] requestArray, int pageNum){
EmbedBuilder eb = new EmbedBuilder();
eb.setColor(new Color(0x00Ae86));
eb.setTitle("Requested TV Shows");
eb.setFooter("Page " + (pageNum + 1));

int numOfItems = 10 * (pageNum + 1);

if(pageNum == (int)Math.floor(requestArray.length / 10.0)){
numOfItems = requestArray.length;
}

//generate the string required for the embed description
String descString = "";
for(int i = pageNum * 10; i < numOfItems ; i++){ //<--- this line
descString += requestArray[i].getTitle() + "\n";
}
eb.setDescription(descString);
return eb;
}


public ArrayList<EmbedBuilder> getTvRequestListArray(TvRequestList[] tvRequests){
//first determine the number of pages that we will need to present with 10 movies per page
int numOfPages = (int)Math.ceil(tvRequests.length / 10.0) ;


//create the embed array
ArrayList<EmbedBuilder> newArray = new ArrayList<>();

for(int i = 0; i < numOfPages; i++){
newArray.add(getTvRequestListEmbed(tvRequests, i));
}

//return newArray
return newArray;
}


public ArrayList<EmbedBuilder> getUnfilledTvRequestList(TvRequestList[] tvRequests){
//run through the movie array and strip it of available movies
ArrayList<TvRequestList> tempTvArray = new ArrayList<>();

for (int i = 0; i < tvRequests.length; i++){
if (!tvRequests[i].getFullyAvailable()) {
tempTvArray.add(tvRequests[i]);
}
}

TvRequestList[] fixedTvArray = tempTvArray.toArray(new TvRequestList[tempTvArray.size()]);

return getTvRequestListArray(fixedTvArray);
}


/**
* wraps EmbedBuilder object into an ArrayList
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@

import java.util.ArrayList;


/**
* This class is responsible for the Search command. Depending on the search query, it makes different calls to Ombi via
* {@link OmbiCallers#ombiTvSearch(String)} or {@link OmbiCallers#ombiMovieInfo(String)}. From there, the information is paginated
* and presented to the user via {@link SearchPaginator}
*/
public class SearchCommand extends Command {

private final SearchPaginator.Builder ePBuilder;
Expand Down Expand Up @@ -109,24 +113,6 @@ protected void execute(CommandEvent event) {

}

private ArrayList<Integer> generateEpisodeIdArray(TvSearch[] tvArray) {

ArrayList<Integer> toReturn = new ArrayList<>();

for (TvSearch tvSearch : tvArray) {
toReturn.add(tvSearch.getId());
}

return toReturn;
}

private ArrayList<Integer> generateMovieIdArray(MovieSearch[] movieArray) {
ArrayList<Integer> toReturn = new ArrayList<>();

for (MovieSearch movieSearch : movieArray) {
toReturn.add(movieSearch.getId());
}
return toReturn;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.github.tcn.plexi.discordBot.commands;

import com.github.tcn.plexi.discordBot.EmbedManager;
import com.github.tcn.plexi.ombi.OmbiCallers;
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;
import org.slf4j.Logger;

import java.util.Set;

/**
* This class creates a command that allows users to view soon to be released movies and television shows.
* If A user sees ones that they might want to watch in the future, they can request that show from this command via
* the reactions located below the paginated embed.
*/


public class UpcomingCommand extends Command {

private final SearchPaginator.Builder paginatorBuilder;
private Logger logger;

public UpcomingCommand(EventWaiter waiter){
this.name = "upcoming";
this.help = "This command lists upcoming movie or tv releases";
this.arguments = "<tv|movie>";
this.aliases = new String[]{"u", "Upcoming", "up", "U", "Up"};
this.ownerCommand = false;
this.guildOnly = true;

//This class uses the SearchPaginator to show movies and tv releases
paginatorBuilder = new SearchPaginator.Builder()
.setDefaultFinalAction()
.setEventWaiter(waiter);

logger = Settings.getInstance().getLogger();
}

@Override
protected void execute(CommandEvent event) {

OmbiCallers caller = new OmbiCallers();
EmbedManager embedManager = new EmbedManager();

//we need to call different methods depending on the media type
if(event.getArgs().toLowerCase().matches("tv|television|telly|tele|t|s|show")){
logger.info(event.getAuthor() + " has used the upcoming tv command.");



TvSearch[] result = caller.getUpcomingTvShows();

//ensure a non-empty result
if(result.length == 0){
event.reply("There are no TV shows scheduled to be released soon");
}else{
//lets tell the user what we are presenting
event.reply("Here are some upcoming TV shows:");

paginatorBuilder.setMediaType(1).setPages(embedManager.getTvSearchEmbedArray(result));

SearchPaginator p = paginatorBuilder
.setUsers(event.getAuthor())
.build();
p.paginate(event.getChannel(), 1);
}


}else if(event.getArgs().toLowerCase().matches("((m(ovie)?|film|feature|flick)s?)|(cine(matic)?)")){
logger.info(event.getAuthor() + " has used the upcoming movie command.");

MovieSearch[] result = caller.getUpcomingMovies();

//make sure that the array is not empty (it really shouldn't be unless there was a worldwide pandemic or something...)
if(result.length == 0){
event.reply("There are currently no movies scheduled to be released soon.");
}else{
//lets tell the user what we are presenting
event.reply("Here are some upcoming movies:");

paginatorBuilder.setMediaType(2).setPages(embedManager.getMovieSearchEmbedArray(result));

SearchPaginator p = paginatorBuilder
.setUsers(event.getAuthor())
.build();

p.paginate(event.getChannel(), 1);
}

}else{
logger.info(event.getAuthor() + " has incorrectly used the upcoming command!");
event.reply("Malformed Command!");
}

}
}
Loading

0 comments on commit 0bfe740

Please sign in to comment.