3 #include <condition_variable>
5 #include <tgbotxx/tgbotxx.hpp>
8 #include <cpr/threadpool.h>
12 using ChatId = decltype(tgbotxx::Chat::id);
13 using UserId = decltype(tgbotxx::User::id);
25 bool middleware(
const tgbotxx::Ptr<tgbotxx::Message> &message);
28 void onStart()
override;
30 void onStop()
override;
32 void onCommand(
const tgbotxx::Ptr<tgbotxx::Message> &message)
override;
34 void onNonCommandMessage(
const tgbotxx::Ptr<tgbotxx::Message> &message)
override;
36 void onCallbackQuery(
const tgbotxx::Ptr<tgbotxx::CallbackQuery> &callbackQuery)
override;
38 void onLongPollError(
const std::string &errorMessage, tgbotxx::ErrorCode errorCode)
override;
41 void onStartCommand(
const tgbotxx::Ptr<tgbotxx::Message> message);
42 void onWatchRepoCommand(
const tgbotxx::Ptr<tgbotxx::Message> message);
43 void onUnwatchRepoCommand(
const tgbotxx::Ptr<tgbotxx::Message> message);
44 void onMyReposCommand(
const tgbotxx::Ptr<tgbotxx::Message> message);
48 void onUserBlockedBot(
const UserId userId);
55 void alertUserRepositoryStarsChange(UserId userId,
const std::string& repositoryName, std::int64_t oldStarsCount, std::int64_t newStarsCount);
57 void alertUserRepositoryWatchersChange(UserId userId,
const std::string& repositoryName, std::int64_t oldWatchersCount, std::int64_t newWatchersCount);
59 void alertUserRepositoryIssuesChange(UserId userId,
const std::string& repositoryName, std::int64_t oldIssuesCount, std::int64_t newIssuesCount);
61 void alertUserRepositoryForksChange(UserId userId,
const std::string& repositoryName, std::int64_t oldForksCount, std::int64_t newForksCount);
63 void alertUserRepositoryPullRequestsChange(UserId userId,
const std::string& repositoryName, std::int64_t oldPullsCount, std::int64_t newPullsCount);
69 void notifyAdmin(
const std::string& msg,
const std::source_location& loc = std::source_location::current());
74 void safeSendMessage(UserId userId, std::string messageText,
75 std::int32_t messageThreadId = 0,
76 const std::string &parseMode =
"",
77 const std::vector<tgbotxx::Ptr<tgbotxx::MessageEntity>> &entities = std::vector<tgbotxx::Ptr<tgbotxx::MessageEntity>>(),
78 bool disableWebPagePreview =
false,
79 bool disableNotification =
false,
80 bool protectContent =
false,
81 std::int32_t replyToMessageId = 0,
82 bool allowSendingWithoutReply =
false,
83 const tgbotxx::Ptr<tgbotxx::IReplyMarkup> &replyMarkup =
nullptr);
86 void safeSendLargeMessage(UserId userId,
const std::string &messageText);
96 UserId m_adminUserId{};
97 std::unique_ptr<GitApi> m_gitApi;
98 std::unique_ptr<std::thread> m_watchdogThread;
99 std::mutex m_sleepMutex;
100 std::atomic<bool> m_watchdogRunning;
101 std::condition_variable m_watchdogCv;
102 std::unique_ptr<cpr::ThreadPool> m_threadPool;
104 inline static constexpr std::size_t kTelegramMessageMax = 4096;
105 inline static constexpr std::size_t kMaxWatchListRepositories = 25;
virtual ~GitBot()=default
static bool isRepositoryFullURL(const std::string &str, std::string &fullname)
Returns true if str is a repository full url e.g "https://github.com/torvalds/linux".
static bool isRepositoryFullName(const std::string &str)
Returns true if str is a repository full name e.g "torvalds/linux".