Skip to content

Commit

Permalink
tg_cpphost: Add WARN_ONCE macro and use it
Browse files Browse the repository at this point in the history
  • Loading branch information
Royna2544 committed Nov 21, 2023
1 parent 43df726 commit e452042
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/CompilerInTelegram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <Logging.h>
#include <NamespaceImport.h>
#include <utils/libutils.h>
#include <utils/LinuxPort.h>

#include <chrono>
#include <fstream>
Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <TimerImpl.h>
#include <Types.h>
#include <tgbot/tgbot.h>
#include <utils/LinuxPort.h>

#include <algorithm>
#include <boost/algorithm/string/replace.hpp>
Expand Down Expand Up @@ -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)) {
Expand Down
19 changes: 19 additions & 0 deletions src/utils/LinuxPort.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <Logging.h> // 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); \
})
1 change: 1 addition & 0 deletions src/utils/libutils.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "libutils.h"
#include "LinuxPort.h"

#include <Logging.h>
#include <RuntimeException.h>
Expand Down
3 changes: 0 additions & 3 deletions src/utils/libutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e452042

Please sign in to comment.