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:
parent
d1de4a7eb9
commit
a4f2218758
@ -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).
|
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
|
```bash
|
||||||
# Edit user ids in `superUsers` and `allowedUsers` fields
|
|
||||||
vim ffmpegbot-docker.yaml
|
|
||||||
docker build --tag 'ffmpegbot' .
|
docker build --tag 'ffmpegbot' .
|
||||||
docker run -d -t -i \
|
docker run -d -t -i \
|
||||||
-e BOT_TOKEN='...' \
|
-e BOT_TOKEN='...' \
|
||||||
-e BOT_USERNAME='...' \
|
-e BOT_USERNAME='...' \
|
||||||
-e APP_ID='...' \
|
-e APP_ID='...' \
|
||||||
-e APP_HASH='...'\
|
-e APP_HASH='...' \
|
||||||
|
-e SUPERUSERS='12345' \
|
||||||
|
-e ALLOWED_USERS='12346,12347' \
|
||||||
--name ffmpegbot ffmpegbot:latest
|
--name ffmpegbot ffmpegbot:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -56,4 +56,5 @@ docker run -d -t -i \
|
|||||||
- `BOT_USERNAME` — Telegram bot username
|
- `BOT_USERNAME` — Telegram bot username
|
||||||
- `APP_ID` — Telegram API app_id (see https://core.telegram.org/api/obtaining_api_id)
|
- `APP_ID` — Telegram API app_id (see https://core.telegram.org/api/obtaining_api_id)
|
||||||
- `APP_HASH` — Telegram API app_hash
|
- `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
|
||||||
|
@ -5,7 +5,8 @@ appId: env(APP_ID)
|
|||||||
appHash: env(APP_HASH)
|
appHash: env(APP_HASH)
|
||||||
# Path to Telegram API file downloader script
|
# Path to Telegram API file downloader script
|
||||||
downloaderScript: pytgfile.py
|
downloaderScript: pytgfile.py
|
||||||
# Superusers can execute /run command
|
# Comma-separated list of superusers
|
||||||
superUsers: [12345]
|
# Superuser can execute /run command
|
||||||
# Allowed user ids
|
superUsers: env(SUPERUSERS)
|
||||||
allowedUsers: [12346, 12347]
|
# Comma-separated list of allowed user ids
|
||||||
|
allowedUsers: env(ALLOWED_USERS)
|
||||||
|
@ -6,7 +6,8 @@ appId: 12345
|
|||||||
appHash: abc123def456
|
appHash: abc123def456
|
||||||
# Path to Telegram API file downloader script
|
# Path to Telegram API file downloader script
|
||||||
downloaderScript: pytgfile.py
|
downloaderScript: pytgfile.py
|
||||||
# Superusers can execute /run command
|
# Comma-separated list of superusers
|
||||||
superUsers: [12345]
|
# Superuser can execute /run command
|
||||||
# Allowed user ids
|
superUsers: 12345
|
||||||
allowedUsers: [12346, 12347]
|
# Comma-separated list of allowed user ids
|
||||||
|
allowedUsers: 12346, 12347
|
||||||
|
@ -1,9 +1,31 @@
|
|||||||
package com.annimon.ffmpegbot;
|
package com.annimon.ffmpegbot;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public record BotConfig(String appId, String appHash,
|
public record BotConfig(String appId, String appHash,
|
||||||
String botToken, String botUsername,
|
String botToken, String botUsername,
|
||||||
String downloaderScript,
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public class MainBotHandler extends BotHandler {
|
|||||||
|
|
||||||
public MainBotHandler(BotConfig botConfig) {
|
public MainBotHandler(BotConfig botConfig) {
|
||||||
super(BotModuleOptions.createDefault(botConfig.botToken()));
|
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);
|
commands = new CommandRegistry<>(botConfig.botUsername(), permissions);
|
||||||
final var sessions = new Sessions();
|
final var sessions = new Sessions();
|
||||||
final var fallbackFileDownloader = new FallbackFileDownloader(
|
final var fallbackFileDownloader = new FallbackFileDownloader(
|
||||||
|
Loading…
Reference in New Issue
Block a user