Compare commits
No commits in common. "e36f0da9ab5b60f4b4de6794f6e6caf80e481d08" and "88ccf172dc9ad2aef10cf408a75a1b82ecd84075" have entirely different histories.
e36f0da9ab
...
88ccf172dc
@ -1,7 +1,7 @@
|
||||
package dev.struchkov.godfather.telegram.main.core;
|
||||
|
||||
import dev.struchkov.godfather.telegram.domain.config.ProxyConfig;
|
||||
import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig;
|
||||
import dev.struchkov.godfather.telegram.domain.config.TelegramConnectConfig;
|
||||
import dev.struchkov.godfather.telegram.main.context.TelegramConnect;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.telegram.telegrambots.bots.DefaultAbsSender;
|
||||
@ -18,13 +18,13 @@ public class TelegramDefaultConnect implements TelegramConnect {
|
||||
private final String botToken;
|
||||
private final AbsSender absSender;
|
||||
|
||||
public TelegramDefaultConnect(TelegramBotConfig connectConfig) {
|
||||
this.botToken = connectConfig.getToken();
|
||||
public TelegramDefaultConnect(TelegramConnectConfig connectConfig) {
|
||||
this.botToken = connectConfig.getBotToken();
|
||||
this.absSender = createAbsSender(connectConfig);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private DefaultAbsSender createAbsSender(TelegramBotConfig connectConfig) {
|
||||
private DefaultAbsSender createAbsSender(TelegramConnectConfig connectConfig) {
|
||||
final DefaultBotOptions botOptions = new DefaultBotOptions();
|
||||
|
||||
final ProxyConfig proxyConfig = connectConfig.getProxyConfig();
|
||||
|
@ -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.Type;
|
||||
import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig;
|
||||
import dev.struchkov.godfather.telegram.domain.config.TelegramConnectConfig;
|
||||
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.TelegramBot;
|
||||
@ -29,11 +29,11 @@ public class TelegramConnectBot implements TelegramConnect {
|
||||
private static final Logger log = LoggerFactory.getLogger(TelegramConnectBot.class);
|
||||
|
||||
private TelegramBot telegramBot;
|
||||
private final TelegramBotConfig telegramBotConfig;
|
||||
private final TelegramConnectConfig telegramConnectConfig;
|
||||
|
||||
public TelegramConnectBot(TelegramBotConfig telegramBotConfig) {
|
||||
this.telegramBotConfig = telegramBotConfig;
|
||||
initLongPolling(telegramBotConfig);
|
||||
public TelegramConnectBot(TelegramConnectConfig telegramConnectConfig) {
|
||||
this.telegramConnectConfig = telegramConnectConfig;
|
||||
initLongPolling(telegramConnectConfig);
|
||||
}
|
||||
|
||||
// public TelegramConnect(TelegramWebHookConfig telegramWebHookConfig) {
|
||||
@ -51,9 +51,9 @@ public class TelegramConnectBot implements TelegramConnect {
|
||||
// }
|
||||
// }
|
||||
|
||||
private void initLongPolling(TelegramBotConfig telegramBotConfig) {
|
||||
private void initLongPolling(TelegramConnectConfig telegramConnectConfig) {
|
||||
|
||||
final ProxyConfig proxyConfig = telegramBotConfig.getProxyConfig();
|
||||
final ProxyConfig proxyConfig = telegramConnectConfig.getProxyConfig();
|
||||
if (checkNotNull(proxyConfig) && proxyConfig.isEnable() && checkNotNull(proxyConfig.getPassword()) && !"".equals(proxyConfig.getPassword())) {
|
||||
try {
|
||||
Authenticator.setDefault(new Authenticator() {
|
||||
@ -82,13 +82,13 @@ public class TelegramConnectBot implements TelegramConnect {
|
||||
botOptions.setProxyType(convertProxyType(proxyConfig.getType()));
|
||||
|
||||
|
||||
final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig, botOptions);
|
||||
final TelegramPollingBot bot = new TelegramPollingBot(telegramConnectConfig, botOptions);
|
||||
|
||||
botapi = new TelegramBotsApi(DefaultBotSession.class);
|
||||
botapi.registerBot(bot);
|
||||
this.telegramBot = bot;
|
||||
} else {
|
||||
final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig);
|
||||
final TelegramPollingBot bot = new TelegramPollingBot(telegramConnectConfig);
|
||||
botapi = new TelegramBotsApi(DefaultBotSession.class);
|
||||
botapi.registerBot(bot);
|
||||
this.telegramBot = bot;
|
||||
@ -111,7 +111,7 @@ public class TelegramConnectBot implements TelegramConnect {
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return telegramBotConfig.getToken();
|
||||
return telegramConnectConfig.getBotToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dev.struchkov.godfather.telegram.quarkus.core;
|
||||
|
||||
import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig;
|
||||
import dev.struchkov.godfather.telegram.domain.config.TelegramConnectConfig;
|
||||
import dev.struchkov.godfather.telegram.quarkus.context.service.EventDistributor;
|
||||
import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramBot;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -16,16 +16,16 @@ import org.telegram.telegrambots.meta.bots.AbsSender;
|
||||
*/
|
||||
public class TelegramPollingBot extends TelegramLongPollingBot implements TelegramBot {
|
||||
|
||||
private final TelegramBotConfig telegramBotConfig;
|
||||
private final TelegramConnectConfig telegramConnectConfig;
|
||||
private EventDistributor eventDistributor;
|
||||
|
||||
public TelegramPollingBot(TelegramBotConfig telegramBotConfig, DefaultBotOptions defaultBotOptions) {
|
||||
public TelegramPollingBot(TelegramConnectConfig telegramConnectConfig, DefaultBotOptions defaultBotOptions) {
|
||||
super(defaultBotOptions);
|
||||
this.telegramBotConfig = telegramBotConfig;
|
||||
this.telegramConnectConfig = telegramConnectConfig;
|
||||
}
|
||||
|
||||
public TelegramPollingBot(TelegramBotConfig telegramBotConfig) {
|
||||
this.telegramBotConfig = telegramBotConfig;
|
||||
public TelegramPollingBot(TelegramConnectConfig telegramConnectConfig) {
|
||||
this.telegramConnectConfig = telegramConnectConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -38,12 +38,12 @@ public class TelegramPollingBot extends TelegramLongPollingBot implements Telegr
|
||||
|
||||
@Override
|
||||
public String getBotUsername() {
|
||||
return telegramBotConfig.getUsername();
|
||||
return telegramConnectConfig.getBotUsername();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBotToken() {
|
||||
return telegramBotConfig.getToken();
|
||||
return telegramConnectConfig.getBotToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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.Type;
|
||||
import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig;
|
||||
import dev.struchkov.godfather.telegram.domain.config.TelegramConnectConfig;
|
||||
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.TelegramBot;
|
||||
@ -29,15 +29,15 @@ public class TelegramConnectBot implements TelegramConnect {
|
||||
private static final Logger log = LoggerFactory.getLogger(TelegramConnectBot.class);
|
||||
|
||||
private TelegramBot telegramBot;
|
||||
private final TelegramBotConfig telegramBotConfig;
|
||||
private final TelegramConnectConfig telegramConnectConfig;
|
||||
|
||||
public TelegramConnectBot(TelegramBotConfig telegramBotConfig) {
|
||||
this.telegramBotConfig = telegramBotConfig;
|
||||
initLongPolling(telegramBotConfig);
|
||||
public TelegramConnectBot(TelegramConnectConfig telegramConnectConfig) {
|
||||
this.telegramConnectConfig = telegramConnectConfig;
|
||||
initLongPolling(telegramConnectConfig);
|
||||
}
|
||||
|
||||
private void initLongPolling(TelegramBotConfig telegramBotConfig) {
|
||||
final ProxyConfig proxyConfig = telegramBotConfig.getProxyConfig();
|
||||
private void initLongPolling(TelegramConnectConfig telegramConnectConfig) {
|
||||
final ProxyConfig proxyConfig = telegramConnectConfig.getProxyConfig();
|
||||
if (checkNotNull(proxyConfig) && checkNotNull(proxyConfig.getPassword()) && !"".equals(proxyConfig.getPassword())) {
|
||||
try {
|
||||
Authenticator.setDefault(new Authenticator() {
|
||||
@ -65,13 +65,13 @@ public class TelegramConnectBot implements TelegramConnect {
|
||||
botOptions.setProxyPort(proxyConfig.getPort());
|
||||
botOptions.setProxyType(convertProxyType(proxyConfig.getType()));
|
||||
|
||||
final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig, botOptions);
|
||||
final TelegramPollingBot bot = new TelegramPollingBot(telegramConnectConfig, botOptions);
|
||||
|
||||
botapi = new TelegramBotsApi(DefaultBotSession.class);
|
||||
botapi.registerBot(bot);
|
||||
this.telegramBot = bot;
|
||||
} else {
|
||||
final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig);
|
||||
final TelegramPollingBot bot = new TelegramPollingBot(telegramConnectConfig);
|
||||
botapi = new TelegramBotsApi(DefaultBotSession.class);
|
||||
botapi.registerBot(bot);
|
||||
this.telegramBot = bot;
|
||||
@ -94,7 +94,7 @@ public class TelegramConnectBot implements TelegramConnect {
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return telegramBotConfig.getToken();
|
||||
return telegramConnectConfig.getBotToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dev.struchkov.godfather.telegram.simple.core;
|
||||
|
||||
import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig;
|
||||
import dev.struchkov.godfather.telegram.domain.config.TelegramConnectConfig;
|
||||
import dev.struchkov.godfather.telegram.simple.context.service.EventDistributor;
|
||||
import dev.struchkov.godfather.telegram.simple.context.service.TelegramBot;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -18,16 +18,16 @@ import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||
*/
|
||||
public class TelegramPollingBot extends TelegramLongPollingBot implements TelegramBot {
|
||||
|
||||
private final TelegramBotConfig telegramBotConfig;
|
||||
private final TelegramConnectConfig telegramConnectConfig;
|
||||
private EventDistributor eventDistributor;
|
||||
|
||||
public TelegramPollingBot(TelegramBotConfig telegramBotConfig, DefaultBotOptions defaultBotOptions) {
|
||||
public TelegramPollingBot(TelegramConnectConfig telegramConnectConfig, DefaultBotOptions defaultBotOptions) {
|
||||
super(defaultBotOptions);
|
||||
this.telegramBotConfig = telegramBotConfig;
|
||||
this.telegramConnectConfig = telegramConnectConfig;
|
||||
}
|
||||
|
||||
public TelegramPollingBot(TelegramBotConfig telegramBotConfig) {
|
||||
this.telegramBotConfig = telegramBotConfig;
|
||||
public TelegramPollingBot(TelegramConnectConfig telegramConnectConfig) {
|
||||
this.telegramConnectConfig = telegramConnectConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -39,12 +39,12 @@ public class TelegramPollingBot extends TelegramLongPollingBot implements Telegr
|
||||
|
||||
@Override
|
||||
public String getBotUsername() {
|
||||
return telegramBotConfig.getUsername();
|
||||
return telegramConnectConfig.getBotUsername();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBotToken() {
|
||||
return telegramBotConfig.getToken();
|
||||
return telegramConnectConfig.getBotToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,47 +0,0 @@
|
||||
package dev.struchkov.godfather.telegram.domain.config;
|
||||
|
||||
/**
|
||||
* TODO: Добавить описание класса.
|
||||
*
|
||||
* @author upagge [18.08.2019]
|
||||
*/
|
||||
public class TelegramBotConfig {
|
||||
|
||||
private String username;
|
||||
private String token;
|
||||
|
||||
private ProxyConfig proxyConfig;
|
||||
|
||||
public TelegramBotConfig(String username, String token) {
|
||||
this.username = username;
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public TelegramBotConfig() {
|
||||
}
|
||||
|
||||
public void setUsername(String botUsername) {
|
||||
this.username = botUsername;
|
||||
}
|
||||
|
||||
public void setToken(String botToken) {
|
||||
this.token = botToken;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public ProxyConfig getProxyConfig() {
|
||||
return proxyConfig;
|
||||
}
|
||||
|
||||
public void setProxyConfig(ProxyConfig proxyConfig) {
|
||||
this.proxyConfig = proxyConfig;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package dev.struchkov.godfather.telegram.domain.config;
|
||||
|
||||
/**
|
||||
* TODO: Добавить описание класса.
|
||||
*
|
||||
* @author upagge [18.08.2019]
|
||||
*/
|
||||
public class TelegramConnectConfig {
|
||||
|
||||
private String botUsername;
|
||||
private String botToken;
|
||||
|
||||
private ProxyConfig proxyConfig;
|
||||
|
||||
public TelegramConnectConfig(String botUsername, String botToken) {
|
||||
this.botUsername = botUsername;
|
||||
this.botToken = botToken;
|
||||
}
|
||||
|
||||
public TelegramConnectConfig() {
|
||||
}
|
||||
|
||||
public void setBotUsername(String botUsername) {
|
||||
this.botUsername = botUsername;
|
||||
}
|
||||
|
||||
public void setBotToken(String botToken) {
|
||||
this.botToken = botToken;
|
||||
}
|
||||
|
||||
public String getBotUsername() {
|
||||
return botUsername;
|
||||
}
|
||||
|
||||
public String getBotToken() {
|
||||
return botToken;
|
||||
}
|
||||
|
||||
public ProxyConfig getProxyConfig() {
|
||||
return proxyConfig;
|
||||
}
|
||||
|
||||
public void setProxyConfig(ProxyConfig proxyConfig) {
|
||||
this.proxyConfig = proxyConfig;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user