Add adminchat channel

This commit is contained in:
Telesphoreo 2020-11-14 20:13:59 -06:00
parent 2c19ce5c65
commit a537183545
7 changed files with 103 additions and 11 deletions

View File

@ -158,6 +158,7 @@ public class ChatManager extends FreedomService
{ {
Displayable display = plugin.rm.getDisplay(sender); Displayable display = plugin.rm.getDisplay(sender);
FLog.info("[STAFF] " + sender.getName() + " " + display.getTag() + ": " + message, true); FLog.info("[STAFF] " + sender.getName() + " " + display.getTag() + ": " + message, true);
plugin.dc.messageAdminChatChannel(sender.getName() + " \u00BB " + message);
for (Player player : server.getOnlinePlayers()) for (Player player : server.getOnlinePlayers())
{ {

View File

@ -1,7 +1,6 @@
package me.totalfreedom.totalfreedommod; package me.totalfreedom.totalfreedommod;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;

View File

@ -72,6 +72,8 @@ public enum ConfigEntry
DISCORD_TOKEN(String.class, "discord.token"), DISCORD_TOKEN(String.class, "discord.token"),
DISCORD_REPORT_CHANNEL_ID(String.class, "discord.report_channel_id"), DISCORD_REPORT_CHANNEL_ID(String.class, "discord.report_channel_id"),
DISCORD_CHAT_CHANNEL_ID(String.class, "discord.chat_channel_id"), DISCORD_CHAT_CHANNEL_ID(String.class, "discord.chat_channel_id"),
DISCORD_ADMINCHAT_CHANNEL_ID(String.class, "discord.adminchat_channel_id"),
DISCORD_ROLE_SYNC(Boolean.class, "discord.role_sync"), DISCORD_ROLE_SYNC(Boolean.class, "discord.role_sync"),
DISCORD_SERVER_ID(String.class, "discord.server_id"), DISCORD_SERVER_ID(String.class, "discord.server_id"),
DISCORD_MASTER_BUILDER_ROLE_ID(String.class, "discord.master_builder_role_id"), DISCORD_MASTER_BUILDER_ROLE_ID(String.class, "discord.master_builder_role_id"),

View File

@ -81,6 +81,7 @@ public class Discord extends FreedomService
bot = JDABuilder.createDefault(ConfigEntry.DISCORD_TOKEN.getString()) bot = JDABuilder.createDefault(ConfigEntry.DISCORD_TOKEN.getString())
.addEventListeners(new PrivateMessageListener(), .addEventListeners(new PrivateMessageListener(),
new DiscordToMinecraftListener(), new DiscordToMinecraftListener(),
new DiscordToAdminChatListener(),
new ListenerAdapter() new ListenerAdapter()
{ {
@Override @Override
@ -332,6 +333,26 @@ public class Discord extends FreedomService
} }
} }
public void messageAdminChatChannel(String message)
{
String chat_channel_id = ConfigEntry.DISCORD_ADMINCHAT_CHANNEL_ID.getString();
if (message.contains("@everyone") || message.contains("@here"))
{
message = StringUtils.remove(message, "@");
}
if (message.toLowerCase().contains("discord.gg"))
{
return;
}
if (enabled && !chat_channel_id.isEmpty())
{
CompletableFuture<Message> sentMessage = bot.getTextChannelById(chat_channel_id).sendMessage(message).submit(true);
sentMessages.add(sentMessage);
}
}
public String formatBotTag() public String formatBotTag()
{ {
SelfUser user = bot.getSelfUser(); SelfUser user = bot.getSelfUser();
@ -356,7 +377,6 @@ public class Discord extends FreedomService
if (bot != null) if (bot != null)
{ {
messageChatChannel("**Server has stopped**"); messageChatChannel("**Server has stopped**");
bot.shutdown();
} }
FLog.info("Discord verification bot has successfully shutdown."); FLog.info("Discord verification bot has successfully shutdown.");
} }

View File

@ -0,0 +1,68 @@
package me.totalfreedom.totalfreedommod.discord;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.FLog;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class DiscordToAdminChatListener extends ListenerAdapter
{
DiscordToMinecraftListener dtml = new DiscordToMinecraftListener();
public void onMessageReceived(MessageReceivedEvent event)
{
String chat_channel_id = ConfigEntry.DISCORD_ADMINCHAT_CHANNEL_ID.getString();
if (event.getMember() != null && !chat_channel_id.isEmpty() && event.getChannel().getId().equals(chat_channel_id))
{
if (!event.getAuthor().getId().equals(Discord.bot.getSelfUser().getId()))
{
Member member = event.getMember();
String tag = dtml.getDisplay(member);
StringBuilder message = new StringBuilder(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_AQUA + "STAFF" + ChatColor.DARK_GRAY + "]");
Message msg = event.getMessage();
if (tag != null)
{
message.append(" ").append(tag);
}
message.append(" " + ChatColor.RED).append(ChatColor.stripColor(member.getEffectiveName())).append(ChatColor.DARK_GRAY).append(":").append(ChatColor.RESET);
ComponentBuilder builder = new ComponentBuilder(message.toString());
if (!msg.getContentDisplay().isEmpty())
{
builder.append(" ").append(ChatColor.stripColor(msg.getContentDisplay()));
message.append(" ").append(ChatColor.stripColor(msg.getContentDisplay())); // for logging
}
if (!msg.getAttachments().isEmpty())
{
for (Message.Attachment attachment : msg.getAttachments())
{
if (attachment.getUrl() == null)
{
continue;
}
builder.append(" ");
TextComponent text = new TextComponent(ChatColor.YELLOW + "[Media]");
text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl()));
builder.append(text);
message.append(" [Media]"); // for logging
}
}
for (Player player : Bukkit.getOnlinePlayers())
{
if (TotalFreedomMod.getPlugin().sl.isStaff(player))
{
player.spigot().sendMessage(builder.create());
}
}
FLog.info(message.toString());
}
}
}
}

View File

@ -28,18 +28,18 @@ public class DiscordToMinecraftListener extends ListenerAdapter
{ {
Member member = event.getMember(); Member member = event.getMember();
String tag = getDisplay(member); String tag = getDisplay(member);
String message = ChatColor.DARK_GRAY + "[" + ChatColor.DARK_AQUA + "Discord" + ChatColor.DARK_GRAY + "]"; StringBuilder message = new StringBuilder(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_AQUA + "Discord" + ChatColor.DARK_GRAY + "]");
Message msg = event.getMessage(); Message msg = event.getMessage();
if (tag != null) if (tag != null)
{ {
message += " " + tag; message.append(" ").append(tag);
} }
message += " " + ChatColor.RED + ChatColor.stripColor(member.getEffectiveName()) + ChatColor.DARK_GRAY + ":" + ChatColor.RESET; message.append(" " + ChatColor.RED).append(ChatColor.stripColor(member.getEffectiveName())).append(ChatColor.DARK_GRAY).append(":").append(ChatColor.RESET);
ComponentBuilder builder = new ComponentBuilder(message); ComponentBuilder builder = new ComponentBuilder(message.toString());
if (!msg.getContentDisplay().isEmpty()) if (!msg.getContentDisplay().isEmpty())
{ {
builder.append(" ").append(ChatColor.stripColor(msg.getContentDisplay())); builder.append(" ").append(ChatColor.stripColor(msg.getContentDisplay()));
message += " " + ChatColor.stripColor(msg.getContentDisplay()); // for logging message.append(" ").append(ChatColor.stripColor(msg.getContentDisplay())); // for logging
} }
if (!msg.getAttachments().isEmpty()) if (!msg.getAttachments().isEmpty())
{ {
@ -53,7 +53,7 @@ public class DiscordToMinecraftListener extends ListenerAdapter
TextComponent text = new TextComponent(ChatColor.YELLOW + "[Media]"); TextComponent text = new TextComponent(ChatColor.YELLOW + "[Media]");
text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl())); text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl()));
builder.append(text); builder.append(text);
message += " [Media]"; // for logging message.append(" [Media]"); // for logging
} }
} }
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers())
@ -63,7 +63,7 @@ public class DiscordToMinecraftListener extends ListenerAdapter
player.spigot().sendMessage(builder.create()); player.spigot().sendMessage(builder.create());
} }
} }
FLog.info(message); FLog.info(message.toString());
} }
} }
} }

View File

@ -31,7 +31,7 @@ server:
# All players who show up as owner # All players who show up as owner
owners: owners:
- Demonic_Mario - Wild1145
# All players who show up as executive # All players who show up as executive
executives: [] executives: []
@ -59,8 +59,10 @@ discord:
server_id: '' server_id: ''
# Channel to send /report messages to # Channel to send /report messages to
report_channel_id: '' report_channel_id: ''
# Channel for discord to minecraft and vice-versa # Channel for Discord to Minecraft and vice-versa
chat_channel_id: '' chat_channel_id: ''
# Channel for Discord to AdminChat and vice-versa
adminchat_channel_id: ''
# Do you want roles to sync with the server? # Do you want roles to sync with the server?
role_sync: false role_sync: false
# Master Builder role ID # Master Builder role ID