Переименовал TelegramBotConfig

This commit is contained in:
Struchkov Mark 2023-02-18 22:16:02 +03:00
parent 88ccf172dc
commit 39e806dc35
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
6 changed files with 53 additions and 53 deletions

View File

@ -1,7 +1,7 @@
package dev.struchkov.godfather.telegram.main.core; package dev.struchkov.godfather.telegram.main.core;
import dev.struchkov.godfather.telegram.domain.config.ProxyConfig; import dev.struchkov.godfather.telegram.domain.config.ProxyConfig;
import dev.struchkov.godfather.telegram.domain.config.TelegramConnectConfig; import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig;
import dev.struchkov.godfather.telegram.main.context.TelegramConnect; import dev.struchkov.godfather.telegram.main.context.TelegramConnect;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.telegram.telegrambots.bots.DefaultAbsSender; import org.telegram.telegrambots.bots.DefaultAbsSender;
@ -18,13 +18,13 @@ public class TelegramDefaultConnect implements TelegramConnect {
private final String botToken; private final String botToken;
private final AbsSender absSender; private final AbsSender absSender;
public TelegramDefaultConnect(TelegramConnectConfig connectConfig) { public TelegramDefaultConnect(TelegramBotConfig connectConfig) {
this.botToken = connectConfig.getBotToken(); this.botToken = connectConfig.getToken();
this.absSender = createAbsSender(connectConfig); this.absSender = createAbsSender(connectConfig);
} }
@NotNull @NotNull
private DefaultAbsSender createAbsSender(TelegramConnectConfig connectConfig) { private DefaultAbsSender createAbsSender(TelegramBotConfig connectConfig) {
final DefaultBotOptions botOptions = new DefaultBotOptions(); final DefaultBotOptions botOptions = new DefaultBotOptions();
final ProxyConfig proxyConfig = connectConfig.getProxyConfig(); final ProxyConfig proxyConfig = connectConfig.getProxyConfig();

View File

@ -2,7 +2,7 @@ package dev.struchkov.godfather.telegram.quarkus.core;
import dev.struchkov.godfather.telegram.domain.config.ProxyConfig; import dev.struchkov.godfather.telegram.domain.config.ProxyConfig;
import dev.struchkov.godfather.telegram.domain.config.ProxyConfig.Type; import dev.struchkov.godfather.telegram.domain.config.ProxyConfig.Type;
import dev.struchkov.godfather.telegram.domain.config.TelegramConnectConfig; import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig;
import dev.struchkov.godfather.telegram.main.context.TelegramConnect; import dev.struchkov.godfather.telegram.main.context.TelegramConnect;
import dev.struchkov.godfather.telegram.quarkus.context.service.EventDistributor; import dev.struchkov.godfather.telegram.quarkus.context.service.EventDistributor;
import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramBot; import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramBot;
@ -29,11 +29,11 @@ public class TelegramConnectBot implements TelegramConnect {
private static final Logger log = LoggerFactory.getLogger(TelegramConnectBot.class); private static final Logger log = LoggerFactory.getLogger(TelegramConnectBot.class);
private TelegramBot telegramBot; private TelegramBot telegramBot;
private final TelegramConnectConfig telegramConnectConfig; private final TelegramBotConfig telegramBotConfig;
public TelegramConnectBot(TelegramConnectConfig telegramConnectConfig) { public TelegramConnectBot(TelegramBotConfig telegramBotConfig) {
this.telegramConnectConfig = telegramConnectConfig; this.telegramBotConfig = telegramBotConfig;
initLongPolling(telegramConnectConfig); initLongPolling(telegramBotConfig);
} }
// public TelegramConnect(TelegramWebHookConfig telegramWebHookConfig) { // public TelegramConnect(TelegramWebHookConfig telegramWebHookConfig) {
@ -51,9 +51,9 @@ public class TelegramConnectBot implements TelegramConnect {
// } // }
// } // }
private void initLongPolling(TelegramConnectConfig telegramConnectConfig) { private void initLongPolling(TelegramBotConfig telegramBotConfig) {
final ProxyConfig proxyConfig = telegramConnectConfig.getProxyConfig(); final ProxyConfig proxyConfig = telegramBotConfig.getProxyConfig();
if (checkNotNull(proxyConfig) && proxyConfig.isEnable() && checkNotNull(proxyConfig.getPassword()) && !"".equals(proxyConfig.getPassword())) { if (checkNotNull(proxyConfig) && proxyConfig.isEnable() && checkNotNull(proxyConfig.getPassword()) && !"".equals(proxyConfig.getPassword())) {
try { try {
Authenticator.setDefault(new Authenticator() { Authenticator.setDefault(new Authenticator() {
@ -82,13 +82,13 @@ public class TelegramConnectBot implements TelegramConnect {
botOptions.setProxyType(convertProxyType(proxyConfig.getType())); botOptions.setProxyType(convertProxyType(proxyConfig.getType()));
final TelegramPollingBot bot = new TelegramPollingBot(telegramConnectConfig, botOptions); final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig, botOptions);
botapi = new TelegramBotsApi(DefaultBotSession.class); botapi = new TelegramBotsApi(DefaultBotSession.class);
botapi.registerBot(bot); botapi.registerBot(bot);
this.telegramBot = bot; this.telegramBot = bot;
} else { } else {
final TelegramPollingBot bot = new TelegramPollingBot(telegramConnectConfig); final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig);
botapi = new TelegramBotsApi(DefaultBotSession.class); botapi = new TelegramBotsApi(DefaultBotSession.class);
botapi.registerBot(bot); botapi.registerBot(bot);
this.telegramBot = bot; this.telegramBot = bot;
@ -111,7 +111,7 @@ public class TelegramConnectBot implements TelegramConnect {
} }
public String getToken() { public String getToken() {
return telegramConnectConfig.getBotToken(); return telegramBotConfig.getToken();
} }
@Override @Override

View File

@ -1,6 +1,6 @@
package dev.struchkov.godfather.telegram.quarkus.core; package dev.struchkov.godfather.telegram.quarkus.core;
import dev.struchkov.godfather.telegram.domain.config.TelegramConnectConfig; import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig;
import dev.struchkov.godfather.telegram.quarkus.context.service.EventDistributor; import dev.struchkov.godfather.telegram.quarkus.context.service.EventDistributor;
import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramBot; import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramBot;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -16,16 +16,16 @@ import org.telegram.telegrambots.meta.bots.AbsSender;
*/ */
public class TelegramPollingBot extends TelegramLongPollingBot implements TelegramBot { public class TelegramPollingBot extends TelegramLongPollingBot implements TelegramBot {
private final TelegramConnectConfig telegramConnectConfig; private final TelegramBotConfig telegramBotConfig;
private EventDistributor eventDistributor; private EventDistributor eventDistributor;
public TelegramPollingBot(TelegramConnectConfig telegramConnectConfig, DefaultBotOptions defaultBotOptions) { public TelegramPollingBot(TelegramBotConfig telegramBotConfig, DefaultBotOptions defaultBotOptions) {
super(defaultBotOptions); super(defaultBotOptions);
this.telegramConnectConfig = telegramConnectConfig; this.telegramBotConfig = telegramBotConfig;
} }
public TelegramPollingBot(TelegramConnectConfig telegramConnectConfig) { public TelegramPollingBot(TelegramBotConfig telegramBotConfig) {
this.telegramConnectConfig = telegramConnectConfig; this.telegramBotConfig = telegramBotConfig;
} }
@Override @Override
@ -38,12 +38,12 @@ public class TelegramPollingBot extends TelegramLongPollingBot implements Telegr
@Override @Override
public String getBotUsername() { public String getBotUsername() {
return telegramConnectConfig.getBotUsername(); return telegramBotConfig.getName();
} }
@Override @Override
public String getBotToken() { public String getBotToken() {
return telegramConnectConfig.getBotToken(); return telegramBotConfig.getToken();
} }
@Override @Override

View File

@ -2,7 +2,7 @@ package dev.struchkov.godfather.telegram.simple.core;
import dev.struchkov.godfather.telegram.domain.config.ProxyConfig; import dev.struchkov.godfather.telegram.domain.config.ProxyConfig;
import dev.struchkov.godfather.telegram.domain.config.ProxyConfig.Type; import dev.struchkov.godfather.telegram.domain.config.ProxyConfig.Type;
import dev.struchkov.godfather.telegram.domain.config.TelegramConnectConfig; import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig;
import dev.struchkov.godfather.telegram.main.context.TelegramConnect; import dev.struchkov.godfather.telegram.main.context.TelegramConnect;
import dev.struchkov.godfather.telegram.simple.context.service.EventDistributor; import dev.struchkov.godfather.telegram.simple.context.service.EventDistributor;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramBot; import dev.struchkov.godfather.telegram.simple.context.service.TelegramBot;
@ -29,15 +29,15 @@ public class TelegramConnectBot implements TelegramConnect {
private static final Logger log = LoggerFactory.getLogger(TelegramConnectBot.class); private static final Logger log = LoggerFactory.getLogger(TelegramConnectBot.class);
private TelegramBot telegramBot; private TelegramBot telegramBot;
private final TelegramConnectConfig telegramConnectConfig; private final TelegramBotConfig telegramBotConfig;
public TelegramConnectBot(TelegramConnectConfig telegramConnectConfig) { public TelegramConnectBot(TelegramBotConfig telegramBotConfig) {
this.telegramConnectConfig = telegramConnectConfig; this.telegramBotConfig = telegramBotConfig;
initLongPolling(telegramConnectConfig); initLongPolling(telegramBotConfig);
} }
private void initLongPolling(TelegramConnectConfig telegramConnectConfig) { private void initLongPolling(TelegramBotConfig telegramBotConfig) {
final ProxyConfig proxyConfig = telegramConnectConfig.getProxyConfig(); final ProxyConfig proxyConfig = telegramBotConfig.getProxyConfig();
if (checkNotNull(proxyConfig) && checkNotNull(proxyConfig.getPassword()) && !"".equals(proxyConfig.getPassword())) { if (checkNotNull(proxyConfig) && checkNotNull(proxyConfig.getPassword()) && !"".equals(proxyConfig.getPassword())) {
try { try {
Authenticator.setDefault(new Authenticator() { Authenticator.setDefault(new Authenticator() {
@ -65,13 +65,13 @@ public class TelegramConnectBot implements TelegramConnect {
botOptions.setProxyPort(proxyConfig.getPort()); botOptions.setProxyPort(proxyConfig.getPort());
botOptions.setProxyType(convertProxyType(proxyConfig.getType())); botOptions.setProxyType(convertProxyType(proxyConfig.getType()));
final TelegramPollingBot bot = new TelegramPollingBot(telegramConnectConfig, botOptions); final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig, botOptions);
botapi = new TelegramBotsApi(DefaultBotSession.class); botapi = new TelegramBotsApi(DefaultBotSession.class);
botapi.registerBot(bot); botapi.registerBot(bot);
this.telegramBot = bot; this.telegramBot = bot;
} else { } else {
final TelegramPollingBot bot = new TelegramPollingBot(telegramConnectConfig); final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig);
botapi = new TelegramBotsApi(DefaultBotSession.class); botapi = new TelegramBotsApi(DefaultBotSession.class);
botapi.registerBot(bot); botapi.registerBot(bot);
this.telegramBot = bot; this.telegramBot = bot;
@ -94,7 +94,7 @@ public class TelegramConnectBot implements TelegramConnect {
} }
public String getToken() { public String getToken() {
return telegramConnectConfig.getBotToken(); return telegramBotConfig.getToken();
} }
@Override @Override

View File

@ -1,6 +1,6 @@
package dev.struchkov.godfather.telegram.simple.core; package dev.struchkov.godfather.telegram.simple.core;
import dev.struchkov.godfather.telegram.domain.config.TelegramConnectConfig; import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig;
import dev.struchkov.godfather.telegram.simple.context.service.EventDistributor; import dev.struchkov.godfather.telegram.simple.context.service.EventDistributor;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramBot; import dev.struchkov.godfather.telegram.simple.context.service.TelegramBot;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -18,16 +18,16 @@ import static dev.struchkov.haiti.utils.Checker.checkNotNull;
*/ */
public class TelegramPollingBot extends TelegramLongPollingBot implements TelegramBot { public class TelegramPollingBot extends TelegramLongPollingBot implements TelegramBot {
private final TelegramConnectConfig telegramConnectConfig; private final TelegramBotConfig telegramBotConfig;
private EventDistributor eventDistributor; private EventDistributor eventDistributor;
public TelegramPollingBot(TelegramConnectConfig telegramConnectConfig, DefaultBotOptions defaultBotOptions) { public TelegramPollingBot(TelegramBotConfig telegramBotConfig, DefaultBotOptions defaultBotOptions) {
super(defaultBotOptions); super(defaultBotOptions);
this.telegramConnectConfig = telegramConnectConfig; this.telegramBotConfig = telegramBotConfig;
} }
public TelegramPollingBot(TelegramConnectConfig telegramConnectConfig) { public TelegramPollingBot(TelegramBotConfig telegramBotConfig) {
this.telegramConnectConfig = telegramConnectConfig; this.telegramBotConfig = telegramBotConfig;
} }
@Override @Override
@ -39,12 +39,12 @@ public class TelegramPollingBot extends TelegramLongPollingBot implements Telegr
@Override @Override
public String getBotUsername() { public String getBotUsername() {
return telegramConnectConfig.getBotUsername(); return telegramBotConfig.getName();
} }
@Override @Override
public String getBotToken() { public String getBotToken() {
return telegramConnectConfig.getBotToken(); return telegramBotConfig.getToken();
} }
@Override @Override

View File

@ -5,35 +5,35 @@ package dev.struchkov.godfather.telegram.domain.config;
* *
* @author upagge [18.08.2019] * @author upagge [18.08.2019]
*/ */
public class TelegramConnectConfig { public class TelegramBotConfig {
private String botUsername; private String name;
private String botToken; private String token;
private ProxyConfig proxyConfig; private ProxyConfig proxyConfig;
public TelegramConnectConfig(String botUsername, String botToken) { public TelegramBotConfig(String name, String token) {
this.botUsername = botUsername; this.name = name;
this.botToken = botToken; this.token = token;
} }
public TelegramConnectConfig() { public TelegramBotConfig() {
} }
public void setBotUsername(String botUsername) { public void setBotUsername(String botUsername) {
this.botUsername = botUsername; this.name = botUsername;
} }
public void setBotToken(String botToken) { public void setBotToken(String botToken) {
this.botToken = botToken; this.token = botToken;
} }
public String getBotUsername() { public String getName() {
return botUsername; return name;
} }
public String getBotToken() { public String getToken() {
return botToken; return token;
} }
public ProxyConfig getProxyConfig() { public ProxyConfig getProxyConfig() {