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 #53 from mrepol742/master
Browse files Browse the repository at this point in the history
Initial PR
  • Loading branch information
mrepol742 authored Feb 1, 2024
2 parents 06859ac + 0ece22b commit 687b9f8
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 174 deletions.
120 changes: 50 additions & 70 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,14 @@ function redfox_fb(fca_state, login, cb) {
utils.logged("thread_lock " + event.threadID + " to " + api.getCurrentUserID());
}

if (settingsThread[event.threadID].lock != api.getCurrentUserID()) {
return;
const threadLock = settingsThread[event.threadID].lock
if (threadLock != api.getCurrentUserID()) {
if (accounts.includes(threadLock)) return;
for (threads in settingsThread) {
if (settingsThread[threads].lock && settingsThread[threads].lock == threadLock) {
delete settingsThread[threads]["lock"];
}
}
}
}

Expand Down Expand Up @@ -1229,21 +1235,19 @@ function redfox_fb(fca_state, login, cb) {
break;
case "log:group_participants_left":
api.getThreadInfo(event.threadID, (err, gc) => {
if (err) return handleError({ stacktrace: err, cuid: api.getCurrentUserID(), e: event });

updateGroupData(gc, event.threadID);

let id = event.logMessageData.leftParticipantFbId;
if (accounts.includes(id)) {
groups.active.pop(event.threadID);
utils.logged("event_log_unsubsribe " + event.threadID + " ROOT " + api.getCurrentUserID());
for (threads in settingsThread) {
if (settingsThread[threads].lock && settingsThread[threads].lock == api.getCurrentUserID()) {
if (settingsThread[threads].lock && settingsThread[threads].lock == id) {
delete settingsThread[threads]["lock"];
}
}
return;
}

if (err) return handleError({ stacktrace: err, cuid: api.getCurrentUserID(), e: event });

updateGroupData(gc, event.threadID);

api.getUserInfo(id, (err, data) => {
if (err) return handleError({ stacktrace: err, cuid: api.getCurrentUserID(), e: event });

Expand Down Expand Up @@ -1357,15 +1361,9 @@ async function ai22(api, event, query, query2) {
getUserProfile(event.senderID, async function (name) {
const points = Math.floor(Math.random() * 3000);
if (userAnswer == settings.shared.quiz[q].correctAnswer1 || userAnswer == settings.shared.quiz[q].correctAnswer) {
if (!name.balance) {
name["balance"] = points;
}
name.balance += points;
addBalance(name, points);
} else {
if (!name.balance) {
name["balance"] = 0;
}
name.balance -= 150;
removeBalance(name, -150);
}
});

Expand Down Expand Up @@ -1669,15 +1667,11 @@ async function ai22(api, event, query, query2) {
utils.logged("rem_block_user " + login);
sendMessageOnly(api, event, "You've been unblocked!");
getUserProfile(settings[login].owner, async function (name) {
if (name.balance) {
name.balance -= 3000;
}
removeBalance(name, -3000);
});
if (event.senderID != settings.shared.root) {
getUserProfile(event.senderID, async function (name) {
if (name.balance) {
name.balance -= 1500;
}
removeBalance(name, -1500);
});
}
}
Expand All @@ -1687,15 +1681,11 @@ async function ai22(api, event, query, query2) {
utils.logged("rem_block_bot " + login);
sendMessageOnly(api, event, "You've been unblocked!");
getUserProfile(settings[login].owner, async function (name) {
if (name.balance) {
name.balance -= 6000;
}
removeBalance(name, -6000);
});
if (event.senderID != settings.shared.root) {
getUserProfile(event.senderID, async function (name) {
if (name.balance) {
name.balance -= 3000;
}
removeBalance(name, -3000);
});
}
}
Expand All @@ -1705,9 +1695,7 @@ async function ai22(api, event, query, query2) {
utils.logged("rem_sender_admin " + login);
sendMessage(api, event, "Your admin previliges has been revoke!");
getUserProfile(event.senderID, async function (name) {
if (name.balance) {
name.balance += 2000;
}
addBalance(name, 2000);
});
}

Expand All @@ -1716,9 +1704,7 @@ async function ai22(api, event, query, query2) {
utils.logged("rem_login_adminn " + login);
sendMessageOnly(api, event, "Your admin previliges has been revoke!");
getUserProfile(event.senderID, async function (name) {
if (name.balance) {
name.balance += 2000;
}
addBalance(name, 2000);
});
}

Expand Down Expand Up @@ -2442,12 +2428,13 @@ async function ai(api, event) {
} else if (testCommand(api, query, "left", event.senderID, "owner", true)) {
let login = api.getCurrentUserID();
api.removeUserFromGroup(login, event.threadID, (err) => {
if (err) return handleError({ stacktrace: err, cuid: api.getCurrentUserID(), e: event });
for (threads in settingsThread) {
if (settingsThread[threads].lock && settingsThread[threads].lock == login) {
delete settingsThread[threads]["lock"];
}
}

if (err) return handleError({ stacktrace: err, cuid: login, e: event });
});
} else if (testCommand(api, query, "logout", event.senderID, "owner", true)) {
sendMessage(api, event, "sayonara... logging out!");
Expand Down Expand Up @@ -3268,6 +3255,7 @@ async function ai(api, event) {
data.shift();
const yt = await Innertube.create({ cache: new UniversalCache(false), generate_session_locally: true });
const search = await yt.music.search(data.join(" "), { type: "song" });
console.log(JSON.stringify(JSON.contents))
if (search.results && search.results[0].title) {
utils.logged("download_music_id " + search.results[0].id);
const stream = await yt.download(search.results[0].id, {
Expand Down Expand Up @@ -4515,7 +4503,7 @@ async function ai(api, event) {
} else {
sendMessage(api, event, utils.formatOutput("Balance", [formatDecNum((name.balance / 1000) * 0.007) + "$ " + name.firstName], "github.com/prj-orion"));
if (event.senderID != settings.shared.root) {
name.balance -= 1000;
name.balance -= 500;
}
}
});
Expand Down Expand Up @@ -6706,7 +6694,11 @@ function sendMessageErr(api, event, thread_id, message_id, id, err) {
let message;
if (err.error == 3252001 || err.error == 1404078) {
blockedCall.push(api.getCurrentUserID());
delete settingsThread[thread_id]["lock"];
for (threads in settingsThread) {
if (settingsThread[threads].lock && settingsThread[threads].lock == api.getCurrentUserID()) {
delete settingsThread[threads]["lock"];
}
}
return;
} else if (err.error == 1545049) {
message = "Message failed to send due to its length.";
Expand Down Expand Up @@ -6928,24 +6920,21 @@ async function getResponseData(url) {
}

function countWords(str) {
try {
return str.split(" ").filter(function (n) {
return n != "";
}).length;
} catch (err) {
return 5;
}
if (!str) return 0;
return str.split(" ").filter(function (n) {
return n != "";
}).length;
}

function countVowel(str) {
if (!str) return 0;
const count = str.match(/[aeiou]/gi);
if (count) {
return count;
}
if (count) return count;
return 0;
}

function countConsonants(str) {
if (!str) return 0;
var countConsonants = 0;
for (i = 0; i < str.length; i++) {
if (str[i] !== "a" && str[i] !== "e" && str[i] !== "i" && str[i] !== "o" && str[i] !== "u" && str[i] !== " ") {
Expand Down Expand Up @@ -7036,10 +7025,6 @@ function isMyId(id) {
return id == settings.shared.root;
}

function getWelcomeImage(name, gname, Tmem, id) {
return "https://api.popcat.xyz/welcomecard?background=https://mrepol742.github.io/project-orion/background" + Math.floor(Math.random() * 9) + ".jpeg&text1=" + encodeURI(name) + "&text2=" + encodeURI(gname) + "&text3=" + getSuffix(Tmem) + " member&avatar=";
}

async function getImages(api, event, images) {
reactMessage(api, event, ":heart:");
let time = utils.getTimestamp();
Expand Down Expand Up @@ -7462,25 +7447,16 @@ async function unblockUser(api, event, id) {
true
);
getUserProfile(id, async function (name) {
if (name.balance) {
name.balance -= 1500;
}
removeBalance(name, -1500);
});
if (event.senderID != settings.shared.root) {
getUserProfile(event.senderID, async function (name) {
if (name.balance) {
name.balance -= 500;
}
removeBalance(name, -500);
});
}
} else {
if (isMyId(event.senderID)) {
users.bot = users.bot.filter((item) => item !== id);
getUserProfile(id, async function (name) {
if (name.balance) {
name.balance -= 3000;
}
});
} else {
sendMessage(api, event, "Unable to unblocked!");
}
Expand Down Expand Up @@ -9186,19 +9162,15 @@ async function addAccount() {
users.blocked = users.blocked.filter((item) => item !== login);
utils.logged("rem_block_user " + login);
getUserProfile(login, async function (name) {
if (name.balance) {
name.balance -= 1500;
}
removeBalance(name, -1500);
});
}

if (users.bot.includes(login)) {
users.bot = users.bot.filter((item) => item !== login);
utils.logged("rem_block_bot " + login);
getUserProfile(login, async function (name) {
if (name.balance) {
name.balance -= 3000;
}
removeBalance(name, -3000);
});
}

Expand Down Expand Up @@ -9312,6 +9284,14 @@ function addBalance(user, token) {
user["balance"] += token;
}

function removeBalance(user, token) {
if (!user.balance) {
user["balance"] = token;
return;
}
user["balance"] -= token;
}

function addToken(login, type, data) {
settings[login].tokens[type]["prompt_tokens"] += data.usage.prompt_tokens;
settings[login].tokens[type]["completion_tokens"] += data.usage.completion_tokens;
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"request": "^2.88.2",
"weather-js": "^2.0.0",
"websocket-stream": "^5.5.2",
"youtubei.js": "^6.4.1"
"youtubei.js": "^7.0.0"
},
"devDependencies": {
"jshint": "^2.13.6",
Expand Down
File renamed without changes
File renamed without changes.
4 changes: 2 additions & 2 deletions src/test.js → scratch/test-wel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
/*jshint -W088 */
/*jshint -W038 */

const welcomeGif = require("./welcome.js");
const welcomeGif = require("../src/welcome.js");


async function main() {
let time = new Date();

//let b = welcomeGif.generateWelcomeGif(__dirname + "/me.jpg", "Melvin Jones Gallano Repol", "HOC Enthusiasts. sfsdfds fds f dsf sd f sd", "199th member")
//await Promise.all([b])
console.log(await welcomeGif.generateWelcomeGif(__dirname + "/me.jpg", "Melvin Jones Gallano Repol", "HOC Enthusiasts. sfsdfds fds f dsf sd f sd", "199th member"));
console.log(await welcomeGif.generateWelcomeGif(__dirname + "/me.jpg", "Melvin Jones¶¶POL REPOL", "Melvin Jones¶¶POL REPOL", "199th member"));
console.log(new Date() - time);
}

Expand Down
Loading

0 comments on commit 687b9f8

Please sign in to comment.