mirror of
https://github.com/danbulant/Shasha
synced 2026-06-15 20:31:11 +00:00
beta
This commit is contained in:
parent
f8cedc0391
commit
e2a0e4d332
6 changed files with 148 additions and 3 deletions
2
Main.js
2
Main.js
|
|
@ -75,6 +75,8 @@ client.on("message", async msg => {
|
|||
if (!msg.guild.dbLoaded) await msg.guild.dbLoad();
|
||||
lgr.message.giveNickHeart(msg);
|
||||
}
|
||||
|
||||
lgr.message.run(msg);
|
||||
});
|
||||
|
||||
client.on("guildMemberRemove", async (member) => {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,6 @@ module.exports = class chat extends commando.Command {
|
|||
}
|
||||
msg.channel.startTyping();
|
||||
return trySend(this.client, msg, await chatAnswer(
|
||||
msg.cleanContent.slice((msg.guild.commandPrefix + msg.command.name).length).trim()));
|
||||
msg.cleanContent.slice((msg.guild.commandPrefix + msg.alias).length + 1).trim()));
|
||||
}
|
||||
};
|
||||
107
cmds/utility/translate.js
Normal file
107
cmds/utility/translate.js
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
'use strict';
|
||||
|
||||
const commando = require("@iceprod/discord.js-commando");
|
||||
const { default: axios } = require("axios");
|
||||
const { Message } = require("discord.js");
|
||||
const { trySend, getChannelMessage, defaultImageEmbed } = require("../../resources/functions");
|
||||
const SPLG = [
|
||||
"en",
|
||||
"ar",
|
||||
"zh",
|
||||
"fr",
|
||||
"de",
|
||||
"hi",
|
||||
"id",
|
||||
"ga",
|
||||
"it",
|
||||
"ja",
|
||||
"ko",
|
||||
"pl",
|
||||
"pt",
|
||||
"ru",
|
||||
"es",
|
||||
"tr",
|
||||
"vi"
|
||||
],
|
||||
REG = /(?<!\\)--m +[^\s\n]+( +\d{17,19})?/;
|
||||
|
||||
module.exports = class translate extends commando.Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: "translate",
|
||||
aliases: ["t", "trans"],
|
||||
memberName: "translate",
|
||||
group: "utility",
|
||||
description: "Translate some alien languages.",
|
||||
details: "Supported languages:\n" +
|
||||
`\`en\` English\n` +
|
||||
`\`ar\` Arabic\n` +
|
||||
`\`zh\` Chinese\n` +
|
||||
`\`fr\` French\n` +
|
||||
`\`de\` German\n` +
|
||||
`\`hi\` Hindi\n` +
|
||||
`\`id\` Indonesian\n` +
|
||||
`\`ga\` Irish\n` +
|
||||
`\`it\` Italian\n` +
|
||||
`\`ja\` Japanese\n` +
|
||||
`\`ko\` Korean\n` +
|
||||
`\`pl\` Polish\n` +
|
||||
`\`pt\` Portuguese\n` +
|
||||
`\`ru\` Russian\n` +
|
||||
`\`es\` Spanish\n` +
|
||||
`\`tr\` Turkish\n` +
|
||||
`\`vi\` Vietnamese`
|
||||
});
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {Message} msg
|
||||
* @param {*} arg
|
||||
*/
|
||||
async run(msg, arg) {
|
||||
if (/(?<!\\)--h/.test(arg)) {
|
||||
const emb = defaultImageEmbed(msg, null, "Usage");
|
||||
emb.setDescription(`\`${(msg.guild?.commandPrefix || msg.client.commandPrefix) + this.name}\` --\`[h|s|m]\`: [Show help | Supported languages | Message to translate \`[ID|link]\`] \`[Target language]\` \`[Text to translate]\`\n\n` +
|
||||
`Example:\n\`${(msg.guild?.commandPrefix || msg.client.commandPrefix) + this.name} ru cyka blyat!!\`\n\`${(msg.guild?.commandPrefix || msg.client.commandPrefix) + this.name} ` +
|
||||
`ja catgirl\`\n\`${(msg.guild?.commandPrefix || msg.client.commandPrefix) + this.name} --m https://discord.com/channels/772073587792281600/822274053925503046/859490929475846144 en\``);
|
||||
return trySend(msg.client, msg, emb);
|
||||
};
|
||||
if (/(?<!\\)--s/.test(arg)) {
|
||||
const emb = defaultImageEmbed(msg, null, "Help");
|
||||
emb.setDescription(this.description + "\n\n" + this.details);
|
||||
return trySend(msg.client, msg, emb);
|
||||
};
|
||||
msg.channel.startTyping();
|
||||
const MA = arg.match(REG);
|
||||
let tmes;
|
||||
if (MA) {
|
||||
const A = MA[0].slice(4).trim().split(/ +/);
|
||||
console.log(A);
|
||||
const C = await getChannelMessage(msg, A[0], A[1]);
|
||||
console.log(C);
|
||||
if (C) tmes = C;
|
||||
};
|
||||
arg = arg.replace(REG, "").trim();
|
||||
const TP = arg.split(/ +/, 1)?.[0].trim();
|
||||
let trans, tar, ic = SPLG.includes(TP);
|
||||
if (tmes) trans = tmes.cleanContent || tmes.content;
|
||||
if (ic) tar = TP; else tar = "en";
|
||||
if (ic) {
|
||||
if (!tmes) trans = msg.cleanContent.slice((msg.guild.commandPrefix + msg.alias + TP).length).trim() || msg.channel.messages.cache.get(msg.channel.lastMessagesID[1])?.cleanContent;
|
||||
} else {
|
||||
if (!tmes) if (!arg || arg.length === 0) trans = msg.channel.messages.cache.get(msg.channel.lastMessagesID[1])?.cleanContent; else trans = msg.cleanContent.slice((msg.guild.commandPrefix + msg.alias).length + 1).trim();
|
||||
};
|
||||
if (!trans || trans.length === 0) {
|
||||
return trySend(msg.client, msg, "Nothing to translate. `--h` for help <:nekohmLife:846371737644957786>");
|
||||
}
|
||||
const res = await axios.post("https://translate.mentality.rip/translate", {
|
||||
q: trans,
|
||||
source: "auto",
|
||||
target: tar
|
||||
}).then(r => {
|
||||
console.log(r.data);
|
||||
return r.data.translatedText;
|
||||
}).catch(console.error);
|
||||
return trySend(msg.client, msg, res);
|
||||
}
|
||||
};
|
||||
|
|
@ -28,4 +28,8 @@ async function letsChat(msg) {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = { letsChat, giveNickHeart }
|
||||
function run(msg) {
|
||||
msg.channel.pushLastMessagesID();
|
||||
}
|
||||
|
||||
module.exports = { letsChat, giveNickHeart, run }
|
||||
|
|
@ -155,4 +155,36 @@ Structures.extend("User", u => {
|
|||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Structures.extend("TextChannel", e => {
|
||||
return class TextChannel extends e {
|
||||
constructor(guild, data) {
|
||||
super(guild, data);
|
||||
this.lastMessagesID = [];
|
||||
};
|
||||
|
||||
pushLastMessagesID() {
|
||||
if (this.lastMessagesID.length === 3) {
|
||||
this.lastMessagesID.shift();
|
||||
};
|
||||
return this.lastMessagesID.push(this.lastMessageID);
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
Structures.extend("DMChannel", e => {
|
||||
return class DMChannel extends e {
|
||||
constructor(client, data) {
|
||||
super(client, data);
|
||||
this.lastMessagesID = [];
|
||||
};
|
||||
|
||||
pushLastMessagesID() {
|
||||
if (this.lastMessagesID.length === 3) {
|
||||
this.lastMessagesID.shift();
|
||||
};
|
||||
return this.lastMessagesID.push(this.lastMessageID);
|
||||
};
|
||||
}
|
||||
});
|
||||
|
|
@ -71,7 +71,7 @@ module.exports = {
|
|||
if (u.startsWith("u ")) {
|
||||
const n = parseInt(u.match(/\d+/), 10);
|
||||
console.log("Removing", C[n].name, C[n].id);
|
||||
return delete C[n];
|
||||
return C.splice(n, 1);
|
||||
}
|
||||
if (u === "r") {
|
||||
if (C.length > 0) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue