diff --git a/src/main/java/net/Broken/Commands/Over18/SM.java b/src/main/java/net/Broken/Commands/Over18/SM.java index fbaa75e..73d07c5 100644 --- a/src/main/java/net/Broken/Commands/Over18/SM.java +++ b/src/main/java/net/Broken/Commands/Over18/SM.java @@ -1,28 +1,31 @@ package net.Broken.Commands.Over18; import net.Broken.Commande; +import net.Broken.Tools.FindContentOnWebPage; import net.Broken.Tools.Redirection; import net.dv8tion.jda.core.events.message.MessageReceivedEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.io.IOException; + /** * TODO Remove this */ public class SM implements Commande { Logger logger = LogManager.getLogger(); - public String HELP="T'es sérieux la?"; @Override public void action(String[] args, MessageReceivedEvent event) { Redirection redirect= new Redirection(); - event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: SM n'est plus disponible pour le moment. Pour plus d'info: https://lc.cx/cbSw :warning: ").queue(); -// try { -// event.getTextChannel().sendMessage(redirect.get("https://bonjourfetish.tumblr.com/random")).queue(); -// } catch (IOException e) { -// logger.warn("Erreur de redirection."); -// event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Erreur de redirection (5 essais), Réessayez__**:warning: ").queue(); -// } + try { + String redirectUrl = redirect.get("https://bonjourfetish.tumblr.com/random"); + String img = FindContentOnWebPage.doYourJob(redirectUrl, "article-picture center", "img"); + event.getTextChannel().sendMessage(img).queue(); + } catch (IOException e) { + logger.warn("Erreur de redirection."); + event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Erreur de redirection (5 essais), Réessayez__**:warning: ").queue(); + } } diff --git a/src/main/java/net/Broken/Commands/Over18/Suicide.java b/src/main/java/net/Broken/Commands/Over18/Suicide.java index 340d6cf..39cf711 100644 --- a/src/main/java/net/Broken/Commands/Over18/Suicide.java +++ b/src/main/java/net/Broken/Commands/Over18/Suicide.java @@ -2,26 +2,61 @@ package net.Broken.Commands.Over18; import net.Broken.Commande; import net.Broken.Tools.EmbedMessageUtils; +import net.Broken.Tools.FindContentOnWebPage; import net.Broken.Tools.Redirection; import net.dv8tion.jda.core.events.message.MessageReceivedEvent; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.IOException; public class Suicide implements Commande{ - private String redirectUrl = "https://suicidegirlsandhopefuls.tumblr.com/random"; + private Logger logger = LogManager.getLogger(); @Override public void action(String[] args, MessageReceivedEvent event) { Redirection redirection = new Redirection(); + + String base = "http://suicidegirls.tumblr.com"; + String redirectUrl = null; try { - event.getTextChannel().sendMessage(redirection.get(redirectUrl)).queue(); + + Boolean success = false; + int tryCount = 0; + while(!success && tryCount < 10 ){ + redirectUrl = redirection.get(base + "/random"); + + String img; + try{ + img = FindContentOnWebPage.doYourJob(redirectUrl, "post photo_nav_caption", "img"); + event.getTextChannel().sendMessage(img).queue(); + success = true; + + }catch (StringIndexOutOfBoundsException | IOException e){ + logger.debug("Photo_nav not found try photoset"); + + try { + String mid = FindContentOnWebPage.doYourJob(redirectUrl, "html_photoset", "iframe"); + img = FindContentOnWebPage.doYourJob(base + mid, "photoset_row", "img"); + event.getTextChannel().sendMessage(img).queue(); + success = true; + } catch (StringIndexOutOfBoundsException | IOException e1) { + logger.debug("Nothing found, assume it's a comment."); + } + + + } + tryCount ++; + } } catch (IOException e) { - LogManager.getLogger().catching(e); - event.getTextChannel().sendMessage(EmbedMessageUtils.getInternalError()).queue(); + logger.catching(e); } + + + + } @Override diff --git a/src/main/java/net/Broken/RestApi/MusicWebAPIController.java b/src/main/java/net/Broken/RestApi/MusicWebAPIController.java index a24475d..687fa97 100644 --- a/src/main/java/net/Broken/RestApi/MusicWebAPIController.java +++ b/src/main/java/net/Broken/RestApi/MusicWebAPIController.java @@ -32,11 +32,16 @@ import java.util.List; @RequestMapping("/api/music/") public class MusicWebAPIController { Logger logger = LogManager.getLogger(); - @Autowired + private final UserRepository userRepository; UserUtils userUtils = UserUtils.getInstance(); + @Autowired + public MusicWebAPIController(UserRepository userRepository) { + this.userRepository = userRepository; + } + @RequestMapping("/currentMusicInfo") public ResponseEntity getCurrentM(@RequestParam(value = "guild") String guildId){ diff --git a/src/main/java/net/Broken/Tools/FindContentOnWebPage.java b/src/main/java/net/Broken/Tools/FindContentOnWebPage.java index 68f7446..a815426 100644 --- a/src/main/java/net/Broken/Tools/FindContentOnWebPage.java +++ b/src/main/java/net/Broken/Tools/FindContentOnWebPage.java @@ -16,6 +16,7 @@ public class FindContentOnWebPage { * @throws IOException */ public static String doYourJob(String url, String divClass, String htmlType) throws IOException { +// System.out.println(url); String source = getSourceUrl(url); int divIndex = source.indexOf(divClass); String sub = source.substring(divIndex); @@ -38,6 +39,7 @@ public class FindContentOnWebPage { public static String getSourceUrl(String url) throws IOException { URL urlC = new URL(url); URLConnection yc = urlC.openConnection(); + yc.setRequestProperty("User-Agent","Googlebot"); BufferedReader in = new BufferedReader(new InputStreamReader( yc.getInputStream(), "UTF-8")); String inputLine; diff --git a/src/main/java/net/Broken/Tools/Redirection.java b/src/main/java/net/Broken/Tools/Redirection.java index 23d30e7..f685135 100644 --- a/src/main/java/net/Broken/Tools/Redirection.java +++ b/src/main/java/net/Broken/Tools/Redirection.java @@ -22,7 +22,9 @@ public class Redirection { * @throws IOException */ public String get(String urlString) throws IOException { + System.setProperty("http.agent","Googlebot"); URLConnection con = new URL(urlString).openConnection(); + con.setRequestProperty("User-Agent","Googlebot"); //System.out.println( "orignal url: " + con.getURL() ); con.connect(); //System.out.println( "connected url: " + con.getURL() ); diff --git a/src/main/java/net/Broken/webView/GeneralWebView.java b/src/main/java/net/Broken/webView/GeneralWebView.java index 71616ad..b867b6e 100644 --- a/src/main/java/net/Broken/webView/GeneralWebView.java +++ b/src/main/java/net/Broken/webView/GeneralWebView.java @@ -4,11 +4,15 @@ import net.Broken.DB.Entity.PlaylistEntity; import net.Broken.DB.Entity.TrackEntity; import net.Broken.DB.Entity.UserEntity; import net.Broken.DB.Repository.UserRepository; +import net.Broken.MainBot; import net.Broken.RestApi.Commands.Play; +import net.dv8tion.jda.core.entities.Guild; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import java.util.ArrayList; import java.util.List; @@ -21,7 +25,12 @@ public class GeneralWebView { @RequestMapping("/") - public String music(Model model){ + public String music(Model model, @CookieValue(value = "guild", defaultValue = "1") String guildId){ + Guild guild = MainBot.jda.getGuildById(guildId); + if(guild != null) + model.addAttribute("guild_name", guild.getName()); + else + model.addAttribute("guild_name", ""); return CheckPage.getPageIfReady("index"); } diff --git a/src/main/java/net/Broken/webView/MusicWebView.java b/src/main/java/net/Broken/webView/MusicWebView.java index 753aa35..6dddf53 100644 --- a/src/main/java/net/Broken/webView/MusicWebView.java +++ b/src/main/java/net/Broken/webView/MusicWebView.java @@ -1,7 +1,10 @@ package net.Broken.webView; +import net.Broken.MainBot; +import net.dv8tion.jda.core.entities.Guild; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.bind.annotation.RequestMapping; /** @@ -10,7 +13,13 @@ import org.springframework.web.bind.annotation.RequestMapping; @Controller public class MusicWebView { @RequestMapping("/music") - public String music(Model model){ + public String music(Model model, @CookieValue(value = "guild", defaultValue = "1") String guildId){ + Guild guild = MainBot.jda.getGuildById(guildId); + if(guild != null) + model.addAttribute("guild_name", guild.getName()); + else + model.addAttribute("guild_name", ""); + return CheckPage.getPageIfReady("music"); } } diff --git a/src/main/resources/static/error/404.html b/src/main/resources/static/error/404.html index 12b027b..ec6ff96 100644 --- a/src/main/resources/static/error/404.html +++ b/src/main/resources/static/error/404.html @@ -3,7 +3,7 @@ - Music Control - Discord Bot + Claptrap Bot diff --git a/src/main/resources/static/favicon.png b/src/main/resources/static/favicon.png index d690bb4..62605a8 100644 Binary files a/src/main/resources/static/favicon.png and b/src/main/resources/static/favicon.png differ diff --git a/src/main/resources/static/js/navabar.js b/src/main/resources/static/js/navabar.js index 15e7d7d..98d4b10 100644 --- a/src/main/resources/static/js/navabar.js +++ b/src/main/resources/static/js/navabar.js @@ -79,7 +79,9 @@ function disconnected() { console.log("Disconnected"); nav_bar_account_link.html(disconnected_link); var modalConnection = $('#modal_connection'); - modalConnection.modal(); + modalConnection.modal({ + dismissible: false // Modal can be dismissed by clicking outside of the modal + }); if (typeof needLogin !== 'undefined'){ modalConnection.modal('open'); } diff --git a/src/main/resources/templates/header.html b/src/main/resources/templates/header.html index edcc37a..eb5181c 100644 --- a/src/main/resources/templates/header.html +++ b/src/main/resources/templates/header.html @@ -4,24 +4,30 @@ + -
+ +