Skip to content

Commit

Permalink
Update TgLongPoll with new method
Browse files Browse the repository at this point in the history
- Add add TEST entry to add_my_executable function
  • Loading branch information
Royna2544 committed Nov 18, 2024
1 parent e509332 commit 0f9e444
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/linux_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ jobs:
- name: Run Tests
run: |
./build/bin/TgBot++_test
cd build
ctest
3 changes: 2 additions & 1 deletion .github/workflows/macos_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ jobs:
- name: Run Tests
run: |
./build/bin/TgBot++_test
cd build
ctest
File renamed without changes.
3 changes: 2 additions & 1 deletion .github/workflows/windows_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ jobs:
- name: Run Tests
run: |
./build/bin/TgBot++_test.exe
cd build
ctest
13 changes: 9 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ endfunction(add_my_library)

function(add_my_executable)
cmake_parse_arguments(TGBOT_EXE
"NO_PREFIX;OPTIONAL" # Options
"NO_PREFIX;OPTIONAL;TEST" # Options
"NAME" # One-value keywords
"SRCS;LIBS;LIBS_WIN32" # Multiple-value keywords
${ARGN}
Expand All @@ -234,14 +234,19 @@ function(add_my_executable)
if (DIRTY_ABSEIL_FIX)
list(APPEND TGBOT_EXE_SRCS ${CMAKE_SOURCE_DIR}/src/logging/log_message.cc)
endif()
set(TGBOT_EXE_NAME_BAK ${TGBOT_EXE_NAME})
if (NOT TGBOT_EXE_NO_PREFIX)
set(TGBOT_EXE_NAME ${PROJECT_NAME}_${TGBOT_EXE_NAME})
endif()
if (TGBOT_EXE_OPTIONAL)
add_executable(${TGBOT_EXE_NAME} EXCLUDE_FROM_ALL ${TGBOT_EXE_SRCS})
else()
add_executable(${TGBOT_EXE_NAME} ${TGBOT_EXE_SRCS})
install(TARGETS ${TGBOT_EXE_NAME} DESTINATION bin)
if (TGBOT_EXE_TEST)
add_test(NAME TestSuite_${TGBOT_EXE_NAME_BAK} COMMAND ${TGBOT_EXE_NAME})
else()
install(TARGETS ${TGBOT_EXE_NAME} DESTINATION bin)
endif()
endif()
add_sanitizers(${TGBOT_EXE_NAME})
target_link_libraries(${TGBOT_EXE_NAME} TgBotLogInit absl::log ${TGBOT_EXE_LIBS})
Expand Down Expand Up @@ -376,7 +381,7 @@ add_my_library(
src/socket/interface/impl/backends/ServerBackend.cpp
src/socket/interface/impl/backends/ServerBackend_${TARGET_VARIANT}.cpp
LIBS TgBot TgBotUtils TgBotWeb TgBotDBImpl absl::status TgBotRandom TgBot_restartfmt_parser
TgBotPPImpl_shared_deps TgBotStringRes ${CMAKE_DL_LIBS} TgBotSocket JsonCpp::JsonCpp
TgBotPPImpl_shared_deps TgBotStringRes ${CMAKE_DL_LIBS} TgBotSocket JsonCpp::JsonCpp TgBotsighandler
STATIC
)
#####################################################################
Expand All @@ -385,7 +390,7 @@ add_my_library(
add_my_executable(
NAME main
SRCS src/main.cpp
LIBS TgBotPPImpl TgBotDBLoading TgBotsighandler TgBot_restartfmt_parser fruit
LIBS TgBotPPImpl TgBotDBLoading TgBot_restartfmt_parser fruit
)

if (UNIX)
Expand Down
11 changes: 6 additions & 5 deletions src/api/TgBotApiImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,16 @@ void TgBotApiImpl::removeInlineQueryKeyboard(const std::string_view key) {
}

void TgBotApiImpl::startPoll() {
LOG(INFO) << "Bot username: " << getBotUser()->username.value_or("Unknown");
LOG(INFO) << "Bot username: " << getBotUser()->username.value();
// Deleting webhook
getApi().deleteWebhook();

TgLongPoll longPoll(_bot, 100, 10,
{"message", "inline_query", "callback_query",
"my_chat_member", "chat_member", "chat_join_request"});
auto* longPoll = _bot.createLongPoll(
100, 10,
{"message", "inline_query", "callback_query", "my_chat_member",
"chat_member", "chat_join_request"});
while (!SignalHandler::isSignaled()) {
longPoll.start();
longPoll->start();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/command_modules/alive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ DECLARE_COMMAND_HANDLER(alive) {
{"_commitid_", data.commitid},
{"_commitmsg_", splitMsg.front()},
{"_botname_", api->getBotUser()->firstName},
{"_botusername_", api->getBotUser()->username.value()}
{"_botusername_", api->getBotUser()->username.value_or("unknown")}
});
});
const auto info = provider->database->queryMediaInfo("alive");
Expand Down
2 changes: 1 addition & 1 deletion src/include/trivial_helpers/_tgbot.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ constexpr auto fmt::formatter<User::Ptr>::parse(ParseContext& ctx) {
template <typename FormatContext>
auto fmt::formatter<User::Ptr>::format(const User::Ptr& user,
FormatContext& ctx) const {
if (!user->lastName.has_value()) {
if (user->lastName.has_value()) {
return fmt::format_to(ctx.out(), "{} {} (id: {})", user->firstName,
user->lastName.value(), user->id);
}
Expand Down
15 changes: 4 additions & 11 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ add_my_executable(
GTest::gtest
GTest::gmock
TgBotPPImpl fruit
OPTIONAL
TEST
)

# Add the test executable to CTest
add_test(NAME TestSuite COMMAND TgBot++_test)

add_my_executable(
NAME test_database
SRCS
Expand All @@ -34,10 +31,8 @@ add_my_executable(
LIBS
GTest::gtest
TgBotDBImpl
OPTIONAL
TEST
)
# Add the test executable to CTest
add_test(NAME TestSuiteDatabase COMMAND TgBot++_test_database)

add_my_executable(
NAME test_socketdatahandler
Expand All @@ -49,7 +44,5 @@ add_my_executable(
GTest::gmock
TgBotPPImpl
fruit
OPTIONAL
)
# Add the test executable to CTest
add_test(NAME TestSuiteSocketDataHandler COMMAND TgBot++_test_socketdatahandler)
TEST
)
3 changes: 2 additions & 1 deletion tests/commands/AliveCmdTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class AliveCommandTest : public CommandTestBase {

TEST_F(AliveCommandTest, hasAliveMediaName) {
setCommandExtArgs();
const auto botUser = std::make_shared<User>();
auto botUser = std::make_shared<User>();
botUser->username = "ALALALASL";

// Would call two times for username, nickname
ON_CALL(*botApi, getBotUser_impl()).WillByDefault(Return(botUser));
Expand Down
4 changes: 2 additions & 2 deletions tests/commands/CommandModulesTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ class CommandTestBase : public CommandModulesTest {
void setCommandExtArgs(
const std::initializer_list<std::string_view>& command) {
setCommandExtArgs();
defaultProvidedMessage->text +=
(*defaultProvidedMessage->text) +=
fmt::format("{}", fmt::join(command, " "));
}
void setCommandExtArgs() {
defaultProvidedMessage->text = "/" + name;
defaultProvidedMessage->entities[0]->length =
defaultProvidedMessage->text.size();
defaultProvidedMessage->text->size();
}
void execute() {
module->_module->function(
Expand Down

0 comments on commit 0f9e444

Please sign in to comment.