Merge branch 'devel'
This commit is contained in:
commit
06ae3c138b
@ -2,10 +2,12 @@ package net.Broken.Commands;
|
|||||||
|
|
||||||
import net.Broken.Commande;
|
import net.Broken.Commande;
|
||||||
import net.Broken.MainBot;
|
import net.Broken.MainBot;
|
||||||
|
import net.Broken.RestApi.CommandInterface;
|
||||||
import net.Broken.Tools.EmbedMessageUtils;
|
import net.Broken.Tools.EmbedMessageUtils;
|
||||||
import net.Broken.Tools.MessageTimeOut;
|
import net.Broken.Tools.MessageTimeOut;
|
||||||
import net.Broken.Tools.PrivateMessage;
|
import net.Broken.Tools.PrivateMessage;
|
||||||
import net.dv8tion.jda.core.EmbedBuilder;
|
import net.dv8tion.jda.core.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.core.Permission;
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
import net.dv8tion.jda.core.entities.Message;
|
import net.dv8tion.jda.core.entities.Message;
|
||||||
import net.dv8tion.jda.core.entities.MessageEmbed;
|
import net.dv8tion.jda.core.entities.MessageEmbed;
|
||||||
@ -36,6 +38,9 @@ public class Help implements Commande {
|
|||||||
String argsString = args[0];
|
String argsString = args[0];
|
||||||
//System.out.println(argsString);
|
//System.out.println(argsString);
|
||||||
if (MainBot.commandes.containsKey(argsString))
|
if (MainBot.commandes.containsKey(argsString))
|
||||||
|
{
|
||||||
|
Commande cmdObj = MainBot.commandes.get(argsString);
|
||||||
|
if(!cmdObj.isAdminCmd() || event.getMember().hasPermission(Permission.ADMINISTRATOR))
|
||||||
{
|
{
|
||||||
logger.info("Aide demmander pour la cmd "+argsString+" par "+event.getAuthor().getName());
|
logger.info("Aide demmander pour la cmd "+argsString+" par "+event.getAuthor().getName());
|
||||||
MessageEmbed messageEmbed;
|
MessageEmbed messageEmbed;
|
||||||
@ -72,6 +77,23 @@ public class Help implements Commande {
|
|||||||
} else{
|
} else{
|
||||||
PrivateMessage.send(event.getAuthor(), messageEmbed,logger);
|
PrivateMessage.send(event.getAuthor(), messageEmbed,logger);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.info("Help wanted for admin command, Denied!");
|
||||||
|
if(!event.isFromType(ChannelType.PRIVATE)) {
|
||||||
|
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getUnautorized()).complete();
|
||||||
|
List<Message> messages = new ArrayList<Message>(){{
|
||||||
|
add(rest);
|
||||||
|
add(event.getMessage());
|
||||||
|
}};
|
||||||
|
new MessageTimeOut(messages,MainBot.messageTimeOut).start();
|
||||||
|
|
||||||
|
} else{
|
||||||
|
PrivateMessage.send(event.getAuthor(), EmbedMessageUtils.getUnautorized(), logger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -94,6 +116,7 @@ public class Help implements Commande {
|
|||||||
{
|
{
|
||||||
StringBuilder txt= new StringBuilder();
|
StringBuilder txt= new StringBuilder();
|
||||||
for (Map.Entry<String, Commande> e : MainBot.commandes.entrySet()) {
|
for (Map.Entry<String, Commande> e : MainBot.commandes.entrySet()) {
|
||||||
|
if(!e.getValue().isAdminCmd() || event.getMember().hasPermission(Permission.ADMINISTRATOR))
|
||||||
txt.append("\n- ").append(e.getKey());
|
txt.append("\n- ").append(e.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +129,14 @@ public class Help implements Commande {
|
|||||||
new MessageTimeOut(messages,MainBot.messageTimeOut).start();
|
new MessageTimeOut(messages,MainBot.messageTimeOut).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
PrivateMessage.send(event.getAuthor(),new EmbedBuilder().setTitle("Command du bot").setDescription(txt.toString()).setFooter("Utilise '//help <commande>' pour plus de détails.",null).setColor(Color.green).setThumbnail(event.getJDA().getSelfUser().getAvatarUrl()).build(),logger);
|
|
||||||
|
String role;
|
||||||
|
if(event.getMember().hasPermission(Permission.ADMINISTRATOR))
|
||||||
|
role = "Admin";
|
||||||
|
else
|
||||||
|
role = "Non Admin";
|
||||||
|
|
||||||
|
PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getHelpList(role, txt.toString()),logger);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package net.Broken.Commands.Over18;
|
package net.Broken.Commands.Over18;
|
||||||
|
|
||||||
import net.Broken.Commande;
|
import net.Broken.Commande;
|
||||||
|
import net.Broken.Tools.EmbedMessageUtils;
|
||||||
|
import net.Broken.Tools.FindContentOnWebPage;
|
||||||
import net.Broken.Tools.Redirection;
|
import net.Broken.Tools.Redirection;
|
||||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@ -14,6 +16,7 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class Madame implements Commande{
|
public class Madame implements Commande{
|
||||||
Logger logger = LogManager.getLogger();
|
Logger logger = LogManager.getLogger();
|
||||||
|
MessageReceivedEvent event;
|
||||||
public String HELP="T'es sérieux la?";
|
public String HELP="T'es sérieux la?";
|
||||||
@Override
|
@Override
|
||||||
public boolean called(String[] args, MessageReceivedEvent event) {
|
public boolean called(String[] args, MessageReceivedEvent event) {
|
||||||
@ -22,6 +25,7 @@ public class Madame implements Commande{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void action(String[] args, MessageReceivedEvent event) {
|
public void action(String[] args, MessageReceivedEvent event) {
|
||||||
|
this.event = event;
|
||||||
|
|
||||||
if(event.getTextChannel().isNSFW()) {
|
if(event.getTextChannel().isNSFW()) {
|
||||||
Redirection redirect = new Redirection();
|
Redirection redirect = new Redirection();
|
||||||
@ -33,11 +37,12 @@ public class Madame implements Commande{
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
String url = redirect.get("http://dites.bonjourmadame.fr/random");
|
String url = redirect.get("http://dites.bonjourmadame.fr/random");
|
||||||
if((url.contains("club") && (url.contains("rejoindre") || url.contains("rejoignez"))) || (url.contains("samedi") && url.contains("dimanche"))){
|
logger.debug("URL: "+url);
|
||||||
|
if(scanPageForTipeee(url)){
|
||||||
logger.debug("Advertisement detected! Retry! ("+url+")");
|
logger.debug("Advertisement detected! Retry! ("+url+")");
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
event.getTextChannel().sendMessage(redirect.get("http://dites.bonjourmadame.fr/random")).queue();
|
event.getTextChannel().sendMessage(url).queue();
|
||||||
success=true;
|
success=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,6 +57,9 @@ public class Madame implements Commande{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}catch (StringIndexOutOfBoundsException e){
|
||||||
|
logger.catching(e);
|
||||||
|
event.getTextChannel().sendMessage(EmbedMessageUtils.getInternalError()).queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,4 +86,37 @@ public class Madame implements Commande{
|
|||||||
public boolean isAdminCmd() {
|
public boolean isAdminCmd() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean isAdvertisementUrl(String url){
|
||||||
|
//Scan url
|
||||||
|
if(url.toLowerCase().contains("club") && (url.toLowerCase().contains("rejoindre") || url.toLowerCase().contains("rejoignez"))){
|
||||||
|
logger.debug("Advertisement detected with \"club\" and \"rejoidre\" or \"rejoignez\"");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(url.contains("samedi") && url.contains("dimanche")){
|
||||||
|
logger.debug("Advertisement detected with \"samedi\" and \"dimanche\"");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean scanPageForTipeee(String url) throws StringIndexOutOfBoundsException, IOException{
|
||||||
|
String content = FindContentOnWebPage.getUrlSource(url);
|
||||||
|
String imgClickLink = content.substring(content.indexOf("photo post"));
|
||||||
|
imgClickLink = imgClickLink.substring(imgClickLink.indexOf("<a"));
|
||||||
|
imgClickLink = imgClickLink.substring(imgClickLink.indexOf("\""));
|
||||||
|
imgClickLink = imgClickLink.substring(0, imgClickLink.indexOf("\">"));
|
||||||
|
imgClickLink = imgClickLink.substring(1);
|
||||||
|
logger.debug("Image link: " + imgClickLink);
|
||||||
|
if(imgClickLink.contains("tipeee")){
|
||||||
|
logger.debug("Detect tipeee link! ");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,5 +98,9 @@ public class EmbedMessageUtils {
|
|||||||
return getError("Vous n'avez pas l'autorisation de faire ça!");
|
return getError("Vous n'avez pas l'autorisation de faire ça!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MessageEmbed getHelpList(String role, String list){
|
||||||
|
return new EmbedBuilder().setTitle("Command du bot ("+role+")").setDescription(list).setFooter("Utilise '//help <commande>' pour plus de détails.",null).setColor(Color.green).setThumbnail(MainBot.jda.getSelfUser().getAvatarUrl()).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -24,7 +24,7 @@ public class FindContentOnWebPage {
|
|||||||
return split[0];
|
return split[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getUrlSource(String url) throws IOException {
|
public static String getUrlSource(String url) throws IOException {
|
||||||
URL urlC = new URL(url);
|
URL urlC = new URL(url);
|
||||||
URLConnection yc = urlC.openConnection();
|
URLConnection yc = urlC.openConnection();
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(
|
BufferedReader in = new BufferedReader(new InputStreamReader(
|
||||||
|
Loading…
Reference in New Issue
Block a user