com.litongjava.tio.utils.telegram.Telegram Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tio-utils Show documentation
Show all versions of tio-utils Show documentation
t-io is a aio framework for java
package com.litongjava.tio.utils.telegram;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
public class Telegram {
private static final ConcurrentHashMap botMap = new ConcurrentHashMap<>();
private static TelegramBot mainBot = null;
// Private constructor to prevent instantiation
private Telegram() {
}
public static void clearBot() {
botMap.clear();
}
public static void addBot(TelegramBot bot) {
if (bot == null) {
throw new IllegalArgumentException("Bot can not be null");
}
if (botMap.containsKey(bot.getName())) {
throw new IllegalArgumentException("The bot name already exists");
}
botMap.put(bot.getName(), bot);
if (mainBot == null)
mainBot = bot;
}
public static TelegramBot use() {
return mainBot;
}
public static TelegramBot use(String botName) {
return botMap.get(botName);
}
public static void setMainBot(String botName) {
if (!botMap.containsKey(botName))
throw new IllegalArgumentException("The bot does not exist: " + botName);
mainBot = botMap.get(botName);
}
public static void config(Consumer botConfig) {
if (mainBot == null)
throw new IllegalStateException("Main bot is not set");
botConfig.accept(mainBot);
}
public static void config(String botName, Consumer botConfig) {
TelegramBot bot = botMap.get(botName);
if (bot == null)
throw new IllegalArgumentException("The bot does not exist: " + botName);
botConfig.accept(bot);
}
}