diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java index 317f222f..12073632 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java @@ -128,6 +128,27 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability initStats(); } + /** + * @return the database of this bot + */ + public DBContext db() { + return db; + } + + /** + * @return the message sender for this bot + */ + public MessageSender sender() { + return sender; + } + + /** + * @return the silent sender for this bot + */ + public SilentSender silent() { + return silent; + } + /** * @return the map of */ @@ -437,7 +458,7 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability Update update = trio.a(); User user = AbilityUtils.getUser(update); - return Pair.of(newContext(update, user, getChatId(update), trio.c()), trio.b()); + return Pair.of(newContext(update, user, getChatId(update), this, trio.c()), trio.b()); } boolean checkBlacklist(Update update) { diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/MessageContext.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/MessageContext.java index c9fc2398..fc650f85 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/MessageContext.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/MessageContext.java @@ -2,6 +2,7 @@ package org.telegram.abilitybots.api.objects; import com.google.common.base.MoreObjects; import com.google.common.base.Objects; +import org.telegram.abilitybots.api.bot.BaseAbilityBot; import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.api.objects.User; @@ -19,16 +20,18 @@ public class MessageContext { private final Long chatId; private final String[] arguments; private final Update update; + private final BaseAbilityBot bot; - private MessageContext(Update update, User user, Long chatId, String[] arguments) { + private MessageContext(Update update, User user, Long chatId, BaseAbilityBot bot, String[] arguments) { this.user = user; this.chatId = chatId; this.update = update; + this.bot = bot; this.arguments = arguments; } - public static MessageContext newContext(Update update, User user, Long chatId, String... arguments) { - return new MessageContext(update, user, chatId, arguments); + public static MessageContext newContext(Update update, User user, Long chatId, BaseAbilityBot bot, String... arguments) { + return new MessageContext(update, user, chatId, bot, arguments); } /** @@ -45,6 +48,13 @@ public class MessageContext { return chatId; } + /** + * @return the bot in which this message is executed + */ + public BaseAbilityBot bot() { + return bot; + } + /** * If there's no message in the update, then this will an empty array. * diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java index f6823690..54ff772e 100644 --- a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java +++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java @@ -503,7 +503,7 @@ public class AbilityBotTest { mockUser(update, message, USER); Pair actualPair = bot.getContext(trio); - Pair expectedPair = Pair.of(newContext(update, USER, GROUP_ID, TEXT), ability); + Pair expectedPair = Pair.of(newContext(update, USER, GROUP_ID, bot, TEXT), ability); assertEquals(expectedPair, actualPair, "Unexpected result when fetching for context"); } @@ -619,7 +619,7 @@ public class AbilityBotTest { when(update.hasMessage()).thenReturn(true); when(update.getMessage()).thenReturn(message); when(message.hasText()).thenReturn(true); - MessageContext creatorCtx = newContext(update, CREATOR, GROUP_ID); + MessageContext creatorCtx = newContext(update, CREATOR, GROUP_ID, bot); defaultAbs.commands().action().accept(creatorCtx); @@ -636,7 +636,7 @@ public class AbilityBotTest { when(update.getMessage()).thenReturn(message); when(message.hasText()).thenReturn(true); - MessageContext userCtx = newContext(update, USER, GROUP_ID); + MessageContext userCtx = newContext(update, USER, GROUP_ID, bot); defaultAbs.commands().action().accept(userCtx); diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/TestUtils.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/TestUtils.java index 19c531da..bf1c3479 100644 --- a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/TestUtils.java +++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/TestUtils.java @@ -43,6 +43,7 @@ public final class TestUtils { static MessageContext mockContext(User user, long groupId, String... args) { Update update = mock(Update.class); Message message = mock(Message.class); + BaseAbilityBot bot = mock(BaseAbilityBot.class); when(update.hasMessage()).thenReturn(true); when(update.getMessage()).thenReturn(message); @@ -50,7 +51,7 @@ public final class TestUtils { when(message.getFrom()).thenReturn(user); when(message.hasText()).thenReturn(true); - return newContext(update, user, groupId, args); + return newContext(update, user, groupId, bot, args); } @NotNull