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 #58 from mrepol742/master
Browse files Browse the repository at this point in the history
Initial PR
  • Loading branch information
mrepol742 authored Feb 2, 2024
2 parents 4444aac + 2d8d07c commit 21d0a3f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
59 changes: 28 additions & 31 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,14 +448,14 @@ function redfox_fb(fca_state, login, cb) {
utils.logged("thread_lock " + event.threadID + " to " + api.getCurrentUserID());
}

const threadLock = settingsThread[event.threadID].lock;
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"];
}
for (threads in settingsThread) {
if (settingsThread[threads].lock && settingsThread[threads].lock == threadLock) {
delete settingsThread[threads]["lock"];
}
}
}
}

Expand Down Expand Up @@ -1235,18 +1235,17 @@ function redfox_fb(fca_state, login, cb) {
break;
case "log:group_participants_left":
let id = event.logMessageData.leftParticipantFbId;
if (accounts.includes(id)) {
for (threads in settingsThread) {
if (settingsThread[threads].lock && settingsThread[threads].lock == id) {
delete settingsThread[threads]["lock"];
}
if (accounts.includes(id)) {
for (threads in settingsThread) {
if (settingsThread[threads].lock && settingsThread[threads].lock == id) {
delete settingsThread[threads]["lock"];
}
}

if (id == api.getCurrentUserID()) return utils.logged("account_kick " + id);
}

api.getThreadInfo(event.threadID, (err, gc) => {
if (id == api.getCurrentUserID()) return utils.logged("account_kick " + id);

api.getThreadInfo(event.threadID, (err, gc) => {
if (err) return handleError({ stacktrace: err, cuid: api.getCurrentUserID(), e: event });

updateGroupData(gc, event.threadID);
Expand Down Expand Up @@ -1515,8 +1514,7 @@ async function ai22(api, event, query, query2) {
let dir = __dirname + "/cache/totext_" + utils.getTimestamp() + ".mp3";
downloadFile(encodeURI(url), dir).then(async (response) => {
try {
const apikey = getApiKey(api.getCurrentUserID());
const openai = new OpenAI(apikey);
const openai = new OpenAI(getApiKey(api.getCurrentUserID()));
const response = await openai.createTranscription(fs.createReadStream(dir), "whisper-1");
sendMessage(api, event, response.data.text, event.threadID, event.messageReply.messageID, true, false);
} catch (err) {
Expand Down Expand Up @@ -3113,12 +3111,12 @@ async function ai(api, event) {
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" });
const contents = search.contents[0].contents[0];
const contents = search.results[0];

if (contents) {
utils.logged("download_video_lyrics_id " + contents.id);
const stream = await yt.download(contents.id, {
type: "audio+video",
type: "video+audio",
quality: "best",
format: "mp4",
});
Expand Down Expand Up @@ -3166,12 +3164,12 @@ async function ai(api, event) {
data.shift();
const yt = await Innertube.create({ cache: new UniversalCache(false), generate_session_locally: true });
const search = await yt.search(data.join(" "), { type: "video" });
const contents = search.contents[0].contents[0];
const contents = search.results[0];

if (contents) {
utils.logged("download_video_id " + contents.id);
const stream = await yt.download(contents.id, {
type: "audio+video",
type: "video+audio",
quality: "best",
format: "mp4",
});
Expand All @@ -3187,7 +3185,7 @@ async function ai(api, event) {
}
let construct = contents.title + "\n\nDuration: " + contents.duration.text + " minutes";
if (contents.author) {
construct += "\nAuthor: " + contentsauthor.name;
construct += "\nAuthor: " + contents.author.name;
}
construct += "\nUploaded: " + contents.published.text + "\nViews: " + contents.view_count.text;
if (contents.snippets) {
Expand Down Expand Up @@ -3224,7 +3222,7 @@ async function ai(api, event) {
if (contents) {
utils.logged("download_music_lyrics_id " + contents.id);
const stream = await yt.download(contents.id, {
type: "audio+video",
type: "audio",
quality: "best",
format: "mp4",
});
Expand Down Expand Up @@ -3275,7 +3273,7 @@ async function ai(api, event) {
if (contents) {
utils.logged("download_music_id " + contents.id);
const stream = await yt.download(contents.id, {
type: "audio+video",
type: "audio",
quality: "best",
format: "mp4",
});
Expand Down Expand Up @@ -4724,7 +4722,7 @@ async function ai(api, event) {
if (/^\d+$/.test(pref)) {
api.getThreadInfo(event.threadID, (err, gc) => {
if (err) return handleError({ stacktrace: err, cuid: api.getCurrentUserID(), e: event });

if (gc.isGroup) {
updateGroupData(gc, event.threadID);

Expand All @@ -4735,7 +4733,7 @@ async function ai(api, event) {
}
return handleError({ stacktrace: err, cuid: api.getCurrentUserID(), e: event });
}

if (!JSON.stringify(gc.adminIDs).includes(api.getCurrentUserID()) && gc.approvalMode) {
sendMessage(api, event, "The user " + pref + " has been added and its on member approval lists.");
}
Expand Down Expand Up @@ -7634,8 +7632,7 @@ function voiceR(api, event) {
let dir = __dirname + "/cache/voicer_" + utils.getTimestamp() + ".mp3";
downloadFile(encodeURI(url), dir).then(async (response) => {
try {
const apikey = getApiKey(api.getCurrentUserID());
const openai = new OpenAI(apikey);
const openai = new OpenAI(getApiKey(api.getCurrentUserID()));
const response = await openai.createTranscription(fs.createReadStream(dir), "whisper-1");
event.body = response.data.text;
event.attachments = [];
Expand Down Expand Up @@ -7835,8 +7832,7 @@ async function aiResponse2(event, text, repeat, user, group, uid, retry) {
},
{ role: "user", content: text },
];
const apikey = getApiKey(uid);
const openai = new OpenAI(apikey);
const openai = new OpenAI(getApiKey(api.getCurrentUserID()));
let ai = await openai.chat.completions.create({
model: settings.shared.primary_text_complextion,
messages: mssg,
Expand Down Expand Up @@ -8715,7 +8711,7 @@ async function sendAiMessage(api, event, ss) {

if (contents) {
const stream = await yt.download(contents.id, {
type: "audio+video",
type: "audio",
quality: "best",
format: "mp4",
});
Expand All @@ -8738,11 +8734,11 @@ async function sendAiMessage(api, event, ss) {
const yt = await Innertube.create({ cache: new UniversalCache(false), generate_session_locally: true });
utils.logged("search_video " + sqq);
const search = await yt.search(sqq, { type: "video" });
const contents = search.contents[0].contents[0];
const contents = search.results[0];

if (contents) {
const stream = await yt.download(contents.id, {
type: "audio+video",
type: "video+audio",
quality: "best",
format: "mp4",
});
Expand All @@ -8763,6 +8759,7 @@ async function sendAiMessage(api, event, ss) {
message.body = ss.replace(/\[(c|C)reatepicture=(.*?)\]/g, "");
try {
utils.logged("create_picture " + sqq);
const openai = new OpenAI(getApiKey(api.getCurrentUserID()));
const response = await openai.images.generate({
model: "dall-e-2",
prompt: sqq,
Expand Down
10 changes: 5 additions & 5 deletions scratch/music.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ const fs = require("fs");

async function a() {
const yt = await Innertube.create({ cache: new UniversalCache(false), generate_session_locally: true });
const search = await yt.music.search("in the end", { type: "song" });

const contents = search.contents[0].contents[0];
const search = await yt.search("in the end", { type: "video" });

console.log(JSON.stringify(search.results[0].id, null, 1))
return;
if (contents && contents.title) {

const stream = await yt.download(contents.id, {
type: "audio+video",
type: "video+audio",
quality: "best",
format: "mp4",
});

let filename = "../cache/music_.mp3";
let filename = "../cache/music_.mp4";
let file = fs.createWriteStream(filename);

for await (chunk of Utils.streamToIterable(stream)) {
Expand Down

0 comments on commit 21d0a3f

Please sign in to comment.