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

Change config to use comma-separated string for providing user ids via environment variable

This commit is contained in:
aNNiMON 2024-09-03 21:27:51 +03:00
parent d1de4a7eb9
commit a4f2218758
5 changed files with 39 additions and 14 deletions

View File

@ -39,14 +39,14 @@ java -jar ./build/libs/ffmpegbot-1.2-SNAPSHOT-all.jar
Note: FFmpeg binary might be installed with limited number of filters and codecs. Some bot features might not work (Audio pitch, robot effect, etc).
```bash
# Edit user ids in `superUsers` and `allowedUsers` fields
vim ffmpegbot-docker.yaml
docker build --tag 'ffmpegbot' .
docker run -d -t -i \
-e BOT_TOKEN='...' \
-e BOT_USERNAME='...' \
-e APP_ID='...' \
-e APP_HASH='...'\
-e APP_HASH='...' \
-e SUPERUSERS='12345' \
-e ALLOWED_USERS='12346,12347' \
--name ffmpegbot ffmpegbot:latest
```
@ -56,4 +56,5 @@ docker run -d -t -i \
- `BOT_USERNAME` — Telegram bot username
- `APP_ID` — Telegram API app_id (see https://core.telegram.org/api/obtaining_api_id)
- `APP_HASH` — Telegram API app_hash
- `SUPERUSERS` — Comma-separated list of superusers. Superuser can execute /run command
- `ALLOWED_USERS` — Comma-separated list of allowed user ids

View File

@ -5,7 +5,8 @@ appId: env(APP_ID)
appHash: env(APP_HASH)
# Path to Telegram API file downloader script
downloaderScript: pytgfile.py
# Superusers can execute /run command
superUsers: [12345]
# Allowed user ids
allowedUsers: [12346, 12347]
# Comma-separated list of superusers
# Superuser can execute /run command
superUsers: env(SUPERUSERS)
# Comma-separated list of allowed user ids
allowedUsers: env(ALLOWED_USERS)

View File

@ -6,7 +6,8 @@ appId: 12345
appHash: abc123def456
# Path to Telegram API file downloader script
downloaderScript: pytgfile.py
# Superusers can execute /run command
superUsers: [12345]
# Allowed user ids
allowedUsers: [12346, 12347]
# Comma-separated list of superusers
# Superuser can execute /run command
superUsers: 12345
# Comma-separated list of allowed user ids
allowedUsers: 12346, 12347

View File

@ -1,9 +1,31 @@
package com.annimon.ffmpegbot;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
public record BotConfig(String appId, String appHash,
String botToken, String botUsername,
String downloaderScript,
Set<Long> superUsers, Set<Long> allowedUsers) {
String superUsers, String allowedUsers) {
Set<Long> superUserIds() {
return toLongs(superUsers);
}
Set<Long> allowedUserIds() {
return toLongs(allowedUsers);
}
private static Set<Long> toLongs(String input) {
if (input == null || input.isEmpty()) {
return Collections.emptySet();
}
return Arrays.stream(input.split(","))
.map(String::trim)
.filter(str -> str.matches("^\\d{1,15}$"))
.map(Long::parseLong)
.collect(Collectors.toSet());
}
}

View File

@ -26,7 +26,7 @@ public class MainBotHandler extends BotHandler {
public MainBotHandler(BotConfig botConfig) {
super(BotModuleOptions.createDefault(botConfig.botToken()));
permissions = new Permissions(botConfig.superUsers(), botConfig.allowedUsers());
permissions = new Permissions(botConfig.superUserIds(), botConfig.allowedUserIds());
commands = new CommandRegistry<>(botConfig.botUsername(), permissions);
final var sessions = new Sessions();
final var fallbackFileDownloader = new FallbackFileDownloader(