use of net.dv8tion.jda.core.requests.RestAction in project FredBoat by Frederikam.
the class HardbanCommand 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 (!checkHardBanAuthorization(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("hardbanSuccess", TextUtils.escapeAndDefuse(target.getUser().getName()), target.getUser().getDiscriminator(), target.getUser().getId()) + "\n" + plainReason;
Consumer<Void> onSuccess = aVoid -> {
Metrics.successfulRestActions.labels("ban").inc();
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.requests.RestAction in project FredBoat by Frederikam.
the class KickCommand 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 (!checkKickAuthorization(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().kick(target, auditLogReason);
// on success
String successOutput = context.i18nFormat("kickSuccess", TextUtils.escapeAndDefuse(target.getUser().getName()), target.getUser().getDiscriminator(), target.getUser().getId()) + "\n" + plainReason;
Consumer<Void> onSuccess = aVoid -> {
Metrics.successfulRestActions.labels("kick").inc();
context.replyWithName(successOutput);
};
// on fail
String failOutput = context.i18nFormat("kickFail", target.getUser());
Consumer<Throwable> onFail = t -> {
CentralMessaging.getJdaRestActionFailureHandler(String.format("Failed to kick 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.requests.RestAction in project Ardent by adamint.
the class Eval method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (Ardent.developers.contains(user.getId())) {
if (args.length == 1)
channel.sendMessage("Use " + args[0] + " (code) to evaluate stuff").queue();
else {
String content = message.getContent().replace(GuildUtils.getPrefix(guild) + args[0] + " ", "");
final MessageBuilder builder = new MessageBuilder();
final Map<String, Object> shortcuts = new HashMap<>();
shortcuts.put("api", message.getJDA());
shortcuts.put("jda", message.getJDA());
shortcuts.put("channel", channel);
shortcuts.put("server", guild);
shortcuts.put("guild", guild);
shortcuts.put("connection", Database.connection);
shortcuts.put("r", Database.r);
shortcuts.put("message", message);
shortcuts.put("msg", message);
shortcuts.put("me", message.getAuthor());
shortcuts.put("bot", message.getJDA().getSelfUser());
shortcuts.put("shard", getShard());
shortcuts.put("shards", ShardManager.getShards());
final int timeout = 10;
final Triple<Object, String, String> result = Engine.GROOVY.eval(shortcuts, Collections.emptyList(), Engine.DEFAULT_IMPORTS, timeout, content);
if (result.getLeft() instanceof RestAction<?>) {
((RestAction<?>) result.getLeft()).queue();
} else if (result.getLeft() != null) {
builder.appendCodeBlock(result.getLeft().toString(), "");
}
if (!result.getMiddle().isEmpty()) {
builder.append("\n").appendCodeBlock(result.getMiddle(), "");
}
if (!result.getRight().isEmpty()) {
builder.append("\n").appendCodeBlock(result.getRight(), "");
}
if (builder.isEmpty()) {
message.addReaction("✅").queue();
} else {
for (final Message m : builder.buildAll(MessageBuilder.SplitPolicy.NEWLINE, MessageBuilder.SplitPolicy.SPACE, MessageBuilder.SplitPolicy.ANYWHERE)) {
channel.sendMessage(m).queue();
}
}
}
}
}
use of net.dv8tion.jda.core.requests.RestAction 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);
}
Aggregations