<commit_before>package geoLearnBot;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.telegram.telegrambots.api.methods.send.SendDocument;
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboardMarkup;
import org.telegram.telegrambots.api.objects.replykeyboard.buttons.KeyboardRow;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.exceptions.TelegramApiException;

public class GeoLearnBot extends TelegramLongPollingBot {

	@Override
	public String getBotUsername() {
		return "geoLearnBot";
	}

	@Override
	public String getBotToken() {
		return "<KEY>";
	}

	// Create a chat pseudo-db
	Map<Long, Chat> chatMap = new HashMap<>();
	// Create a chat pseudo-favorite-db

	// Fetch list of minerals
	List<Minerals> mineralsList = FetchMinerals.fetchMinerals();

	public static int randomNumberPicker(List<Minerals> mineralsList) {
		int random = new Random().nextInt(mineralsList.size());
		return random;
	}

	@Override
	public void onUpdateReceived(Update update) {
		// check if the update has a message and the message has text
		if (update.hasMessage() && update.getMessage().hasText()) {

			if (chatMap.containsKey(update.getMessage().getChatId()) == false) {
				List<Integer> seenMineral = new ArrayList<>();
				List<Integer> favoriteMineral = new ArrayList<>();
				Chat newChat = new Chat(update.getMessage().getChatId(), seenMineral, favoriteMineral);
				chatMap.put(newChat.getId(), newChat);
			}

			// =============================== Main Options
			// ============================================================

			// /start || 1
			if (update.getMessage().getText().equals("/start") || update.getMessage().getText().equals("1")) {
				SendMessage message = new SendMessage().setChatId(update.getMessage().getChatId())
						.setText(
						// @formatter:off
								"*You can discover this Bot by picking a number or with the /menu to the right of your text input*"
								+ "\n\n*1*. /start Show this start menu"
								+ "\n*2*. /help Need help ?"
								+ "\n*3*. /random See a random mineral"
								+ "\n*4*. /collection See your mineral collection"
//								+ "\n*X*. /filter Filter minerals (sorry, nothing here yet...)"
//								+ "\n*X*. /search Search for a specific mineral (sorry, nothing here yet...)"
//								+ "\n*X*. /compare Compare two minerals (sorry, nothing here yet...)"
								+ "\n*5*. /list Choose from a selection of minerals"
								+ "\n*6*. /play Test your knowledge (sorry, nothing here yet...)"
								+ "\n*7*. /glossary Glossary"								
								+ "\n*8*. /acknowledgements Acknowledgements")
								// @formatter:on
						.enableMarkdown(true);
				try {
					sendMessage(message); // Call method to send message
				} catch (TelegramApiException e) {
					e.printStackTrace();
				}
			}

			// /help || 2
			if (update.getMessage().getText().equals("/help") || update.getMessage().getText().equals("2")) {
				String winky = "\ud83d\ude09";
				SendMessage message = new SendMessage().setChatId(update.getMessage().getChatId())
						.setText(
						// @formatter:off
								"*Here is what this bot can do:*"
								+ "\n\nType \"/\" for main options:"
								+ "\n/start, /help, /random, /collection, /list, /play, /glossary or /acknowledgements "
								+ "\n\nYou can also use 1, 2, 3, 4, 5 and 6 to navigate the main options, have fun !"
								+ "\n\n*Errors:* if you keep asking for more minerals and they're not coming, well... why "
								+ "don't you read the text and wait a little " + winky + " ?")
								// @formatter:on
						.enableMarkdown(true);
				try {
					sendMessage(message); // Call method to send message
				} catch (TelegramApiException e) {
					e.printStackTrace();
				}
			}

			// /random || 3
			if (update.getMessage().getText().equals("/random") || update.getMessage().getText().equals("3")) {

				KeyboardRow keyboardSingleButton = new KeyboardRow();
				keyboardSingleButton.add(0, "Add to my collection!");

				List<KeyboardRow> keyboard = new ArrayList<>();
				keyboard.add(keyboardSingleButton);

				ReplyKeyboardMarkup replyMarkup = new ReplyKeyboardMarkup();
				replyMarkup.setKeyboard(keyboard).setOneTimeKeyboad(true).setResizeKeyboard(true);

				int random = randomNumberPicker(mineralsList);
				int mineralToDisplay = -1;
				while (chatMap.get(update.getMessage().getChatId()).getSeenMineral().contains(random) == true) {
					random = randomNumberPicker(mineralsList);
				}
				chatMap.get(update.getMessage().getChatId()).getSeenMineral().add(random);
				mineralToDisplay = random;

				SendMessage message = new SendMessage().setChatId(update.getMessage().getChatId())
						.setText(
								// @formatter:off
								mineralsList.get(mineralToDisplay).toString())						
						.enableHtml(true)
						.setReplyMarkup(replyMarkup);
								// @formatter:on
				try {
					sendMessage(message);
				} catch (TelegramApiException e) {
					e.printStackTrace();
				}

			}

			// /Add to my collection!
			if (update.getMessage().getText().equals("Add to my collection!")) {

				int seenArraySize = chatMap.get(update.getMessage().getChatId()).getSeenMineral().size();
				int lastIntInSeenArray = chatMap.get(update.getMessage().getChatId()).getSeenMineral()
						.get(seenArraySize - 1);

				if (chatMap.get(update.getMessage().getChatId()).getFavoriteMineral()
						.contains(lastIntInSeenArray) == false) {
					chatMap.get(update.getMessage().getChatId()).getFavoriteMineral().add(lastIntInSeenArray);
					System.out.println("chatMap after adding mineral: " + chatMap);
				} else {
					SendMessage message = new SendMessage().setChatId(update.getMessage().getChatId())
							// @formatter:off
							.setText(
									"Sorry "
									+ update.getMessage().getChat().getFirstName()
									+ ", that mineral is already in your collection."
									)
							.enableMarkdown(true);
							// @formatter:on
					System.out.println("chatMap after NOT adding mineral: " + chatMap);
					try {
						sendMessage(message);
					} catch (TelegramApiException e) {
						e.printStackTrace();
					}
				}
			}

			// /Remove from my collection !

			// /Show my collection || 4
			if (update.getMessage().getText().equals("collection")) {
				// System.out.println(chatMap.get(update.getMessage().getChatId()).getFavoriteMineral());
				SendMessage message = new SendMessage().setChatId(update.getMessage().getChatId())
						// @formatter:off
						.setText(
								mineralsList.get(0).toStringSimple()
								);
						// @formatter:on<commit_msg>working on remove from collection<commit_after>package geoLearnBot;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.telegram.telegrambots.api.methods.send.SendDocument;
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboardMarkup;
import org.telegram.telegrambots.api.objects.replykeyboard.buttons.KeyboardRow;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.exceptions.TelegramApiException;

public class GeoLearnBot extends TelegramLongPollingBot {

	@Override
	public String getBotUsername() {
		return "geoLearnBot";
	}

	@Override
	public String getBotToken() {
		return "<KEY>";
	}

	// Create a chat pseudo-db
	Map<Long, Chat> chatMap = new HashMap<>();
	// Create a chat pseudo-favorite-db

	// Fetch list of minerals
	List<Minerals> mineralsList = FetchMinerals.fetchMinerals();

	public static int randomNumberPicker(List<Minerals> mineralsList) {
		int random = new Random().nextInt(mineralsList.size());
		return random;
	}

	@Override
	public void onUpdateReceived(Update update) {
		// check if the update has a message and the message has text
		if (update.hasMessage() && update.getMessage().hasText()) {

			if (chatMap.containsKey(update.getMessage().getChatId()) == false) {
				List<Integer> seenMineral = new ArrayList<>();
				List<Integer> favoriteMineral = new ArrayList<>();
				Chat newChat = new Chat(update.getMessage().getChatId(), seenMineral, favoriteMineral);
				chatMap.put(newChat.getId(), newChat);
			}

			// =============================== Main Options
			// ============================================================

			// /start || 1
			if (update.getMessage().getText().equals("/start") || update.getMessage().getText().equals("1")) {
				SendMessage message = new SendMessage().setChatId(update.getMessage().getChatId())
						.setText(
						// @formatter:off
								"*You can discover this Bot by picking a number or with the /menu to the right of your text input*"
								+ "\n\n*1*. /start Show this start menu"
								+ "\n*2*. /help Need help ?"
								+ "\n*3*. /random See a random mineral"
								+ "\n*4*. /collection See your mineral collection"
//								+ "\n*X*. /filter Filter minerals (sorry, nothing here yet...)"
//								+ "\n*X*. /search Search for a specific mineral (sorry, nothing here yet...)"
//								+ "\n*X*. /compare Compare two minerals (sorry, nothing here yet...)"
								+ "\n*5*. /list Choose from a selection of minerals"
								+ "\n*6*. /play Test your knowledge (sorry, nothing here yet...)"
								+ "\n*7*. /glossary Glossary"								
								+ "\n*8*. /acknowledgements Acknowledgements")
								// @formatter:on
						.enableMarkdown(true);
				try {
					sendMessage(message); // Call method to send message
				} catch (TelegramApiException e) {
					e.printStackTrace();
				}
			}

			// /help || 2
			if (update.getMessage().getText().equals("/help") || update.getMessage().getText().equals("2")) {
				String winky = "\ud83d\ude09";
				SendMessage message = new SendMessage().setChatId(update.getMessage().getChatId())
						.setText(
						// @formatter:off
								"*Here is what this bot can do:*"
								+ "\n\nType \"/\" for main options:"
								+ "\n/start, /help, /random, /collection, /list, /play, /glossary or /acknowledgements "
								+ "\n\nYou can also use 1, 2, 3, 4, 5 and 6 to navigate the main options, have fun !"
								+ "\n\n*Errors:* if you keep asking for more minerals and they're not coming, well... why "
								+ "don't you read the text and wait a little " + winky + " ?")
								// @formatter:on
						.enableMarkdown(true);
				try {
					sendMessage(message); // Call method to send message
				} catch (TelegramApiException e) {
					e.printStackTrace();
				}
			}

			// /random || 3
			if (update.getMessage().getText().equals("/random") || update.getMessage().getText().equals("3")) {

				KeyboardRow keyboardFavoriteActions = new KeyboardRow();
				keyboardFavoriteActions.add(0, "Add to my collection!");
				keyboardFavoriteActions.add(1, "Remove from my collection!");

				List<KeyboardRow> keyboard = new ArrayList<>();
				keyboard.add(keyboardFavoriteActions);

				ReplyKeyboardMarkup replyMarkup = new ReplyKeyboardMarkup();
				replyMarkup.setKeyboard(keyboard).setOneTimeKeyboad(true).setResizeKeyboard(true);

				int random = randomNumberPicker(mineralsList);
				int mineralToDisplay = -1;
				while (chatMap.get(update.getMessage().getChatId()).getSeenMineral().contains(random) == true) {
					random = randomNumberPicker(mineralsList);
				}
				chatMap.get(update.getMessage().getChatId()).getSeenMineral().add(random);
				mineralToDisplay = random;

				SendMessage message = new SendMessage().setChatId(update.getMessage().getChatId())
						.setText(
								// @formatter:off
								mineralsList.get(mineralToDisplay).toString())						
						.enableHtml(true)
						.setReplyMarkup(replyMarkup);
								// @formatter:on
				try {
					sendMessage(message);
				} catch (TelegramApiException e) {
					e.printStackTrace();
				}

			}

			// /Add to my collection!
			if (update.getMessage().getText().equals("Add to my collection!")) {
				int seenArraySize = chatMap.get(update.getMessage().getChatId()).getSeenMineral().size();
				int lastIntInSeenArray = chatMap.get(update.getMessage().getChatId()).getSeenMineral()
						.get(seenArraySize - 1);
				if (chatMap.get(update.getMessage().getChatId()).getFavoriteMineral()
						.contains(lastIntInSeenArray) == false) {
					chatMap.get(update.getMessage().getChatId()).getFavoriteMineral().add(lastIntInSeenArray);
					System.out.println("chatMap after adding mineral: " + chatMap);
					SendMessage message = new SendMessage().setChatId(update.getMessage().getChatId())
							// @formatter:off
							.setText(
									"There you go "
									+ update.getMessage().getChat().getFirstName()
									+ ", "
									+ mineralsList.get(lastIntInSeenArray).getTitle()
									+ " has been added to your collection."
									)
							.enableMarkdown(true);
							// @formatter:on
					System.out.println("chatMap after NOT adding mineral: " + chatMap);
					try {
						sendMessage(message);
					} catch (TelegramApiException e) {
						e.printStackTrace();
					}
				} else {
					SendMessage message = new SendMessage().setChatId(update.getMessage().getChatId())
							// @formatter:off
							.setText(
									"Sorry "
									+ update.getMessage().getChat().getFirstName()
									+ ", "
									+ mineralsList.get(lastIntInSeenArray).getTitle()
									+ " is already in your collection."
									)
							.enableMarkdown(true);
							// @formatter:on
					System.out.println("chatMap after NOT adding mineral: " + chatMap);
					try {
						sendMessage(message);
					} catch (TelegramApiException e) {
						e.printStackTrace();
					}
				}
			}

			// /Remove from my collection !
			if (update.getMessage().getText().equals("Remove from my collection!")) {
				// get int of mineral last seen
				int seenArraySize = chatMap.get(update.getMessage().getChatId()).getSeenMineral().size();
				int lastIntInSeenArray = chatMap.get(update.getMessage().getChatId()).getSeenMineral()
						.get(seenArraySize - 1);
				// check if in favorites
				if (chatMap.get(update.getMessage().getChatId()).getFavoriteMineral()
						.contains(lastIntInSeenArray) == true) {
					chatMap.get(update.getMessage().getChatId()).getFavoriteMineral().remove(lastIntInSeenArray);
					SendMessage message = new SendMessage().setChatId(update.getMessage().getChatId())
							// @formatter:off
							.setText(
									"There you go  "
									+ update.getMessage().getChat().getFirstName()
									+ ", "
									+ "THAT MINERAL"
									+ " has been removed from your collection."
									)
							.enableMarkdown(true);
							// @formatter:on
					System.out.println("chatMap after removing mineral: " + chatMap);
					try {
						sendMessage(message);
					} catch (TelegramApiException e) {
						e.printStackTrace();
					}
				} else {
					SendMessage message = new SendMessage().setChatId(update.getMessage().getChatId())
							// @formatter:off
							.setText(
									"Sorry "
									+ update.getMessage().getChat().getFirstName()
									+ ", I can't remove "
									+ "THAT MINERAL"
									+ " because it isn't yet in your collection."
									)
							.enableMarkdown(true);
							// @formatter:on
					System.out.println("chatMap after NOT removing mineral: " + chatMap);
					try {
						sendMessage(message);
					} catch (TelegramApiException e) {
						e.printStackTrace();
					}
				}
			}

			// /Show my collection || 4
			if (update.getMessage().getText().equals("collection")) {
				// System.out.println(chatMap.get(update.getMessage().getChatId()).getFavoriteMineral());
				SendMessage message = new SendMessage().setChatId(update.getMessage().getChatId())
						// @formatter:off
						.setText(
								mineralsList.get(0).toStringSimple()
								);
						// @formatter:on
{'fraction_non_alphanumeric': 0.15264310290897717, 'fraction_numerical': 0.003753518923991242, 'mean_word_length': 3.098974358974359, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2134191', 'n_tokens_mistral': 6243, 'n_tokens_neox': 4696, 'n_words': 1034}