Revert "Merge Develop branch"

This commit is contained in:
Jack Bond-Preston 2016-08-19 17:43:30 +01:00 committed by GitHub
parent b68ac1d3b2
commit b39bb04a55
4 changed files with 13 additions and 41 deletions

View File

@ -1,4 +1,4 @@
#trivia-bot <img src="https://cdn.discordapp.com/attachments/164732409919569920/205700949304541184/emoji.png" width="30" height="30" /> <img src="http://vps307652.ovh.net:8080/buildStatus/icon?job=trivia-bot" /> #trivia-bot <img src="https://cdn.discordapp.com/attachments/164732409919569920/205700949304541184/emoji.png" width="30" height="30" /> <img src="https://travis-ci.org/jackb-p/trivia-bot.svg?branch=release" />
A bot which provides a Trivia game for [Discord](https://discordapp.com/). A bot which provides a Trivia game for [Discord](https://discordapp.com/).
@ -10,7 +10,7 @@ It requires no special permissions at this time (only read/write to channels).
### Installation ### Installation
[Releases](https://github.com/jackb-p/trivia-bot/releases) are available for tagged versions. These are compiled on Debian Jessie by Jenkins. Note that you still require the dependency library files, so you will still have to build V8 and add it to your `LD_LIBRARY_PATH`. To run on other systems you will need to compile yourself - a CMake configuration is included. Windows releases will happen one day. [Releases](https://github.com/jackb-p/trivia-bot/releases) are available for tagged versions. These are compiled on Ubuntu by Travis CI. To run on other systems you will need to compile yourself - a CMake configuration is included. Windows releases will happen one day.
If you want to install a version for which a release does not exist, you will also have to compile manually. Compilation instructions are available for Linux below. If you want to install a version for which a release does not exist, you will also have to compile manually. Compilation instructions are available for Linux below.
@ -18,19 +18,7 @@ If you want to install a version for which a release does not exist, you will al
### Running ### Running
To run simply execute the program: `./TriviaBot` To run simply execute the program: `./TriviaBot`
#### Configuration If you do not want to be prompted for your token every launch, provide it as an argument: `./TriviaBot {TOKEN}`
The config file is automatically generated if it is not present. The JSON format is used. You must edit the config file for the bot to work correctly, the bot token is required.
The current configuration options are as follows:
1. **General**
| Field | Description |
| --- | --- |
| `api_cert_file` | The path to the Discord API .crt file for HTTPS. |
| `bot_token` | Your Discord bot token. |
| `owner_id` | The user ID of the owner of the bot. This allows owner-only (maintenance) commands, such as `shutdown`. |
| `js_allowed_roles` | List of role names which are allowed to use the `createjs` ands `js` commands. |
### Trivia Questions ### Trivia Questions
Questions are obtained from [trivia-db on Sourceforge](https://sourceforge.net/projects/triviadb/). Questions are obtained from [trivia-db on Sourceforge](https://sourceforge.net/projects/triviadb/).
@ -42,7 +30,6 @@ LoadDB.cpp takes some time to execute.
### Commands ### Commands
#### Trivia Game
`` `trivia`` is the base command. `` `trivia`` is the base command.
| Argument | Description | | Argument | Description |
@ -51,10 +38,6 @@ LoadDB.cpp takes some time to execute.
| stop | Stops the trivia game currently in the channel the message is sent from, if there is one. | | stop | Stops the trivia game currently in the channel the message is sent from, if there is one. |
| help | Prints a help list, similar to this table. | | help | Prints a help list, similar to this table. |
#### Javascript Commands
The Javascript system is designed to mirror the old [Boobot implementation](https://www.boobot.party/). For now there are some exceptions:
1. Message objects aren't implemented.
2. Properties are not case sensitive. You must use `server.Name`, not `server.name`. This will not be changed.
### Compiling ### Compiling
#### Dependencies #### Dependencies
@ -65,16 +48,15 @@ The Javascript system is designed to mirror the old [Boobot implementation](http
| cURL | [curl.haxx.se](https://curl.haxx.se/) | | | cURL | [curl.haxx.se](https://curl.haxx.se/) | |
| sqlite3 | [sqlite.org](https://www.sqlite.org/) | Included as submodule. Uses a [different repo](https://github.com/azadkuh/sqlite-amalgamation/). | | sqlite3 | [sqlite.org](https://www.sqlite.org/) | Included as submodule. Uses a [different repo](https://github.com/azadkuh/sqlite-amalgamation/). |
| nlohmann/json | [nlohmann/json](https://github.com/nlohmann/json) | (Slightly modified) source file included in repo. | | nlohmann/json | [nlohmann/json](https://github.com/nlohmann/json) | (Slightly modified) source file included in repo. |
| V8 | [Google V8](https://developers.google.com/v8/) | Debian/Ubuntu `libv8` packages are too outdated. Must be built manually. | | V8 | [Google V8](https://developers.google.com/v8/) | Debian/Ubuntu `libv8` packages are too outdated. |
#### Linux (Debian) #### Linux (debian)
c++14 support is required. gcc 5 and above recommended, however it compiles on 4.9.2 (and possibly some versions below.) c++14 support is required. gcc 5 and above recommended.
1. Clone the github repo: `git clone https://github.com/jackb-p/TriviaDiscord.git TriviaDiscord` 1. Clone the github repo: `git clone https://github.com/jackb-p/TriviaDiscord.git TriviaDiscord`
2. Navigate to repository directory: `cd TriviaDiscord` 2. Navigate to repository directory: `cd TriviaDiscord`
3. Clone the submodules: `git submodule init` and `git submodule update` 3. Clone the submodules: `git submodule init` and `git submodule update`
4. Install other dependencies: `sudo apt-get install build-essential cmake libboost-all-dev libcurl4-openssl-dev libssl-dev` (Package managers and names may vary, but all of these should be easy to find through a simple Google search.) V8 may require other dependencies. 4. Install other dependencies: `sudo apt-get install cmake libboost-all-dev libcurl-dev` (Package managers and names may vary, but all of these should be easy to find through a simple Google search.)
5. Build V8. Put the library files into lib/v8/lib/ and the include files into lib/v8/include. More instructions will be added at some point for this step. 5. `cd TriviaBot`
6. `cd TriviaBot` 6. `cmake .`
7. `cmake .` 7. `make`
8. `make`

View File

@ -34,7 +34,7 @@ void BotConfig::load_from_json(std::string data) {
owner_id = parsed.value("owner_id", ""); owner_id = parsed.value("owner_id", "");
cert_location = parsed.value("api_cert_file", "bot/http/DiscordCA.crt"); cert_location = parsed.value("api_cert_file", "bot/http/DiscordCA.crt");
js_allowed_roles = parsed["v8"].value("js_allowed_roles", std::unordered_set<std::string> { "Admin", "Coder" }); createjs_roles = parsed["v8"].value("createjs_allowed_roles", std::unordered_set<std::string> { "Admin", "Coder" });
Logger::write("config.json file loaded", Logger::LogLevel::Info); Logger::write("config.json file loaded", Logger::LogLevel::Info);
} }
@ -45,7 +45,7 @@ void BotConfig::create_new_file() {
{ "owner_id", "" }, { "owner_id", "" },
{ "api_cert_file", "bot/http/DiscordCA.crt" }, { "api_cert_file", "bot/http/DiscordCA.crt" },
{ "v8", { { "v8", {
{ "js_allowed_roles", { { "createjs_allowed_roles", {
"Admin", "Coder", "Bot Commander" "Admin", "Coder", "Bot Commander"
} } } }
} } } }

View File

@ -13,7 +13,7 @@ public:
std::string token; std::string token;
std::string owner_id; std::string owner_id;
std::string cert_location; std::string cert_location;
std::unordered_set<std::string> js_allowed_roles; std::unordered_set<std::string> createjs_roles;
private: private:
void load_from_json(std::string data); void load_from_json(std::string data);

View File

@ -517,16 +517,6 @@ void GatewayHandler::on_event_message_create(json data, client &c, websocketpp::
DiscordObjects::GuildMember *member = *std::find_if(guild.members.begin(), guild.members.end(), [sender](DiscordObjects::GuildMember *m) { DiscordObjects::GuildMember *member = *std::find_if(guild.members.begin(), guild.members.end(), [sender](DiscordObjects::GuildMember *m) {
return sender.id == m->user->id; return sender.id == m->user->id;
}); });
BotConfig &conf = config;
bool disallowed = std::find_if(member->roles.begin(), member->roles.end(), [conf](DiscordObjects::Role *r) -> bool {
return conf.createjs_roles.count(r->name);
}) == member->roles.end(); // checks if the user has the required roles
if (disallowed) {
DiscordAPI::send_message(channel.id, ":warning: You do not have permission to use this command.", config.token, config.cert_location);
return;
}
std::string js = message.substr(4); std::string js = message.substr(4);
auto it = v8_instances.find(channel.guild_id); auto it = v8_instances.find(channel.guild_id);
if (it != v8_instances.end() && js.length() > 0) { if (it != v8_instances.end() && js.length() > 0) {