use of net.dv8tion.jda.api.entities.GuildChannel in project MMDBot by MinecraftModDevelopment.
the class CmdCommunityChannel method execute.
/**
* Execute.
*
* @param event The {@link SlashCommandEvent CommandEvent} that triggered this Command.
*/
@Override
protected void execute(final SlashCommandEvent event) {
if (!Utils.checkCommand(this, event)) {
return;
}
final var guild = event.getGuild();
final var author = guild.getMember(event.getUser());
if (author == null) {
return;
}
Member user = event.getOption("user").getAsMember();
String channel = event.getOption("channel").getAsString();
final var categoryID = MMDBot.getConfig().getCommunityChannelCategory();
final var category = guild.getCategoryById(categoryID);
if (categoryID == 0 || category == null) {
MMDBot.LOGGER.warn("Community channel category is incorrectly configured");
event.reply("Community channel category is incorrectly configured. Please contact the bot maintainers.").queue();
return;
}
final Set<Permission> ownerPermissions = MMDBot.getConfig().getCommunityChannelOwnerPermissions();
if (ownerPermissions.isEmpty()) {
MMDBot.LOGGER.warn("Community channel owner permissions is incorrectly configured");
event.reply("Channel owner permissions is incorrectly configured. Please contact the bot maintainers.").queue();
return;
}
final Set<Permission> diff = Sets.difference(ownerPermissions, event.getGuild().getSelfMember().getPermissions());
if (!diff.isEmpty()) {
MMDBot.LOGGER.warn("Cannot assign permissions to channel owner due to insufficient permissions: {}", diff);
event.reply("Cannot assign certain permissions to channel owner due to insufficient permissions; " + "continuing anyway...").queue();
ownerPermissions.removeIf(diff::contains);
}
final List<Emote> emote = new ArrayList<>(4);
emote.addAll(guild.getEmotesByName("mmd1", true));
emote.addAll(guild.getEmotesByName("mmd2", true));
emote.addAll(guild.getEmotesByName("mmd3", true));
emote.addAll(guild.getEmotesByName("mmd4", true));
// Flavor text: if the emotes are available, use them, else just use plain MMD
final var emoteText = emote.size() == 4 ? emote.stream().map(Emote::getAsMention).collect(Collectors.joining()) : "";
final var flavorText = emoteText.isEmpty() ? "MMD" : emoteText;
MMDBot.LOGGER.info("Creating new community channel for {} ({}), named \"{}\" (command issued by {} ({}))", user.getEffectiveName(), user.getUser().getName(), channel, author.getEffectiveName(), author.getUser().getName());
category.createTextChannel(channel).flatMap(ch -> category.modifyTextChannelPositions().sortOrder(Comparator.comparing(GuildChannel::getName)).map($ -> ch)).flatMap(ch -> ch.putPermissionOverride(user).setAllow(ownerPermissions).map($ -> ch)).flatMap(ch -> ch.sendMessage(new MessageBuilder().appendFormat("Welcome %s to your new community channel, %s!%n", user.getAsMention(), ch.getAsMention()).append('\n').append("Please adhere to the Code of Conduct of the server").appendFormat(" (which can be visited from the <#%s> channel),", MMDBot.getConfig().getChannel("info.rules")).append(" specifically the Channel Policy section.").append('\n').append('\n').appendFormat("Thank you, and enjoy your new home here at %s!", flavorText).build()).map($ -> ch)).queue(c -> event.reply("Successfully created community channel at " + c.getAsMention() + "!").queue());
}
use of net.dv8tion.jda.api.entities.GuildChannel in project Bean by Xirado.
the class InteractionCommandHandler method handleUserContextCommand.
public void handleUserContextCommand(@NotNull UserContextInteractionEvent event) {
if (!event.isFromGuild())
return;
Guild guild = event.getGuild();
Member member = event.getMember();
UserContextCommand command = null;
if (registeredGuildCommands.containsKey(guild.getIdLong())) {
List<UserContextCommand> guildCommands = registeredGuildCommands.get(guild.getIdLong()).stream().filter(cmd -> cmd instanceof UserContextCommand).map(cmd -> (UserContextCommand) cmd).toList();
UserContextCommand guildCommand = guildCommands.stream().filter(cmd -> cmd.getData().getName().equalsIgnoreCase(event.getName())).findFirst().orElse(null);
if (guildCommand != null)
command = guildCommand;
}
if (command == null) {
UserContextCommand globalCommand = getRegisteredUserContextCommands().stream().filter(cmd -> cmd.getData().getName().equalsIgnoreCase(event.getName())).findFirst().orElse(null);
if (globalCommand != null)
command = globalCommand;
}
if (command == null)
return;
List<Permission> neededPermissions = command.getRequiredUserPermissions();
List<Permission> neededBotPermissions = command.getRequiredBotPermissions();
if (neededPermissions != null && !member.hasPermission((GuildChannel) event.getChannel(), neededPermissions)) {
event.reply(LocaleLoader.ofGuild(guild).get("general.no_perms", String.class)).queue();
return;
}
if (neededBotPermissions != null && !event.getGuild().getSelfMember().hasPermission((GuildChannel) event.getChannel(), neededBotPermissions)) {
event.reply(LocaleLoader.ofGuild(guild).get("general.no_bot_perms1", String.class)).queue();
return;
}
if (command.getCommandFlags().contains(CommandFlag.MUST_BE_IN_VC)) {
GuildVoiceState guildVoiceState = member.getVoiceState();
if (guildVoiceState == null || !guildVoiceState.inAudioChannel()) {
event.replyEmbeds(EmbedUtil.errorEmbed("You are not connected to a voice-channel!")).queue();
return;
}
}
if (command.getCommandFlags().contains(CommandFlag.MUST_BE_IN_SAME_VC)) {
GuildVoiceState voiceState = member.getVoiceState();
AudioManager manager = event.getGuild().getAudioManager();
if (manager.isConnected()) {
if (!manager.getConnectedChannel().equals(voiceState.getChannel())) {
event.replyEmbeds(EmbedUtil.errorEmbed("You must be listening in " + manager.getConnectedChannel().getAsMention() + "to do this!")).setEphemeral(true).queue();
return;
}
}
}
UserContextCommand finalCommand = command;
Runnable r = () -> {
try {
finalCommand.executeCommand(event);
Metrics.COMMANDS.labels("success").inc();
} catch (Exception e) {
Metrics.COMMANDS.labels("failed").inc();
LinkedDataObject translation = event.getGuild() == null ? LocaleLoader.getForLanguage("en_US") : LocaleLoader.ofGuild(event.getGuild());
if (event.isAcknowledged())
event.getHook().sendMessageEmbeds(EmbedUtil.errorEmbed(translation.getString("general.unknown_error_occured"))).setEphemeral(true).queue(s -> {
}, ex -> {
});
else
event.replyEmbeds(EmbedUtil.errorEmbed(translation.getString("general.unknown_error_occured"))).setEphemeral(true).queue(s -> {
}, ex -> {
});
LOGGER.error("Could not execute user-context-menu-command", e);
EmbedBuilder builder = new EmbedBuilder().setTitle("An error occurred while executing a user-context-command!").addField("Guild", event.getGuild() == null ? "None (Direct message)" : event.getGuild().getIdLong() + " (" + event.getGuild().getName() + ")", true).addField("Channel", event.getGuild() == null ? "None (Direct message)" : event.getChannel().getName(), true).addField("User", event.getUser().getAsMention() + " (" + event.getUser().getAsTag() + ")", true).addField("Command", event.getName(), false).setColor(EmbedUtil.ERROR_COLOR);
event.getJDA().openPrivateChannelById(Bean.OWNER_ID).flatMap(c -> c.sendMessageEmbeds(builder.build()).content("```fix\n" + ExceptionUtils.getStackTrace(e) + "\n```")).queue();
}
};
Bean.getInstance().getCommandExecutor().submit(r);
}
use of net.dv8tion.jda.api.entities.GuildChannel in project Bean by Xirado.
the class InteractionCommandHandler method handleMessageContextCommand.
public void handleMessageContextCommand(@NotNull MessageContextInteractionEvent event) {
if (!event.isFromGuild())
return;
Guild guild = event.getGuild();
Member member = event.getMember();
MessageContextCommand command = null;
if (registeredGuildCommands.containsKey(guild.getIdLong())) {
List<MessageContextCommand> guildCommands = registeredGuildCommands.get(guild.getIdLong()).stream().filter(cmd -> cmd instanceof MessageContextCommand).map(cmd -> (MessageContextCommand) cmd).toList();
MessageContextCommand guildCommand = guildCommands.stream().filter(cmd -> cmd.getData().getName().equalsIgnoreCase(event.getName())).findFirst().orElse(null);
if (guildCommand != null)
command = guildCommand;
}
if (command == null) {
MessageContextCommand globalCommand = getRegisteredMessageContextCommands().stream().filter(cmd -> cmd.getData().getName().equalsIgnoreCase(event.getName())).findFirst().orElse(null);
if (globalCommand != null)
command = globalCommand;
}
if (command == null)
return;
List<Permission> neededPermissions = command.getRequiredUserPermissions();
List<Permission> neededBotPermissions = command.getRequiredBotPermissions();
if (neededPermissions != null && !member.hasPermission((GuildChannel) event.getChannel(), neededPermissions)) {
event.reply(LocaleLoader.ofGuild(guild).get("general.no_perms", String.class)).queue();
return;
}
if (neededBotPermissions != null && !event.getGuild().getSelfMember().hasPermission((GuildChannel) event.getChannel(), neededBotPermissions)) {
event.reply(LocaleLoader.ofGuild(guild).get("general.no_bot_perms1", String.class)).queue();
return;
}
if (command.getCommandFlags().contains(CommandFlag.MUST_BE_IN_VC)) {
GuildVoiceState guildVoiceState = member.getVoiceState();
if (guildVoiceState == null || !guildVoiceState.inAudioChannel()) {
event.replyEmbeds(EmbedUtil.errorEmbed("You are not connected to a voice-channel!")).queue();
return;
}
}
if (command.getCommandFlags().contains(CommandFlag.MUST_BE_IN_SAME_VC)) {
GuildVoiceState voiceState = member.getVoiceState();
AudioManager manager = event.getGuild().getAudioManager();
if (manager.isConnected()) {
if (!manager.getConnectedChannel().equals(voiceState.getChannel())) {
event.replyEmbeds(EmbedUtil.errorEmbed("You must be listening in " + manager.getConnectedChannel().getAsMention() + "to do this!")).setEphemeral(true).queue();
return;
}
}
}
MessageContextCommand finalCommand = command;
Runnable r = () -> {
try {
finalCommand.executeCommand(event);
Metrics.COMMANDS.labels("success").inc();
} catch (Exception e) {
Metrics.COMMANDS.labels("failed").inc();
LinkedDataObject translation = event.getGuild() == null ? LocaleLoader.getForLanguage("en_US") : LocaleLoader.ofGuild(event.getGuild());
if (event.isAcknowledged())
event.getHook().sendMessageEmbeds(EmbedUtil.errorEmbed(translation.getString("general.unknown_error_occured"))).setEphemeral(true).queue(s -> {
}, ex -> {
});
else
event.replyEmbeds(EmbedUtil.errorEmbed(translation.getString("general.unknown_error_occured"))).setEphemeral(true).queue(s -> {
}, ex -> {
});
LOGGER.error("Could not execute message-context-menu-command", e);
EmbedBuilder builder = new EmbedBuilder().setTitle("An error occurred while executing a message-context-command!").addField("Guild", event.getGuild() == null ? "None (Direct message)" : event.getGuild().getIdLong() + " (" + event.getGuild().getName() + ")", true).addField("Channel", event.getGuild() == null ? "None (Direct message)" : event.getChannel().getName(), true).addField("User", event.getUser().getAsMention() + " (" + event.getUser().getAsTag() + ")", true).addField("Command", event.getName(), false).setColor(EmbedUtil.ERROR_COLOR);
event.getJDA().openPrivateChannelById(Bean.OWNER_ID).flatMap(c -> c.sendMessageEmbeds(builder.build()).content("```fix\n" + ExceptionUtils.getStackTrace(e) + "\n```")).queue();
}
};
Bean.getInstance().getCommandExecutor().submit(r);
}
use of net.dv8tion.jda.api.entities.GuildChannel in project Emolga by TecToast.
the class EmolgaDiktaturCommand method process.
@Override
public void process(GuildCommandEvent e) {
Guild g = e.getGuild();
JSONObject members = new JSONObject();
JSONObject channels = new JSONObject();
e.getChannel().sendMessage("**Möge die Emolga-Diktatur beginnen!**").queue();
g.loadMembers().onSuccess(list -> {
for (Member member : list) {
if (member.isOwner())
continue;
if (member.getId().equals(e.getJDA().getSelfUser().getId()))
member.modifyNickname("Diktator").queue();
if (!g.getSelfMember().canInteract(member))
continue;
members.put(member.getId(), member.getEffectiveName());
member.modifyNickname("Emolga-Anhänger").queue();
}
for (GuildChannel gc : g.getChannels()) {
gc.getManager().setName("Emolga-" + gc.getName()).queue();
}
getEmolgaJSON().getJSONObject("emolgareset").put(g.getId(), members);
saveEmolgaJSON();
});
}
use of net.dv8tion.jda.api.entities.GuildChannel in project c10ver by Gartham.
the class DungeonGame method startDungeon.
private void startDungeon(ButtonClickEvent e) {
// This is broken lmao.
t = e.getMessage();
// try {
// Thread.sleep((long) (Math.random() * 3500 + 1500));
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
var dungeon = Dungeon.simpleEasyDungeon();
var initialRoom = dungeon.getInitialRoom();
var dirsel = new CustomDirsel();
dirsel.disableDirections();
for (var d : initialRoom.getConnectionDirectionsUnmodifiable()) dirsel.enable(d);
var inp = new InputConsumer<ButtonClickEvent>() {
DungeonRoom currentRoom = initialRoom;
@Override
public boolean consume(ButtonClickEvent event, InputProcessor<? extends ButtonClickEvent> processor, InputConsumer<ButtonClickEvent> consumer) {
if (event.getMessageIdLong() != t.getIdLong())
return false;
if (event.getUser().getIdLong() != target.getIdLong()) {
event.reply("That's not for you. >:(").setEphemeral(true).queue();
return true;
}
if (event.getComponentId().equals("act")) {
if (currentRoom.isClaimed()) {
event.reply("You already collected the loot from this room... (You're not supposed to be able to click that button again!)").setEphemeral(true).queue();
return true;
}
currentRoom.setClaimed(true);
var user = clover.getEconomy().getUser(target.getId());
Receipt receipt;
var lr = (LootRoom) currentRoom;
receipt = user.reward(lr.getRewards().autoSetMultipliers(user, channel.getType().isGuild() ? ((GuildChannel) channel).getGuild() : null));
currentRoom.prepare(dirsel, "act");
event.editComponents(dirsel.actionRows()).queue();
t.reply(target.getAsMention() + ", you earned:\n\n" + Utilities.listRewards(receipt)).queue();
// Resend message? Send ephemeral rewards?
} else if (event.getComponentId().equals("repeat")) {
var dsn = new CustomDirsel();
dsn.disableManaged();
var s = channel.sendMessageEmbeds(event.getMessage().getEmbeds()).setActionRows(event.getMessage().getActionRows());
event.editComponents(dsn.actionRows()).queue(x -> s.queue(q -> t = q));
} else {
var dir = DirectionSelector.getDirectionSelected(event);
currentRoom = currentRoom.getRoom(dir);
if (currentRoom == null) {
// Player moved in the wrong direction.
event.reply("You are not supposed to be able to click that!").setEphemeral(true).queue();
return true;
// processor.removeInputConsumer(consumer);
} else if (!currentRoom.isClaimed() && currentRoom instanceof EnemyRoom) {
dirsel.reset();
dirsel.disableManaged();
event.editComponents(dirsel.actionRows()).setContent("**You got into a fight!!!**").setEmbeds(new EmbedBuilder().setColor(new Color(0xFF0000)).setTitle("Room #" + (dungeon.index(currentRoom) + 1)).setDescription("```" + currentRoom.getRoom().tilemapString() + "```").setFooter("Choose a path.").build()).queue();
channel.sendMessage("The room was full of enemies!").queue(x -> {
channel.sendTyping().queue(x0 -> {
var room = (EnemyRoom) currentRoom;
currentRoom.setClaimed(true);
GarmonTeam player = new GarmonTeam(target.getAsTag(), new PlayerFighter(target.getName(), target.getEffectiveAvatarUrl(), BigInteger.valueOf(25), BigInteger.valueOf(100), BigInteger.valueOf(100), BigInteger.valueOf(25), BigInteger.valueOf(5)));
var team = room.getEnemies();
GarmonBattle battle = new GarmonBattle(player, team);
player.setController(new PlayerController(battle, clover, target, channel));
team.setController(new CreatureAI(battle, channel));
battle.startAsync(true, winner -> {
if (winner == player) {
EconomyUser user = clover.getEconomy().getUser(target.getId());
RewardsOperation rewop = RewardsOperation.build(user, channel.getGuild(), BigInteger.valueOf((long) (Math.random() * 142 + 25)), new ItemBunch<>(new VoteToken(gartham.c10ver.economy.items.valuables.VoteToken.Type.NORMAL)));
currentRoom.prepare(dirsel, "act");
channel.sendMessage(target.getAsMention() + ", you won the fight!\nYou earned:\n\n" + Utilities.listRewards(user.reward(rewop))).setEmbeds(new EmbedBuilder().setColor(new Color(0xFF00)).setTitle("Room #" + (dungeon.index(currentRoom) + 1)).setDescription("```" + currentRoom.getRoom().tilemapString() + "```").setFooter("Choose a path.").build()).setActionRows(dirsel.actionRows()).queue(msg -> t = msg);
}
}, (long) (2000 + Math.random() * 1000));
});
});
} else {
currentRoom.prepare(dirsel, "act");
event.editMessageEmbeds(new EmbedBuilder().setTitle("Room #" + (dungeon.index(currentRoom) + 1)).setDescription("```" + currentRoom.getRoom().tilemapString() + "```").setFooter("Choose a path.").build()).setActionRows(dirsel.actionRows()).setContent("").queue();
}
}
return true;
}
};
clover.getEventHandler().getButtonClickProcessor().registerInputConsumer(inp);
t.editMessage(new MessageBuilder().setEmbeds(new EmbedBuilder().setTitle("W1-1").setDescription("```" + initialRoom.getRoom().tilemapString() + "```").setFooter("Choose a path.").build()).setActionRows(dirsel.actionRows()).build()).queue();
}
Aggregations