working
This commit is contained in:
15
arch-discordbots-service/service/.vscode/c_cpp_properties.json
vendored
Normal file
15
arch-discordbots-service/service/.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "gnu17",
|
||||
"intelliSenseMode": "linux-gcc-x64"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
34
arch-discordbots-service/service/.vscode/launch.json
vendored
Normal file
34
arch-discordbots-service/service/.vscode/launch.json
vendored
Normal file
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
5
arch-discordbots-service/service/.vscode/settings.json
vendored
Normal file
5
arch-discordbots-service/service/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"vector": "cpp"
|
||||
}
|
||||
}
|
||||
28
arch-discordbots-service/service/.vscode/tasks.json
vendored
Normal file
28
arch-discordbots-service/service/.vscode/tasks.json
vendored
Normal file
@@ -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"
|
||||
}
|
||||
@@ -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
|
||||
|
||||
BIN
arch-discordbots-service/service/main
Executable file
BIN
arch-discordbots-service/service/main
Executable file
Binary file not shown.
@@ -1,13 +1,24 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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<string[2]> &scripts) {
|
||||
ifstream infile("bots");
|
||||
string exec(const char* cmd) {
|
||||
array<char, 128> buffer;
|
||||
string result;
|
||||
unique_ptr<FILE, decltype(&pclose)> 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<DATA> &scripts) {
|
||||
ifstream infile("scripts");
|
||||
string line;
|
||||
int linenum = 0;
|
||||
while (getline(infile, line)) {
|
||||
@@ -26,29 +77,17 @@ void loadfile(vector<string[2]> &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<string[2]> &scripts) {
|
||||
|
||||
int main() {
|
||||
|
||||
vector<string[2]> scripts;
|
||||
vector<DATA> scripts;
|
||||
|
||||
loadfile(scripts);
|
||||
|
||||
for (int i = 0; i < scripts.size(); i++) {
|
||||
DATA data = scripts.at(i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -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
|
||||
~/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
|
||||
Reference in New Issue
Block a user