<commit_before>/*
 * 
 * AIBot, a Discord bot made by AlienIdeology
 * 
 * 
 * 2017 (c) AIBot
 */
package Command.UtilityModule;

import Command.Command;
import static Command.UtilityModule.SearchCommand.HELP;
import Resource.Emoji;
import Resource.Info;
import Resource.Prefix;
import Resource.Search;
import Resource.SearchResult;
import Resource.WebScraper;
import Setting.SmartLogger;
import java.awt.Color;
import java.io.IOException;
import java.time.Instant;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.entities.MessageEmbed;
import net.dv8tion.jda.core.entities.MessageReaction;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;

/**
 *
 * @author <NAME> <alien.ideology at alien.org>
 */
public class IMDbCommand implements Command {

    public final static  String HELP = "This command is for a search result from IMDB.\n"
                                     + "Command Usage: `"+ Prefix.getDefaultPrefix() +"imdb`\n"
                                     + "Parameter: `-h | [Keywords] | -m [Keywods] |null`\n"
                                     + "[Keywords]: Search IMDB with [Keywords].\n"
                                     + "-m [Keywods]: Get the specific information for a title.\n";
    
    @Override
    public boolean called(String[] args, MessageReceivedEvent e) {
        return true;
    }

    @Override
    public void help(MessageReceivedEvent e) {
        embed.setColor(Color.red);
        embed.setTitle("Utility Module", null);
        embed.addField("IMDB -Help", HELP, true);
        embed.setFooter("Command Help/Usage", Info.I_HELP);
        embed.setTimestamp(Instant.now());

        MessageEmbed me = embed.build();
        e.getChannel().sendMessage(me).queue();
        embed.clearFields();
    }

    @Override
    public void action(String[] args, MessageReceivedEvent e) {
        if(args.length == 0 || "-h".equals(args[0])) 
        {
            help(e);
        }
        
        else if("-m".equals(args[0]))
        {
            String input = "";
            for(int i = 1; i < args.length; i++){ input += args[i].substring(0,1).toUpperCase() + args[i].substring(1) + " "; }
            input = input.substring(0, input.length()-1);
            
            try {
                SearchResult results = Search.IMDbSearch(input).get(0);
                WebScraper.getIMDbThumbNail(results);
                EmbedBuilder imdbinfo = WebScraper.getIMDbInfo(results);
                imdbinfo.setFooter("Request by " + e.getAuthor().getName(), e.getAuthor().getEffectiveAvatarUrl());
                imdbinfo.setTimestamp(Instant.now());
                
                e.getChannel().sendMessage("Searching........").complete().editMessage(imdbinfo.build()).complete();
                imdbinfo.clearFields();
            } catch (IOException ex) {
                SmartLogger.errorLog(ex, e, this.getClass().getName(), "Input is " + input);
            } catch (IndexOutOfBoundsException ioobe) {
                e.getChannel().sendMessage(Emoji.error + " An error occured. Please enter a valid IMDb **title**.").queue();
            }
            
        }
        
        else 
        {
            String input = "";
            for(int i = 0; i < args.length; i++){ input += args[i].substring(0,1).toUpperCase() + args[i].substring(1) + " "; }
            input = input.substring(0, input.length()-1);
            
            try {
                List<SearchResult> results = Search.IMDbSearch(input);
                String titles = "";
                String names = "";
                String characters = "";
                
                //Get Titles, Names, Characters and make the texts
                for(int i = 0; i < results.size(); i ++)
                {
                    SearchResult sr = results.get(i);
                    if("Titles".equals(sr.getText()))
                    {
                        titles += "**" + (i+1) + ".** [" + sr.getTitle() + "](" + sr.getLink() + ")\n";
                    }
                    else if("Names".equals(sr.getText()))
                        names += "**" + (i+1) + ".** [" + sr.getTitle() + "](" + sr.getLink() + ")\n";
                    else if("Characters".equals(sr.getText()))
                        characters += "**" + (i+1) + ".** [" + sr.getTitle() + "](" + sr.getLink() + ")\n";
                }
                
                //Prevent null Messages
                if(results.isEmpty())
                {
                    e.getChannel().sendMessage(Emoji.error + " No results.").queue();
                    return;
                }
                if("".equals(titles))
                    titles = "None";
                if("".equals(names))
                    names = "None";
                if("".equals(characters))
                    characters = "None\n";
                    
                //Get Thumbnail of the first SearchResult
                WebScraper.getIMDbThumbNail(results.get(0));
                
                //Build EMbed Message
                EmbedBuilder embeds = new EmbedBuilder();
                embeds.setColor(Info.setColor());
                embeds.setAuthor("IMDb Search Results for \"" + input + "\"", 
                        "http://www.imdb.com/find?q=" + input.replaceAll(" ", "+"), null);
                embeds.addField("Titles", titles, false);<commit_msg>!Reconstruct<commit_after>/*
 * 
 * AIBot, a Discord bot made by AlienIdeology
 * 
 * 
 * 2017 (c) AIBot
 */
package Command.UtilityModule;

import Command.Command;
import static Command.UtilityModule.SearchCommand.HELP;
import Resource.Emoji;
import Resource.Info;
import Resource.Prefix;
import Resource.Search;
import Resource.SearchResult;
import Resource.UtilTool;
import Resource.WebScraper;
import Setting.SmartLogger;
import java.awt.Color;
import java.io.IOException;
import java.time.Instant;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.entities.MessageEmbed;
import net.dv8tion.jda.core.entities.MessageReaction;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;

/**
 *
 * @author <NAME> <alien.ideology at alien.org>
 */
public class IMDbCommand implements Command {

    public final static  String HELP = "This command is for a search result from IMDB.\n"
                                     + "Command Usage: `"+ Prefix.getDefaultPrefix() +"imdb`\n"
                                     + "Parameter: `-h | [Keywords] | -m [Keywods] |null`\n"
                                     + "[Keywords]: Search IMDB with [Keywords].\n"
                                     + "-m [Keywods]: Get the specific information for a title.\n";
    
    @Override
    public boolean called(String[] args, MessageReceivedEvent e) {
        return true;
    }

    @Override
    public void help(MessageReceivedEvent e) {
        embed.setColor(Color.red);
        embed.setTitle("Utility Module", null);
        embed.addField("IMDB -Help", HELP, true);
        embed.setFooter("Command Help/Usage", Info.I_HELP);
        embed.setTimestamp(Instant.now());

        MessageEmbed me = embed.build();
        e.getChannel().sendMessage(me).queue();
        embed.clearFields();
    }

    @Override
    public void action(String[] args, MessageReceivedEvent e) {
        if(args.length == 0 || "-h".equals(args[0])) 
        {
            help(e);
        }
        
        else if("-m".equals(args[0]))
        {
            String input = "";
            for(int i = 1; i < args.length; i++){ input += args[i].substring(0,1).toUpperCase() + args[i].substring(1) + " "; }
            input = input.substring(0, input.length()-1);
            
            try {
                SearchResult results = Search.IMDbSearch(input).get(0);
                WebScraper.getIMDbThumbNail(results);
                EmbedBuilder imdbinfo = WebScraper.getIMDbInfo(results);
                imdbinfo.setFooter("Request by " + e.getAuthor().getName(), e.getAuthor().getEffectiveAvatarUrl());
                imdbinfo.setTimestamp(Instant.now());
                
                e.getChannel().sendMessage("Searching........").complete().editMessage(imdbinfo.build()).complete();
                imdbinfo.clearFields();
            } catch (IOException ex) {
                SmartLogger.errorLog(ex, e, this.getClass().getName(), "Input is " + input);
            } catch (IndexOutOfBoundsException ioobe) {
                e.getChannel().sendMessage(Emoji.error + " An error occured. Please enter a valid IMDb **title**.").queue();
            }
            
        }
        
        else 
        {
            String input = "";
            for(int i = 0; i < args.length; i++){ input += args[i].substring(0,1).toUpperCase() + args[i].substring(1) + " "; }
            input = input.substring(0, input.length()-1);
            
            try {
                List<SearchResult> results = Search.IMDbSearch(input);
                String titles = "";
                String names = "";
                String characters = "";
                
                //Get Titles, Names, Characters and make the texts
                for(int i = 0; i < results.size(); i ++)
                {
                    SearchResult sr = results.get(i);
                    if("Titles".equals(sr.getText()))
                    {
                        titles += "**" + (i+1) + ".** [" + sr.getTitle() + "](" + sr.getLink() + ")\n";
                    }
                    else if("Names".equals(sr.getText()))
                        names += "**" + (i+1) + ".** [" + sr.getTitle() + "](" + sr.getLink() + ")\n";
                    else if("Characters".equals(sr.getText()))
                        characters += "**" + (i+1) + ".** [" + sr.getTitle() + "](" + sr.getLink() + ")\n";
                }
                
                //Prevent null Messages
                if(results.isEmpty())
                {
                    e.getChannel().sendMessage(Emoji.error + " No results.").queue();
                    return;
                }
                if("".equals(titles))
                    titles = "None";
                if("".equals(names))
                    names = "None";
                if("".equals(characters))
                    characters = "None\n";
                    
                //Get Thumbnail of the first SearchResult
                WebScraper.getIMDbThumbNail(results.get(0));
                
                //Build EMbed Message
                EmbedBuilder embeds = new EmbedBuilder();
                embeds.setColor(UtilTool.setColor());
                embeds.setAuthor("IMDb Search Results for \"" + input + "\"", 
                        "http://www.imdb.com/find?q=" + input.replaceAll(" ", "+"), null);
                embeds.addField("Titles", titles, false);
{'fraction_non_alphanumeric': 0.1424988804299149, 'fraction_numerical': 0.0055530676220331395, 'mean_word_length': 1.6828447861604998, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6811033', 'n_tokens_mistral': 3247, 'n_tokens_neox': 3088, 'n_words': 609}