mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
More discord stuff
This commit is contained in:
parent
481983aeaf
commit
92ad950155
@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.banning.Ban;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.punishments.Punishment;
|
||||
import me.totalfreedom.totalfreedommod.punishments.PunishmentType;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
@ -49,6 +50,10 @@ public class Command_doom extends FreedomCommand
|
||||
admin.setActive(false);
|
||||
plugin.al.save();
|
||||
plugin.al.updateTables();
|
||||
if (plugin.dc.enabled && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean())
|
||||
{
|
||||
plugin.dc.syncRoles(admin);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove from whitelist
|
||||
|
@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.Arrays;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.util.Ips;
|
||||
@ -12,7 +13,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Manage my admin entry", usage = "/<command> [-o <admin>] <clearips | clearip <ip> | setlogin <message> | clearlogin | setacformat <format> | clearacformat> | oldtags | logstick>")
|
||||
@CommandParameters(description = "Manage my admin entry", usage = "/<command> [-o <admin>] <clearips | clearip <ip> | setlogin <message> | clearlogin | setacformat <format> | clearacformat> | oldtags | logstick | syncroles>")
|
||||
public class Command_myadmin extends FreedomCommand
|
||||
{
|
||||
|
||||
@ -206,6 +207,34 @@ public class Command_myadmin extends FreedomCommand
|
||||
return true;
|
||||
}
|
||||
|
||||
case "syncroles":
|
||||
{
|
||||
if (plugin.dc.enabled)
|
||||
{
|
||||
if (!ConfigEntry.DISCORD_ROLE_SYNC.getBoolean())
|
||||
{
|
||||
msg("Role syncing is not enabled.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
boolean synced = plugin.dc.syncRoles(target);
|
||||
if (target.getDiscordID() == null)
|
||||
{
|
||||
msg("Please run /linkdiscord first!", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
if (synced)
|
||||
{
|
||||
msg("Successfully synced your roles.", ChatColor.GREEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg("Failed to sync your roles, please check the console.", ChatColor.RED);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
return false;
|
||||
|
@ -47,6 +47,11 @@ public class Command_report extends FreedomCommand
|
||||
String report = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
|
||||
plugin.cm.reportAction(playerSender, player, report);
|
||||
|
||||
if (plugin.dc.enabled)
|
||||
{
|
||||
plugin.dc.sendReport(playerSender, player, report);
|
||||
}
|
||||
|
||||
msg(ChatColor.GREEN + "Thank you, your report has been successfully logged.");
|
||||
|
||||
return true;
|
||||
|
@ -6,8 +6,10 @@ import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.masterbuilder.MasterBuilder;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.playerverification.VPlayer;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.util.Ips;
|
||||
@ -108,6 +110,11 @@ public class Command_saconfig extends FreedomCommand
|
||||
plugin.rm.updateDisplay(player);
|
||||
}
|
||||
|
||||
if (plugin.dc.enabled && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean())
|
||||
{
|
||||
plugin.dc.syncRoles(admin);
|
||||
}
|
||||
|
||||
msg("Set " + admin.getName() + "'s rank to " + rank.getName());
|
||||
return true;
|
||||
}
|
||||
@ -206,6 +213,21 @@ public class Command_saconfig extends FreedomCommand
|
||||
{
|
||||
plugin.rm.updateDisplay(player);
|
||||
}
|
||||
|
||||
// Attempt to find discord account
|
||||
if (plugin.mbl.isMasterBuilder(player))
|
||||
{
|
||||
MasterBuilder masterBuilder = plugin.mbl.getMasterBuilder(player);
|
||||
admin.setDiscordID(plugin.mbl.getMasterBuilder(player).getDiscordID());
|
||||
}
|
||||
else if (plugin.pv.getVerificationPlayer(admin.getName()) != null)
|
||||
{
|
||||
VPlayer vPlayer = plugin.pv.getVerificationPlayer(admin.getName());
|
||||
if (vPlayer.getDiscordId() != null)
|
||||
{
|
||||
admin.setDiscordID(vPlayer.getDiscordId());
|
||||
}
|
||||
}
|
||||
}
|
||||
else // Existing admin
|
||||
{
|
||||
@ -248,12 +270,32 @@ public class Command_saconfig extends FreedomCommand
|
||||
admin.setActive(true);
|
||||
admin.setLastLogin(new Date());
|
||||
|
||||
// Attempt to find discord account
|
||||
if (plugin.mbl.isMasterBuilder(player))
|
||||
{
|
||||
MasterBuilder masterBuilder = plugin.mbl.getMasterBuilder(player);
|
||||
admin.setDiscordID(plugin.mbl.getMasterBuilder(player).getDiscordID());
|
||||
}
|
||||
else if (plugin.pv.getVerificationPlayer(admin.getName()) != null)
|
||||
{
|
||||
VPlayer vPlayer = plugin.pv.getVerificationPlayer(admin.getName());
|
||||
if (vPlayer.getDiscordId() != null)
|
||||
{
|
||||
admin.setDiscordID(vPlayer.getDiscordId());
|
||||
}
|
||||
}
|
||||
|
||||
plugin.al.save();
|
||||
plugin.al.updateTables();
|
||||
if (player != null)
|
||||
{
|
||||
plugin.rm.updateDisplay(player);
|
||||
}
|
||||
|
||||
if (plugin.dc.enabled && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean())
|
||||
{
|
||||
plugin.dc.syncRoles(admin);
|
||||
}
|
||||
}
|
||||
|
||||
if (player != null)
|
||||
@ -302,6 +344,12 @@ public class Command_saconfig extends FreedomCommand
|
||||
{
|
||||
plugin.rm.updateDisplay(player);
|
||||
}
|
||||
|
||||
if (plugin.dc.enabled && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean())
|
||||
{
|
||||
plugin.dc.syncRoles(admin);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -42,10 +42,18 @@ public enum ConfigEntry
|
||||
SERVER_MOTD(String.class, "server.motd"),
|
||||
SERVER_OWNERS(List.class, "server.owners"),
|
||||
SERVER_EXECUTIVES(List.class, "server.executives"),
|
||||
SERVER_MASTER_BUILDER_MANAGEMENT(List.class, "server.emaster_builder_management"),
|
||||
SERVER_BAN_URL(String.class, "server.ban_url"),
|
||||
SERVER_PERMBAN_URL(String.class, "server.permban_url"),
|
||||
//
|
||||
DISCORD_TOKEN(String.class, "discord.token"),
|
||||
DISCORD_REPORT_CHANNEL_ID(String.class, "discord.report_channel_id"),
|
||||
DISCORD_ROLE_SYNC(Boolean.class, "discord.role_sync"),
|
||||
DISCORD_SERVER_ID(String.class, "discord.server_id"),
|
||||
DISCORD_SUPER_ROLE_ID(String.class, "discord.super_role_id"),
|
||||
DISCORD_TELNET_ROLE_ID(String.class, "discord.telnet_role_id"),
|
||||
DISCORD_SENIOR_ROLE_ID(String.class, "discord.senior_role_id"),
|
||||
|
||||
//
|
||||
ADMINLIST_CLEAN_THESHOLD_HOURS(Integer.class, "adminlist.clean_threshold_hours"),
|
||||
ADMINLIST_CONSOLE_IS_SENIOR(Boolean.class, "adminlist.console_is_senior"),
|
||||
|
@ -1,6 +1,8 @@
|
||||
package me.totalfreedom.totalfreedommod.discord;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import java.time.Instant;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -10,10 +12,20 @@ import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.playerverification.VPlayer;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import net.dv8tion.jda.core.AccountType;
|
||||
import net.dv8tion.jda.core.EmbedBuilder;
|
||||
import net.dv8tion.jda.core.JDA;
|
||||
import net.dv8tion.jda.core.JDABuilder;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.Member;
|
||||
import net.dv8tion.jda.core.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.core.entities.Role;
|
||||
import net.dv8tion.jda.core.entities.TextChannel;
|
||||
import net.dv8tion.jda.core.managers.GuildController;
|
||||
import net.dv8tion.jda.core.requests.restaction.AuditableRestAction;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Discord extends FreedomService
|
||||
{
|
||||
@ -96,4 +108,146 @@ public class Discord extends FreedomService
|
||||
}
|
||||
FLog.info("Discord verification bot has successfully shutdown.");
|
||||
}
|
||||
|
||||
public void sendReport(Player reporter, Player reported, String reason)
|
||||
{
|
||||
if (ConfigEntry.DISCORD_REPORT_CHANNEL_ID.getString() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (ConfigEntry.DISCORD_SERVER_ID.getString() == null)
|
||||
{
|
||||
FLog.severe("No discord server ID was specified in the config, but there is a report channel id.");
|
||||
return;
|
||||
}
|
||||
Guild server = bot.getGuildById(ConfigEntry.DISCORD_SERVER_ID.getString());
|
||||
if (server == null)
|
||||
{
|
||||
FLog.severe("The discord server ID specified is invalid, or the bot is not on the server.");
|
||||
return;
|
||||
}
|
||||
TextChannel channel = server.getTextChannelById(ConfigEntry.DISCORD_REPORT_CHANNEL_ID.getString());
|
||||
if (channel == null)
|
||||
{
|
||||
FLog.severe("The report channel ID specified in the config is invalid");
|
||||
return;
|
||||
}
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
embedBuilder.setTitle("Report for " + reported.getName());
|
||||
embedBuilder.setDescription(reason);
|
||||
embedBuilder.setFooter("Reported by " + reporter.getName(), "https://minotar.net/helm/" + reporter.getName() + ".png");
|
||||
embedBuilder.setTimestamp(Instant.from(ZonedDateTime.now()));
|
||||
MessageEmbed embed = embedBuilder.build();
|
||||
channel.sendMessage(embed).complete();
|
||||
}
|
||||
|
||||
public static boolean syncRoles(Admin admin)
|
||||
{
|
||||
if (admin.getDiscordID() == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Guild server = bot.getGuildById(ConfigEntry.DISCORD_SERVER_ID.getString());
|
||||
if (server == null)
|
||||
{
|
||||
FLog.severe("The discord server ID specified is invalid, or the bot is not on the server.");
|
||||
return false;
|
||||
}
|
||||
|
||||
GuildController controller = new GuildController(server);
|
||||
|
||||
Member member = server.getMemberById(admin.getDiscordID());
|
||||
if (member == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Role superAdminRole = server.getRoleById(ConfigEntry.DISCORD_SUPER_ROLE_ID.getString());
|
||||
if (superAdminRole == null)
|
||||
{
|
||||
FLog.severe("The specified Super Admin role does not exist!");
|
||||
return false;
|
||||
}
|
||||
Role telnetAdminRole = server.getRoleById(ConfigEntry.DISCORD_TELNET_ROLE_ID.getString());
|
||||
if (telnetAdminRole == null)
|
||||
{
|
||||
FLog.severe("The specified Telnet Admin role does not exist!");
|
||||
return false;
|
||||
}
|
||||
Role seniorAdminRole = server.getRoleById(ConfigEntry.DISCORD_SENIOR_ROLE_ID.getString());
|
||||
if (seniorAdminRole == null)
|
||||
{
|
||||
FLog.severe("The specified Senior Admin role does not exist!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!admin.isActive())
|
||||
{
|
||||
if (member.getRoles().contains(superAdminRole))
|
||||
{
|
||||
controller.removeRolesFromMember(member, superAdminRole).complete();
|
||||
}
|
||||
if (member.getRoles().contains(telnetAdminRole))
|
||||
{
|
||||
controller.removeRolesFromMember(member, telnetAdminRole).complete();
|
||||
}
|
||||
if (member.getRoles().contains(seniorAdminRole))
|
||||
{
|
||||
controller.removeRolesFromMember(member, seniorAdminRole).complete();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (admin.getRank().equals(Rank.SUPER_ADMIN))
|
||||
{
|
||||
if (!member.getRoles().contains(superAdminRole))
|
||||
{
|
||||
controller.addRolesToMember(member, superAdminRole).complete();
|
||||
}
|
||||
if (member.getRoles().contains(telnetAdminRole))
|
||||
{
|
||||
controller.removeRolesFromMember(member, telnetAdminRole).complete();
|
||||
}
|
||||
if (member.getRoles().contains(seniorAdminRole))
|
||||
{
|
||||
controller.removeRolesFromMember(member, seniorAdminRole).complete();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (admin.getRank().equals(Rank.TELNET_ADMIN))
|
||||
{
|
||||
if (!member.getRoles().contains(telnetAdminRole))
|
||||
{
|
||||
controller.addRolesToMember(member, telnetAdminRole).complete();
|
||||
}
|
||||
if (member.getRoles().contains(superAdminRole))
|
||||
{
|
||||
controller.removeRolesFromMember(member, superAdminRole).complete();
|
||||
}
|
||||
if (member.getRoles().contains(seniorAdminRole))
|
||||
{
|
||||
controller.removeRolesFromMember(member, seniorAdminRole).complete();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (admin.getRank().equals(Rank.SENIOR_ADMIN))
|
||||
{
|
||||
if (!member.getRoles().contains(seniorAdminRole))
|
||||
{
|
||||
controller.addRolesToMember(member, seniorAdminRole).complete();
|
||||
}
|
||||
if (member.getRoles().contains(superAdminRole))
|
||||
{
|
||||
controller.removeRolesFromMember(member, superAdminRole).complete();
|
||||
}
|
||||
if (member.getRoles().contains(telnetAdminRole))
|
||||
{
|
||||
controller.removeRolesFromMember(member, telnetAdminRole).complete();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod.discord;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.playerverification.VPlayer;
|
||||
import net.dv8tion.jda.core.events.message.priv.PrivateMessageReceivedEvent;
|
||||
import net.dv8tion.jda.core.hooks.ListenerAdapter;
|
||||
@ -23,6 +24,7 @@ public class MessageListener extends ListenerAdapter
|
||||
Discord.LINK_CODES.remove(code);
|
||||
event.getChannel().sendMessage("Link successful. Now this Discord account is linked with the Minecraft account `" + admin.getName() + "`.\n"
|
||||
+ "Now when you are an impostor on the server, you may use `/verify` to verify.").complete();
|
||||
Discord.syncRoles(admin);
|
||||
}
|
||||
if (Discord.PLAYER_LINK_CODES.get(code) != null)
|
||||
{
|
||||
|
@ -38,7 +38,7 @@ public class FUtil
|
||||
//
|
||||
public static final String SAVED_FLAGS_FILENAME = "savedflags.dat";
|
||||
// See https://github.com/TotalFreedom/License - None of the listed names may be removed.
|
||||
public static final List<String> DEVELOPERS = Arrays.asList("Madgeek1450", "Prozza", "WickedGamingUK", "aggelosQQ", "OxLemonxO", "Wild1145", "Catholic_Mario");
|
||||
public static final List<String> DEVELOPERS = Arrays.asList("Madgeek1450", "Prozza", "WickedGamingUK", "aggelosQQ", "OxLemonxO", "Wild1145", "Catholic_Mario", "Arcaknight");
|
||||
public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";
|
||||
public static final Map<String, ChatColor> CHAT_COLOR_NAMES = new HashMap<>();
|
||||
public static final List<ChatColor> CHAT_COLOR_POOL = Arrays.asList(
|
||||
|
@ -24,6 +24,9 @@ server:
|
||||
# All players who show up as executive
|
||||
executives: []
|
||||
|
||||
# All those who can manage the master builder list
|
||||
master_builder_management: []
|
||||
|
||||
# URL players should appeal for bans at
|
||||
ban_url: http://totalfreedom.boards.net/
|
||||
|
||||
@ -34,6 +37,20 @@ server:
|
||||
discord:
|
||||
# If you do not have a token, make a bot account and get one at https://discordapp.com/developers/applications/me
|
||||
token: ''
|
||||
# The official discord server's ID for this server
|
||||
server_id: ''
|
||||
# Channel to send /report messages to
|
||||
report_channel_id: ''
|
||||
# Do you want roles to sync with the server?
|
||||
role_sync: false
|
||||
# The official discord server's ID for this server
|
||||
server_id: ''
|
||||
# Super Admin role ID
|
||||
super_role_id: ''
|
||||
# Telnet Admin role ID
|
||||
telnet_role_id: ''
|
||||
# Senior Admin role ID
|
||||
senior_role_id: ''
|
||||
|
||||
# Admin list
|
||||
adminlist:
|
||||
|
Loading…
Reference in New Issue
Block a user