1
0
mirror of https://github.com/aNNiMON/ffmpegbot synced 2024-09-19 22:54:20 +03:00

Add note if user is not allowed to use the bot

This commit is contained in:
aNNiMON 2024-07-07 19:39:01 +03:00
parent bc4e3af5bc
commit 3335720b61
2 changed files with 18 additions and 3 deletions

View File

@ -41,7 +41,7 @@ public class MainBotHandler extends BotHandler {
commands.registerBundle(new InputParametersBundle(sessions)); commands.registerBundle(new InputParametersBundle(sessions));
commands.registerBundle(new YtDlpCommandBundle(sessions)); commands.registerBundle(new YtDlpCommandBundle(sessions));
commands.registerBundle(new AdminCommandBundle(sessions)); commands.registerBundle(new AdminCommandBundle(sessions));
commands.register(new HelpCommand()); commands.register(new HelpCommand(permissions));
} }
@Override @Override

View File

@ -1,5 +1,6 @@
package com.annimon.ffmpegbot.commands; package com.annimon.ffmpegbot.commands;
import com.annimon.ffmpegbot.Permissions;
import com.annimon.tgbotsmodule.commands.TextCommand; import com.annimon.tgbotsmodule.commands.TextCommand;
import com.annimon.tgbotsmodule.commands.authority.For; import com.annimon.tgbotsmodule.commands.authority.For;
import com.annimon.tgbotsmodule.commands.context.MessageContext; import com.annimon.tgbotsmodule.commands.context.MessageContext;
@ -9,6 +10,11 @@ import java.util.EnumSet;
import java.util.Set; import java.util.Set;
public class HelpCommand implements TextCommand { public class HelpCommand implements TextCommand {
private final Permissions permissions;
public HelpCommand(Permissions permissions) {
this.permissions = permissions;
}
@Override @Override
public String command() { public String command() {
@ -28,8 +34,17 @@ public class HelpCommand implements TextCommand {
@Override @Override
public void accept(@NotNull MessageContext ctx) { public void accept(@NotNull MessageContext ctx) {
boolean hasRights = permissions.hasRights(ctx.sender, ctx.update(), ctx.user(), EnumSet.of(For.USER));
String rightsText = "";
if (!hasRights) {
rightsText = """
<i>Note: You are not in the list of allowed users.
This bot is for personal use only, consider setting up your own instance:</i>
https://github.com/aNNiMON/ffmpegbot
""".stripIndent() + "\n\n";
}
ctx.replyToMessage(""" ctx.replyToMessage("""
<b>Media processing</b> %s<b>Media processing</b>
Send any media to start processing. Send any media to start processing.
<b>Input parameters</b> (in reply to media processing message) <b>Input parameters</b> (in reply to media processing message)
@ -41,6 +56,6 @@ public class HelpCommand implements TextCommand {
/dl link [format] download a media using yt-dlp /dl link [format] download a media using yt-dlp
<code>link</code> a link to download (it must be supported by yt-dlp) <code>link</code> a link to download (it must be supported by yt-dlp)
<code>format</code> (optional) a download format. Can be "best", "audio", "240", "360", "480", "720" or "1080" <code>format</code> (optional) a download format. Can be "best", "audio", "240", "360", "480", "720" or "1080"
""".stripIndent()).enableHtml().callAsync(ctx.sender); """.stripIndent().formatted(rightsText)).enableHtml().disableWebPagePreview().callAsync(ctx.sender);
} }
} }