diff --git a/TelegramBots.wiki/abilities/Advanced.md b/TelegramBots.wiki/abilities/Advanced.md index ec2f4617..49cd2016 100644 --- a/TelegramBots.wiki/abilities/Advanced.md +++ b/TelegramBots.wiki/abilities/Advanced.md @@ -64,4 +64,15 @@ protected boolean allowContinuousText() { Please note that this may cause ability overlap. If multiple abilities can match the same command, the longest match will be taken. For example, if you have two abilities `do` and `do1`, the command `/do1` will trigger the `do1` ability. ## Statistics -AbilityBot can accrue basic statistics about the usage of your abilities and replies. Simply `enableStats()` on an Ability builder or `enableStats()` on replies to activate this feature. Once activated, you may call `/stats` and the bot will print a basic list of statistics. At the moment, AbilityBot only tracks hits. In the future, this will be enhanced to track more stats. \ No newline at end of file +AbilityBot can accrue basic statistics about the usage of your abilities and replies. Simply `enableStats()` on an Ability builder or `enableStats()` on replies to activate this feature. Once activated, you may call `/stats` and the bot will print a basic list of statistics. At the moment, AbilityBot only tracks hits. In the future, this will be enhanced to track more stats. + +## Execute code on bot registration +If you want to execute custom logic to initialize your bot, but you can't do it in the constructor, +you can override the `onRegister()` method: +``` +@Override +public void onRegister() { + super.onRegister(); + // Execute custom initialize logic here +} +``` diff --git a/TelegramBots.wiki/abilities/Bot-Testing.md b/TelegramBots.wiki/abilities/Bot-Testing.md index 4713518d..18993f46 100644 --- a/TelegramBots.wiki/abilities/Bot-Testing.md +++ b/TelegramBots.wiki/abilities/Bot-Testing.md @@ -104,6 +104,8 @@ public class ExampleBotTest { public void setUp() { // Create your bot bot = new ExampleBot(); + // Call onRegister() to initialize abilities etc. + bot.onRegister(); // Create a new sender as a mock silent = mock(SilentSender.class); // Set your bot silent sender to the mocked sender @@ -156,6 +158,7 @@ public class ExampleBotTest { // Offline instance will get deleted at JVM shutdown db = MapDBContext.offlineInstance("test"); bot = new ExampleBot(db); + bot.onRegister(); ... } @@ -180,6 +183,7 @@ public class ExampleBotTest { @Before public void setUp() { bot = new ExampleBot(db); + bot.onRegister(); sender = mock(MessageSender.class); SilentSender silent = new SilentSender(sender); // Create setter in your bot