Removed emojis.h; embedded help files into executable
This commit is contained in:
parent
f7ec5bfd8e
commit
0bd2793b5a
13 changed files with 50 additions and 33 deletions
|
@ -10,6 +10,7 @@ add_subdirectory(lib/rest-beast)
|
|||
add_subdirectory(lib/websocket-simpleweb)
|
||||
add_subdirectory(lib/plugin-overload)
|
||||
add_subdirectory(lib/plugin-ratelimit)
|
||||
include(embed.cmake)
|
||||
INCLUDE_DIRECTORIES(${discordpp_SOURCE_DIR} ${discordpp-rest-beast_SOURCE_DIR} ${discordpp-websocket-simpleweb_SOURCE_DIR} ${discordpp-plugin-overload_SOURCE_DIR} ${discordpp-plugin-ratelimit_SOURCE_DIR})
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
|
@ -20,7 +21,6 @@ add_executable(weymou
|
|||
base/src/bot.cpp
|
||||
base/src/extras.cpp
|
||||
base/src/database.cpp
|
||||
user/src/cust.cpp
|
||||
|
||||
base/src/abstract/intents.cpp
|
||||
base/src/abstract/fetch.cpp
|
||||
|
@ -33,6 +33,8 @@ add_executable(weymou
|
|||
base/src/abstract/user.cpp
|
||||
base/src/abstract/member.cpp
|
||||
|
||||
user/src/cust.cpp
|
||||
user/src/help_pages.cpp
|
||||
user/modules/useful.cpp
|
||||
user/modules/servermanagement.cpp
|
||||
user/modules/misc.cpp
|
||||
|
@ -43,6 +45,7 @@ add_executable(weymou
|
|||
target_include_directories(weymou PRIVATE
|
||||
base/include/
|
||||
user/include/
|
||||
${EMBED_OUTDIR}
|
||||
)
|
||||
|
||||
target_precompile_headers(weymou PRIVATE
|
||||
|
@ -63,7 +66,4 @@ target_link_libraries(weymou PUBLIC
|
|||
|
||||
|
||||
configure_file(config.json ./ COPYONLY)
|
||||
configure_file(help/syntaxes.json ./ COPYONLY)
|
||||
configure_file(help/help_syntaxtmpl.txt ./ COPYONLY)
|
||||
configure_file(help/help_notfound.txt ./ COPYONLY)
|
||||
configure_file(help/help_1.txt ./ COPYONLY)
|
||||
embed(help/*)
|
||||
|
|
15
embed.cmake
Normal file
15
embed.cmake
Normal file
|
@ -0,0 +1,15 @@
|
|||
SET(EMBED_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}/embeds)
|
||||
file(MAKE_DIRECTORY ${EMBED_OUTDIR})
|
||||
|
||||
function(embed filesglob)
|
||||
SET(RESOURCE_COMPILER xxd)
|
||||
FILE(GLOB_RECURSE COMPILED_RESOURCES ${filesglob})
|
||||
FOREACH(INPUT_FILE ${COMPILED_RESOURCES})
|
||||
get_filename_component(OUTPUT_FILE ${INPUT_FILE} NAME_WE)
|
||||
get_filename_component(INPUT_FILE_DIR ${INPUT_FILE} DIRECTORY)
|
||||
get_filename_component(INPUT_FILE_NAME ${INPUT_FILE} NAME)
|
||||
execute_process(COMMAND ${RESOURCE_COMPILER} -i ${INPUT_FILE_NAME} ${EMBED_OUTDIR}/embed_${OUTPUT_FILE}.h
|
||||
WORKING_DIRECTORY ${INPUT_FILE_DIR})
|
||||
message("Generating header for ${INPUT_FILE}...")
|
||||
ENDFOREACH()
|
||||
endfunction()
|
|
@ -11,7 +11,7 @@
|
|||
"examples": [
|
||||
"",
|
||||
"2",
|
||||
"poll"
|
||||
"ban"
|
||||
]
|
||||
},
|
||||
"serverinfo": {
|
||||
|
@ -20,7 +20,7 @@
|
|||
"examples": [
|
||||
"",
|
||||
"emotes",
|
||||
"poll"
|
||||
"roles"
|
||||
]
|
||||
},
|
||||
"prefix": {
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
#pragma once
|
|
@ -1,4 +1,3 @@
|
|||
#pragma once
|
||||
#include "emojis.h"
|
||||
|
||||
#define NO_SUCH_USER ":warning: I couldn't find the user you requested. It may not have been cached yet.\n *Try mentioning the user instead*"
|
||||
|
|
4
user/include/help_pages.hpp
Normal file
4
user/include/help_pages.hpp
Normal file
|
@ -0,0 +1,4 @@
|
|||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
extern const std::unordered_map<std::string, std::string> help_files;
|
|
@ -1,3 +1,2 @@
|
|||
#pragma once
|
||||
#include "emojis.h"
|
||||
#define permassert(msg, channel, permission) if (not channel->has_perm(msg->author, permission)) {channel->send(":warning: You need the permission **"#permission"** to do that"); return;} 0
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
#include <fmt/format.h>
|
||||
#include "extras.hpp"
|
||||
#include "cust.hpp"
|
||||
#include "emojis.h"
|
||||
#include "bot.hpp"
|
||||
#include "abstract/message.hpp"
|
||||
#include "abstract/channel.hpp"
|
||||
#include "help_pages.hpp"
|
||||
using namespace std;
|
||||
|
||||
static json syntaxes;
|
||||
static json syntaxes = json::parse(help_files.find("syntaxes")->second);
|
||||
|
||||
|
||||
|
||||
|
@ -39,7 +39,6 @@ class Help {
|
|||
static void help(Message *msg, Channel *channel, cmdargs& args) {
|
||||
string help_name;
|
||||
string helpfile_name;
|
||||
ostringstream help_text;
|
||||
bool help_mainpage = true;
|
||||
bool not_found = false;
|
||||
bool from_template = false;
|
||||
|
@ -55,8 +54,8 @@ class Help {
|
|||
// Check if help page is a main page
|
||||
help_mainpage = extras::is_digits(helpfile_name);
|
||||
// Find given help page
|
||||
ifstream help_file("help_"+helpfile_name+".txt");
|
||||
if (not help_file) {
|
||||
auto help_file = help_files.find("help_"+helpfile_name);
|
||||
if (help_file == help_files.end()) {
|
||||
// Check if notfound page exists
|
||||
if (not_found) {
|
||||
// Error page couldn't be found
|
||||
|
@ -74,8 +73,7 @@ class Help {
|
|||
not_found = true;
|
||||
goto send_help;
|
||||
}
|
||||
help_text << help_file.rdbuf();
|
||||
help_file.close();
|
||||
const string &help_text = help_file->second;
|
||||
// Send text
|
||||
json embed;
|
||||
{
|
||||
|
@ -95,7 +93,7 @@ class Help {
|
|||
syntax_list.pop_back(); // Remove trailing ','
|
||||
}
|
||||
// Generate list of available syntax pages
|
||||
embed["description"] = fmt::format(help_text.str(), help_name, syntax_list);
|
||||
embed["description"] = fmt::format(help_text, help_name, syntax_list);
|
||||
} else {
|
||||
// Check if templating is enabled
|
||||
if (from_template) {
|
||||
|
@ -109,11 +107,11 @@ class Help {
|
|||
}
|
||||
}
|
||||
// Apply template
|
||||
embed["description"] = fmt::format(help_text.str(), help_name, string(syntax["usage"]), examples.str());
|
||||
embed["description"] = fmt::format(help_text, help_name, string(syntax["usage"]), examples.str());
|
||||
} else if (help_mainpage) {
|
||||
embed["description"] = fmt::format(help_text.str(), get_prefix(channel), *extras::get_bot_invite_link(), string(env.settings["supportdiscord"]));
|
||||
embed["description"] = fmt::format(help_text, get_prefix(channel), *extras::get_bot_invite_link(), string(env.settings["supportdiscord"]));
|
||||
} else {
|
||||
embed["description"] = help_text.str();
|
||||
embed["description"] = help_text;
|
||||
}
|
||||
}
|
||||
// The rest of the embed can differ too
|
||||
|
@ -138,14 +136,6 @@ public:
|
|||
Help() {
|
||||
// Commands
|
||||
register_command("help", help, 1);
|
||||
// Load syntaxes JSON
|
||||
ifstream i("syntaxes.json");
|
||||
if (not i) {
|
||||
cerr << "Error: syntaxes.json does not exist" << endl;
|
||||
abort();
|
||||
}
|
||||
i >> syntaxes;
|
||||
i.close();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <chrono>
|
||||
#include "extras.hpp"
|
||||
#include "cust.hpp"
|
||||
#include "emojis.h"
|
||||
#include "bot.hpp"
|
||||
#include "abstract/permissions.hpp"
|
||||
#include "abstract/cache.hpp"
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include "cust.hpp"
|
||||
#include "database.hpp"
|
||||
#include "generic_msgs.h"
|
||||
#include "emojis.h"
|
||||
#include "bot.hpp"
|
||||
#include "abstract/fetch.hpp"
|
||||
#include "abstract/guild.hpp"
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include "help.hpp"
|
||||
#include "extras.hpp"
|
||||
#include "cust.hpp"
|
||||
#include "emojis.h"
|
||||
#include "bot.hpp"
|
||||
#include "abstract/cache.hpp"
|
||||
#include "abstract/channel.hpp"
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include <array> // TODO: remove when no longer needed
|
||||
#include "extras.hpp"
|
||||
#include "cust.hpp"
|
||||
#include "emojis.h"
|
||||
#include "generic_msgs.h"
|
||||
#include "help.hpp"
|
||||
#include "bot.hpp"
|
||||
|
|
15
user/src/help_pages.cpp
Normal file
15
user/src/help_pages.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include "help_pages.hpp"
|
||||
|
||||
#include "embed_help_1.h"
|
||||
#include "embed_help_notfound.h"
|
||||
#include "embed_help_syntaxtmpl.h"
|
||||
#include "embed_syntaxes.h"
|
||||
|
||||
const std::unordered_map<std::string, std::string> help_files = {
|
||||
{"help_1", std::string(reinterpret_cast<char*>(help_1_txt), help_1_txt_len)},
|
||||
{"help_notfound", std::string(reinterpret_cast<char*>(help_notfound_txt), help_notfound_txt_len)},
|
||||
{"help_syntaxtmpl", std::string(reinterpret_cast<char*>(help_syntaxtmpl_txt), help_syntaxtmpl_txt_len)},
|
||||
{"syntaxes", std::string(reinterpret_cast<char*>(syntaxes_json), syntaxes_json_len)}
|
||||
};
|
Reference in a new issue