Skip to content

Commit

Permalink
Merge pull request #30 from Zastinian/beta
Browse files Browse the repository at this point in the history
Update to version 3.3.0
  • Loading branch information
Zastinian authored Nov 30, 2024
2 parents b35706d + 53a4bf2 commit e4deee2
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 15 deletions.
6 changes: 6 additions & 0 deletions hedystia.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ module.exports = async (hedystia, m) => {
cont = status;
}
}
const privateStatus = globalThis.db.config.select("private", { id: "private" })[0].value;
if (!privateStatus) {
if (!isGroup) {
return;
}
}
if (!cont) {
return;
}
Expand Down
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,25 @@ try {
: Buffer.alloc(0);
return await hedystia.sendMessage(jid, { audio: buffer, ptt, ...options }, { quoted });
};
hedystia.replyAudio = async (path, m, opts = {}) => {
const p = /^https?/.test(path) ? { url: path } : path;
return await hedystia.sendMessage(
opts.chat || m.chat,
{
audio: p,
fileName: opts.filename || `${Date.now}.mp3`,
ptt: opts.ptt || false,
mimetype: opts.ptt ? "audio/ogg; codecs=opus" : "audio/mpeg",
contextInfo: {
mentionedJid: opts.mentions || [m.sender],
},
},
{
quoted: m || m,
ephemeralExpiration: m.ephemeral || null,
},
);
};
hedystia.sendTextWithMentions = async (jid, text, quoted, options = {}) =>
hedystia.sendMessage(
jid,
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hedystiamd",
"version": "3.2.1",
"version": "3.3.0",
"description": "A whatsapp bot that can be used to play music",
"main": "index.js",
"type": "commonjs",
Expand All @@ -26,7 +26,6 @@
"node-webpmux": "^3.2.0",
"pino": "^9.5.0",
"qrcode-terminal": "0.12.0",
"soundcloud.ts": "^0.5.5",
"wa-sticker-formatter": "4.4.4"
},
"devDependencies": {
Expand Down
77 changes: 77 additions & 0 deletions src/commands/owner/private.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module.exports = {
name: "lang",
run: async ({ bot, lang, args, message, types }) => {
if (!types.isBotOwner) {
return bot.sendMessage(message.chat, { text: lang.global.noOwner }, { quoted: message });
}
if (!args[0]) {
return bot.sendMessage(
message.chat,
{ text: lang.owner.private.noPrivate },
{ quoted: message },
);
}
const newPrivateStatus = args[0].toLowerCase();
if (
newPrivateStatus === "true" ||
newPrivateStatus === "on" ||
newPrivateStatus === "encendido" ||
newPrivateStatus === "enabled" ||
newPrivateStatus === "false" ||
newPrivateStatus === "off" ||
newPrivateStatus === "apagado" ||
newPrivateStatus === "desactivado" ||
newPrivateStatus === "disabled"
) {
let l;
let n;
switch (newPrivateStatus) {
case "true":
l = true;
n = "True";
break;
case "on":
l = true;
n = "True";
break;
case "enabled":
l = true;
n = "True";
break;
case "false":
l = false;
n = "False";
break;
case "off":
l = false;
n = "False";
break;
case "apagado":
l = false;
n = "False";
break;
case "desactivado":
l = false;
n = "False";
break;
case "disabled":
l = false;
n = "False";
break;
}
global.db.config.update("private", { id: "private" }, { value: l });
return bot.sendMessage(
message.chat,
{ text: `${lang.owner.private.correct}`.replace("{custom}", n) },
{ quoted: message },
);
}
return bot.sendMessage(
message.chat,
{
text: `${lang.owner.private.errorExisting}`.replace("{custom}", "true, false"),
},
{ quoted: message },
);
},
};
79 changes: 66 additions & 13 deletions src/commands/utils/play.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
const cloud = require("soundcloud.ts").default;
const getYouTubeId = (url) => {
let match = null;
const regexWatch =
/(?:https?:\/\/(?:www\.)?youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|(?:.*?[?&]v=))([a-zA-Z0-9_-]{11}))/;
const regexShorts = /(?:https?:\/\/(?:www\.)?youtu\.be\/([a-zA-Z0-9_-]{11}))/;
const regexDirectShorts = /(?:https?:\/\/(?:www\.)?youtube\.com\/shorts\/([a-zA-Z0-9_-]{11}))/;
match = url.match(regexWatch);
if (match) return match[1];
match = url.match(regexShorts);
if (match) return match[1];
match = url.match(regexDirectShorts);
if (match) return match[1];
return null;
};

module.exports = {
name: "play",
Expand All @@ -12,24 +25,64 @@ module.exports = {
{ quoted: message },
);
}
const client = new cloud();
const customRegex = /^.+\/.+$/;
bot.sendMessage(message.chat, { text: lang.music.play.download }, { quoted: message });
let track;
if (customRegex.test(text)) {
track = await client.tracks.getAlt(text);
const id = getYouTubeId(text);
if (id) {
const song = await fetch(`https://scrapers.hedystia.com/search/youtube/video?id=${id}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-GitHub-First-Request-URL": "https://github.com/Zastinian/HedystiaMD",
"X-GitHub-Second-Request-URL": "https://github.com/Hidekijs",
},
})
.then((res) => res.json())
.then((data) => data)
.catch(() => null);
if (!song) return bot.sendMessage(message.chat, { text: lang.music.play.not_found });
track = await fetch(`https://scrapers.hedystia.com/downloads/yt-music?url=${song.url}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-GitHub-First-Request-URL": "https://github.com/Zastinian/HedystiaMD",
"X-GitHub-Second-Request-URL": "https://github.com/Hidekijs",
},
})
.then((res) => res.json())
.then((data) => data)
.catch(() => null);
} else {
track = await client.tracks.searchAlt(text);
const songs = await fetch(`https://scrapers.hedystia.com/search/youtube/name?text=${text}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-GitHub-First-Request-URL": "https://github.com/Zastinian/HedystiaMD",
"X-GitHub-Second-Request-URL": "https://github.com/Hidekijs",
},
})
.then((res) => res.json())
.then((data) => data)
.catch(() => null);
if (!songs || !songs[0])
return bot.sendMessage(message.chat, { text: lang.music.play.not_found });
track = await fetch(`https://scrapers.hedystia.com/downloads/yt-music?url=${songs[0].url}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-GitHub-First-Request-URL": "https://github.com/Zastinian/HedystiaMD",
"X-GitHub-Second-Request-URL": "https://github.com/Hidekijs",
},
})
.then((res) => res.json())
.then((data) => data)
.catch(() => null);
}
if (!track || !track[0])
if (!track) return bot.sendMessage(message.chat, { text: lang.music.play.not_found });
if (!track.lowFileLink)
return bot.sendMessage(message.chat, { text: lang.music.play.not_found });
try {
await client.util.downloadTrack(`${track[0].user.permalink}/${track[0].permalink}`, "./tmp");
return bot.sendMessage(message.chat, {
audio: { url: `${path.join(__dirname, "../../../tmp")}/${track[0].title}.mp3` },
mimetype: "audio/mpeg",
fileName: `${track[0].title}`,
});
return await bot.replyAudio(track.lowFileLink, message, { replyAudio: false });
} catch {
return bot.sendMessage(message.chat, { text: lang.music.play.error }, { quoted: message });
}
Expand Down
75 changes: 75 additions & 0 deletions src/db/migrations/2024-11-29T13-45-23.456Z.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const readline = require("readline");

function getPrivateStatus() {
return new Promise((resolve) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const askPrivate = async () => {
console.log("");
rl.question(
"\x1b[93mTell me if you want to disable or enable private chats (true/false)\x1b[94m\n⤳\x1b[0m ",
(input) => {
const value = input.toLowerCase().trim();
if (
value === "true" ||
value === "on" ||
lang === "encendido" ||
value === "enabled" ||
value === "false" ||
value === "off" ||
value === "apagado" ||
value === "desactivado" ||
value === "disabled"
) {
let l;
switch (value) {
case "true":
l = true;
break;
case "on":
l = true;
break;
case "enabled":
l = true;
break;
case "false":
l = false;
break;
case "off":
l = false;
break;
case "apagado":
l = false;
break;
case "desactivado":
l = false;
break;
case "disabled":
l = false;
break;
}
resolve(l);
rl.close();
} else {
console.log("");
console.log("\x1b[91mERROR: \x1b[92mThe private status provided is not correct\x1b[0m");
setTimeout(() => {
console.log("");
askPrivate();
});
}
},
);
};
askPrivate();
});
}

module.exports = async (config) => {
config.deleteTableIfExists("private");
config.createTable("private", ["id", "value"]);
const p = await getPrivateStatus();
config.insert("private", { id: "private", value: p });
};
17 changes: 17 additions & 0 deletions src/db/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,21 @@ module.exports = async (migrations, config) => {
);
},
);
await migrations.createMigration(
{
id: "2024-11-29T13-45-23.456Z",
description: "Added disable private chats",
timestamp: Date.now(),
},
async () => {
console.log("\n");
console.log("\x1b[97mCreating the migrations 2024-11-29T13:45:23.456Z\x1b[0m");
const migration = require("./2024-11-29T13-45-23.456Z");
await migration(config);
console.log("");
console.log(
"\x1b[95mThe creation of the migrations 2024-11-29T13:45:23.456Z has been completed\x1b[0m",
);
},
);
};
5 changes: 5 additions & 0 deletions src/lang/en/bot.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
"errorLength": "❌ | The prefix must have a maximum length of 6",
"correct": "✔️ | The prefix was changed correctly the new prefix is: {custom}"
},
"private": {
"noPrivate": "❌ | You have not specified if you want to disable or enable private chats",
"errorExisting": "❌ | The specified status does not exist, the existing statuses are: {custom}",
"correct": "✔️ | The status has been changed correctly now the new status is: {custom}"
},
"antiLinks": {
"enabled": "✔️ | The anti-links system has been activated.",
"disabled": "✔️ | The anti-links system has been deactivated.",
Expand Down
5 changes: 5 additions & 0 deletions src/lang/es/bot.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
"errorLength": "❌ | El prefix debe tener una longitud máxima de 6",
"correct": "✔️ | El prefix se ha cambiado correctamente el nuevo prefix es: {custom}"
},
"private": {
"noPrivate": "❌ | No has especificado si deseas desactivar o activar los chats privados",
"errorExisting": "❌ | El estado especificado no existe, los estados existentes son: {custom}",
"correct": "✔️ | El estado ha sido cambiado correctamente ahora el nuevo estado es: {custom}"
},
"antiLinks": {
"enabled": "✔️ | El sistema de anti-links ha sido activado.",
"disabled": "✔️ | El sistema de anti-links ha sido desactivado.",
Expand Down

0 comments on commit e4deee2

Please sign in to comment.