Compare commits
8 commits
162a91ca48
...
591652f33f
Author | SHA1 | Date | |
---|---|---|---|
591652f33f | |||
49e13885fe | |||
0bde6afdce | |||
c782708fa6 | |||
1cd6a6009d | |||
520ca95b29 | |||
ff98b259e7 | |||
fa4b5165e8 |
11 changed files with 126 additions and 38 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -10,3 +10,7 @@ bin/yt-dlp
|
||||||
bin/HandBrakeCLI
|
bin/HandBrakeCLI
|
||||||
bin/upload.sh
|
bin/upload.sh
|
||||||
bin/dectalk
|
bin/dectalk
|
||||||
|
|
||||||
|
asset/ytp/sources
|
||||||
|
asset/ytp/music
|
||||||
|
asset/ytp/sounds
|
|
@ -56,7 +56,7 @@ export default {
|
||||||
return interaction.editReply('successfully deleted the following tag: ' + args.trigger);
|
return interaction.editReply('successfully deleted the following tag: ' + args.trigger);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return interaction.editReply(`You are not the owner of this tag, if you think it is problematic ask an admin to remove it by doing ${this.client.commandHandler.prefix[0]}tag ${args.trigger} --remove`);
|
return interaction.editReply(`You are not the owner of this tag, if you think it is problematic ask a user with the 'Administrator' permission to remove it by doing ${this.client.commandHandler.prefix[0]}tag ${args.trigger} --remove`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -43,7 +43,7 @@ export default {
|
||||||
.setTimestamp();
|
.setTimestamp();
|
||||||
|
|
||||||
user.send({ embeds: [Embed] });
|
user.send({ embeds: [Embed] });
|
||||||
return interaction.reply({ content: `DM sent to ${user.username}` });
|
return interaction.reply({ content: `DM sent to ${user.username} (${user.id})` });
|
||||||
/*
|
/*
|
||||||
const Attachment = (message.attachments).array();
|
const Attachment = (message.attachments).array();
|
||||||
if (Attachment[0]) {
|
if (Attachment[0]) {
|
||||||
|
|
|
@ -18,7 +18,7 @@ export default {
|
||||||
|
|
||||||
const streamPipeline = util.promisify(stream.pipeline);
|
const streamPipeline = util.promisify(stream.pipeline);
|
||||||
const res = await fetch(args.file.url);
|
const res = await fetch(args.file.url);
|
||||||
if (!res.ok) return interaction.editReply('An error has occured while trying to download your image.');
|
if (!res.ok) return interaction.editReply('An error has occured while trying to download the command.');
|
||||||
await streamPipeline(res.body, fs.createWriteStream(`./tmp/${args.file.name}`));
|
await streamPipeline(res.body, fs.createWriteStream(`./tmp/${args.file.name}`));
|
||||||
|
|
||||||
let command = await import(`../../tmp/${args.file.name}`);
|
let command = await import(`../../tmp/${args.file.name}`);
|
||||||
|
|
|
@ -34,10 +34,10 @@ export default {
|
||||||
Blacklists.create(body);
|
Blacklists.create(body);
|
||||||
let user = userid;
|
let user = userid;
|
||||||
await client.users.fetch(userid);
|
await client.users.fetch(userid);
|
||||||
user = client.users.resolve(userid).tag;
|
user = client.users.resolve(userid).username;
|
||||||
|
|
||||||
|
|
||||||
return interaction.editReply(`${user} has been blacklisted from ${command} with the following reason \`${reason}\``);
|
return interaction.editReply(`${user} (${userid}) has been blacklisted from ${command} with the following reason \`${reason}\``);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const row = new ActionRowBuilder()
|
const row = new ActionRowBuilder()
|
||||||
|
|
|
@ -25,7 +25,7 @@ export default {
|
||||||
for (let i = 0; i < Donator.length; i++) {
|
for (let i = 0; i < Donator.length; i++) {
|
||||||
const user = await client.users.fetch(Donator[i].get('userID').toString());
|
const user = await client.users.fetch(Donator[i].get('userID').toString());
|
||||||
if (user !== null) {
|
if (user !== null) {
|
||||||
description += `**${user.tag} (${user.id}) | ${Donator[i].get('comment')}**\n`;
|
description += `**${user.username} (${user.id}) | ${Donator[i].get('comment')}**\n`;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
description += `**A user of discord (${user.id}) | ${Donator[i].get('comment')} (This user no longer share a server with the bot)**\n`;
|
description += `**A user of discord (${user.id}) | ${Donator[i].get('comment')} (This user no longer share a server with the bot)**\n`;
|
||||||
|
@ -36,26 +36,26 @@ export default {
|
||||||
description += 'No one :(\n';
|
description += 'No one :(\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
description += `\nThanks to ${tina.tag} (336492042299637771) for inspiring me for making this bot!`;
|
description += `\nThanks to ${tina.username} (336492042299637771) for inspiring me for making this bot!`;
|
||||||
|
|
||||||
// description += '\nThanks to Jetbrains for providing their IDE!';
|
// description += '\nThanks to Jetbrains for providing their IDE!';
|
||||||
|
|
||||||
exec('git rev-parse --short HEAD', (err, stdout) => {
|
exec('git rev-parse --short HEAD', (err, stdout) => {
|
||||||
const aboutEmbed = new EmbedBuilder()
|
const aboutEmbed = new EmbedBuilder()
|
||||||
.setColor(interaction.member ? interaction.member.displayHexColor : 'Navy')
|
.setColor(interaction.member ? interaction.member.displayHexColor : 'Navy')
|
||||||
.setAuthor({ name: client.user.tag, iconURL: client.user.displayAvatarURL(), url: 'https://libtar.de' })
|
.setAuthor({ name: client.user.username, iconURL: client.user.displayAvatarURL(), url: 'https://libtar.de' })
|
||||||
.setTitle('About me')
|
.setTitle('About me')
|
||||||
.setDescription(description)
|
.setDescription(description)
|
||||||
.addFields(
|
.addFields(
|
||||||
{ name: 'Current commit', value: stdout },
|
{ name: 'Current commit', value: stdout },
|
||||||
{ name: 'Current maintainer', value: `${maintainer.tag} (${ownerId})` },
|
{ name: 'Current maintainer', value: `${maintainer.username} (${ownerId})` },
|
||||||
{ name: 'Gitea (Main)', value: 'https://git.namejeff.xyz/Supositware/Haha-Yes', inline: true },
|
{ name: 'Gitea (Main)', value: 'https://git.namejeff.xyz/Supositware/Haha-Yes', inline: true },
|
||||||
{ name: 'Github (Mirror)', value: 'https://github.com/Supositware/Haha-yes', inline: true },
|
{ name: 'Github (Mirror)', value: 'https://github.com/Supositware/Haha-yes', inline: true },
|
||||||
{ name: 'Privacy Policy', value: 'https://libtar.de/discordprivacy.txt', inline: true },
|
{ name: 'Privacy Policy', value: 'https://libtar.de/discordprivacy.txt', inline: true },
|
||||||
{ name: 'Status page', value: uptimePage.toString(), inline: true },
|
{ name: 'Status page', value: uptimePage.toString(), inline: true },
|
||||||
|
|
||||||
)
|
)
|
||||||
.setFooter({ text: `Original bot made by ${creator.tag} (267065637183029248)` });
|
.setFooter({ text: `Original bot made by ${creator.username} (267065637183029248)` });
|
||||||
|
|
||||||
interaction.reply({ embeds: [aboutEmbed] });
|
interaction.reply({ embeds: [aboutEmbed] });
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,10 +11,17 @@ export default {
|
||||||
if (interaction.type !== InteractionType.ApplicationCommand) return;
|
if (interaction.type !== InteractionType.ApplicationCommand) return;
|
||||||
|
|
||||||
const globalBlacklist = await db.Blacklists.findOne({ where: { type:'global', uid:interaction.user.id } });
|
const globalBlacklist = await db.Blacklists.findOne({ where: { type:'global', uid:interaction.user.id } });
|
||||||
|
// const serverBlacklist = await db.Blacklists.findOne({ where: { type:'guild', uid:interaction.guild.id } });
|
||||||
const commandBlacklist = await db.Blacklists.findOne({ where: { type:interaction.commandName, uid:interaction.user.id } });
|
const commandBlacklist = await db.Blacklists.findOne({ where: { type:interaction.commandName, uid:interaction.user.id } });
|
||||||
|
|
||||||
if (globalBlacklist) {
|
if (globalBlacklist) {
|
||||||
return interaction.reply({ content: `You are globally blacklisted for the following reason: \`${globalBlacklist.reason}\``, ephemeral: true });
|
return interaction.reply({ content: `You are globally blacklisted for the following reason: \`${globalBlacklist.reason}\``, ephemeral: true });
|
||||||
}
|
}
|
||||||
|
/* Server blacklist is untested
|
||||||
|
else if (serverBlacklist) {
|
||||||
|
return interaction.reply({ content: `This guild has been blacklisted for the following reason: \`${serverBlacklist.reason}\``, ephemeral: true });
|
||||||
|
}
|
||||||
|
*/
|
||||||
else if (commandBlacklist) {
|
else if (commandBlacklist) {
|
||||||
return interaction.reply({ content: `You are blacklisted for the following reason: \`${commandBlacklist.reason}\``, ephemeral: true });
|
return interaction.reply({ content: `You are blacklisted for the following reason: \`${commandBlacklist.reason}\``, ephemeral: true });
|
||||||
}
|
}
|
||||||
|
@ -29,12 +36,8 @@ export default {
|
||||||
|
|
||||||
const isOptOut = await db.optout.findOne({ where: { userID: interaction.user.id } });
|
const isOptOut = await db.optout.findOne({ where: { userID: interaction.user.id } });
|
||||||
|
|
||||||
if (isOptOut) {
|
const timestamp = new Date();
|
||||||
console.log(`A user launched command \x1b[33m${commandName}\x1b[0m using slash`);
|
console.log(`[${timestamp.toISOString()}] \x1b[33m${ isOptOut ? 'A user' : `${userTag} (${userID})`}\x1b[0m launched command \x1b[33m${commandName}\x1b[0m using slash`);
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.log(`\x1b[33m${userTag} (${userID})\x1b[0m launched command \x1b[33m${commandName}\x1b[0m using slash`);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Owner only check
|
// Owner only check
|
||||||
|
@ -64,6 +67,18 @@ export default {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Check if the limit of parallel execution has been reached
|
||||||
|
if (command.parallelLimit) {
|
||||||
|
console.log('Command has a parallel limit');
|
||||||
|
const doParallelLimit = ratelimiter.checkParallel(interaction.user, commandName, command);
|
||||||
|
console.log(doParallelLimit);
|
||||||
|
if (doParallelLimit) {
|
||||||
|
return await interaction.reply({ content: doParallelLimit, ephemeral: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
ratelimiter.addParallel(commandName);
|
||||||
|
}
|
||||||
|
|
||||||
// Check the ratelimit
|
// Check the ratelimit
|
||||||
const doRateLimit = ratelimiter.check(interaction.user, commandName, command);
|
const doRateLimit = ratelimiter.check(interaction.user, commandName, command);
|
||||||
if (doRateLimit) {
|
if (doRateLimit) {
|
||||||
|
@ -88,10 +103,14 @@ export default {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isOptOut) {
|
if (!isOptOut) {
|
||||||
console.log(`\x1b[33m⤷\x1b[0m with args ${JSON.stringify(args)}`);
|
console.log(`[${timestamp.toISOString()}] \x1b[33m⤷\x1b[0m with args ${JSON.stringify(args)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
await command.execute(interaction, args, client);
|
await command.execute(interaction, args, client)
|
||||||
|
.then(() => {
|
||||||
|
const hasPrallelLimit = ratelimiter.checkParallel(interaction.user, commandName, command);
|
||||||
|
if (hasPrallelLimit) ratelimiter.removeParallel(commandName);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
|
@ -281,11 +281,17 @@ export default {
|
||||||
if (!command) return;
|
if (!command) return;
|
||||||
|
|
||||||
const globalBlacklist = await db.Blacklists.findOne({ where: { type:'global', uid:message.author.id } });
|
const globalBlacklist = await db.Blacklists.findOne({ where: { type:'global', uid:message.author.id } });
|
||||||
|
// const serverBlacklist = await db.Blacklists.findOne({ where: { type:'guild', uid:message.guild.id } });
|
||||||
const commandBlacklist = await db.Blacklists.findOne({ where: { type:commandName, uid:message.author.id } });
|
const commandBlacklist = await db.Blacklists.findOne({ where: { type:commandName, uid:message.author.id } });
|
||||||
|
|
||||||
if (globalBlacklist) {
|
if (globalBlacklist) {
|
||||||
return message.reply({ content: `You are globally blacklisted for the following reason: \`${globalBlacklist.reason}\``, ephemeral: true });
|
return message.reply({ content: `You are globally blacklisted for the following reason: \`${globalBlacklist.reason}\``, ephemeral: true });
|
||||||
}
|
}
|
||||||
|
/* Server blacklist is untested
|
||||||
|
else if (serverBlacklist) {
|
||||||
|
return message.reply({ content: `This guild has been blacklisted for the following reason: \`${serverBlacklist.reason}\``, ephemeral: true });
|
||||||
|
}
|
||||||
|
*/
|
||||||
else if (commandBlacklist) {
|
else if (commandBlacklist) {
|
||||||
return message.reply({ content: `You are blacklisted for the following reason: \`${commandBlacklist.reason}\``, ephemeral: true });
|
return message.reply({ content: `You are blacklisted for the following reason: \`${commandBlacklist.reason}\``, ephemeral: true });
|
||||||
}
|
}
|
||||||
|
@ -295,12 +301,9 @@ export default {
|
||||||
|
|
||||||
const isOptOut = await db.optout.findOne({ where: { userID: message.author.id } });
|
const isOptOut = await db.optout.findOne({ where: { userID: message.author.id } });
|
||||||
|
|
||||||
if (isOptOut) {
|
const timestamp = new Date();
|
||||||
console.log(`A user launched command \x1b[33m${commandName}\x1b[0m using prefix`);
|
console.log(`[${timestamp.toISOString()}] \x1b[33m${ isOptOut ? 'A user' : `${userTag} (${userID})`}\x1b[0m launched command \x1b[33m${commandName}\x1b[0m using slash`);
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.log(`\x1b[33m${userTag} (${userID})\x1b[0m launched command \x1b[33m${commandName}\x1b[0m using prefix`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Owner only check
|
// Owner only check
|
||||||
if (command.ownerOnly && message.author.id !== ownerId) {
|
if (command.ownerOnly && message.author.id !== ownerId) {
|
||||||
|
@ -327,6 +330,18 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the limit of parallel execution has been reached
|
||||||
|
if (command.parallelLimit) {
|
||||||
|
console.log('Command has a parallel limit');
|
||||||
|
const doParallelLimit = ratelimiter.checkParallel(message.author, commandName, command);
|
||||||
|
console.log(doParallelLimit);
|
||||||
|
if (doParallelLimit) {
|
||||||
|
return await message.reply({ content: doParallelLimit, ephemeral: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
ratelimiter.addParallel(commandName);
|
||||||
|
}
|
||||||
|
|
||||||
// Check the ratelimit
|
// Check the ratelimit
|
||||||
const doRateLimit = ratelimiter.check(message.author, commandName, command);
|
const doRateLimit = ratelimiter.check(message.author, commandName, command);
|
||||||
if (doRateLimit) {
|
if (doRateLimit) {
|
||||||
|
@ -411,10 +426,14 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isOptOut && argsLength > 0) {
|
if (!isOptOut && argsLength > 0) {
|
||||||
console.log(`\x1b[33m⤷\x1b[0m with args ${JSON.stringify(args)}`);
|
console.log(`[${timestamp.toISOString()}]\x1b[33m⤷\x1b[0m with args ${JSON.stringify(args)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
await command.execute(message, args, client);
|
await command.execute(message, args, client)
|
||||||
|
.then(() => {
|
||||||
|
const hasPrallelLimit = ratelimiter.checkParallel(message.author, commandName, command);
|
||||||
|
if (hasPrallelLimit) ratelimiter.removeParallel(commandName);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
|
@ -23,11 +23,11 @@ async function download(url, output) {
|
||||||
fs.renameSync(tmpPath, path);
|
fs.renameSync(tmpPath, path);
|
||||||
fs.chmodSync(path, '755');
|
fs.chmodSync(path, '755');
|
||||||
console.log(`${url} download finished.`);
|
console.log(`${url} download finished.`);
|
||||||
resolve(true);
|
return resolve(true);
|
||||||
});
|
});
|
||||||
filePath.on('error', (err) => {
|
filePath.on('error', (err) => {
|
||||||
filePath.close();
|
filePath.close();
|
||||||
reject(err);
|
return reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
// This is kind of useless since you can just do `./yt-dlp --update-to nightly` which I didn't know about when I wrote that.
|
||||||
import utils from './downloadutils.js';
|
import utils from './downloadutils.js';
|
||||||
|
|
||||||
|
(async () => {
|
||||||
if (process.platform !== 'linux' && process.argv[2] !== '-f') {
|
if (process.platform !== 'linux' && process.argv[2] !== '-f') {
|
||||||
console.error('This script only download the linux version of yt-dlp. If you want to download anyway try again with -f');
|
console.error('This script only download the linux version of yt-dlp. If you want to download anyway try again with -f or execute ./bin/yt-dlp --update-to nightly');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
else if (process.platform !== 'linux' && process.argv[2] === '-f') {
|
else if (process.platform !== 'linux' && process.argv[2] === '-f') {
|
||||||
|
@ -10,4 +12,6 @@ else if (process.platform !== 'linux' && process.argv[2] === '-f') {
|
||||||
|
|
||||||
const downloadUrl = 'https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp';
|
const downloadUrl = 'https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp';
|
||||||
|
|
||||||
utils.download(downloadUrl, './bin/yt-dlp');
|
await utils.download(downloadUrl, './bin/yt-dlp');
|
||||||
|
|
||||||
|
});
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
const ratelimit = {};
|
const ratelimit = {};
|
||||||
|
const parallelLimit = {};
|
||||||
const { ownerId } = process.env;
|
const { ownerId } = process.env;
|
||||||
|
|
||||||
import db from '../models/index.js';
|
import db from '../models/index.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
check,
|
check,
|
||||||
|
addParallel,
|
||||||
|
removeParallel,
|
||||||
|
checkParallel,
|
||||||
};
|
};
|
||||||
function check(user, commandName, commands) {
|
function check(user, commandName, commands) {
|
||||||
const userID = user.id;
|
const userID = user.id;
|
||||||
|
@ -53,3 +57,41 @@ function check(user, commandName, commands) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addParallel(commandName) {
|
||||||
|
// console.log(`[ADD] Adding parallel to ${commandName}`);
|
||||||
|
if (!parallelLimit[commandName]) parallelLimit[commandName] = 0;
|
||||||
|
|
||||||
|
const prevNumber = parallelLimit[commandName];
|
||||||
|
|
||||||
|
// console.log(`[ADD] Previous parallel executions: ${prevNumber}`);
|
||||||
|
// console.log(`[ADD] Current parallel executions: ${JSON.stringify(parallelLimit)}`);
|
||||||
|
parallelLimit[commandName] = prevNumber + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeParallel(commandName) {
|
||||||
|
// console.log(`[REMOVE] Removing parallel to ${commandName}`);
|
||||||
|
|
||||||
|
// This shouldn't be possible
|
||||||
|
if (!parallelLimit[commandName]) parallelLimit[commandName] = 0;
|
||||||
|
|
||||||
|
const prevNumber = parallelLimit[commandName];
|
||||||
|
|
||||||
|
// console.log(`[REMOVE] previous number: ${prevNumber}`);
|
||||||
|
// console.log(`[REMOVE] previous parallel limit: ${JSON.stringify(parallelLimit)}`);
|
||||||
|
parallelLimit[commandName] = prevNumber - 1;
|
||||||
|
// console.log(`[REMOVE] current parallel limit: ${JSON.stringify(parallelLimit)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkParallel(user, commandName, command) {
|
||||||
|
// Don't apply the rate limit to bot owner
|
||||||
|
if (user.id === ownerId) return false;
|
||||||
|
|
||||||
|
// console.log(`[CHECK] command limit: ${command.parallelLimit}`);
|
||||||
|
// console.log(`[CHECK] current parallel executions: ${parallelLimit[commandName]}`);
|
||||||
|
if (parallelLimit[commandName] >= command.parallelLimit) {
|
||||||
|
return 'There are currently too many parallel execution of this command, please wait before retrying.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
Loading…
Reference in a new issue