package com.mrpowergamerbr.loritta.commands.vanilla.misc;

import java.util.Arrays;
import java.util.List;

import com.mrpowergamerbr.loritta.Loritta;
import com.mrpowergamerbr.loritta.commands.CommandBase;
import com.mrpowergamerbr.loritta.commands.CommandCategory;
import com.mrpowergamerbr.loritta.commands.CommandContext;
import com.mrpowergamerbr.temmiewebhook.DiscordEmbed;
import com.mrpowergamerbr.temmiewebhook.DiscordMessage;
import com.mrpowergamerbr.temmiewebhook.TemmieWebhook;
import com.mrpowergamerbr.temmiewebhook.embed.AuthorEmbed;

import net.dv8tion.jda.core.entities.Message;

public class QuoteCommand extends CommandBase {
	@Override
	public String getLabel() {
		return "mencionar";
	}

	@Override
	public String getDescription() {
		return "Menciona uma mensagem, dica: para copiar o ID da mensagem, ative o modo de desenvolvedor do Discord e clique com botão direito em uma mensagem!";
	}
	
	@Override
	public boolean hasCommandFeedback() {
		return false;
	}

	@Override
	public List<String> getExample() {
		return Arrays.asList("msgId Olá!");
	}

	@Override
	public CommandCategory getCategory() {
		return CommandCategory.DISCORD;
	}

	@Override
	public void run(CommandContext context) {
		if (context.getArgs().length >= 1) {
			TemmieWebhook temmie = Loritta.getOrCreateWebhook(context.getEvent().getTextChannel(), "Quote Webhook");
			
			Message msg = context.getEvent().getTextChannel().getMessageById(context.getArgs()[0]).complete();
			
			if (msg == null) {
				return;
			}
			
			context.getMessage().delete().complete(); // ok, vamos deletar a msg original
			
			DiscordEmbed embed = DiscordEmbed
					.builder()
					.author(new AuthorEmbed(msg.getAuthor().getName() + " disse...", null, msg.getAuthor().getEffectiveAvatarUrl(), null))
					.color(123)
					.description(msg.getRawContent())
					.title("Wow!")
					.build();
			
			DiscordMessage dm = DiscordMessage
					.builder()
					.avatarUrl(context.getMessage().getAuthor().getEffectiveAvatarUrl())
					.username(context.getMessage().getAuthor().getName())
					.content(context.getEvent().getMessage().getRawContent().replace(context.getConfig().commandPrefix() + "mencionar " + context.getArgs()[0], "").trim())
					.embed(embed)
					.build();
			
			
			dm.setEmbeds(Arrays.asList(embed));
			
			temmie.sendMessage(dm);
			
			System.out.println("Enviado!");
		} else {
			context.explain();
		}
	}
}

@@ -144,16 +144,67 @@
 oritta;%0A
+import com.mrpowergamerbr.loritta.LorittaLauncher;%0A
 import c
@@ -594,16 +594,115 @@
 rEmbed;%0A
+import com.mrpowergamerbr.temmiewebhook.embed.FooterEmbed;%0A%0Aimport net.dv8tion.jda.core.Permission;
 %0Aimport 
@@ -1058,17 +1058,16 @@
 m!%22;%0A%09%7D%0A
-%09
 %0A%09@Overr
@@ -1508,19 +1508,16 @@
 hook%22);%0A
-%09%09%09
 %0A%09%09%09Mess
@@ -1607,27 +1607,24 @@
 complete();%0A
-%09%09%09
 %0A%09%09%09if (msg 
@@ -1651,20 +1651,152 @@
 n;%0A%09%09%09%7D%0A
+%0A
 %09%09%09
-%0A
+if (context.getGuild().getMember(LorittaLauncher.getInstance().getJda().getSelfUser()).hasPermission(Permission.MESSAGE_MANAGE)) %7B%0A%09
 %09%09%09conte
@@ -1867,24 +1867,26 @@
 original%0A%09%09%09
+%7D%0A
 %0A%09%09%09DiscordE
@@ -1975,20 +1975,25 @@
 or().get
-Name
+AsMention
 () + %22 d
@@ -2117,16 +2117,19 @@
 ))%0A%09%09%09%09%09
+// 
 .title(%22
@@ -2135,16 +2135,300 @@
 %22Wow!%22)%0A
+%09%09%09%09%09.footer(new FooterEmbed(%22em #%22 + context.getMessage().getTextChannel().getName() + (context.getGuild().getMember(LorittaLauncher.getInstance().getJda().getSelfUser()).hasPermission(Permission.MESSAGE_MANAGE) ? %22%22 : %22 %7C N%C3%A3o tenho permiss%C3%A3o para deletar mensagens!%22), null, null))%0A
 %09%09%09%09%09.bu
@@ -2430,27 +2430,24 @@
 %09%09.build();%0A
-%09%09%09
 %0A%09%09%09DiscordM
@@ -2813,23 +2813,17 @@
 uild();%0A
-%09%09%09%0A%09%09%09
+%0A
 %0A%09%09%09dm.s
@@ -2854,19 +2854,16 @@
 mbed));%0A
-%09%09%09
 %0A%09%09%09temm
@@ -2882,19 +2882,16 @@
 ge(dm);%0A
-%09%09%09
 %0A%09%09%09Syst

Verifique se a Loritta tem permissão para mexer nas mensagens da guild antes de tentar deletar elas ao usar "+mencionar", caso não tenha, simplesmente não delete ela! (e avise que ela não tem permissão para deletar as mensagens)