|
|
|
#ifndef BOT_H
|
|
|
|
#define BOT_H
|
|
|
|
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include <sstream>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <iterator>
|
|
|
|
#include <regex>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <libtelegram/libtelegram.h>
|
|
|
|
|
|
|
|
class MarkovDB {
|
|
|
|
public:
|
|
|
|
virtual bool add_ngrams(std::vector<std::string> words) = 0;
|
|
|
|
virtual std::string get_continuation(std::vector<std::string> prompt, int &score) = 0;
|
|
|
|
virtual ~MarkovDB() {}
|
|
|
|
virtual bool batch_add_ngrams(std::vector<std::vector<std::string>> batch) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MarkovChain {
|
|
|
|
protected:
|
|
|
|
MarkovDB &markov;
|
|
|
|
|
|
|
|
int order = 1;
|
|
|
|
bool MAKE_LOWER = false;
|
|
|
|
|
|
|
|
bool process_string(std::string& message);
|
|
|
|
std::vector<std::string> split_string(std::string message);
|
|
|
|
bool test();
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool add_ngrams(std::string message);
|
|
|
|
|
|
|
|
std::string continue_message(std::string message, int &score);
|
|
|
|
|
|
|
|
MarkovChain (int ord, bool lower, MarkovDB &db)
|
|
|
|
: markov(db), MAKE_LOWER(lower), order(ord) {;
|
|
|
|
};
|
|
|
|
|
|
|
|
int import_from_file(std::string filename);
|
|
|
|
|
|
|
|
std::vector<std::vector<std::string>> get_words(std::string message);
|
|
|
|
|
|
|
|
virtual ~MarkovChain() {};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Bot {
|
|
|
|
protected:
|
|
|
|
MarkovChain markov;
|
|
|
|
int replies = 200;
|
|
|
|
int SCORE_THRESHOLD = 100;
|
|
|
|
public:
|
|
|
|
virtual void run() = 0;
|
|
|
|
Bot(int replies, int score_threshold, MarkovChain m)
|
|
|
|
: markov(m), replies(replies), SCORE_THRESHOLD(score_threshold) {};
|
|
|
|
~Bot() {};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class TelegramBotM: public Bot {
|
|
|
|
protected:
|
|
|
|
std::string api_key = "";
|
|
|
|
telegram::sender sender;
|
|
|
|
telegram::listener::poll listener;
|
|
|
|
std::string chain_name = "markov";
|
|
|
|
std::string get_token();
|
|
|
|
void add_echo();
|
|
|
|
|
|
|
|
public:
|
|
|
|
TelegramBotM(int order, MarkovChain &m, std::string chain_name) :
|
|
|
|
api_key(get_token()), sender(get_token()), listener(sender),
|
|
|
|
chain_name(chain_name), Bot(200, 100, m) {
|
|
|
|
add_echo();
|
|
|
|
};
|
|
|
|
|
|
|
|
void run() override {
|
|
|
|
listener.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
~TelegramBotM() {};
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|