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

Upgrade dependencies

This commit is contained in:
aNNiMON 2023-10-18 21:26:22 +03:00
parent 1aa86b12cf
commit aa3b01ea5e
4 changed files with 19 additions and 20 deletions

View File

@ -1,5 +1,5 @@
plugins { plugins {
id 'com.github.johnrengelman.shadow' version '7.0.0' id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'java' id 'java'
id 'application' id 'application'
} }
@ -21,8 +21,8 @@ repositories {
} }
dependencies { dependencies {
implementation 'com.annimon:tgbots-module:6.3.1' implementation 'com.annimon:tgbots-module:6.5.1'
implementation 'org.slf4j:slf4j-simple:2.0.5' implementation 'org.slf4j:slf4j-simple:2.0.9'
} }
test { test {

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@ -15,11 +15,8 @@ import com.annimon.tgbotsmodule.commands.authority.For;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.User;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import java.util.EnumSet;
public class MainBotHandler extends BotHandler { public class MainBotHandler extends BotHandler {
private final BotConfig botConfig; private final BotConfig botConfig;
private final Permissions permissions; private final Permissions permissions;
@ -27,9 +24,10 @@ public class MainBotHandler extends BotHandler {
private final MediaProcessingBundle mediaProcessingBundle; private final MediaProcessingBundle mediaProcessingBundle;
public MainBotHandler(BotConfig botConfig) { public MainBotHandler(BotConfig botConfig) {
super(botConfig.botToken());
this.botConfig = botConfig; this.botConfig = botConfig;
permissions = new Permissions(botConfig.superUsers(), botConfig.allowedUsers()); permissions = new Permissions(botConfig.superUsers(), botConfig.allowedUsers());
commands = new CommandRegistry<>(this, this::checkAccess); 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(
new TelegramFileDownloader(), new TelegramFileDownloader(),
@ -48,7 +46,7 @@ public class MainBotHandler extends BotHandler {
@Override @Override
protected BotApiMethod<?> onUpdate(@NotNull Update update) { protected BotApiMethod<?> onUpdate(@NotNull Update update) {
if (commands.handleUpdate(update)) { if (commands.handleUpdate(this, update)) {
return null; return null;
} }
if (update.hasMessage() && permissions.isUserAllowed(update.getMessage().getFrom().getId())) { if (update.hasMessage() && permissions.isUserAllowed(update.getMessage().getFrom().getId())) {
@ -62,16 +60,6 @@ public class MainBotHandler extends BotHandler {
return botConfig.botUsername(); return botConfig.botUsername();
} }
@Override
public String getBotToken() {
return botConfig.botToken();
}
private boolean checkAccess(Update update, @NotNull User user, @NotNull EnumSet<For> roles) {
final long userId = user.getId();
return permissions.hasAccess(userId, roles);
}
@Override @Override
public void handleTelegramApiException(TelegramApiException ex) { public void handleTelegramApiException(TelegramApiException ex) {
throw new TelegramRuntimeException(ex); throw new TelegramRuntimeException(ex);

View File

@ -1,15 +1,26 @@
package com.annimon.ffmpegbot; package com.annimon.ffmpegbot;
import com.annimon.tgbotsmodule.commands.authority.Authority;
import com.annimon.tgbotsmodule.commands.authority.For; import com.annimon.tgbotsmodule.commands.authority.For;
import com.annimon.tgbotsmodule.services.CommonAbsSender;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.User;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Set; import java.util.Set;
public record Permissions(Set<Long> superUsers, Set<Long> allowedUsers) { public record Permissions(Set<Long> superUsers, Set<Long> allowedUsers) implements Authority<For> {
public static final EnumSet<For> SUPERUSERS = EnumSet.of(For.CREATOR); public static final EnumSet<For> SUPERUSERS = EnumSet.of(For.CREATOR);
public static final EnumSet<For> ALLOWED_USERS = EnumSet.of(For.CREATOR, For.ADMIN); public static final EnumSet<For> ALLOWED_USERS = EnumSet.of(For.CREATOR, For.ADMIN);
@Override
public boolean hasRights(@NotNull CommonAbsSender sender, @NotNull Update update,
@NotNull User user, @NotNull EnumSet<For> roles) {
final long userId = user.getId();
return hasAccess(userId, roles);
}
boolean hasAccess(long userId, @NotNull EnumSet<For> roles) { boolean hasAccess(long userId, @NotNull EnumSet<For> roles) {
if (roles.contains(For.CREATOR) && superUsers().contains(userId)) if (roles.contains(For.CREATOR) && superUsers().contains(userId))
return true; return true;