Repository navigation
Expand file tree
/
Copy pathutils.hpp
More file actions
70 lines (61 loc) · 1.91 KB
/
Copy pathutils.hpp
File metadata and controls
70 lines (61 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2025 vende11s
#pragma once
#include <chrono>
#include <thread>
#include <random>
#include <cmath>
#include <ctime>
#include "TelegramBotApi.hpp"
#include "OfferQuery.hpp"
// Cross-platform thread-safe localtime
static std::tm get_local_tm(std::time_t t) {
std::tm tm{};
#ifdef _WIN32
localtime_s(&tm, &t); // Windows
#else
localtime_r(&t, &tm); // Linux/macOS
#endif
return tm;
}
// Return current time as HH:MM:SS
static std::string current_time_hms() {
auto now = std::chrono::system_clock::now();
std::time_t now_time = std::chrono::system_clock::to_time_t(now);
std::tm tm = get_local_tm(now_time);
char buf[9]; // HH:MM:SS
std::strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
return std::string(buf);
}
namespace utils{
inline void LOG(std::string message) {
std::string data = "[" + current_time_hms() + "] " + message + "\n";
std::clog << data;
std::ofstream log("data.log", std::ios_base::app);
log << data;
}
inline void wait(int seconds, int refresh_seconds_randomization, bool dont_random = 0) {
static std::random_device rd;
static std::mt19937 engine(rd());
std::uniform_int_distribution<> distrib(0, refresh_seconds_randomization);
int random = distrib(engine);
if(distrib(engine) % 2 == 0) {
random = -random; // randomize direction
}
random += seconds; // add randomization to the wait time
random = std::abs(random); // ensure positive random value
if (dont_random) {
random = seconds; // ignore randomization if requested
}
std::this_thread::sleep_for(std::chrono::seconds(random));
LOG("Waited for " + std::to_string(random) + " seconds");
}
inline void drawLogo() {
std::cout << R"(
_____ _ ____
| ___|_ _ ___| |_| __ ) _ _ _ _ ___ _ __
| |_ / _` / __| __| _ \| | | | | | |/ _ \ '__|
| _| (_| \__ \ |_| |_) | |_| | |_| | __/ |
|_| \__,_|___/\__|____/ \__,_|\__, |\___|_|
|___/v1.2.1)"<<std::endl;
}
}