2016-07-10 01:18:13 +01:00
|
|
|
#ifndef BOT_QUESTIONHELPER
|
|
|
|
#define BOT_QUESTIONHELPER
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
#include <sqlite3.h>
|
|
|
|
#include <boost/thread.hpp>
|
|
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
|
|
|
|
|
|
class GatewayHandler;
|
2016-08-15 17:47:34 +01:00
|
|
|
class BotConfig;
|
2016-07-10 01:18:13 +01:00
|
|
|
namespace DiscordObjects {
|
|
|
|
class User;
|
|
|
|
}
|
|
|
|
|
|
|
|
class TriviaGame {
|
|
|
|
public:
|
2016-08-15 17:47:34 +01:00
|
|
|
TriviaGame(BotConfig &c, GatewayHandler *gh, std::string channel_id, int total_questions, int delay);
|
2016-07-10 01:18:13 +01:00
|
|
|
~TriviaGame();
|
|
|
|
|
|
|
|
void start();
|
2016-07-10 19:17:35 +01:00
|
|
|
void interrupt();
|
2016-07-10 01:18:13 +01:00
|
|
|
void handle_answer(std::string answer, DiscordObjects::User sender);
|
|
|
|
|
|
|
|
private:
|
2016-08-15 17:47:34 +01:00
|
|
|
BotConfig &config;
|
|
|
|
|
2016-07-10 01:18:13 +01:00
|
|
|
int questions_asked;
|
|
|
|
int total_questions;
|
2016-07-10 19:17:35 +01:00
|
|
|
boost::posix_time::seconds interval;
|
2016-07-10 01:18:13 +01:00
|
|
|
|
|
|
|
void question();
|
|
|
|
void give_hint(int hints_given, std::string hint);
|
|
|
|
void increase_score(std::string user_id);
|
|
|
|
void update_average_time(std::string user_id, int time);
|
|
|
|
|
|
|
|
std::string channel_id;
|
|
|
|
GatewayHandler *gh;
|
|
|
|
|
|
|
|
const char hide_char = '#';
|
|
|
|
|
|
|
|
std::string current_question;
|
|
|
|
std::set<std::string> current_answers;
|
|
|
|
|
|
|
|
// <user_id, score>
|
|
|
|
std::map<std::string, int> scores;
|
|
|
|
// <user_id, average_time>
|
|
|
|
std::map<std::string, int> average_times;
|
|
|
|
|
2016-07-12 20:47:18 +01:00
|
|
|
std::unique_ptr<boost::thread> current_thread;
|
2016-07-10 01:18:13 +01:00
|
|
|
|
|
|
|
boost::posix_time::ptime question_start;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|