use of com.jagrosh.jdautilities.command.CommandEvent in project GeyserDiscordBot by GeyserMC.
the class UnmuteCommand method execute.
@Override
protected void execute(CommandEvent event) {
List<String> args = new ArrayList<>(Arrays.asList(event.getArgs().split(" ")));
// Fetch the user
Member member = BotHelpers.getMember(event.getGuild(), args.remove(0));
// Check user is valid
if (member == null) {
event.getMessage().replyEmbeds(new EmbedBuilder().setTitle("Invalid user").setDescription("The user ID specified doesn't link with any valid user in this server.").setColor(BotColors.FAILURE.getColor()).build()).queue();
return;
}
// Check we can target the user
if (!event.getSelfMember().canInteract(member) || !event.getMember().canInteract(member)) {
event.getMessage().replyEmbeds(new EmbedBuilder().setTitle("Higher role").setDescription("Either the bot or you cannot target that user.").setColor(BotColors.FAILURE.getColor()).build()).queue();
return;
}
// Get the user from the member
User user = member.getUser();
boolean silent = false;
// We clone the args here to prevent a CME
for (String arg : args.toArray(new String[0])) {
if (!arg.startsWith("-") || arg.length() < 2) {
break;
}
if (arg.toCharArray()[1] == 's') {
// Check for silent flag
silent = true;
} else {
event.getMessage().replyEmbeds(new EmbedBuilder().setTitle("Invalid option").setDescription("The option `" + arg + "` is invalid").setColor(BotColors.FAILURE.getColor()).build()).queue();
}
args.remove(0);
}
// Get the reason or use None
String reasonParts = String.join(" ", args);
String reason;
if (reasonParts.trim().isEmpty()) {
reason = "*None*";
} else {
reason = reasonParts;
}
// Let the user know they're muted if we are not being silent
if (!silent) {
user.openPrivateChannel().queue((channel) -> channel.sendMessageEmbeds(new EmbedBuilder().setTitle("You have been unmuted from GeyserMC!").addField("Reason", reason, false).setTimestamp(Instant.now()).setColor(BotColors.FAILURE.getColor()).build()).queue(message -> {
}, throwable -> {
}), throwable -> {
});
}
// Find and remove the 'muted' role
Role muteRole = event.getGuild().getRolesByName("muted", true).get(0);
event.getGuild().removeRoleFromMember(member, muteRole).queue();
// UnPersist the role
GeyserBot.storageManager.removePersistentRole(member, muteRole);
// Log the change
int id = GeyserBot.storageManager.addLog(event.getMember(), "unmute", user, reason);
MessageEmbed mutedEmbed = new EmbedBuilder().setTitle("Unmuted user").addField("User", user.getAsMention(), false).addField("Staff member", event.getAuthor().getAsMention(), false).addField("Reason", reason, false).setFooter("ID: " + id).setTimestamp(Instant.now()).setColor(BotColors.SUCCESS.getColor()).build();
// Send the embed as a reply and to the log
ServerSettings.getLogChannel(event.getGuild()).sendMessageEmbeds(mutedEmbed).queue();
event.getMessage().replyEmbeds(mutedEmbed).queue();
}
use of com.jagrosh.jdautilities.command.CommandEvent in project GeyserDiscordBot by GeyserMC.
the class UnbanCommand method execute.
@Override
protected void execute(CommandEvent event) {
List<String> args = new ArrayList<>(Arrays.asList(event.getArgs().split(" ")));
// Fetch the user
User user = BotHelpers.getUser(args.remove(0));
// Check user is valid
if (user == null) {
event.getMessage().replyEmbeds(new EmbedBuilder().setTitle("Invalid user").setDescription("The user ID specified doesn't link with any valid user in this server.").setColor(BotColors.FAILURE.getColor()).build()).queue();
return;
}
// Check if the user is banned
try {
event.getGuild().retrieveBan(user).complete();
} catch (ErrorResponseException ignored) {
event.getMessage().replyEmbeds(new EmbedBuilder().setTitle("User not banned").setDescription("The user ID specified doesn't have a ban on this server.").setColor(BotColors.FAILURE.getColor()).build()).queue();
return;
}
boolean silent = false;
// We clone the args here to prevent a CME
for (String arg : args.toArray(new String[0])) {
if (!arg.startsWith("-") || arg.length() < 2) {
break;
}
if (arg.toCharArray()[1] == 's') {
// Check for silent flag
silent = true;
} else {
event.getMessage().replyEmbeds(new EmbedBuilder().setTitle("Invalid option").setDescription("The option `" + arg + "` is invalid").setColor(BotColors.FAILURE.getColor()).build()).queue();
}
args.remove(0);
}
// Get the reason or use None
String reasonParts = String.join(" ", args);
String reason;
if (reasonParts.trim().isEmpty()) {
reason = "*None*";
} else {
reason = reasonParts;
}
// Let the user know they're unbanned if we are not being silent
if (!silent) {
user.openPrivateChannel().queue((channel) -> channel.sendMessageEmbeds(new EmbedBuilder().setTitle("You have been unbanned from GeyserMC!").addField("Reason", reason, false).setTimestamp(Instant.now()).setColor(BotColors.SUCCESS.getColor()).build()).queue(message -> {
}, throwable -> {
}), throwable -> {
});
}
// Unban user
event.getGuild().unban(user).queue();
// Log the change
int id = GeyserBot.storageManager.addLog(event.getMember(), "unban", user, reason);
MessageEmbed unbannedEmbed = new EmbedBuilder().setTitle("Unbanned user").addField("User", user.getAsMention(), false).addField("Staff member", event.getAuthor().getAsMention(), false).addField("Reason", reason, false).setFooter("ID: " + id).setTimestamp(Instant.now()).setColor(BotColors.SUCCESS.getColor()).build();
// Send the embed as a reply and to the log
ServerSettings.getLogChannel(event.getGuild()).sendMessageEmbeds(unbannedEmbed).queue();
event.getMessage().replyEmbeds(unbannedEmbed).queue();
}
use of com.jagrosh.jdautilities.command.CommandEvent in project GeyserDiscordBot by GeyserMC.
the class TagAliasCommand method execute.
@Override
protected void execute(CommandEvent event) {
if (SwearHandler.filteredMessages.contains(event.getMessage().getIdLong())) {
return;
}
EmbedBuilder embed = new EmbedBuilder();
String[] args = event.getArgs().split(" ");
if (args.length == 0) {
embed.setTitle("Invalid usage");
embed.setDescription("Missing tag name. `" + PropertiesManager.getPrefix() + "tag alias <name>`");
embed.setColor(BotColors.FAILURE.getColor());
event.getMessage().replyEmbeds(embed.build()).queue();
return;
}
Command foundTag = null;
for (Command tag : TagsManager.getTags()) {
if (tag.getName().equals(args[0]) || Arrays.stream(tag.getAliases()).anyMatch(s -> s.equals(args[0]))) {
foundTag = tag;
break;
}
}
if (foundTag == null) {
embed.setTitle("Missing tag");
embed.setDescription("No tag with the name `" + args[0] + "`, do `" + PropertiesManager.getPrefix() + "tags` for the full list.");
embed.setColor(BotColors.FAILURE.getColor());
event.getMessage().replyEmbeds(embed.build()).queue();
return;
}
if (foundTag.getAliases().length > 0) {
embed.setTitle("Aliases for " + foundTag.getName() + " (" + foundTag.getAliases().length + ")");
embed.setDescription("`" + String.join("`, `", foundTag.getAliases()) + "`");
embed.setFooter("Use `" + PropertiesManager.getPrefix() + "tag <name>` to show a tag");
embed.setColor(BotColors.SUCCESS.getColor());
} else {
embed.setTitle("No aliases for " + foundTag.getName());
embed.setDescription("No aliases where found for the tag with the name `" + foundTag.getName() + "`.");
embed.setColor(BotColors.FAILURE.getColor());
}
event.getMessage().replyEmbeds(embed.build()).queue();
}
use of com.jagrosh.jdautilities.command.CommandEvent in project Vinny by kikkia.
the class FormattingUtils method cleanSayCommand.
public static String cleanSayCommand(CommandEvent commandEvent) {
StringBuilder sb = new StringBuilder();
String[] words = commandEvent.getArgs().split(" ");
Pattern inviteRegx = Pattern.compile("discord(?:app\\.com\\/invite|\\.gg)\\/([a-z0-9]{1,16})", Pattern.CASE_INSENSITIVE);
Pattern userMentionRegx = Pattern.compile("\\<\\@([0-9]+)\\>");
Pattern roleMentionRegx = Pattern.compile("\\<\\@\\&([0-9]+)\\>");
for (String word : words) {
// Escape everyone
if (word.equalsIgnoreCase("@everyone")) {
sb.append("(at)everyone ");
continue;
}
// Escape here
if (word.equalsIgnoreCase("@here")) {
sb.append("(at)here ");
continue;
}
// Escape all user mentions
Matcher mentionMatcher = userMentionRegx.matcher(word);
if (mentionMatcher.find()) {
String userId = mentionMatcher.group(1);
// If any users match the id
List<User> mentionedUser = commandEvent.getMessage().getMentionedUsers().stream().filter(user -> user.getId().equals(userId)).collect(Collectors.toList());
// Check if user was mentioned
if (!mentionedUser.isEmpty()) {
sb.append(mentionedUser.get(0).getName()).append(" ");
continue;
}
}
// Escape all role mentions
Matcher roleMatcher = roleMentionRegx.matcher(word);
if (roleMatcher.find()) {
String roleId = roleMatcher.group(1);
List<Role> mentionedRole = commandEvent.getMessage().getMentionedRoles().stream().filter(role -> role.getId().equals(roleId)).collect(Collectors.toList());
if (!mentionedRole.isEmpty()) {
sb.append(mentionedRole.get(0).getName()).append(" ");
continue;
}
}
// Get rid of invites
Matcher matcher = inviteRegx.matcher(word);
if (matcher.find()) {
word = "`invite`";
}
sb.append(word).append(" ");
}
return sb.toString();
}
use of com.jagrosh.jdautilities.command.CommandEvent in project MusicBot by jagrosh.
the class ForceRemoveCmd method doCommand.
@Override
public void doCommand(CommandEvent event) {
if (event.getArgs().isEmpty()) {
event.replyError("You need to mention a user!");
return;
}
AudioHandler handler = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler();
if (handler.getQueue().isEmpty()) {
event.replyError("There is nothing in the queue!");
return;
}
User target;
List<Member> found = FinderUtil.findMembers(event.getArgs(), event.getGuild());
if (found.isEmpty()) {
event.replyError("Unable to find the user!");
return;
} else if (found.size() > 1) {
OrderedMenu.Builder builder = new OrderedMenu.Builder();
for (int i = 0; i < found.size() && i < 4; i++) {
Member member = found.get(i);
builder.addChoice("**" + member.getUser().getName() + "**#" + member.getUser().getDiscriminator());
}
builder.setSelection((msg, i) -> removeAllEntries(found.get(i - 1).getUser(), event)).setText("Found multiple users:").setColor(event.getSelfMember().getColor()).useNumbers().setUsers(event.getAuthor()).useCancelButton(true).setCancel((msg) -> {
}).setEventWaiter(bot.getWaiter()).setTimeout(1, TimeUnit.MINUTES).build().display(event.getChannel());
return;
} else {
target = found.get(0).getUser();
}
removeAllEntries(target, event);
}
Aggregations