use of fredboat.commandmeta.abs.CommandContext 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 fredboat.commandmeta.abs.CommandContext in project FredBoat by Frederikam.
the class NodeAdminCommand method show.
private void show(@Nonnull CommandContext context) {
String name = context.args[1];
List<LavalinkSocket> nodes = Launcher.getBotController().getAudioConnectionFacade().getLavalink().getNodes().stream().filter(ll -> ll.getName().equals(name)).collect(Collectors.toList());
if (nodes.isEmpty()) {
context.reply("No such node: " + name + ", showing a list of all nodes instead");
list(context);
return;
}
RemoteStats stats = nodes.get(0).getStats();
String out = "No stats have been received from this node! Is the node down?";
if (stats != null) {
out = TextUtils.asCodeBlock(stats.getAsJson().toString(4), "json");
}
context.reply(out);
}
Aggregations