diff --git a/index.js b/index.js index 16b802b5..9b06fc17 100644 --- a/index.js +++ b/index.js @@ -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"]; + } + } } } @@ -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 }); @@ -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); } }); @@ -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); }); } } @@ -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); }); } } @@ -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); }); } @@ -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); }); } @@ -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!"); @@ -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, { @@ -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; } } }); @@ -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."; @@ -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] !== " ") { @@ -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(); @@ -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!"); } @@ -9186,9 +9162,7 @@ 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); }); } @@ -9196,9 +9170,7 @@ async function addAccount() { 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); }); } @@ -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; diff --git a/package-lock.json b/package-lock.json index 2bde1ab7..04c7a1e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,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", @@ -2751,9 +2751,9 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, "node_modules/youtubei.js": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/youtubei.js/-/youtubei.js-6.4.1.tgz", - "integrity": "sha512-GVrDkJmF5t378SeDiZPEAoegZ1pxjbEzNyXTuiQnL5LzPSZKA3IoJwL8lBNlRMKyksI5RbieoHzULsEt4AIbFw==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/youtubei.js/-/youtubei.js-7.0.0.tgz", + "integrity": "sha512-z87cv6AAjj0c98BkD0qTJvBDTF2DdT+FntJUjmi+vHY2EV+CepeYQAE/eLsdhGvCb6LrNBgGVwVUzXpHYi8NoA==", "funding": [ "https://github.com/sponsors/LuanRT" ], @@ -4896,9 +4896,9 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, "youtubei.js": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/youtubei.js/-/youtubei.js-6.4.1.tgz", - "integrity": "sha512-GVrDkJmF5t378SeDiZPEAoegZ1pxjbEzNyXTuiQnL5LzPSZKA3IoJwL8lBNlRMKyksI5RbieoHzULsEt4AIbFw==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/youtubei.js/-/youtubei.js-7.0.0.tgz", + "integrity": "sha512-z87cv6AAjj0c98BkD0qTJvBDTF2DdT+FntJUjmi+vHY2EV+CepeYQAE/eLsdhGvCb6LrNBgGVwVUzXpHYi8NoA==", "requires": { "jintr": "^1.1.0", "tslib": "^2.5.0", diff --git a/package.json b/package.json index 21570c66..10823c1c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/me.jpg b/scratch/me.jpg similarity index 100% rename from src/me.jpg rename to scratch/me.jpg diff --git a/src/removeDuplicateData.js b/scratch/removeDuplicateData.js similarity index 100% rename from src/removeDuplicateData.js rename to scratch/removeDuplicateData.js diff --git a/src/test.js b/scratch/test-wel.js similarity index 75% rename from src/test.js rename to scratch/test-wel.js index deb8f7e8..3c2f9c3b 100644 --- a/src/test.js +++ b/scratch/test-wel.js @@ -5,7 +5,7 @@ /*jshint -W088 */ /*jshint -W038 */ -const welcomeGif = require("./welcome.js"); +const welcomeGif = require("../src/welcome.js"); async function main() { @@ -13,7 +13,7 @@ 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); } diff --git a/src/welcome.js b/src/welcome.js index a984e37d..c6c10cd9 100644 --- a/src/welcome.js +++ b/src/welcome.js @@ -10,91 +10,26 @@ var Canvas = require("canvas"); const fs = require("fs"); const utils = require("./redfox/utils.js"); -let mathSansMap = { - a: "๐–บ", - b: "๐–ป", - c: "๐–ผ", - d: "๐–ฝ", - e: "๐–พ", - f: "๐–ฟ", - g: "๐—€", - h: "๐—", - i: "๐—‚", - j: "๐—ƒ", - k: "๐—„", - l: "๐—…", - m: "๐—†", - n: "๐—‡", - o: "๐—ˆ", - p: "๐—‰", - q: "๐—Š", - r: "๐—‹", - s: "๐—Œ", - t: "๐—", - u: "๐—Ž", - v: "๐—", - w: "๐—", - x: "๐—‘", - y: "๐—’", - z: "๐—“", - A: "๐– ", - B: "๐–ก", - C: "๐–ข", - D: "๐–ฃ", - E: "๐–ค", - F: "๐–ฅ", - G: "๐–ฆ", - H: "๐–ง", - I: "๐–จ", - J: "๐–ฉ", - K: "๐–ช", - L: "๐–ซ", - M: "๐–ฌ", - N: "๐–ญ", - O: "๐–ฎ", - P: "๐–ฏ", - Q: "๐–ฐ", - R: "๐–ฑ", - S: "๐–ฒ", - T: "๐–ณ", - U: "๐–ด", - V: "๐–ต", - W: "๐–ถ", - X: "๐–ท", - Y: "๐–ธ", - Z: "๐–น", - 1: "๐Ÿฃ", - 2: "๐Ÿค", - 3: "๐Ÿฅ", - 4: "๐Ÿฆ", - 5: "๐Ÿง", - 6: "๐Ÿจ", - 7: "๐Ÿฉ", - 8: "๐Ÿช", - 9: "๐Ÿซ", - 0: "๐Ÿข", -}; - async function generateWelcomeGif(pictureFile, name, group, member) { - + name = name.normalize("NFKC"); + group = group.normalize("NFKC"); + if (name.length > 26) { name = name.substring(0, 26) + "..."; } if (group.length > 26) { group = group.substring(0, 26) + "..."; } - name = toMathSans(name); - group = toMathSans(group); - member = toMathSans(member); + const callBack = async (ctx, width, height, totalFrames, currentFrame) => { ctx.fillStyle = "#212121"; ctx.textAlign = "center"; - ctx.font = 'bold 30px "Operator Mono Bold"'; + ctx.font = 'bold 28px "Operator Mono Bold"'; ctx.fillText(name, width * 0.5, height * 0.7); - ctx.font = 'bold 21px "Operator Mono Bold"'; + ctx.font = '18px "Operator Mono"'; ctx.fillText(group, width * 0.5, height * 0.8); - ctx.font = 'bold 17px "Operator Mono Bold"'; + ctx.font = '15px "Operator Mono"'; ctx.fillText(member, width * 0.5, height * 0.9); x = width / 2; @@ -110,7 +45,7 @@ async function generateWelcomeGif(pictureFile, name, group, member) { let img = fs.readFileSync(pictureFile); let img1 = new Canvas.Image(); img1.src = img; - ctx.drawImage(img1, x - radius, y - radius, radius * 2, radius * 2); + ctx.drawImage(img1, x - radius, y - radius, radius * 3, radius * 3); ctx.restore(); ctx.stroke(); }; @@ -121,8 +56,8 @@ async function generateWelcomeGif(pictureFile, name, group, member) { repeat: 0, algorithm: "neuquant", optimiser: true, - fps: 60, - quality: 70, + fps: 40, + quality: 50, }; return await canvasGif(__dirname + "/welcome/welcome" + Math.floor(Math.random() * 10) + ".gif", callBack, options) @@ -132,7 +67,6 @@ async function generateWelcomeGif(pictureFile, name, group, member) { return returnD() + "/welcome_" + timesta + ".gif"; }) .catch((error) => { - console.log(error); return error; }); } @@ -140,24 +74,6 @@ async function generateWelcomeGif(pictureFile, name, group, member) { function returnD() { return __dirname.replace("src", "cache"); } - -function toMathSans(text) { - if (typeof text === "string") { - return text - .split(" ") - .map(function (a) { - return a - .split("") - .map(function (b) { - return mathSansMap[b] ? mathSansMap[b] : b; - }) - .join(""); - }) - .join(" "); - } - return text; -} - module.exports = { generateWelcomeGif }; \ No newline at end of file