From 8d6e5c80d34e5a5025e2c169defd4278166cc418 Mon Sep 17 00:00:00 2001 From: Varun <31084854+Borumer@users.noreply.github.com> Date: Mon, 20 Jul 2020 18:21:21 -0400 Subject: [PATCH 1/5] Add CommandMessage class This class adds argument functionality to a given message that a user typed, that also counts as a command --- .../bots/commandbot/CommandMessage.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/CommandMessage.java diff --git a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/CommandMessage.java b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/CommandMessage.java new file mode 100644 index 00000000..ce84f8c3 --- /dev/null +++ b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/CommandMessage.java @@ -0,0 +1,74 @@ +package org.telegram.telegrambots.extensions.bots.commandbot; + +import org.telegram.telegrambots.meta.api.objects.Message; + +/** + * @author Varun Singh + * This class adds argument functionality to a given message that a user typed, that also counts as a command + */ +public class CommandMessage { + /** + * The message associated with the command + */ + private Message commandMessage; + + /** + * Constructor for CommandMessage + * @param msg The message that represents the command that the user typed + * Preconditions: + * msg.isCommand() is true + * msg.hasText() is true + * Postcondition: + * The developer has the ability to determine which command the message is executing + */ + public CommandMessage(Message msg) { + commandMessage = msg; + } + + public Message getCommandMessage() { + return commandMessage; + } + + /** + * @return the String representation of the message for ease + */ + public String getMessageText() { + return commandMessage.getText(); + } + + /** + * Separates the given text after the command into an ordered array of arguments + * @return each argument as a String item in an array + */ + public String[] getArgs() { + return getArgsStr().split(" "); + } + + /** + * @return the text of the command WITHOUT the slash + * For example, if /language English + */ + public String getCommandText() { + return getCommandText(false).substring(1); + } + + /** + * @return The text of the message from and including the '/' to the space, + * which assumes the end of the command name and start of the command arguments + */ + public String getCommandText(boolean includeHandle) { + if (includeHandle || commandMessage.isUserMessage()) { + return getMessageText().substring(0, getMessageText().indexOf(" ")); + } else + return getMessageText().substring(0, getMessageText().indexOf("@")); + } + + /** + * Singles out the text of the message after the command + * @return all the arguments grouped in one string + */ + public String getArgsStr() { + return getMessageText().substring(getCommandText(true).length() + 1); // Skip space + } + +} From e09c13cf0e16b9b200edcd6f09527cb419280237 Mon Sep 17 00:00:00 2001 From: ekiauhce Date: Sat, 30 Jan 2021 10:20:50 +0300 Subject: [PATCH 2/5] Change "compile" to "implementation" (Gradle dependency) and "groovy" to "gradle" (language identifier) --- TelegramBots.wiki/Getting-Started.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TelegramBots.wiki/Getting-Started.md b/TelegramBots.wiki/Getting-Started.md index 0c8907ca..2759079a 100644 --- a/TelegramBots.wiki/Getting-Started.md +++ b/TelegramBots.wiki/Getting-Started.md @@ -16,8 +16,8 @@ First you need ot get the library and add it to your project. There are few poss ``` * With **Gradle**: - ```groovy - compile group: 'org.telegram', name: 'telegrambots', version: '5.0.1' + ```gradle + implementation 'org.telegram:telegrambots:5.0.1' ``` 2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots). From 37171fa94ae8b345f345c6499b024b91ebfb6506 Mon Sep 17 00:00:00 2001 From: ekiauhce Date: Sat, 30 Jan 2021 10:24:00 +0300 Subject: [PATCH 3/5] Change "compile" to "implementation" (Gradle dependency) --- README.md | 8 +++++--- telegrambots-abilities/README.md | 2 +- telegrambots-extensions/README.md | 2 +- telegrambots-spring-boot-starter/README.md | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index abb79697..eac3ce7a 100644 --- a/README.md +++ b/README.md @@ -31,12 +31,14 @@ Just import add the library to your project with one of these options: ``` + 2. Using Gradle: + ```gradle - compile "org.telegram:telegrambots:5.0.1" + implementation 'org.telegram:telegrambots:5.0.1' ``` - 2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/5.0.1) - 3. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/5.0.1) + 3. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/5.0.1) + 4. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/5.0.1) In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`. diff --git a/telegrambots-abilities/README.md b/telegrambots-abilities/README.md index 52d18fe0..e0a5ad4b 100644 --- a/telegrambots-abilities/README.md +++ b/telegrambots-abilities/README.md @@ -25,7 +25,7 @@ Usage **Gradle** ```gradle - compile "org.telegram:telegrambots-abilities:5.0.1" + implementation 'org.telegram:telegrambots-abilities:5.0.1' ``` **JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v5.0.1) diff --git a/telegrambots-extensions/README.md b/telegrambots-extensions/README.md index 5deffb45..36f1a19a 100644 --- a/telegrambots-extensions/README.md +++ b/telegrambots-extensions/README.md @@ -23,5 +23,5 @@ Just import add the library to your project with one of these options: 2. Using Gradle: ```gradle - compile "org.telegram:telegrambotsextensions:5.0.1" + implementation 'org.telegram:telegrambotsextensions:5.0.1' ``` \ No newline at end of file diff --git a/telegrambots-spring-boot-starter/README.md b/telegrambots-spring-boot-starter/README.md index 5501393d..b5b02ef1 100644 --- a/telegrambots-spring-boot-starter/README.md +++ b/telegrambots-spring-boot-starter/README.md @@ -25,7 +25,7 @@ Usage **Gradle** ```gradle - compile "org.telegram:telegrambots-spring-boot-starter:5.0.1" + implementation 'org.telegram:telegrambots-spring-boot-starter:5.0.1' ``` Motivation From 9ae03e511fbfa229a5a4d8dcfe3c8cfe8663c036 Mon Sep 17 00:00:00 2001 From: ekiauhce Date: Sat, 30 Jan 2021 10:25:08 +0300 Subject: [PATCH 4/5] Add Gradle to Usage block --- telegrambots-chat-session-bot/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/telegrambots-chat-session-bot/README.md b/telegrambots-chat-session-bot/README.md index 99446945..90071394 100644 --- a/telegrambots-chat-session-bot/README.md +++ b/telegrambots-chat-session-bot/README.md @@ -19,6 +19,12 @@ Usage ``` +**Gradle** + +```gradle + implementation 'org.telegram:telegrambots-chat-session-bot:5.0.1' +``` + Motivation ---------- Implementation of bot dialogs require saving some data about current state of conversation. From 97b427d9fa2e9c770f495b8901121bb986a1da60 Mon Sep 17 00:00:00 2001 From: ekiauhce Date: Sat, 30 Jan 2021 10:25:40 +0300 Subject: [PATCH 5/5] Change "groovy" to "gradle" (language identifier) --- TelegramBots.wiki/abilities/Simple-Example.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TelegramBots.wiki/abilities/Simple-Example.md b/TelegramBots.wiki/abilities/Simple-Example.md index ca569282..381bc03c 100644 --- a/TelegramBots.wiki/abilities/Simple-Example.md +++ b/TelegramBots.wiki/abilities/Simple-Example.md @@ -13,8 +13,8 @@ As with any Java project, you will need to set your dependencies. ``` * **Gradle** -```groovy - implementation group: 'org.telegram', name: 'telegrambots-abilities', version: '5.0.1' +```gradle + implementation 'org.telegram:telegrambots-abilities:5.0.1' ``` * [JitPack](https://jitpack.io/#rubenlagus/TelegramBots)