diff --git a/src/CompilerInTelegram.cpp b/src/CompilerInTelegram.cpp index 8f725b42..e18ee17f 100644 --- a/src/CompilerInTelegram.cpp +++ b/src/CompilerInTelegram.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include diff --git a/src/main.cpp b/src/main.cpp index 0a144b28..cb15f739 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -285,6 +286,8 @@ int main(void) { bot.getApi().deleteMessage(message->chat->id, message->messageId); } catch (const TgBot::TgException &) { // bot is not admin. nothing it can do + WARN_ONCE(1, "bot is not admin in chat " LONGFMT ", cannot use decho!", + message->chat->id); return; } if (hasExtArgs(message)) { diff --git a/src/utils/LinuxPort.h b/src/utils/LinuxPort.h new file mode 100644 index 00000000..2759a2ed --- /dev/null +++ b/src/utils/LinuxPort.h @@ -0,0 +1,19 @@ +#pragma once + +#include // LOG_W + +#include "config.h" +#define IS_DEFINED IS_BUILTIN + +#define unlikely(x) __builtin_expect(!!(x), 0) + +#define WARN_ONCE(condition, format...) ({ \ + static bool __warned; \ + int __ret_warn_once = !!(condition); \ + \ + if (unlikely(__ret_warn_once && !__warned)) { \ + __warned = true; \ + LOG_W(format); \ + } \ + unlikely(__ret_warn_once); \ +}) diff --git a/src/utils/libutils.cpp b/src/utils/libutils.cpp index 3a0ecd62..5d79cfbb 100644 --- a/src/utils/libutils.cpp +++ b/src/utils/libutils.cpp @@ -1,4 +1,5 @@ #include "libutils.h" +#include "LinuxPort.h" #include #include diff --git a/src/utils/libutils.h b/src/utils/libutils.h index afd89a14..dc595092 100644 --- a/src/utils/libutils.h +++ b/src/utils/libutils.h @@ -47,6 +47,3 @@ bool runCommand(const std::string& command, std::string& res); // MIME std::string getMIMEString(const std::string& path); - -#include "config.h" -#define IS_DEFINED IS_BUILTIN