use of net.dv8tion.jda.core.entities.Member in project FredBoat by Frederikam.
the class ConfigCommand method setConfig.
private void setConfig(CommandContext context) {
Member invoker = context.invoker;
if (!PermsUtil.checkPermsWithFeedback(PermissionLevel.ADMIN, context)) {
return;
}
if (context.args.length != 2) {
HelpCommand.sendFormattedCommandHelp(context);
return;
}
String key = context.args[0];
String val = context.args[1];
switch(key) {
case "track_announce":
if (val.equalsIgnoreCase("true") | val.equalsIgnoreCase("false")) {
Launcher.getBotController().getGuildConfigService().transformGuildConfig(context.guild, gc -> gc.setTrackAnnounce(Boolean.valueOf(val)));
context.replyWithName("`track_announce` " + context.i18nFormat("configSetTo", val));
} else {
context.reply(context.i18nFormat("configMustBeBoolean", TextUtils.escapeAndDefuse(invoker.getEffectiveName())));
}
break;
case "auto_resume":
if (val.equalsIgnoreCase("true") | val.equalsIgnoreCase("false")) {
Launcher.getBotController().getGuildConfigService().transformGuildConfig(context.guild, gc -> gc.setAutoResume(Boolean.valueOf(val)));
context.replyWithName("`auto_resume` " + context.i18nFormat("configSetTo", val));
} else {
context.reply(context.i18nFormat("configMustBeBoolean", TextUtils.escapeAndDefuse(invoker.getEffectiveName())));
}
break;
default:
context.reply(context.i18nFormat("configUnknownKey", TextUtils.escapeAndDefuse(invoker.getEffectiveName())));
break;
}
}
use of net.dv8tion.jda.core.entities.Member in project FredBoat by Frederikam.
the class ClearCommand method onInvoke.
// TODO: Redo this
// TODO: i18n this class
@Override
public void onInvoke(@Nonnull CommandContext context) {
JDA jda = context.guild.getJDA();
TextChannel channel = context.channel;
Member invoker = context.invoker;
if (!invoker.hasPermission(channel, Permission.MESSAGE_MANAGE) && !PermsUtil.checkPerms(PermissionLevel.BOT_ADMIN, invoker)) {
context.replyWithName("You must have Manage Messages to do that!");
return;
}
if (!context.guild.getSelfMember().hasPermission(channel, Permission.MESSAGE_HISTORY)) {
context.reply(context.i18n("permissionMissingBot") + " **" + Permission.MESSAGE_HISTORY.getName() + "**");
return;
}
MessageHistory history = new MessageHistory(channel);
history.retrievePast(50).queue(msgs -> {
Metrics.successfulRestActions.labels("retrieveMessageHistory").inc();
ArrayList<Message> toDelete = new ArrayList<>();
for (Message msg : msgs) {
if (msg.getAuthor().equals(jda.getSelfUser()) && youngerThanTwoWeeks(msg)) {
toDelete.add(msg);
}
}
if (toDelete.isEmpty()) {
context.reply("No messages found.");
} else if (toDelete.size() == 1) {
context.reply("Found one message, deleting.");
CentralMessaging.deleteMessage(toDelete.get(0));
} else {
if (!context.hasPermissions(Permission.MESSAGE_MANAGE)) {
context.reply("I must have the `Manage Messages` permission to delete my own messages in bulk.");
return;
}
context.reply("Deleting **" + toDelete.size() + "** messages.");
CentralMessaging.deleteMessages(channel, toDelete);
}
}, CentralMessaging.getJdaRestActionFailureHandler(String.format("Failed to retrieve message history in channel %s in guild %s", channel.getId(), context.guild.getId())));
}
use of net.dv8tion.jda.core.entities.Member in project FredBoat by Frederikam.
the class SoftbanCommand method onInvoke.
@Override
public void onInvoke(@Nonnull CommandContext context) {
Guild guild = context.guild;
// Ensure we have a search term
if (!context.hasArguments()) {
HelpCommand.sendFormattedCommandHelp(context);
return;
}
// was there a target provided?
Member target = ArgumentUtil.checkSingleFuzzyMemberSearchResult(context, context.args[0]);
if (target == null)
return;
// are we allowed to do that?
if (!checkAuthorization(context, target))
return;
// putting together a reason
String plainReason = DiscordUtil.getReasonForModAction(context);
String auditLogReason = DiscordUtil.formatReasonForAuditLog(plainReason, context.invoker);
// putting together the action
RestAction<Void> modAction = guild.getController().ban(target, 7, auditLogReason);
// on success
String successOutput = context.i18nFormat("softbanSuccess", TextUtils.escapeAndDefuse(target.getUser().getName()), target.getUser().getDiscriminator(), target.getUser().getId()) + "\n" + plainReason;
Consumer<Void> onSuccess = aVoid -> {
Metrics.successfulRestActions.labels("ban").inc();
guild.getController().unban(target.getUser()).queue(__ -> Metrics.successfulRestActions.labels("unban").inc(), CentralMessaging.getJdaRestActionFailureHandler(String.format("Failed to unban user %s in guild %s", target.getUser().getId(), guild.getId())));
context.replyWithName(successOutput);
};
// on fail
String failOutput = context.i18nFormat("modBanFail", target.getUser());
Consumer<Throwable> onFail = t -> {
CentralMessaging.getJdaRestActionFailureHandler(String.format("Failed to ban user %s in guild %s", target.getUser().getId(), guild.getId())).accept(t);
context.replyWithName(failOutput);
};
// issue the mod action
modAction.queue(onSuccess, onFail);
}
use of net.dv8tion.jda.core.entities.Member 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.Member in project SkyBot by duncte123.
the class GuildUtils method getBotAndUserCount.
/**
* Returns an array with the member counts of the guild
* 0 = the total users
* 1 = the total bots
* 3 = the total members
*
* @param g The {@link Guild Guild} to count the users in
* @return an array with the member counts of the guild
*/
public static long[] getBotAndUserCount(Guild g) {
MemberCacheView memberCache = g.getMemberCache();
long totalCount = memberCache.size();
long botCount = memberCache.stream().filter(it -> it.getUser().isBot()).count();
long userCount = totalCount - botCount;
return new long[] { userCount, botCount, totalCount };
}
Aggregations