summaryrefslogtreecommitdiff
path: root/src/main/java/files/Bot.java
diff options
context:
space:
mode:
authormavlonerkinboev <mavlonbek.ibragimov007@gmail.com>2021-07-25 18:15:07 +0500
committermavlonerkinboev <mavlonbek.ibragimov007@gmail.com>2021-07-25 18:15:07 +0500
commitaffa90bfec4d21c27702c04c4e1d2450e9201baa (patch)
tree40e2f6277011ca639a87d51ac7c88bd5403b69e4 /src/main/java/files/Bot.java
parent93a0320b6f9693b5aaf8c645bc6572634da580b6 (diff)
seventeenth commit
Diffstat (limited to 'src/main/java/files/Bot.java')
-rw-r--r--src/main/java/files/Bot.java94
1 files changed, 48 insertions, 46 deletions
diff --git a/src/main/java/files/Bot.java b/src/main/java/files/Bot.java
index dcbb64a..c1cff05 100644
--- a/src/main/java/files/Bot.java
+++ b/src/main/java/files/Bot.java
@@ -3,90 +3,92 @@ package files;
import com.pengrad.telegrambot.TelegramBot;
import com.pengrad.telegrambot.UpdatesListener;
import com.pengrad.telegrambot.model.CallbackQuery;
-import com.pengrad.telegrambot.model.Update;
+import com.pengrad.telegrambot.model.request.ParseMode;
import com.pengrad.telegrambot.request.SendMessage;
import com.pengrad.telegrambot.request.SendPhoto;
-import com.pengrad.telegrambot.request.SendVideo;
-import com.pengrad.telegrambot.response.SendResponse;
-import java.io.FileInputStream;
-import java.io.IOException;
+import java.io.*;
import java.util.Properties;
+// TODO: 7/25/21 Добавить поиск Аниме OVA, аниме по жанру, Дорамы, случайное аниме
+
public class Bot {
- public static void main(String[] args) throws IOException {
- // Loading properties
- Properties properties = new Properties();
- properties.load(new FileInputStream("app.properties"));
- // Creating telegram bot
- TelegramBot telegramBot = new TelegramBot(properties.getProperty("TELEGRAM_TOKEN"));
+ public static Properties properties = loadProperties(new File("app.properties"));
+ public static TelegramBot telegramBot = new TelegramBot(properties.getProperty("TELEGRAM_TOKEN"));
+ public static FileWriter log;
+
+ public static void main(String[] args) throws IOException {
+ log = new FileWriter("log.txt", false);
- // Setting updates listener
telegramBot.setUpdatesListener(updates -> {
updates.forEach(update -> {
if (UserCallbackQuery.checkIfNotNull(update.callbackQuery())) {
- UserCallbackQuery.setInformation(update.callbackQuery());
- UserCallbackQuery.execute(telegramBot);
- } else if (UserMessage.checkIfNotNull(update.message())) {
- UserMessage.setInformation(update.message());
- UserMessage.execute(telegramBot, update);
+ try {
+ UserCallbackQuery.execute(update.callbackQuery());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (UserMessage.checkIfNotNull(update.message())) {
+ try {
+ UserMessage.execute(update.message());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
});
return UpdatesListener.CONFIRMED_UPDATES_ALL;
});
}
- public static void showAnimeAtMainMenu(TelegramBot telegramBot, Update update, byte index, String url, String typeOfAnime) {
+ public static Properties loadProperties(File file) {
+ Properties properties = new Properties();
+ try (FileInputStream fis = new FileInputStream(file)) {
+ properties.load(fis);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return properties;
+ }
+
+ public static void sendAnimeAtMainMenu(String url, String typeOfAnime) {
Anime[] anime = new Anime[28];
+ byte index = Anime.indexOfAnime;
try {
- anime = Parser.getAnimeAtMainMenu(url);
+ anime = Parse.getAnimeAtMainMenu(url, typeOfAnime);
} catch (IOException e) {
e.printStackTrace();
}
Anime.setList(anime);
- telegramBot.execute(new SendPhoto(UserMessage.chatId, anime[index].getImage()).caption(anime[index].showInfo()).replyMarkup(MyKeyboard.getCarousel(typeOfAnime)));
+ telegramBot.execute(new SendPhoto(UserMessage.chatId, anime[index].getImage()).caption(anime[index].showInfo()).parseMode(ParseMode.HTML).replyMarkup(MyKeyboard.getCarousel(typeOfAnime)));
}
- public static void showAnimeAtMainMenuByCallBackQuery(TelegramBot telegramBot, CallbackQuery callbackQuery, byte index, String typeOfAnime, Anime[] list) {
- telegramBot.execute(new SendPhoto(callbackQuery.message().chat().id(), list[index].getImage()).caption(list[index].showInfo()).replyMarkup(MyKeyboard.getCarousel(typeOfAnime)));
+ public static void sendAnimeAtMainMenuByCallBackQuery(String typeOfAnime) {
+ Anime[] anime = Anime.list;
+ byte index = Anime.indexOfAnime;
+ telegramBot.execute(new SendPhoto(UserCallbackQuery.chatId, anime[index].getImage()).caption(anime[index].showInfo()).parseMode(ParseMode.HTML).replyMarkup(MyKeyboard.getCarousel(typeOfAnime)));
}
- public static void showSearchedAnime(TelegramBot telegramBot, Update update, byte index, String searchedAnime) throws IOException {
- byte animeAtSearchSize = Parser.getAnimeAtSearchSize("https://animego.org/search/all?q=" + searchedAnime);
+ public static void sendSearchedAnime(byte index, String searchedAnime) throws IOException {
+ byte animeAtSearchSize = Parse.getAnimeAtSearchSize("https://animego.org/search/all?q=" + searchedAnime);
if (animeAtSearchSize > 0) {
- Anime[] anime = new Anime[Parser.getAnimeAtSearchSize("https://animego.org/search/all?q=" + searchedAnime)];
+ Anime[] anime = new Anime[Parse.getAnimeAtSearchSize("https://animego.org/search/all?q=" + searchedAnime)];
try {
- anime = Parser.getAnimeAtSearch("https://animego.org/search/all?q=" + searchedAnime);
+ anime = Parse.getAnimeAtSearch("https://animego.org/search/all?q=" + searchedAnime);
} catch (IOException e) {
e.printStackTrace();
}
Anime.setSearchedAnimeSize(animeAtSearchSize);
Anime.setList(anime);
- telegramBot.execute(new SendPhoto(update.message().chat().id(), anime[index].getImage()).caption(anime[index].showInfo()).replyMarkup(MyKeyboard.getCarousel("SearchedAnime")));
+ telegramBot.execute(new SendPhoto(UserMessage.chatId, anime[index].getImage()).caption(anime[index].showInfo()).parseMode(ParseMode.HTML).replyMarkup(MyKeyboard.getCarousel("SearchedAnime")));
} else {
- telegramBot.execute(new SendMessage(update.message().chat().id(), "Прости, но я не смог найти аниме с таким названием...\nДавай поищем другое аниме!"));
+ telegramBot.execute(new SendMessage(UserMessage.chatId, "Прости, но я не смог найти аниме с таким названием...\nДавай поищем другое аниме!"));
Anime.setIsSearchingAnAnime(true);
}
}
- public static void showSearchedAnimeByCallBackQuery(TelegramBot telegramBot, CallbackQuery callbackQuery, byte index, Anime[] list) {
- telegramBot.execute(new SendPhoto(callbackQuery.message().chat().id(), list[index].getImage()).caption(list[index].showInfo()).replyMarkup(MyKeyboard.getCarousel("SearchedAnime")));
- }
-
- public static void showRecentlyAddedAnime(TelegramBot telegramBot, Update update, byte index) throws IOException {
- showAnimeAtMainMenu(telegramBot, update, index, "https://anime.anidub.life/anime/anime_ongoing/", "RecentlyAddedAnime");
- }
-
- public static void showRecentlyAddedAnimeByCallBackQuery(TelegramBot telegramBot, CallbackQuery callbackQuery, byte index) {
- showAnimeAtMainMenuByCallBackQuery(telegramBot, callbackQuery, index,"RecentlyAddedAnime", Anime.getList());
- }
-
- public static void showRecentlyReleasedAnime(TelegramBot telegramBot, Update update, byte index) throws IOException {
- showAnimeAtMainMenu(telegramBot, update, index, "https://animego.org/anime?sort=a.startDate&direction=desc", "RecentlyReleasedAnime");
- }
-
- public static void showRecentlyReleasedAnimeByCallBackQuery(TelegramBot telegramBot, CallbackQuery callbackQuery, byte index) {
- showAnimeAtMainMenuByCallBackQuery(telegramBot, callbackQuery, index,"RecentlyReleasedAnime", Anime.getList());
+ public static void sendSearchedAnimeByCallBackQuery(CallbackQuery callbackQuery, byte index, Anime[] list) {
+ telegramBot.execute(new SendPhoto(callbackQuery.message().chat().id(), list[index].getImage()).caption(list[index].showInfo()).parseMode(ParseMode.HTML).replyMarkup(MyKeyboard.getCarousel("SearchedAnime")));
}
}