use of net.dv8tion.jda.core.entities.Member in project FlareBot by FlareBot.
the class NINOCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
if (args.length >= 1) {
if (args[0].equalsIgnoreCase("enable") || args[0].equalsIgnoreCase("disable")) {
boolean enabled = args[0].equalsIgnoreCase("enable");
ArrayList<URLCheckFlag> flags = new ArrayList<>();
if (args.length >= 2) {
if (args[1].equalsIgnoreCase("all"))
flags.addAll(Arrays.asList(URLCheckFlag.values));
else if (args[1].equalsIgnoreCase("default"))
flags.addAll(URLCheckFlag.getDefaults());
else {
String[] strFlags = seperator.split(MessageUtils.getMessage(args, 1));
URLCheckFlag checkFlag;
for (String flag : strFlags) {
if ((checkFlag = URLCheckFlag.getFlag(flag)) != null)
flags.add(checkFlag);
else {
MessageUtils.sendWarningMessage("'" + flag + "' is not a valid flag!", channel);
return;
}
}
}
}
if (enabled) {
if (flags.isEmpty())
flags.addAll(URLCheckFlag.getDefaults());
guild.getNINO().getURLFlags().addAll(flags);
} else {
if (flags.isEmpty())
guild.getNINO().getURLFlags().clear();
else
guild.getNINO().getURLFlags().removeAll(flags);
}
boolean all = (enabled ? guild.getNINO().getURLFlags().size() == URLCheckFlag.getAllFlags().size() : guild.getNINO().getURLFlags().isEmpty());
channel.sendMessage(MessageUtils.getEmbed(sender).setDescription(FormatUtils.formatCommandPrefix(guild, "I have " + (enabled ? "enabled " : "disabled ") + (all ? "all the flags." : "the " + listToString(flags) + " flag(s)!") + "\n\nTo see the whitelist do `{%}nino whitelist list` and to post the" + " attempts to the modlog enable it with `{%}modlog enable NINO <#channel>`")).setColor(enabled ? ColorUtils.GREEN : ColorUtils.RED).build()).queue();
} else if (args[0].equalsIgnoreCase("whitelist")) {
if (args.length == 2) {
if (args[1].equalsIgnoreCase("list")) {
StringBuilder sb = new StringBuilder();
StringBuilder channels = new StringBuilder();
for (String invite : guild.getNINO().getWhitelist()) sb.append("`").append(invite).append("`").append("\n");
for (long channelId : guild.getNINO().getChannels()) {
if (guild.getGuild().getTextChannelById(channelId) != null)
channels.append(guild.getGuild().getTextChannelById(channelId).getAsMention()).append("\n");
else
guild.getNINO().getChannels().remove(channelId);
}
channel.sendMessage(MessageUtils.getEmbed(sender).setColor(ColorUtils.FLAREBOT_BLUE).addField("Whitelisted Invites", sb.toString(), false).addField("Whitelisted Channels", channels.toString(), false).build()).queue();
} else
MessageUtils.sendUsage(this, channel, sender, args);
} else if (args.length == 3) {
if (args[1].equalsIgnoreCase("add") || args[1].equalsIgnoreCase("remove")) {
String whitelist = args[2];
boolean added = args[1].equalsIgnoreCase("add");
TextChannel tc = GuildUtils.getChannel(whitelist, guild);
if (tc != null) {
if (added)
guild.getNINO().addChannel(tc.getIdLong());
else
guild.getNINO().removeChannel(tc.getIdLong());
MessageUtils.sendSuccessMessage((added ? "Added " : "Removed ") + tc.getAsMention() + (added ? " to" : " from") + " the whitelist!", channel, sender);
} else if (URLConstants.URL_PATTERN_NO_PROTOCOL.matcher(whitelist).matches()) {
if (added)
guild.getNINO().addUrl(whitelist);
else
guild.getNINO().removeUrl(whitelist);
MessageUtils.sendSuccessMessage((added ? "Added " : "Removed ") + "`" + whitelist + "` " + (added ? "to" : "from") + " the whitelist!", channel, sender);
} else {
MessageUtils.sendWarningMessage("That is an invalid input! " + "Please try and whitelist a Discord invite or ", channel);
}
} else
MessageUtils.sendUsage(this, channel, sender, args);
} else
MessageUtils.sendUsage(this, channel, sender, args);
} else if (args[0].equalsIgnoreCase("message")) {
if (args.length == 1) {
MessageUtils.sendUsage(this, channel, sender, args);
return;
}
String msg = null;
if (args.length >= 3) {
msg = MessageUtils.getMessage(args, 2);
if (msg.length() > 250) {
MessageUtils.sendWarningMessage("That message is a tad too long, please make it 250 characters max!" + "\n```\n" + msg + "\n```", channel, sender);
return;
}
}
if (args[1].equalsIgnoreCase("set")) {
if (msg != null) {
guild.getNINO().setRemoveMessage(msg);
MessageUtils.sendSuccessMessage("Message has been set!\n```" + msg + "\n```", channel, sender);
} else
MessageUtils.sendWarningMessage("Please specify a message!", channel);
} else if (args[1].equalsIgnoreCase("add")) {
if (msg != null) {
guild.getNINO().addRemoveMessage(msg);
MessageUtils.sendSuccessMessage("Message has been added!\n```" + msg + "\n```", channel, sender);
} else
MessageUtils.sendWarningMessage("Please specify a message!", channel);
} else if (args[1].equalsIgnoreCase("remove")) {
int messageId = 1;
if (args.length > 2)
messageId = GeneralUtils.getInt(args[2], 1);
int size = guild.getNINO().getRemoveMessages().size();
if (size == 0) {
MessageUtils.sendInfoMessage("This guild has no remove messages!", channel);
return;
}
if (messageId <= 0 || messageId >= size) {
MessageUtils.sendWarningMessage("Invalid message ID!", channel);
return;
}
String tmp = guild.getNINO().getRemoveMessages().get(messageId);
guild.getNINO().getRemoveMessages().remove(tmp);
MessageUtils.sendSuccessMessage("Successfully removed message with ID " + messageId + "!\n```\n" + tmp + "\n```", channel);
} else if (args[1].equalsIgnoreCase("clear")) {
guild.getNINO().clearRemoveMessages();
MessageUtils.sendSuccessMessage("Successfully removed **all** messages from this guild!", channel);
} else if (args[1].equalsIgnoreCase("list")) {
int page = 1;
if (args.length > 2)
page = GeneralUtils.getInt(args[2], 1);
listMessages(guild, page, channel, sender);
} else
MessageUtils.sendUsage(this, channel, sender, args);
} else if (args[0].equalsIgnoreCase("flags")) {
Set<URLCheckFlag> flags = guild.getNINO().getURLFlags();
boolean all = flags.size() == URLCheckFlag.getAllFlags().size();
EmbedBuilder eb = MessageUtils.getEmbed(sender);
if (!flags.isEmpty())
eb.addField("Enabled", flags.stream().map(URLCheckFlag::toString).collect(Collectors.joining("\n")), false);
if (!all)
eb.addField("Disabled", URLCheckFlag.getAllFlags().stream().filter(f -> !flags.contains(f)).map(URLCheckFlag::toString).collect(Collectors.joining("\n")), false);
channel.sendMessage(eb.build()).queue();
} else if (args[0].equalsIgnoreCase("mode")) {
if (args.length == 2) {
NINOMode mode = NINOMode.getMode(args[1]);
if (mode == null)
MessageUtils.sendWarningMessage("That is an invalid mode!", channel);
else {
guild.getNINO().setMode(mode.getMode());
MessageUtils.sendSuccessMessage("Changed NINO's mode to " + mode.toString(), channel, sender);
}
} else {
StringBuilder sb = new StringBuilder();
for (NINOMode mode : NINOMode.values()) sb.append(mode.toString()).append(" (").append(mode.getMode()).append(") - ").append(mode.getExplanation()).append("\n");
MessageUtils.sendMessage("Current Mode: " + guild.getNINO().getNINOMode().toString() + "\nNINO will " + WordUtils.uncapitalize(guild.getNINO().getNINOMode().getExplanation(), '~') + "\n\n**Available Modes**\n" + sb.toString().trim() + "\n\n\n" + "Protocol is the `http://` or `https://` at the start of a URL. Example: `https://google.com`\n" + "Following a URL is when we will check to see if it is a masked link " + "(something like goo.gl, bit.ly etc) and if so follow the redirects and if we see a bad " + "link then it will be caught. This means people can't hide bad links. " + "It does have the disadvantage of being a bit slower though (it will still catch before " + "any human can click it). Example: `https://goo.gl/NfYi94`", channel, sender);
}
} else
MessageUtils.sendUsage(this, channel, sender, args);
} else
MessageUtils.sendUsage(this, channel, sender, args);
}
use of net.dv8tion.jda.core.entities.Member in project FlareBot by FlareBot.
the class KickCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
if (args.length >= 1) {
User user = GuildUtils.getUser(args[0], guild.getGuildId());
if (user == null) {
MessageUtils.sendErrorMessage("We cannot find that user! Try their ID if you didn't already.", channel, sender);
return;
}
Member target = guild.getGuild().getMember(user);
if (target == null) {
MessageUtils.sendErrorMessage("That user is not on this server therefore cannot be kicked!", channel, sender);
return;
}
String reason = null;
if (args.length >= 2)
reason = MessageUtils.getMessage(args, 1);
ModlogHandler.getInstance().handleAction(guild, channel, sender, user, ModAction.KICK, reason);
} else {
MessageUtils.sendUsage(this, channel, sender, args);
}
}
use of net.dv8tion.jda.core.entities.Member in project Frost by woojiahao.
the class UserID method checkInput.
@Override
public boolean checkInput(DiscordSet set, String input) {
if (!super.checkInput(set, input))
return false;
if (set.getGuild().getMemberById(input) == null) {
set.getFrom().sendMessage("Unable to find member of ID: " + input).queue();
return false;
}
Member invoker = set.getGuild().getMember(set.getUser());
Member target = set.getGuild().getMemberById(input);
if (invoker.isOwner()) {
return true;
} else if (target.isOwner()) {
set.getFrom().sendMessage("Nice try kiddo, you are still to young to do that").queue();
return false;
}
if (invoker.getRoles().get(0).getPosition() < target.getRoles().get(0).getPosition()) {
set.getFrom().sendMessage("You think I will allow you to do that?").queue();
return false;
}
return true;
}
use of net.dv8tion.jda.core.entities.Member in project FredBoat by Frederikam.
the class ArgumentUtil method checkSingleFuzzySearchResult.
/**
* Processes a list of mentionables (roles / users).
* Replies in the context of there are none / more than one mentionable and returns null, otherwise returns the
* single mentionable.
*/
@Nullable
public static IMentionable checkSingleFuzzySearchResult(@Nonnull List<IMentionable> list, @Nonnull CommandContext context, @Nonnull String term) {
switch(list.size()) {
case 0:
context.reply(context.i18nFormat("fuzzyNothingFound", term));
return null;
case 1:
return list.get(0);
default:
StringBuilder searchResults = new StringBuilder();
int i = 0;
for (IMentionable mentionable : list) {
if (i == FUZZY_RESULT_LIMIT)
break;
if (mentionable instanceof Member) {
Member member = (Member) mentionable;
searchResults.append("\nUSER ").append(member.getUser().getId()).append(" ").append(member.getEffectiveName());
} else if (mentionable instanceof Role) {
Role role = (Role) mentionable;
searchResults.append("\nROLE ").append(role.getId()).append(" ").append(role.getName());
} else {
throw new IllegalArgumentException("Expected Role or Member, got " + mentionable);
}
i++;
}
if (list.size() > FUZZY_RESULT_LIMIT) {
searchResults.append("\n[...]");
}
context.reply(context.i18n("fuzzyMultiple") + "\n" + TextUtils.asCodeBlock(searchResults.toString()));
return null;
}
}
use of net.dv8tion.jda.core.entities.Member in project FredBoat by Frederikam.
the class UserInfoCommand method onInvoke.
@Override
public void onInvoke(@Nonnull CommandContext context) {
Member target;
StringBuilder knownServers = new StringBuilder();
List<String> matchedGuildNames = new ArrayList<>();
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yyyy");
if (!context.hasArguments()) {
target = context.invoker;
} else {
target = ArgumentUtil.checkSingleFuzzyMemberSearchResult(context, context.rawArgs, true);
}
if (target == null)
return;
Launcher.getBotController().getJdaEntityProvider().streamGuilds().forEach(guild -> {
if (guild.getMemberById(target.getUser().getId()) != null) {
matchedGuildNames.add(guild.getName());
}
});
if (matchedGuildNames.size() >= 30) {
knownServers.append(matchedGuildNames.size());
} else {
int i = 0;
for (String guildName : matchedGuildNames) {
i++;
knownServers.append(guildName);
if (i < matchedGuildNames.size()) {
knownServers.append(",\n");
}
}
}
// DMify if I can
context.reply(CentralMessaging.getClearThreadLocalEmbedBuilder().setColor(target.getColor()).setThumbnail(target.getUser().getAvatarUrl()).setTitle(context.i18nFormat("userinfoTitle", target.getEffectiveName()), null).addField(context.i18n("userinfoUsername"), TextUtils.escapeMarkdown(target.getUser().getName()) + "#" + target.getUser().getDiscriminator(), true).addField(context.i18n("userinfoId"), target.getUser().getId(), true).addField(context.i18n("userinfoNick"), TextUtils.escapeMarkdown(target.getEffectiveName()), // Known Nickname
true).addField(context.i18n("userinfoKnownServer"), knownServers.toString(), // Known Server
true).addField(context.i18n("userinfoJoinDate"), target.getJoinDate().format(dtf), true).addField(context.i18n("userinfoCreationTime"), target.getUser().getCreationTime().format(dtf), true).addField(context.i18n("userinfoBlacklisted"), Boolean.toString(Launcher.getBotController().getRatelimiter().isBlacklisted(target.getUser().getIdLong())), true).build());
}
Aggregations