mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 02:05:41 +00:00
Add adminchat channel
This commit is contained in:
parent
2c19ce5c65
commit
a537183545
@ -158,6 +158,7 @@ public class ChatManager extends FreedomService
|
||||
{
|
||||
Displayable display = plugin.rm.getDisplay(sender);
|
||||
FLog.info("[STAFF] " + sender.getName() + " " + display.getTag() + ": " + message, true);
|
||||
plugin.dc.messageAdminChatChannel(sender.getName() + " \u00BB " + message);
|
||||
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
|
@ -1,7 +1,6 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
|
@ -72,6 +72,8 @@ public enum ConfigEntry
|
||||
DISCORD_TOKEN(String.class, "discord.token"),
|
||||
DISCORD_REPORT_CHANNEL_ID(String.class, "discord.report_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_SERVER_ID(String.class, "discord.server_id"),
|
||||
DISCORD_MASTER_BUILDER_ROLE_ID(String.class, "discord.master_builder_role_id"),
|
||||
|
@ -81,6 +81,7 @@ public class Discord extends FreedomService
|
||||
bot = JDABuilder.createDefault(ConfigEntry.DISCORD_TOKEN.getString())
|
||||
.addEventListeners(new PrivateMessageListener(),
|
||||
new DiscordToMinecraftListener(),
|
||||
new DiscordToAdminChatListener(),
|
||||
new ListenerAdapter()
|
||||
{
|
||||
@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()
|
||||
{
|
||||
SelfUser user = bot.getSelfUser();
|
||||
@ -356,7 +377,6 @@ public class Discord extends FreedomService
|
||||
if (bot != null)
|
||||
{
|
||||
messageChatChannel("**Server has stopped**");
|
||||
bot.shutdown();
|
||||
}
|
||||
FLog.info("Discord verification bot has successfully shutdown.");
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -28,18 +28,18 @@ public class DiscordToMinecraftListener extends ListenerAdapter
|
||||
{
|
||||
Member member = event.getMember();
|
||||
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();
|
||||
if (tag != null)
|
||||
{
|
||||
message += " " + tag;
|
||||
message.append(" ").append(tag);
|
||||
}
|
||||
message += " " + ChatColor.RED + ChatColor.stripColor(member.getEffectiveName()) + ChatColor.DARK_GRAY + ":" + ChatColor.RESET;
|
||||
ComponentBuilder builder = new ComponentBuilder(message);
|
||||
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 += " " + ChatColor.stripColor(msg.getContentDisplay()); // for logging
|
||||
message.append(" ").append(ChatColor.stripColor(msg.getContentDisplay())); // for logging
|
||||
}
|
||||
if (!msg.getAttachments().isEmpty())
|
||||
{
|
||||
@ -53,7 +53,7 @@ public class DiscordToMinecraftListener extends ListenerAdapter
|
||||
TextComponent text = new TextComponent(ChatColor.YELLOW + "[Media]");
|
||||
text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl()));
|
||||
builder.append(text);
|
||||
message += " [Media]"; // for logging
|
||||
message.append(" [Media]"); // for logging
|
||||
}
|
||||
}
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
@ -63,7 +63,7 @@ public class DiscordToMinecraftListener extends ListenerAdapter
|
||||
player.spigot().sendMessage(builder.create());
|
||||
}
|
||||
}
|
||||
FLog.info(message);
|
||||
FLog.info(message.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ server:
|
||||
|
||||
# All players who show up as owner
|
||||
owners:
|
||||
- Demonic_Mario
|
||||
- Wild1145
|
||||
|
||||
# All players who show up as executive
|
||||
executives: []
|
||||
@ -59,8 +59,10 @@ discord:
|
||||
server_id: ''
|
||||
# Channel to send /report messages to
|
||||
report_channel_id: ''
|
||||
# Channel for discord to minecraft and vice-versa
|
||||
# Channel for Discord to Minecraft and vice-versa
|
||||
chat_channel_id: ''
|
||||
# Channel for Discord to AdminChat and vice-versa
|
||||
adminchat_channel_id: ''
|
||||
# Do you want roles to sync with the server?
|
||||
role_sync: false
|
||||
# Master Builder role ID
|
||||
|
Loading…
Reference in New Issue
Block a user