use of net.dv8tion.jda.core.entities.TextChannel in project FredBoat by Frederikam.
the class CommandManager method prefixCalled.
public void prefixCalled(CommandContext context) {
Guild guild = context.guild;
Command invoked = context.command;
TextChannel channel = context.channel;
Member invoker = context.invoker;
totalCommandsExecuted.incrementAndGet();
Metrics.commandsExecuted.labels(invoked.getClass().getSimpleName()).inc();
if (FeatureFlags.PATRON_VALIDATION.isActive()) {
PatronageChecker.Status status = patronageChecker.getStatus(guild);
if (!status.isValid()) {
String msg = "Access denied. This bot can only be used if invited from <https://patron.fredboat.com/> " + "by someone who currently has a valid pledge on Patreon.\n**Denial reason:** " + status.getReason() + "\n\n";
msg += "Do you believe this to be a mistake? If so reach out to Fre_d on Patreon <" + BotConstants.PATREON_CAMPAIGN_URL + ">";
context.reply(msg);
return;
}
}
// Hardcode music commands in FredBoatHangout. Blacklist any channel that isn't #spam_and_music or #staff, but whitelist Admins
if (guild.getIdLong() == BotConstants.FREDBOAT_HANGOUT_ID && DiscordUtil.isOfficialBot(credentials)) {
if (// #spam_and_music
!channel.getId().equals("174821093633294338") && // #staff
!channel.getId().equals("217526705298866177") && !PermsUtil.checkPerms(PermissionLevel.ADMIN, invoker)) {
context.deleteMessage();
context.replyWithName("Please read <#219483023257763842> for server rules and only use commands in <#174821093633294338>!", msg -> CentralMessaging.restService.schedule(() -> CentralMessaging.deleteMessage(msg), 5, TimeUnit.SECONDS));
return;
}
}
if (disabledCommands.contains(invoked)) {
context.replyWithName("Sorry the `" + context.command.name + "` command is currently disabled. Please try again later");
return;
}
if (invoked instanceof ICommandRestricted) {
if (!PermsUtil.checkPermsWithFeedback(((ICommandRestricted) invoked).getMinimumPerms(), context)) {
return;
}
}
if (invoked instanceof IMusicCommand) {
musicTextChannelProvider.setMusicChannel(channel);
}
try {
invoked.onInvoke(context);
} catch (Exception e) {
TextUtils.handleException(e, context);
}
}
use of net.dv8tion.jda.core.entities.TextChannel in project SkyBot by duncte123.
the class AnnounceCommand method executeCommand.
@Override
public void executeCommand(String invoke, String[] args, GuildMessageReceivedEvent event) {
Permission[] perms = { Permission.ADMINISTRATOR };
if (!event.getMember().hasPermission(perms)) {
MessageUtils.sendMsg(event, "I'm sorry but you don't have permission to run this command.");
return;
}
if (event.getMessage().getMentionedChannels().size() < 1) {
MessageUtils.sendMsg(event, "Correct usage is `" + PREFIX + getName() + " [#Channel] [Message]`");
return;
}
try {
TextChannel targetChannel = event.getMessage().getMentionedChannels().get(0);
if (!targetChannel.getGuild().getSelfMember().hasPermission(targetChannel, Permission.MESSAGE_WRITE, Permission.MESSAGE_READ)) {
MessageUtils.sendMsg(event, "I can not talk in " + targetChannel.getAsMention());
MessageUtils.sendError(event.getMessage());
return;
}
String msg = event.getMessage().getContentRaw().split("\\s+", 3)[2];
@SinceSkybot(version = "3.52.3") EmbedBuilder embed = EmbedUtils.defaultEmbed().setDescription(msg).setFooter(null, "");
if (!event.getMessage().getAttachments().isEmpty()) {
event.getMessage().getAttachments().stream().filter(Message.Attachment::isImage).findFirst().ifPresent(attachment -> {
if (invoke.endsWith("2"))
embed.setThumbnail(attachment.getUrl());
else
embed.setImage(attachment.getUrl());
});
}
MessageUtils.sendEmbed(targetChannel, embed.build());
MessageUtils.sendSuccess(event.getMessage());
} catch (ArrayIndexOutOfBoundsException ex) {
MessageUtils.sendErrorWithMessage(event.getMessage(), "Please! You either forgot the text or to mention the channel!");
ComparatingUtils.execCheck(ex);
} catch (Exception e) {
MessageUtils.sendMsg(event, "WHOOPS: " + e.getMessage());
e.printStackTrace();
}
}
use of net.dv8tion.jda.core.entities.TextChannel in project SkyBot by duncte123.
the class MessageUtils method sendErrorJSON.
/**
* This will react with a ❌ if the user doesn't have permission to run the command or any other error while execution
*
* @param message the message to add the reaction to
* @param error the cause
*/
public static void sendErrorJSON(Message message, Throwable error, final boolean print) {
if (print)
logger.error(error.getLocalizedMessage(), error);
// Makes no difference if we use sendError or check here both perm types
if (message.getChannelType() == ChannelType.TEXT) {
TextChannel channel = message.getTextChannel();
if (!channel.getGuild().getSelfMember().hasPermission(channel, Permission.MESSAGE_READ, Permission.MESSAGE_WRITE, Permission.MESSAGE_ATTACH_FILES, Permission.MESSAGE_ADD_REACTION)) {
return;
}
}
message.addReaction("❌").queue(null, CUSTOM_QUEUE_ERROR);
message.getChannel().sendFile(EarthUtils.throwableToJSONObject(error).toString(4).getBytes(), "error.json", new MessageBuilder().setEmbed(EmbedUtils.defaultEmbed().setTitle("We got an error!").setDescription(String.format("Error type: %s", error.getClass().getSimpleName())).build()).build()).queue();
}
use of net.dv8tion.jda.core.entities.TextChannel in project SkyBot by duncte123.
the class ModerationUtils method modLog.
/**
* This will send a message to a channel called modlog
*
* @param mod The mod that performed the punishment
* @param punishedUser The user that got punished
* @param punishment The type of punishment
* @param reason The reason of the punishment
* @param time How long it takes for the punishment to get removed
* @param g A instance of the {@link Guild}
*/
public static void modLog(User mod, User punishedUser, String punishment, String reason, String time, Guild g) {
String chan = GuildSettingsUtils.getGuild(g).getLogChannel();
if (chan != null && !chan.isEmpty()) {
TextChannel logChannel = AirUtils.getLogChannel(chan, g);
String length = "";
if (time != null && !time.isEmpty()) {
length = " lasting " + time + "";
}
MessageUtils.sendMsg(logChannel, String.format("User **%s** got **%s** by **%s**%s%s", String.format("%#s", punishedUser), punishment, String.format("%#s", mod), length, reason.isEmpty() ? "" : " with reason _\"" + reason + "\"_"));
}
}
use of net.dv8tion.jda.core.entities.TextChannel in project DiscordSRV by Scarsz.
the class DiscordSRV method processChatMessage.
public void processChatMessage(Player player, String message, String channel, boolean cancelled) {
// log debug message to notify that a chat message was being processed
debug("Chat message received, canceled: " + cancelled);
if (player == null) {
debug("Received chat message was from a null sender, not processing message");
return;
}
// return if player doesn't have permission
if (!player.hasPermission("discordsrv.chat")) {
debug("User " + player.getName() + " sent a message but it was not delivered to Discord due to lack of permission");
return;
}
// return if mcMMO is enabled and message is from party or admin chat
if (Bukkit.getPluginManager().isPluginEnabled("mcMMO")) {
boolean usingAdminChat = com.gmail.nossr50.api.ChatAPI.isUsingAdminChat(player);
boolean usingPartyChat = com.gmail.nossr50.api.ChatAPI.isUsingPartyChat(player);
if (usingAdminChat || usingPartyChat)
return;
}
// return if event canceled
if (getConfig().getBoolean("DontSendCanceledChatEvents") && cancelled) {
debug("User " + player.getName() + " sent a message but it was not delivered to Discord because the chat event was canceled and DontSendCanceledChatEvents is true");
return;
}
// return if should not send in-game chat
if (!getConfig().getBoolean("DiscordChatChannelMinecraftToDiscord")) {
debug("User " + player.getName() + " sent a message but it was not delivered to Discord because DiscordChatChannelMinecraftToDiscord is false");
return;
}
// return if doesn't match prefix filter
if (!DiscordUtil.strip(message).startsWith(getConfig().getString("DiscordChatChannelPrefix"))) {
debug("User " + player.getName() + " sent a message but it was not delivered to Discord because the message didn't start with \"" + getConfig().getString("DiscordChatChannelPrefix") + "\" (DiscordChatChannelPrefix): \"" + message + "\"");
return;
}
GameChatMessagePreProcessEvent preEvent = (GameChatMessagePreProcessEvent) api.callEvent(new GameChatMessagePreProcessEvent(channel, message, player));
if (preEvent.isCancelled()) {
DiscordSRV.debug("GameChatMessagePreProcessEvent was cancelled, message send aborted");
return;
}
// update channel from event in case any listeners modified it
channel = preEvent.getChannel();
// update message from event in case any listeners modified it
message = preEvent.getMessage();
String userPrimaryGroup = VaultHook.getPrimaryGroup(player);
boolean hasGoodGroup = StringUtils.isNotBlank(userPrimaryGroup);
// capitalize the first letter of the user's primary group to look neater
if (hasGoodGroup)
userPrimaryGroup = userPrimaryGroup.substring(0, 1).toUpperCase() + userPrimaryGroup.substring(1);
String discordMessage = (hasGoodGroup ? LangUtil.Message.CHAT_TO_DISCORD.toString() : LangUtil.Message.CHAT_TO_DISCORD_NO_PRIMARY_GROUP.toString()).replaceAll("%time%|%date%", TimeUtil.timeStamp()).replace("%channelname%", channel != null ? channel.substring(0, 1).toUpperCase() + channel.substring(1) : "").replace("%primarygroup%", userPrimaryGroup).replace("%username%", DiscordUtil.strip(DiscordUtil.escapeMarkdown(player.getName()))).replace("%world%", player.getWorld().getName()).replace("%worldalias%", DiscordUtil.strip(MultiverseCoreHook.getWorldAlias(player.getWorld().getName())));
if (PluginUtil.pluginHookIsEnabled("placeholderapi"))
discordMessage = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, discordMessage);
discordMessage = discordMessage.replace("%displayname%", DiscordUtil.strip(DiscordUtil.escapeMarkdown(player.getDisplayName()))).replace("%message%", DiscordUtil.strip(message));
discordMessage = DiscordUtil.strip(discordMessage);
if (getConfig().getBoolean("DiscordChatChannelTranslateMentions"))
discordMessage = DiscordUtil.convertMentionsFromNames(discordMessage, getMainGuild());
GameChatMessagePostProcessEvent postEvent = (GameChatMessagePostProcessEvent) api.callEvent(new GameChatMessagePostProcessEvent(channel, discordMessage, player, preEvent.isCancelled()));
if (postEvent.isCancelled()) {
DiscordSRV.debug("GameChatMessagePostProcessEvent was cancelled, message send aborted");
return;
}
// update channel from event in case any listeners modified it
channel = postEvent.getChannel();
// update message from event in case any listeners modified it
discordMessage = postEvent.getProcessedMessage();
if (!getConfig().getBoolean("Experiment_WebhookChatMessageDelivery")) {
if (channel == null) {
DiscordUtil.sendMessage(getMainTextChannel(), discordMessage);
} else {
DiscordUtil.sendMessage(getDestinationTextChannelForGameChannelName(channel), discordMessage);
}
} else {
if (channel == null)
channel = getMainChatChannel();
TextChannel destinationChannel = getDestinationTextChannelForGameChannelName(channel);
if (!DiscordUtil.checkPermission(destinationChannel.getGuild(), Permission.MANAGE_WEBHOOKS)) {
DiscordSRV.error("Couldn't deliver chat message as webhook because the bot lacks the \"Manage Webhooks\" permission.");
return;
}
if (PluginUtil.pluginHookIsEnabled("placeholderapi"))
message = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, message);
message = DiscordUtil.strip(message);
if (getConfig().getBoolean("DiscordChatChannelTranslateMentions"))
message = DiscordUtil.convertMentionsFromNames(message, getMainGuild());
WebhookUtil.deliverMessage(destinationChannel, player, message);
}
}
Aggregations