chore: unify checkstyle, fix violations, cleanup bin/
This commit is contained in:
parent
9c5e5bccae
commit
da9271b283
17 changed files with 363 additions and 67 deletions
|
|
@ -11,6 +11,8 @@ import java.nio.file.Path;
|
|||
|
||||
public final class BotLauncher {
|
||||
|
||||
private BotLauncher() {}
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BotLauncher.class);
|
||||
|
||||
public static void main(final String[] args) {
|
||||
|
|
@ -33,7 +35,9 @@ public final class BotLauncher {
|
|||
Path path = Path.of(System.getProperty("user.dir")).resolve(fileName);
|
||||
if (Files.notExists(path)) {
|
||||
try (InputStream in = BotLauncher.class.getResourceAsStream("/" + fileName)) {
|
||||
if (in == null) throw new IOException("Resource not found: " + fileName);
|
||||
if (in == null) {
|
||||
throw new IOException("Resource not found: " + fileName);
|
||||
}
|
||||
Files.copy(in, path);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,9 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class AuthService implements AutoCloseable {
|
||||
|
||||
|
|
@ -36,7 +38,9 @@ public final class AuthService implements AutoCloseable {
|
|||
|
||||
public void verifyNewUser(final String code, final String discordId) {
|
||||
Optional<String> nick = db.consumeVerificationCode(code.toUpperCase());
|
||||
if (nick.isEmpty()) throw new IllegalArgumentException("Invalid or expired code: " + code);
|
||||
if (nick.isEmpty()) {
|
||||
throw new IllegalArgumentException("Invalid or expired code: " + code);
|
||||
}
|
||||
db.addUser(nick.get(), discordId);
|
||||
log.info("New user registered: {} -> {}", nick.get(), discordId);
|
||||
}
|
||||
|
|
@ -75,8 +79,9 @@ public final class AuthService implements AutoCloseable {
|
|||
private void kickExpiredLogins() {
|
||||
try {
|
||||
List<String> expired = db.popExpiredLogins();
|
||||
if (!expired.isEmpty())
|
||||
if (!expired.isEmpty()) {
|
||||
log.info("Expired logins cleaned up: {}", expired);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Error during expired login cleanup", e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,13 +13,48 @@ public final class BotCfg implements BotConfig {
|
|||
cfg = new YamlConfig(configPath);
|
||||
}
|
||||
|
||||
@Override public String getToken() { return cfg.getRequired("token", String.class); }
|
||||
@Override public String getDbType() { return cfg.getRequired("db_type", String.class); }
|
||||
@Override public String getDbHost() { return cfg.getRequired("db_host", String.class); }
|
||||
@Override public int getDbPort() { return cfg.getRequired("db_port", Integer.class); }
|
||||
@Override public String getDbName() { return cfg.getRequired("db_name", String.class); }
|
||||
@Override public String getDbUser() { return cfg.getRequired("db_user", String.class); }
|
||||
@Override public String getDbPassword() { return cfg.getRequired("db_password", String.class); }
|
||||
@Override public int getAuthTimeoutSeconds() { return cfg.getRequired("auth_timeout_seconds", Integer.class); }
|
||||
@Override public int getVerificationCodeLength() { return cfg.getRequired("verification_code_length",Integer.class); }
|
||||
@Override
|
||||
public String getToken() {
|
||||
return cfg.getRequired("token", String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDbType() {
|
||||
return cfg.getRequired("db_type", String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDbHost() {
|
||||
return cfg.getRequired("db_host", String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDbPort() {
|
||||
return cfg.getRequired("db_port", Integer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDbName() {
|
||||
return cfg.getRequired("db_name", String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDbUser() {
|
||||
return cfg.getRequired("db_user", String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDbPassword() {
|
||||
return cfg.getRequired("db_password", String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAuthTimeoutSeconds() {
|
||||
return cfg.getRequired("auth_timeout_seconds", Integer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVerificationCodeLength() {
|
||||
return cfg.getRequired("verification_code_length", Integer.class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,12 @@ public final class LoginReactionListener extends ListenerAdapter {
|
|||
|
||||
@Override
|
||||
public void onMessageReactionAdd(final MessageReactionAddEvent event) {
|
||||
if (event.getUser() == null || event.getUser().isBot()) return;
|
||||
if (!CHECKMARK.equals(event.getReaction().getEmoji().getName())) return;
|
||||
if (event.getUser() == null || event.getUser().isBot()) {
|
||||
return;
|
||||
}
|
||||
if (!CHECKMARK.equals(event.getReaction().getEmoji().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ищем токен по message_id — бот сохранил его при отправке
|
||||
db.consumeLoginTokenByMessageId(event.getMessageId()).ifPresent(nick ->
|
||||
|
|
|
|||
|
|
@ -18,11 +18,17 @@ public final class VerifyListener extends ListenerAdapter {
|
|||
|
||||
@Override
|
||||
public void onMessageReceived(final MessageReceivedEvent event) {
|
||||
if (event.getAuthor().isBot()) return;
|
||||
if (!event.isFromType(ChannelType.PRIVATE)) return;
|
||||
if (event.getAuthor().isBot()) {
|
||||
return;
|
||||
}
|
||||
if (!event.isFromType(ChannelType.PRIVATE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String content = event.getMessage().getContentRaw().trim();
|
||||
if (!content.toUpperCase().startsWith(COMMAND)) return;
|
||||
if (!content.toUpperCase().startsWith(COMMAND)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String[] parts = content.split("\\s+", 2);
|
||||
if (parts.length < 2) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue