first commit
This commit is contained in:
commit
7349b743e3
21 files changed
+1527
No files matched your search
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
#include <optional>
|
||||
|
||||
struct ScanRecord {
|
||||
std::string ts;
|
||||
std::string url;
|
||||
std::string label;
|
||||
int count = 0;
|
||||
bool changed = false;
|
||||
};
|
||||
|
||||
// Thread-safe replacement for the python `state` dict. Shared between the
|
||||
// SniperEngine worker thread and the Discord bot command handlers.
|
||||
class SniperState {
|
||||
public:
|
||||
std::atomic<bool> running{false};
|
||||
std::atomic<int> total_scans{0};
|
||||
std::atomic<int> total_changes{0};
|
||||
|
||||
void setLastOffers(const std::string& url, std::vector<std::string> offers);
|
||||
std::optional<std::vector<std::string>> getLastOffers(const std::string& url);
|
||||
std::map<std::string, int> stockCounts();
|
||||
|
||||
void addHistory(ScanRecord rec);
|
||||
std::vector<ScanRecord> getHistory();
|
||||
|
||||
void clearOffers();
|
||||
void resetCounters();
|
||||
void resetHistory();
|
||||
|
||||
private:
|
||||
std::mutex mtx_;
|
||||
std::map<std::string, std::vector<std::string>> last_offers_;
|
||||
std::deque<ScanRecord> history_;
|
||||
static constexpr size_t kMaxHistory = 200;
|
||||
};
|
||||
Reference in new issue
Block a user