Compare commits
2 Commits
88ccf172dc
...
e36f0da9ab
Author | SHA1 | Date | |
---|---|---|---|
e36f0da9ab | |||
39e806dc35 |
@ -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.TelegramConnectConfig;
|
||||
import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig;
|
||||
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(TelegramConnectConfig connectConfig) {
|
||||
this.botToken = connectConfig.getBotToken();
|
||||
public TelegramDefaultConnect(TelegramBotConfig connectConfig) {
|
||||
this.botToken = connectConfig.getToken();
|
||||
this.absSender = createAbsSender(connectConfig);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private DefaultAbsSender createAbsSender(TelegramConnectConfig connectConfig) {
|
||||
private DefaultAbsSender createAbsSender(TelegramBotConfig 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.TelegramConnectConfig;
|
||||
import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig;
|
||||
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 TelegramConnectConfig telegramConnectConfig;
|
||||
private final TelegramBotConfig telegramBotConfig;
|
||||
|
||||
public TelegramConnectBot(TelegramConnectConfig telegramConnectConfig) {
|
||||
this.telegramConnectConfig = telegramConnectConfig;
|
||||
initLongPolling(telegramConnectConfig);
|
||||
public TelegramConnectBot(TelegramBotConfig telegramBotConfig) {
|
||||
this.telegramBotConfig = telegramBotConfig;
|
||||
initLongPolling(telegramBotConfig);
|
||||
}
|
||||
|
||||
// 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())) {
|
||||
try {
|
||||
Authenticator.setDefault(new Authenticator() {
|
||||
@ -82,13 +82,13 @@ public class TelegramConnectBot implements TelegramConnect {
|
||||
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.registerBot(bot);
|
||||
this.telegramBot = bot;
|
||||
} else {
|
||||
final TelegramPollingBot bot = new TelegramPollingBot(telegramConnectConfig);
|
||||
final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig);
|
||||
botapi = new TelegramBotsApi(DefaultBotSession.class);
|
||||
botapi.registerBot(bot);
|
||||
this.telegramBot = bot;
|
||||
@ -111,7 +111,7 @@ public class TelegramConnectBot implements TelegramConnect {
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return telegramConnectConfig.getBotToken();
|
||||
return telegramBotConfig.getToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,6 @@
|
||||
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.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 TelegramConnectConfig telegramConnectConfig;
|
||||
private final TelegramBotConfig telegramBotConfig;
|
||||
private EventDistributor eventDistributor;
|
||||
|
||||
public TelegramPollingBot(TelegramConnectConfig telegramConnectConfig, DefaultBotOptions defaultBotOptions) {
|
||||
public TelegramPollingBot(TelegramBotConfig telegramBotConfig, DefaultBotOptions defaultBotOptions) {
|
||||
super(defaultBotOptions);
|
||||
this.telegramConnectConfig = telegramConnectConfig;
|
||||
this.telegramBotConfig = telegramBotConfig;
|
||||
}
|
||||
|
||||
public TelegramPollingBot(TelegramConnectConfig telegramConnectConfig) {
|
||||
this.telegramConnectConfig = telegramConnectConfig;
|
||||
public TelegramPollingBot(TelegramBotConfig telegramBotConfig) {
|
||||
this.telegramBotConfig = telegramBotConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -38,12 +38,12 @@ public class TelegramPollingBot extends TelegramLongPollingBot implements Telegr
|
||||
|
||||
@Override
|
||||
public String getBotUsername() {
|
||||
return telegramConnectConfig.getBotUsername();
|
||||
return telegramBotConfig.getUsername();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBotToken() {
|
||||
return telegramConnectConfig.getBotToken();
|
||||
return telegramBotConfig.getToken();
|
||||
}
|
||||
|
||||
@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.TelegramConnectConfig;
|
||||
import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig;
|
||||
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 TelegramConnectConfig telegramConnectConfig;
|
||||
private final TelegramBotConfig telegramBotConfig;
|
||||
|
||||
public TelegramConnectBot(TelegramConnectConfig telegramConnectConfig) {
|
||||
this.telegramConnectConfig = telegramConnectConfig;
|
||||
initLongPolling(telegramConnectConfig);
|
||||
public TelegramConnectBot(TelegramBotConfig telegramBotConfig) {
|
||||
this.telegramBotConfig = telegramBotConfig;
|
||||
initLongPolling(telegramBotConfig);
|
||||
}
|
||||
|
||||
private void initLongPolling(TelegramConnectConfig telegramConnectConfig) {
|
||||
final ProxyConfig proxyConfig = telegramConnectConfig.getProxyConfig();
|
||||
private void initLongPolling(TelegramBotConfig telegramBotConfig) {
|
||||
final ProxyConfig proxyConfig = telegramBotConfig.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(telegramConnectConfig, botOptions);
|
||||
final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig, botOptions);
|
||||
|
||||
botapi = new TelegramBotsApi(DefaultBotSession.class);
|
||||
botapi.registerBot(bot);
|
||||
this.telegramBot = bot;
|
||||
} else {
|
||||
final TelegramPollingBot bot = new TelegramPollingBot(telegramConnectConfig);
|
||||
final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig);
|
||||
botapi = new TelegramBotsApi(DefaultBotSession.class);
|
||||
botapi.registerBot(bot);
|
||||
this.telegramBot = bot;
|
||||
@ -94,7 +94,7 @@ public class TelegramConnectBot implements TelegramConnect {
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return telegramConnectConfig.getBotToken();
|
||||
return telegramBotConfig.getToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,6 @@
|
||||
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.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 TelegramConnectConfig telegramConnectConfig;
|
||||
private final TelegramBotConfig telegramBotConfig;
|
||||
private EventDistributor eventDistributor;
|
||||
|
||||
public TelegramPollingBot(TelegramConnectConfig telegramConnectConfig, DefaultBotOptions defaultBotOptions) {
|
||||
public TelegramPollingBot(TelegramBotConfig telegramBotConfig, DefaultBotOptions defaultBotOptions) {
|
||||
super(defaultBotOptions);
|
||||
this.telegramConnectConfig = telegramConnectConfig;
|
||||
this.telegramBotConfig = telegramBotConfig;
|
||||
}
|
||||
|
||||
public TelegramPollingBot(TelegramConnectConfig telegramConnectConfig) {
|
||||
this.telegramConnectConfig = telegramConnectConfig;
|
||||
public TelegramPollingBot(TelegramBotConfig telegramBotConfig) {
|
||||
this.telegramBotConfig = telegramBotConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -39,12 +39,12 @@ public class TelegramPollingBot extends TelegramLongPollingBot implements Telegr
|
||||
|
||||
@Override
|
||||
public String getBotUsername() {
|
||||
return telegramConnectConfig.getBotUsername();
|
||||
return telegramBotConfig.getUsername();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBotToken() {
|
||||
return telegramConnectConfig.getBotToken();
|
||||
return telegramBotConfig.getToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,47 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
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