Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
e5a9b6557d | |||
09830a6736 | |||
bc63dabb81 | |||
a802e6ae38 | |||
301d99ca2f | |||
b68ac1d3b2 |
12
.gitignore
vendored
12
.gitignore
vendored
@ -1,14 +1,14 @@
|
||||
# VS files
|
||||
/.vs/
|
||||
/TriviaBot.sln
|
||||
/TriviaBot.VC*
|
||||
/TriviaBot/TriviaBot.vcxproj*
|
||||
/TriviaBot/x64/
|
||||
/Toast.sln
|
||||
/Toast.VC*
|
||||
/Toast/Toast.vcxproj*
|
||||
/Toast/x64/
|
||||
/x64/
|
||||
|
||||
# Data files
|
||||
/TriviaBot/data_management/questions
|
||||
/TriviaBot/bot/db/trivia.db
|
||||
/Toast/data_management/questions
|
||||
/Toast/bot/db/trivia.db
|
||||
|
||||
# Config file
|
||||
config.json
|
||||
|
28
.travis.yml
28
.travis.yml
@ -1,28 +0,0 @@
|
||||
sudo: required
|
||||
dist: trusty
|
||||
language: cpp
|
||||
compiler: gcc
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- boost-latest
|
||||
packages:
|
||||
- g++-5
|
||||
- gcc-5
|
||||
- libboost1.55-all-dev
|
||||
- libcurl4-openssl-dev
|
||||
- cmake
|
||||
install: export CXX="g++-5" CC="gcc-5";
|
||||
script:
|
||||
- cd TriviaBot
|
||||
- cmake .
|
||||
- make
|
||||
deploy:
|
||||
provider: releases
|
||||
api_key:
|
||||
secure: sbZntceUqjyFZ13TlwuU0Jdtfma/jXHprv4z+pYrmuO3/YarKMtwlvM6UniagF2wVcHTFtiBmlbxfSyRfpy+P6XGkpvIJtJFrsMaSAoZpLI6mbSPsPxUCvc1VW3EESGIlWTJ97TZmU3opLjLSQIgYK1NB1+1KtLedVnQy6KCtTFthjupNwDIeSIFyPR31BgL0yQ7owPYZ63koS4U32ABPFxTYUPDbkI+Xq02nrzbn3OGKQY1cXmLJtvaTi+QQARfCFGYNTB4Ngt04LtpzBP5eeyj2P3YslZj9Xyr9PgqDt0uS2I5m/hLWsSLf/ssJ06EIBt2mYIORVV/XcgBw13VUBHawbd6hLfxSmSwhYpTewcjVbU1gE09kYmyVJ+KKKcbJjhWknIRd6z9+rLGwGb+zlgFnR9KFa4VqBSxGzfujwtBJVntaz0QVWb8vNL5U1xz1FyOBUT+6jWbr0L9d8QyK0ivPUbiYXwMQAoAEjjq7VbG985eyrTjxB6oxiWg9W8RveS1Mbb++/NWRSvsIfA1oEPrOgJONiOUP1+1XQ0rFLWpVHw5n4yuWFo6XpbfauCujIA4bNPGPqR0cfHj8QbUK9JDoA1SiOWsburQqUNqo0WHTUvrgut3OaP8jysDKsmoh8/tWeKlc6l5IqKQ4qu28sOQLd8RHcKOToKSfIOwRdA=
|
||||
file: TriviaBot
|
||||
skip_cleanup: true
|
||||
on:
|
||||
tags: true
|
13
README.md
13
README.md
@ -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" />
|
||||
# Toast <img src="https://www.ahealthiermichigan.org/wp-content/uploads/2014/09/Transform-toast-into-breakfast.jpg" width="30" height="30" />
|
||||
|
||||
A bot which provides a Trivia game for [Discord](https://discordapp.com/).
|
||||
|
||||
@ -16,7 +16,7 @@ If you want to install a version for which a release does not exist, you will al
|
||||
|
||||
|
||||
### Running
|
||||
To run simply execute the program: `./TriviaBot`
|
||||
To run simply execute the program: `./Toast`
|
||||
|
||||
#### Configuration
|
||||
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.
|
||||
@ -53,8 +53,9 @@ LoadDB.cpp takes some time to execute.
|
||||
|
||||
#### 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.
|
||||
2. Properties *are* case sensitive. You must use `server.Name`, not `server.name`. This will not be changed.
|
||||
|
||||
### Compiling
|
||||
#### Dependencies
|
||||
@ -70,11 +71,11 @@ The Javascript system is designed to mirror the old [Boobot implementation](http
|
||||
#### Linux (Debian)
|
||||
c++14 support is required. gcc 5 and above recommended, however it compiles on 4.9.2 (and possibly some versions below.)
|
||||
|
||||
1. Clone the github repo: `git clone https://github.com/jackb-p/TriviaDiscord.git TriviaDiscord`
|
||||
2. Navigate to repository directory: `cd TriviaDiscord`
|
||||
1. Clone the github repo: `git clone https://github.com/jackb-p/Toast.git ToastBot`
|
||||
2. Navigate to repository directory: `cd ToastBot`
|
||||
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.
|
||||
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.
|
||||
6. `cd TriviaBot`
|
||||
6. `cd Toast`
|
||||
7. `cmake .`
|
||||
8. `make`
|
||||
|
@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 2.8.7)
|
||||
project(TriviaBot)
|
||||
project(Toast)
|
||||
|
||||
###############################################################################
|
||||
## get source ## ##############################################################
|
||||
@ -14,7 +14,7 @@ link_directories(../lib/v8/lib)
|
||||
###############################################################################
|
||||
|
||||
# add the data to the target, so it becomes visible in some IDE
|
||||
add_executable(TriviaBot ${sources})
|
||||
add_executable(Toast ${sources})
|
||||
|
||||
# add some compiler flags
|
||||
set (CMAKE_CXX_FLAGS "-std=c++14 -Wall ${CMAKE_CXX_FLAGS}")
|
||||
@ -27,7 +27,7 @@ find_package(Boost COMPONENTS system thread regex REQUIRED)
|
||||
find_package(OpenSSL REQUIRED)
|
||||
find_package(CURL REQUIRED)
|
||||
|
||||
target_link_libraries(TriviaBot PUBLIC
|
||||
target_link_libraries(Toast PUBLIC
|
||||
${Boost_LIBRARIES}
|
||||
${OPENSSL_LIBRARIES}
|
||||
${CURL_LIBRARIES}
|
@ -511,7 +511,7 @@ void GatewayHandler::on_event_message_create(json data, client &c, websocketpp::
|
||||
DiscordAPI::send_message(channel.id, m, config.token, config.cert_location);
|
||||
}
|
||||
else if (words[0] == "`info") {
|
||||
DiscordAPI::send_message(channel.id, ":information_source: **trivia-bot** by Jack. <http://github.com/jackb-p/TriviaDiscord>", config.token, config.cert_location);
|
||||
DiscordAPI::send_message(channel.id, ":information_source: **toast** by Jack. <http://github.com/jackb-p/Toast>", config.token, config.cert_location);
|
||||
}
|
||||
else if (words[0] == "~js" && words.size() > 1) {
|
||||
DiscordObjects::GuildMember *member = *std::find_if(guild.members.begin(), guild.members.end(), [sender](DiscordObjects::GuildMember *m) {
|
||||
@ -519,7 +519,7 @@ void GatewayHandler::on_event_message_create(json data, client &c, websocketpp::
|
||||
});
|
||||
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);
|
||||
return conf.js_allowed_roles.count(r->name);
|
||||
}) == member->roles.end(); // checks if the user has the required roles
|
||||
|
||||
if (disallowed) {
|
||||
@ -537,7 +537,7 @@ void GatewayHandler::on_event_message_create(json data, client &c, websocketpp::
|
||||
auto &member = *std::find_if(guild.members.begin(), guild.members.end(), [sender](DiscordObjects::GuildMember *m) { 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);
|
||||
return conf.js_allowed_roles.count(r->name);
|
||||
}) == member->roles.end(); // checks if the user has the required roles
|
||||
|
||||
if (disallowed) {
|
@ -368,6 +368,10 @@ void V8Instance::js_get_user(Local<Name> property, const PropertyCallbackInfo<Va
|
||||
std::string name = member->nick == "null" ? member->user->username : member->nick;
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), name.c_str(), NewStringType::kNormal).ToLocalChecked());
|
||||
}
|
||||
else if (property_s == "TrueName") { // ignores nick
|
||||
std::string name = member->user->username;
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), name.c_str(), NewStringType::kNormal).ToLocalChecked());
|
||||
}
|
||||
else if (property_s == "Mention") {
|
||||
std::string mention = "<@" + member->user->id + ">";
|
||||
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), mention.c_str(), NewStringType::kNormal).ToLocalChecked());
|
@ -1,64 +0,0 @@
|
||||
#include <curl/curl.h>
|
||||
#include <include/libplatform/libplatform.>
|
||||
#include <include/v8.h>
|
||||
|
||||
#include "ClientConnection.hpp"
|
||||
#include "Logger.hpp"
|
||||
#include "DiscordAPI.hpp"
|
||||
|
||||
std::string bot_token;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
|
||||
v8::V8::InitializeICUDefaultLocation(argv[0]);
|
||||
v8::V8::InitializeExternalStartupData(argv[0]);
|
||||
v8::Platform* platform = v8::platform::CreateDefaultPlatform();
|
||||
v8::V8::InitializePlatform(platform);
|
||||
v8::V8::Initialize();
|
||||
|
||||
Logger::write("Initialised V8 and curl", Logger::LogLevel::Debug);
|
||||
|
||||
if (argc == 2) {
|
||||
bot_token = argv[1];
|
||||
}
|
||||
else {
|
||||
std::cout << "Please enter your bot token: " << std::endl;
|
||||
std::cin >> bot_token;
|
||||
}
|
||||
|
||||
std::string args = "/?v=5&encoding=json";
|
||||
std::string url = DiscordAPI::get_gateway().value("url", "wss://gateway.discord.gg");
|
||||
|
||||
bool retry = true;
|
||||
while (retry) {
|
||||
try {
|
||||
ClientConnection conn;
|
||||
conn.start(url + args);
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
Logger::write("std exception: " + std::string(e.what()), Logger::LogLevel::Severe);
|
||||
retry = false;
|
||||
}
|
||||
catch (websocketpp::lib::error_code e) {
|
||||
Logger::write("websocketpp exception: " + e.message(), Logger::LogLevel::Severe);
|
||||
}
|
||||
catch (...) {
|
||||
Logger::write("other exception.", Logger::LogLevel::Severe);
|
||||
retry = false;
|
||||
}
|
||||
}
|
||||
|
||||
v8::V8::Dispose();
|
||||
v8::V8::ShutdownPlatform();
|
||||
delete platform;
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
Logger::write("Cleaned up", Logger::LogLevel::Info);
|
||||
|
||||
std::cout << "Press enter to exit" << std::endl;
|
||||
std::getchar();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user