diff --git a/arch-discordbots-service/service/.vscode/c_cpp_properties.json b/arch-discordbots-service/service/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..0b0fa12 --- /dev/null +++ b/arch-discordbots-service/service/.vscode/c_cpp_properties.json @@ -0,0 +1,15 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "gnu17", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/arch-discordbots-service/service/.vscode/launch.json b/arch-discordbots-service/service/.vscode/launch.json new file mode 100644 index 0000000..1bb985a --- /dev/null +++ b/arch-discordbots-service/service/.vscode/launch.json @@ -0,0 +1,34 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "g++ - Build and debug active file", + "type": "cppdbg", + "request": "launch", + "program": "${fileDirname}/${fileBasenameNoExtension}", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ], + "preLaunchTask": "C/C++: g++ build active file", + "miDebuggerPath": "/usr/bin/gdb" + } + ] +} \ No newline at end of file diff --git a/arch-discordbots-service/service/.vscode/settings.json b/arch-discordbots-service/service/.vscode/settings.json new file mode 100644 index 0000000..a3b2b51 --- /dev/null +++ b/arch-discordbots-service/service/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "vector": "cpp" + } +} \ No newline at end of file diff --git a/arch-discordbots-service/service/.vscode/tasks.json b/arch-discordbots-service/service/.vscode/tasks.json new file mode 100644 index 0000000..05054c5 --- /dev/null +++ b/arch-discordbots-service/service/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: g++ build active file", + "command": "/usr/bin/g++", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/arch-discordbots-service/service/build b/arch-discordbots-service/service/build index 319104d..edde842 100755 --- a/arch-discordbots-service/service/build +++ b/arch-discordbots-service/service/build @@ -1 +1 @@ -g++-10 -fconcepts-ts $1.cpp -o $1.o && chmod +x $1.o +g++ $1.cpp -o $1.o && chmod +x $1.o diff --git a/arch-discordbots-service/service/main b/arch-discordbots-service/service/main new file mode 100755 index 0000000..4194e0b Binary files /dev/null and b/arch-discordbots-service/service/main differ diff --git a/arch-discordbots-service/service/main.cpp b/arch-discordbots-service/service/main.cpp index 4820c31..f7d7270 100644 --- a/arch-discordbots-service/service/main.cpp +++ b/arch-discordbots-service/service/main.cpp @@ -1,13 +1,24 @@ +#include +#include #include #include +#include +#include #include #include #include using namespace std; -static inline string trim(string &s) { +class DATA { + public: + string loc = ""; + string script = ""; + string name = ""; +}; + +static inline void trim(string &s) { s.erase(s.begin(), find_if(s.begin(), s.end(), [](unsigned char ch) { return !isspace(ch); })); @@ -16,8 +27,48 @@ static inline string trim(string &s) { }).base(), s.end()); } -void loadfile(vector &scripts) { - ifstream infile("bots"); +string exec(const char* cmd) { + array buffer; + string result; + unique_ptr pipe(popen(cmd, "r"), pclose); + if (!pipe) { + throw runtime_error("popen() failed!"); + } + while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { + result += buffer.data(); + } + trim(result); + return result; +} + + +const int DATALEN = 2; +void splitData(string str, DATA &data) { + + stringstream ssin(str); + + while (ssin.good()) { + if (data.loc.length() == 0) { + ssin >> data.loc; + continue; + } + + if (data.script.length() > 0) + data.loc += " " + data.script; + + ssin >> data.script; + } + + if (data.loc[0] == '~') + data.loc = getenv("HOME") + data.loc.substr(1); + + string cmd = "cd \"" + data.loc + "\" && cut -d \"=\" -f 2 <<< $(npm run env | grep npm_package_name)"; + data.name = exec(cmd.c_str()); + +} + +void loadfile(vector &scripts) { + ifstream infile("scripts"); string line; int linenum = 0; while (getline(infile, line)) { @@ -26,29 +77,17 @@ void loadfile(vector &scripts) { string str = iss.str(); if (str.length() == 0 || str.substr(0,1) == "#") - break; + continue; - string loc = ""; - string script = "start"; + DATA data; + splitData(str, data); - size_t pos = 0; - string token; - while ((pos = str.find(":")) != string::npos) { - token = str.substr(0, pos); - trim(token); - if (loc.length() == 0) - loc = token; - else - script = token; - str.erase(0, pos + 1); - } - - if (loc.length() == 0) { + if (data.loc.length() == 0) { cout << "WARNING: skipping line " << linenum << endl; - break; + continue; } - scripts.push_back({ loc, script }); + scripts.push_back(data); } @@ -56,10 +95,14 @@ void loadfile(vector &scripts) { int main() { - vector scripts; + vector scripts; loadfile(scripts); - + for (int i = 0; i < scripts.size(); i++) { + DATA data = scripts.at(i); + } + + return 0; } \ No newline at end of file diff --git a/arch-discordbots-service/service/scripts b/arch-discordbots-service/service/scripts index a94496b..ece2d5d 100644 --- a/arch-discordbots-service/service/scripts +++ b/arch-discordbots-service/service/scripts @@ -1,7 +1,7 @@ -~/discordBots/autovc/ : start -~/discordBots/autorole/ : start -~/discordBots/funnyBike/cleverbot/ : start -~/discordBots/funnyBike/watch-it-talk/ : start -~/discordBots/funnyBike/wolframalpha/ : start -~/discordBots/IKEA-Canada-Support/rolemanager : tmux -~/discordBots/thom wishlane server/rolemanager : tmux \ No newline at end of file +~/discordBots/autovc/ start +~/discordBots/autorole/ start +#~/discordBots/funnyBike/cleverbot/ start +#~/discordBots/funnyBike/watch-it-talk/ start +#~/discordBots/funnyBike/wolframalpha/ start +~/discordBots/IKEA-Canada-Support/rolemanager tmux +~/discordBots/thom wishlane server/rolemanager tmux \ No newline at end of file