use of fredboat.commandmeta.abs.ICommandRestricted in project FredBoat by Frederikam.
the class HelpCommand method sendFormattedCommandHelp.
private static void sendFormattedCommandHelp(CommandContext context, String trigger) {
Command command = CommandRegistry.findCommand(trigger);
if (command == null) {
String out = "`" + TextUtils.escapeMarkdown(context.getPrefix()) + trigger + "`: " + context.i18n("helpUnknownCommand");
out += "\n" + context.i18nFormat("helpCommandsPromotion", "`" + TextUtils.escapeMarkdown(context.getPrefix()) + CommandInitializer.COMMANDS_COMM_NAME + "`");
context.replyWithName(out);
return;
}
String out = getFormattedCommandHelp(context, command, trigger);
if (command instanceof ICommandRestricted && ((ICommandRestricted) command).getMinimumPerms() == PermissionLevel.BOT_OWNER)
out += "\n#" + context.i18n("helpCommandOwnerRestricted");
out = TextUtils.asCodeBlock(out, "md");
out = context.i18n("helpProperUsage") + out;
context.replyWithName(out);
}
use of fredboat.commandmeta.abs.ICommandRestricted in project FredBoat by Frederikam.
the class CommandsCommand method addModuleCommands.
private EmbedBuilder addModuleCommands(@Nonnull EmbedBuilder embedBuilder, @Nonnull CommandContext context, @Nonnull CommandRegistry module) {
List<Command> commands = module.getDeduplicatedCommands().stream().filter(command -> {
if (command instanceof ICommandRestricted) {
if (((ICommandRestricted) command).getMinimumPerms().getLevel() >= PermissionLevel.BOT_ADMIN.getLevel()) {
return PermsUtil.checkPerms(PermissionLevel.BOT_ADMIN, context.invoker);
}
}
return true;
}).collect(Collectors.toList());
String prefix = context.getPrefix();
if (commands.size() >= 6) {
// split the commands into three even columns
StringBuilder[] sbs = new StringBuilder[3];
sbs[0] = new StringBuilder();
sbs[1] = new StringBuilder();
sbs[2] = new StringBuilder();
int i = 0;
for (Command c : commands) {
if (c instanceof DestroyCommand) {
// dont want to publicly show this one
continue;
}
sbs[i++ % 3].append(prefix).append(c.name).append("\n");
}
return embedBuilder.addField(context.i18n(module.module.translationKey), sbs[0].toString(), true).addField("", sbs[1].toString(), true).addField("", sbs[2].toString(), true);
} else {
StringBuilder sb = new StringBuilder();
for (Command c : commands) {
sb.append(prefix).append(c.name).append("\n");
}
return embedBuilder.addField(context.i18n(module.module.translationKey), sb.toString(), true).addBlankField(true).addBlankField(true);
}
}
use of fredboat.commandmeta.abs.ICommandRestricted 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);
}
}
Aggregations