43 lines
1.1 KiB
C++
43 lines
1.1 KiB
C++
#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;
|
|
};
|