Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #73 from mrepol742/master
Browse files Browse the repository at this point in the history
Initial Commit
  • Loading branch information
mrepol742 authored Feb 8, 2024
2 parents 8095e9b + eba1b98 commit ddb2a16
Show file tree
Hide file tree
Showing 6 changed files with 354 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/cache/*
/data/cookies/*
/build/*
/log/*
.nosave
3 changes: 0 additions & 3 deletions data/crash-log.json

This file was deleted.

97 changes: 65 additions & 32 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ mmmmm m mm mmm mmmm mmm # #" m"# " "#
"
`);

let folder_dir = ["/cache", "/data", "/data/cookies"];
let folder_dir = ["/cache", "/data", "/data/cookies", "/log"];
for (folder in folder_dir) {
writeFolder(__dirname + folder_dir[folder]);
}

let data_json = ["groups", "pin", "accountPreferences", "threadPreferences", "users", "crash-log"];
let data_json = ["groups", "pin", "accountPreferences", "threadPreferences", "users"];
for (file in data_json) {
writeFile(__dirname + "/data/" + data_json[file] + ".json", "{}");
}
Expand All @@ -61,7 +61,6 @@ let settings = JSON.parse(fs.readFileSync(__dirname + "/data/accountPreferences.
let settingsThread = JSON.parse(fs.readFileSync(__dirname + "/data/threadPreferences.json", "utf8"));
let users = JSON.parse(fs.readFileSync(__dirname + "/data/users.json", "utf8"));
let groups = JSON.parse(fs.readFileSync(__dirname + "/data/groups.json", "utf8"));
let crashLog = JSON.parse(fs.readFileSync(__dirname + "/data/crash-log.json"));

let quiz = JSON.parse(fs.readFileSync(__dirname + "/src/data/quiz.json", "utf-8"));
let asciifonts = JSON.parse(fs.readFileSync(__dirname + "/src/data/ascii.json"));
Expand All @@ -79,6 +78,11 @@ if (R_S_H_12_mmm) {
settingsThread = { default: { leave: false, unsend: false, nsfw: true, cmd: 1 } };
}

/*
* Logs
*/
let crashLog = "";

console.log("\tProject Information");
console.log("Users" + "\n Total: " + Object.keys(users.list).length + "\n Blocked: " + (users.blocked.length + users.bot.length) + "\n Muted: " + users.muted.length + "\n Admin: " + users.admin.length);

Expand Down Expand Up @@ -127,11 +131,12 @@ const normalize = /[\u0300-\u036f|\u00b4|\u0060|\u005e|\u007e]/g;
/*
* CREATE SERVER
*/

/*
const PORT = 8080;
const LOG_PORT = 8081;
http.createServer(getRoutes()).listen(PORT, () => {
utils.logged("server_running http://localhost:" + PORT);
http.createServer(getLogs()).listen(LOG_PORT, () => {
utils.logged("log_server_running http://0.0.0.0:" + LOG_PORT);
});
*/

Expand Down Expand Up @@ -303,13 +308,12 @@ function redfox_fb(fca_state, login, cb) {
handleError({ stacktrace: err, cuid: login });

if (err && err.error && err.error == "unable to get cookie.") {

accounts = accounts.filter((item) => item !== login);
for (threads in settingsThread) {
if (settingsThread[threads].lock && settingsThread[threads].lock == login) {
delete settingsThread[threads]["lock"];
for (threads in settingsThread) {
if (settingsThread[threads].lock && settingsThread[threads].lock == login) {
delete settingsThread[threads]["lock"];
}
}
}

unlinkIfExists(__dirname + "/data/cookies/" + login + ".bin");
unlinkIfExists(__dirname + "/data/cookies/" + login + ".key");
Expand Down Expand Up @@ -403,16 +407,15 @@ function redfox_fb(fca_state, login, cb) {

api.eventListener(async (err, event) => {
if (err) {

if (err && err.error && err.error == "unable to get cookie.") {
handleError({ stacktrace: err, cuid: login, e: event });
handleError({ stacktrace: err, cuid: login, e: event });

accounts = accounts.filter((item) => item !== login);
for (threads in settingsThread) {
if (settingsThread[threads].lock && settingsThread[threads].lock == login) {
delete settingsThread[threads]["lock"];
accounts = accounts.filter((item) => item !== login);
for (threads in settingsThread) {
if (settingsThread[threads].lock && settingsThread[threads].lock == login) {
delete settingsThread[threads]["lock"];
}
}
}
unlinkIfExists(__dirname + "/data/cookies/" + login + ".bin");
unlinkIfExists(__dirname + "/data/cookies/" + login + ".key");
}
Expand Down Expand Up @@ -641,6 +644,8 @@ function redfox_fb(fca_state, login, cb) {
newThread["name"] = gc.threadName;
}

newThread["created_date"] = new Date().toISOString();

groups.list.push(newThread);

sendMessageOnly(api, event, {
Expand Down Expand Up @@ -1424,7 +1429,7 @@ async function ai22(api, event, query, query2) {
api.unsendMessage(event.messageReply.messageID, (err) => {
if (err) return handleError({ stacktrace: err, cuid: api.getCurrentUserID(), e: event });
});
return;
return true;
}
}
}
Expand Down Expand Up @@ -1878,7 +1883,8 @@ async function ai(api, event) {

if (event.type == "message_reply") {
if (event.body != "." && event.body != "?" && event.body != "!") {
ai22(api, event, query, query2);
let st = ai22(api, event, query, query2);
if (st) return;
// TODO: undefined sender id no idea why
if (accounts.includes(event.messageReply.senderID)) {
someA(api, event, query, input);
Expand Down Expand Up @@ -2370,7 +2376,7 @@ async function ai(api, event) {
sendMessage(api, event, handleError({ stacktrace: err, cuid: api.getCurrentUserID(), e: event }));
}
}
} else if (testCommand(api, query, "clear--cache", event.senderID, "admin", true)) {
} else if (testCommand(api, query, "clear--cache", event.senderID, "root", true)) {
let count = 0;
fs.readdir(__dirname + "/cache/", function (err, files) {
if (err) return handleError({ stacktrace: err, cuid: api.getCurrentUserID(), e: event });
Expand Down Expand Up @@ -4099,7 +4105,7 @@ async function ai(api, event) {
});
sendMessage(api, event, "Please check your inbox.");
});
} else if (testCommand(api, query2, "handleMessageRequest--tid", event.senderID, "admin")) {
} else if (testCommand(api, query2, "handleMessageRequest--tid", event.senderID, "owner")) {
let data = input.split(" ");
if (data.length < 3) {
sendMessage(api, event, "Houston! Unknown or missing option.\n\n Usage: handleMessageRequest --tid threadid" + "\n " + example[Math.floor(Math.random() * example.length)] + " handleMessageRequest --tid 0000000000000");
Expand Down Expand Up @@ -4841,7 +4847,7 @@ async function ai(api, event) {

sendMessage(api, event, "Changes have been reflected to following accounts:\n" + utils.formatOutput("ApiKey", data1, "github.com/prj-orion"));
}
} else if (testCommand(api, query2, "setKey", event.senderID, "admin")) {
} else if (testCommand(api, query2, "setKey", event.senderID, "root")) {
let data = input.split(" ");
if (data.length < 2 || !data[1].includes(":")) {
sendMessage(api, event, "Houston! Unknown or missing option.\n\n Usage: setKey name:key instead.");
Expand Down Expand Up @@ -5307,8 +5313,6 @@ async function ai(api, event) {
sendMessage(api, event, formatGen(cmdPage["help1"]) + NP);
settingsThread[event.threadID].cmd = 1;
}
} else if (data[1] == "admin") {
sendMessage(api, event, formatGen(cmdPage["admin"]));
} else if (data[1] == "owner") {
sendMessage(api, event, formatGen(cmdPage["owner"]));
} else if (data[1] == "root") {
Expand All @@ -5317,7 +5321,7 @@ async function ai(api, event) {
sendMessage(api, event, formatGen(cmdPage["help1"]) + NP);
settingsThread[event.threadID].cmd = 1;
} else {
sendMessage(api, event, "Houston! Unknown or missing option.\n\n Usage: cmd option \n Options: \n next, prev, admin, owner and root" + "\n " + example[Math.floor(Math.random() * example.length)] + " cmd next");
sendMessage(api, event, "Houston! Unknown or missing option.\n\n Usage: cmd option \n Options: \n next, prev, owner and root" + "\n " + example[Math.floor(Math.random() * example.length)] + " cmd next");
}
} else if (testCommand(api, query2, "wiki", event.senderID)) {
if (isGoingToFast(api, event)) return;
Expand Down Expand Up @@ -5997,7 +6001,7 @@ async function ai(api, event) {
sendMessage(api, event, "Token provided is too larged! Maximum of 10, 000 tokens");
} else if ((picker == 1 && /^head(s|)$/.test(data[1])) || (picker == 0 && /^tail(s|)$/.test(data[1]))) {
if (points >= 2000) {
points = points - (points * 0.15);
points = points - points * 0.15;
}
addBalance(name, points);
sendMessage(api, event, "You win!");
Expand Down Expand Up @@ -6631,6 +6635,8 @@ function isGoingToFast(api, event) {
if (data1[event.senderID].gender != "") {
newUser["gender"] = data1[event.senderID].gender;
}
newUser["created_date"] = new Date().toISOString();

users.list.push(newUser);

reactMessage(api, event, ":heart:");
Expand Down Expand Up @@ -8073,12 +8079,18 @@ function findPrefix(event, id) {
}

function saveState() {
let dir = __dirname + "/log/main.log";
if (!fs.existsSync(dir)) {
fs.writeFileSync(dir, "", "utf8");
}
fs.appendFileSync(dir, crashLog);
crashLog = "";

if (R_S_H_12_mmm) return;
fs.writeFileSync(__dirname + "/data/users.json", JSON.stringify(users), "utf8");
fs.writeFileSync(__dirname + "/data/groups.json", JSON.stringify(groups), "utf8");
fs.writeFileSync(__dirname + "/data/accountPreferences.json", JSON.stringify(settings), "utf8");
fs.writeFileSync(__dirname + "/data/threadPreferences.json", JSON.stringify(settingsThread), "utf8");
fs.writeFileSync(__dirname + "/data/crash-log.json", JSON.stringify(crashLog, null, 4), "utf8");
}

function getIdFromUrl(url) {
Expand Down Expand Up @@ -8326,6 +8338,21 @@ function getCountryOrigin(model) {
return "Singapore";
}

function getLogs() {
return async function (req, res) {
let ress = req.url;
let url = ress.split("?")[0];
utils.logged(req.method + " " + req.headers.origin + " " + url);
if (!fs.existsSync(__dirname + "/log/main.log")) {
res.writeHead(200);
res.end("No logs found!");
} else {
let file = fs.readFileSync(__dirname + "/log/main.log", "utf8");
res.writeHead(200);
res.end(file);
}
};
}
function getRoutes() {
return async function (req, res) {
let ress = req.url;
Expand Down Expand Up @@ -9145,14 +9172,15 @@ function handleError(err) {
crashes++;
utils.logged(err.stacktrace);
let eid = Math.floor(100000000 + Math.random() * 900000000);
crashLog[eid] = { date: new Date() };
let cInfo = "\n\n-----------\ndate: " + new Date().toISOString();
if (err.cuid) {
crashLog[eid]["cuid"] = err.cuid;
cInfo += "\ncuid: " + err.cuid;
}
if (err.e) {
crashLog[eid]["event"] = err.e;
cInfo += "\nevent: " + err.e;
}
crashLog[eid]["stacktrace"] = err.stacktrace;
cInfo += "\nstacktrace: " + err.stacktrace;
crashLog += cInfo;
let ct =
"\n\n^@^C^A>^D^A^@^P^C^AL^D^A^@^T^@^C^A" +
"\n- project orion build __version__ github.com/prj-orion^M" +
Expand Down Expand Up @@ -9199,6 +9227,8 @@ function updateUserData(user, uid) {
if (user[uid].gender != "") {
name["gender"] = user[uid].gender;
}

name["updated_date"] = new Date().toISOString();
}
});
}
Expand All @@ -9209,8 +9239,11 @@ function updateGroupData(gc, gid) {
if (gc.threadName) {
group["name"] = gc.threadName;
}

let arr = gc.participantIDs;
group["members"] = arr.length;

group["updated_date"] = new Date().toISOString();
}
});
}
Expand Down
1 change: 0 additions & 1 deletion src/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ function gen() {

help["root"] = help["root"].sort((a, b) => a.localeCompare(b));
help["owner"] = help["owner"].sort((a, b) => a.localeCompare(b));
help["admin"] = help["admin"].sort((a, b) => a.localeCompare(b));
commandAll = commandAll.sort((a, b) => a.localeCompare(b));

for (cmd in commandAll) {
Expand Down
Loading

0 comments on commit ddb2a16

Please sign in to comment.