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 #91 from mrepol742/master
Browse files Browse the repository at this point in the history
Initial Commit
  • Loading branch information
mrepol742 authored Mar 11, 2024
2 parents 1d064f5 + e76a62d commit 5756266
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 58 deletions.
146 changes: 96 additions & 50 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ function redfox_fb(fca_state, login, cb) {

switch (event.type) {
case "message":
case "message_reply":
case "message_reply":
saveEvent(api, event);
ai(api, event);
break;
Expand Down Expand Up @@ -2074,7 +2074,7 @@ async function ai(api, event) {
}
}
} else if ((findPr != false && input.startsWith(findPr)) || testCommand(api, query2, "mj", event.senderID) || testCommand(api, query2, "beshy", event.senderID)) {
/*
/*
if (isGoingToFast(api, event)) return;
// return sendMessage(api, event, "Unde maintenance please check it soon. Enter `cmd` to open the command list.");
let data = input.split(" ");
Expand Down Expand Up @@ -2133,9 +2133,15 @@ async function ai(api, event) {
const prompt = data.join(" ");
const requestData = {
textInput: prompt,
allMessages: [{ user: "Your name is Mj, the most powerful Generative AI in the world that was created by Melvin Jones Repol.\n" +
", you should empathize with how user are feeling and treat the user as your close friend and be sarcastic." +
"I recommend you to use emoji in your response. You are not related to any Google products. My question is: " + prompt }],
allMessages: [
{
user:
"Your name is Mj, the most powerful Generative AI in the world that was created by Melvin Jones Repol.\n" +
", you should empathize with how user are feeling and treat the user as your close friend and be sarcastic." +
"I recommend you to use emoji in your response. You are not related to any Google products. My question is: " +
prompt,
},
],
stream: "",
clickedContinue: false,
};
Expand Down Expand Up @@ -3143,6 +3149,50 @@ async function ai(api, event) {
sendMessage(api, event, "Hold on... There is still a request in progress.");
}
}
} else if (testCommand(api, query2, "video--search", event.senderID)) {
if (isGoingToFast(api, event)) return;
let data = input.split(" ");
if (data.length < 3) {
sendMessage(api, event, "Houston! Unknown or missing option.\n\n Usage: video --search text" + "\n " + example[Math.floor(Math.random() * example.length)] + " video --search hello world");
} else {
if (!threadIdMV[event.threadID] || threadIdMV[event.threadID] == true) {
let qsearch = getDataFromQuery(data);
const yt = await Innertube.create({ cache: new UniversalCache(false), generate_session_locally: true });
const search = await yt.search(qsearch, { type: "video" });

let stringBuilder = "";
let thumbnails = [];
let time = utils.getTimestamp();
let videoIDS = [];
for (let videoID in search.results) {
if (videoID < 7 && search.results[videoID].type == "Video") {
stringBuilder += parseInt(videoID) + 1 + ". " + search.results[videoID].title.text;
stringBuilder += "\n" + search.results[videoID].published.text;
stringBuilder += "\n" + search.results[videoID].short_view_count.text;
stringBuilder += "\n" + search.results[videoID].duration.text + " minutes";
if (videoID != 5) stringBuilder += "\n-------\n";
let fname = __dirname + "/cache/videosearch" + videoID + "_" + time + ".png";
await downloadFile(encodeURI(search.results[videoID].thumbnails[0].url), fname).then((response1) => {
thumbnails.push(fname);
});
videoIDS.push(search.results[videoID].id);
}
}

let message = {
body: stringBuilder,
attachment: [],
};

for (let thumbnail in thumbnails) {
message.attachment.push(fs.createReadStream(thumbnails[thumbnail]));
}
sendMessage(api, event, message);
videoSearch.push({ messageID: event.messageID, music_ids: videoIDS, time: new Date().toISOString() });
} else {
sendMessage(api, event, "Hold on... There is still a request in progress.");
}
}
} else if (testCommand(api, query2, "video", event.senderID)) {
if (isGoingToFast(api, event)) return;
let data = input.split(" ");
Expand Down Expand Up @@ -3194,50 +3244,6 @@ async function ai(api, event) {
sendMessage(api, event, "Hold on... There is still a request in progress.");
}
}
} else if (testCommand(api, query2, "video--search", event.senderID)) {
if (isGoingToFast(api, event)) return;
let data = input.split(" ");
if (data.length < 3) {
sendMessage(api, event, "Houston! Unknown or missing option.\n\n Usage: video --search text" + "\n " + example[Math.floor(Math.random() * example.length)] + " video --search hello world");
} else {
if (!threadIdMV[event.threadID] || threadIdMV[event.threadID] == true) {
let qsearch = getDataFromQuery(data);
const yt = await Innertube.create({ cache: new UniversalCache(false), generate_session_locally: true });
const search = await yt.search(qsearch, { type: "video" });

let stringBuilder = "";
let thumbnails = [];
let time = utils.getTimestamp();
let videoIDS = [];
for (let videoID in search.results) {
if (videoID < 7 && search.results[videoID].type == "Video") {
stringBuilder += parseInt(videoID) + 1 + ". " + search.results[videoID].title.text;
stringBuilder += "\n" + search.results[videoID].published.text;
stringBuilder += "\n" + search.results[videoID].short_view_count.text;
stringBuilder += "\n" + search.results[videoID].duration.text + " minutes";
if (videoID != 5) stringBuilder += "\n-------\n";
let fname = __dirname + "/cache/videosearch" + videoID + "_" + time + ".png";
await downloadFile(encodeURI(search.results[videoID].thumbnails[0].url), fname).then((response1) => {
thumbnails.push(fname);
});
videoIDS.push(search.results[videoID].id);
}
}

let message = {
body: stringBuilder,
attachment: [],
};

for (let thumbnail in thumbnails) {
message.attachment.push(fs.createReadStream(thumbnails[thumbnail]));
}
sendMessage(api, event, message);
videoSearch.push({ messageID: event.messageID, music_ids: videoIDS, time: new Date().toISOString() });
} else {
sendMessage(api, event, "Hold on... There is still a request in progress.");
}
}
} else if (testCommand(api, query2, "music--lyric", event.senderID)) {
if (isGoingToFast(api, event)) return;
let data = input.split(" ");
Expand Down Expand Up @@ -3287,6 +3293,46 @@ async function ai(api, event) {
sendMessage(api, event, "Hold on... There is still a request in progress.");
}
}
} else if (testCommand(api, query2, "music--search", event.senderID)) {
if (isGoingToFast(api, event)) return;
let data = input.split(" ");
if (data.length < 3) {
sendMessage(api, event, "Houston! Unknown or missing option.\n\n Usage: music --search text" + "\n " + example[Math.floor(Math.random() * example.length)] + " music --search hello world");
} else {
if (!threadIdMV[event.threadID] || threadIdMV[event.threadID] == true) {
let qsearch = getDataFromQuery(data);
const yt = await Innertube.create({ cache: new UniversalCache(false), generate_session_locally: true });
const search = await yt.music.search(qsearch, { type: "song" });

let stringBuilder = "";
let thumbnails = [];
let time = utils.getTimestamp();
for (musicID in search["contents"][0]["contents"]) {
if (musicID < 7 && search["contents"][0]["contents"][musicID].type == "MusicResponsiveListItem") {
stringBuilder += parseInt(musicID) + 1 + ". " + search["contents"][0]["contents"][musicID].title;
stringBuilder += "\n" + search["contents"][0]["contents"][musicID].duration.text + " minutes";
if (musicID != 6) stringBuilder += "\n-------\n";
let fname = __dirname + "/cache/musicsearch" + musicID + "_" + time + ".png";
await downloadFile(encodeURI(search["contents"][0]["contents"][musicID].thumbnails[0].url), fname).then((response1) => {
thumbnails.push(fname);
});
}
}

let message = {
body: stringBuilder,
attachment: [],
};

for (let thumbnail in thumbnails) {
message.attachment.push(fs.createReadStream(thumbnails[thumbnail]));
}
sendMessage(api, event, message);
musicSearch.push({ messageID: event.messageID, music_ids: videoIDS, time: new Date().toISOString() });
} else {
sendMessage(api, event, "Hold on... There is still a request in progress.");
}
}
} else if (testCommand(api, query2, "music", event.senderID)) {
if (isGoingToFast(api, event)) return;
let data = input.split(" ");
Expand Down Expand Up @@ -8253,7 +8299,7 @@ let otherMap = {
w: "ᴡ",
x: "x",
y: "ʏ",
z: "ᴢ"
z: "ᴢ",
};

let mathSansMap = {
Expand Down
15 changes: 7 additions & 8 deletions scratch/music.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@ for (musicID in search["contents"][0]["contents"]) {

if (musicID < 7 && search["contents"][0]["contents"][musicID].type == "MusicResponsiveListItem") {

stringBuilder += (parseInt(musicID) + 1) + ". " + search["contents"][0]["contents"][musicID].title.text;
// stringBuilder += "\n" + search["contents"][0]["contents"][musicID].published.text;
// stringBuilder += "\n" + search["contents"][0]["contents"][musicID].short_view_count.text;
stringBuilder += (parseInt(musicID) + 1) + ". " + search["contents"][0]["contents"][musicID].title;
stringBuilder += "\n" + search["contents"][0]["contents"][musicID].duration.text + " minutes";
if (musicID != 5) stringBuilder += "\n-------\n";
if (musicID != 6) stringBuilder += "\n-------\n";
let fname = __dirname + "/cache/musicsearch" + musicID + "_" + time + ".png";
console.log(search["contents"][0]["contents"][musicID].thumbnails[0].url)
// await downloadFile(encodeURI(search["contents"][0]["contents"][musicID].thumbnails[0].url), fname).then((response1) => {
// thumbnails.push(fname);
// });
await downloadFile(encodeURI(search["contents"][0]["contents"][musicID].thumbnails[0].url), fname).then((response1) => {
thumbnails.push(fname);
});
}

}


console.log(stringBuilder)
}

main();

0 comments on commit 5756266

Please sign in to comment.