Search in sources :

Example 11 with CommandContext

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);
}
Also used : ArgumentUtil(fredboat.util.ArgumentUtil) CentralMessaging(fredboat.messaging.CentralMessaging) Logger(org.slf4j.Logger) Member(net.dv8tion.jda.core.entities.Member) Command(fredboat.commandmeta.abs.Command) LoggerFactory(org.slf4j.LoggerFactory) CommandContext(fredboat.commandmeta.abs.CommandContext) TextUtils(fredboat.util.TextUtils) IModerationCommand(fredboat.commandmeta.abs.IModerationCommand) RestAction(net.dv8tion.jda.core.requests.RestAction) Consumer(java.util.function.Consumer) Guild(net.dv8tion.jda.core.entities.Guild) Permission(net.dv8tion.jda.core.Permission) Context(fredboat.messaging.internal.Context) DiscordUtil(fredboat.util.DiscordUtil) HelpCommand(fredboat.command.info.HelpCommand) Metrics(fredboat.feature.metrics.Metrics) Nonnull(javax.annotation.Nonnull) Guild(net.dv8tion.jda.core.entities.Guild) Member(net.dv8tion.jda.core.entities.Member)

Example 12 with CommandContext

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);
}
Also used : LavalinkSocket(lavalink.client.io.LavalinkSocket) Launcher(fredboat.main.Launcher) RemoteStats(lavalink.client.io.RemoteStats) URISyntaxException(java.net.URISyntaxException) Command(fredboat.commandmeta.abs.Command) ICommandRestricted(fredboat.commandmeta.abs.ICommandRestricted) CommandContext(fredboat.commandmeta.abs.CommandContext) PermissionLevel(fredboat.definitions.PermissionLevel) TextUtils(fredboat.util.TextUtils) LavalinkLoadBalancer(lavalink.client.io.LavalinkLoadBalancer) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) LavalinkSocket(lavalink.client.io.LavalinkSocket) Context(fredboat.messaging.internal.Context) Lavalink(lavalink.client.io.Lavalink) HelpCommand(fredboat.command.info.HelpCommand) URI(java.net.URI) Nonnull(javax.annotation.Nonnull) PermsUtil(fredboat.perms.PermsUtil) RemoteStats(lavalink.client.io.RemoteStats)

Aggregations

CommandContext (fredboat.commandmeta.abs.CommandContext)12 Command (fredboat.commandmeta.abs.Command)11 Context (fredboat.messaging.internal.Context)10 TextUtils (fredboat.util.TextUtils)10 Nonnull (javax.annotation.Nonnull)10 CentralMessaging (fredboat.messaging.CentralMessaging)7 HelpCommand (fredboat.command.info.HelpCommand)6 ICommandRestricted (fredboat.commandmeta.abs.ICommandRestricted)5 PermissionLevel (fredboat.definitions.PermissionLevel)5 Launcher (fredboat.main.Launcher)4 Collectors (java.util.stream.Collectors)4 Guild (net.dv8tion.jda.core.entities.Guild)4 GuildPlayer (fredboat.audio.player.GuildPlayer)3 IModerationCommand (fredboat.commandmeta.abs.IModerationCommand)3 Module (fredboat.definitions.Module)3 Metrics (fredboat.feature.metrics.Metrics)3 PermsUtil (fredboat.perms.PermsUtil)3 ArgumentUtil (fredboat.util.ArgumentUtil)3 DiscordUtil (fredboat.util.DiscordUtil)3 Consumer (java.util.function.Consumer)3