Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/main/java/tk/sciwhiz12/concord/ChatBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,21 @@ boolean checkSatisfaction() {
return false;
}

if (channel.getType() != ChannelType.TEXT) {
Concord.LOGGER.error(BOT, "The channel with ID {} is not a TEXT channel, it was of type {}.",
if (channel.getType() != ChannelType.TEXT && channel.getType() != ChannelType.GUILD_PUBLIC_THREAD &&
channel.getType() != ChannelType.GUILD_PRIVATE_THREAD) {
Concord.LOGGER.error(BOT,
"The channel with ID {} is not a TEXT channel or non-announcement thread, it was of type {}.",
ConcordConfig.CHAT_CHANNEL_ID.get(), channel.getType());
return false;
}

// Guild and channel IDs are correct, now to check permissions

// If the channel is a thread, also require thread message send permissions
if (channel.getType().isThread()) {
REQUIRED_PERMISSIONS.add(Permission.MESSAGE_SEND_IN_THREADS);
}

final Sets.SetView<Permission> missingPermissions = Sets
.difference(REQUIRED_PERMISSIONS, guild.getSelfMember().getPermissions(channel));

Expand Down
19 changes: 15 additions & 4 deletions src/main/java/tk/sciwhiz12/concord/command/ReportCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -79,10 +81,19 @@ private static int report(CommandContext<CommandSourceStack> ctx) throws Command

final ChatBot bot = Concord.getBot();
final String channelID = ConcordConfig.REPORT_CHANNEL_ID.get();
final TextChannel channel = channelID.isBlank() ? null : bot.getDiscord().getTextChannelById(channelID);
final GuildMessageChannel channel = channelID.isBlank() ? null :
bot.getDiscord().getChannelById(GuildMessageChannel.class, channelID);

// If reporting is disabled, also tell the user
if (channel == null) {
// Check permissions and channel type to see if sending is allowed
boolean sendingAllowed = false;
if (channel != null && (channel.getType() == ChannelType.TEXT || channel.getType() == ChannelType.GUILD_PUBLIC_THREAD ||
channel.getType() == ChannelType.GUILD_PRIVATE_THREAD)) {
sendingAllowed = channel.canTalk() && channel.getGuild().getSelfMember()
.hasPermission(channel, Permission.MESSAGE_EMBED_LINKS);
}

// If reporting is disabled or not possible, also tell the user
if (!sendingAllowed) {
ctx.getSource().sendFailure(
Translations.COMMAND_REPORT_STATUS.resolvedComponent(ctx.getSource(),
Translations.COMMAND_STATUS_DISABLED.resolvedComponent(ctx.getSource())
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/tk/sciwhiz12/concord/msg/Messaging.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.entities.sticker.StickerItem;
import net.minecraft.ChatFormatting;
import net.minecraft.locale.Language;
Expand Down Expand Up @@ -244,7 +244,8 @@ public static void sendToAllPlayers(MinecraftServer server, Member member, Messa
}

public static void sendToChannel(JDA discord, CharSequence text) {
final TextChannel channel = discord.getTextChannelById(ConcordConfig.CHAT_CHANNEL_ID.get());
final GuildMessageChannel channel = discord.getChannelById(GuildMessageChannel.class,
ConcordConfig.CHAT_CHANNEL_ID.get());
if (channel != null) {
Collection<Message.MentionType> allowedMentions = Collections.emptySet();
if (ConcordConfig.ALLOW_MENTIONS.get()) {
Expand Down