Skip to content

Makcal/TgBotStater

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TgBotStater

A C++ library for constructing Telegram bots in compile-time!

Installation

The recommended way of connecting the library is via Conan package manager. For now it should be possible to install it via

conan create . --build=missing

Usage

Basic example of syntax

See test.cpp

Handlers

All handlers are constexpr structural lambdas or similar objects. If you need some runtime dependecies, pass them through Dependecies template type parameter of Setup and Stater's constructor argument.

Valid handler signatures:

  • from void(const EventArgs&...)
  • up to void(StateOption&, const EventArgs&..., const TgBot::Api&, const StateStorageProxy&, const Dependencies&)

Everything except for EventArgs is optional. Handlers that are not bound to a specific state can't take state parameter. For the lists of EventArgs see CallbackArgs member at event.hpp

Note

To get chatId or an event's similar target id, you'd better use StateProxy.getKey(). But it's also possible to reference message.chat->... objects in message handlers as the chat's id is used for chat/user recognition. Other handler types have similar things, but you'd better check the source code of event.hpp for that information.

Reference to a state

Important

When you put a new state object into a storage, the old one most probably dies and its reference is invalidated. Be very careful with this! See an example:

[](StateA& state, const Message& m, const StateProxy& stateManager) {
    std::println("{}", state.foo); // OK
    stateManager.put(StateB{});
    std::println("{}", state.foo); // UB, the reference is dangling
}

About

A C++ library for constructing Telegram bots in compile-time!

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •