forked from Supositware/Haha-Yes
Compare commits
1 commit
fa95596906
...
634e4a85af
Author | SHA1 | Date | |
---|---|---|---|
634e4a85af |
19 changed files with 5624 additions and 2944 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,4 +4,3 @@ bin/
|
|||
config/config.json
|
||||
json/board/
|
||||
unloaded/
|
||||
database.sqlite3
|
76
commands/AI/img2img
Normal file
76
commands/AI/img2img
Normal file
|
@ -0,0 +1,76 @@
|
|||
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
|
||||
import fetch from 'node-fetch';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
|
||||
const { stableHordeApi, stableHordeID } = process.env;
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('img2img')
|
||||
.setDescription('AI generated image with stable diffusion (If credit are low it may be slow)')
|
||||
.addAttachmentOption(option =>
|
||||
option.setName('image')
|
||||
.setDescription('Image you want to modify')
|
||||
.setRequired(true))
|
||||
.addStringOption(option =>
|
||||
option.setName('prompt')
|
||||
.setDescription('What do you want the AI to generate?')
|
||||
.setRequired(true)),
|
||||
category: 'AI',
|
||||
async execute(interaction, args, client) {
|
||||
await interaction.deferReply();
|
||||
fetch(args.image.url)
|
||||
.then((res) => {
|
||||
const dest = fs.createWriteStream(`${os.tmpdir()}/${args.image.name}`);
|
||||
res.body.pipe(dest);
|
||||
dest.on('finish', () => {
|
||||
const b64Image = fs.readFileSync(`${os.tmpdir()}/${args.image.name}`, { encoding: 'base64' });
|
||||
generate(interaction, args.prompt, b64Image, client);
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
async function generate(i, prompt, b64Img) {
|
||||
const body = {
|
||||
prompt: prompt,
|
||||
params: {
|
||||
n: 1,
|
||||
width: 512,
|
||||
height: 512,
|
||||
},
|
||||
cfg_scale: 9,
|
||||
use_gfpgan: true,
|
||||
use_real_esrgan: true,
|
||||
use_ldsr: true,
|
||||
use_upscaling: true,
|
||||
steps: 50,
|
||||
nsfw: i.channel.nsfw ? true : false,
|
||||
censor_nsfw: i.channel.nsfw ? true : false,
|
||||
source_image: b64Img,
|
||||
};
|
||||
|
||||
const fetchParameters = {
|
||||
method: 'post',
|
||||
body: JSON.stringify(body),
|
||||
headers: { 'Content-Type': 'application/json', 'apikey': stableHordeApi },
|
||||
};
|
||||
|
||||
let response = await fetch('https://stablehorde.net/api/v2/generate/sync', fetchParameters);
|
||||
|
||||
response = await response.json();
|
||||
|
||||
let creditResponse = await fetch(`https://stablehorde.net/api/v2/users/${stableHordeID}`);
|
||||
creditResponse = await creditResponse.json();
|
||||
|
||||
const stableEmbed = new EmbedBuilder()
|
||||
.setColor(i.member ? i.member.displayHexColor : 'Navy')
|
||||
.setTitle(prompt)
|
||||
.setURL('https://aqualxx.github.io/stable-ui/')
|
||||
.setFooter({ text: `**Credit left: ${creditResponse.kudos}** Seed: ${response.generations[0].seed} worker ID: ${response.generations[0].worker_id} worker name: ${response.generations[0].worker_name}` });
|
||||
|
||||
fs.writeFileSync(`${os.tmpdir()}/${i.id}.png`, response.generations[0].img, 'base64');
|
||||
|
||||
await i.editReply({ embeds: [stableEmbed], files: [`${os.tmpdir()}/${i.id}.png`] });
|
||||
}
|
|
@ -1,153 +0,0 @@
|
|||
/* TODO
|
||||
*
|
||||
* To be merged with commands/AI/txt2img.js
|
||||
*
|
||||
*/
|
||||
import { SlashCommandBuilder, EmbedBuilder, AttachmentBuilder, ButtonBuilder, ActionRowBuilder, ButtonStyle } from 'discord.js';
|
||||
import fetch from 'node-fetch';
|
||||
import os from 'node:os';
|
||||
import fs from 'node:fs';
|
||||
import stream from 'node:stream';
|
||||
import util from 'node:util';
|
||||
|
||||
import db from '../../models/index.js';
|
||||
|
||||
const { stableHordeApi, stableHordeID } = process.env;
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('img2img')
|
||||
.setDescription('AI generated image with stable diffusion (If credit are low it may be slow)')
|
||||
.addAttachmentOption(option =>
|
||||
option.setName('image')
|
||||
.setDescription('Image you want to modify')
|
||||
.setRequired(true))
|
||||
.addStringOption(option =>
|
||||
option.setName('prompt')
|
||||
.setDescription('What do you want the AI to generate?')
|
||||
.setRequired(true)),
|
||||
category: 'AI',
|
||||
async execute(interaction, args, client) {
|
||||
await interaction.deferReply();
|
||||
|
||||
const streamPipeline = util.promisify(stream.pipeline);
|
||||
const res = await fetch(args.image.url);
|
||||
if (!res.ok) return interaction.editReply('An error has occured while trying to download your image.');
|
||||
await streamPipeline(res.body, fs.createWriteStream(`${os.tmpdir()}/${args.image.name}.webp`));
|
||||
|
||||
const b64Image = fs.readFileSync(`${os.tmpdir()}/${args.image.name}.webp`, { encoding: 'base64' });
|
||||
generate(interaction, args.prompt, client, b64Image);
|
||||
},
|
||||
};
|
||||
|
||||
async function generate(i, prompt, client, b64Img) {
|
||||
console.log('Generating image');
|
||||
const body = {
|
||||
prompt: prompt,
|
||||
params: {
|
||||
n: 1,
|
||||
width: 512,
|
||||
height: 512,
|
||||
},
|
||||
cfg_scale: 9,
|
||||
use_gfpgan: true,
|
||||
use_real_esrgan: true,
|
||||
use_ldsr: true,
|
||||
use_upscaling: true,
|
||||
steps: 50,
|
||||
nsfw: i.channel.nsfw ? true : false,
|
||||
censor_nsfw: i.channel.nsfw ? true : false,
|
||||
source_image: b64Img,
|
||||
source_processing: 'img2img',
|
||||
shared: true,
|
||||
};
|
||||
|
||||
const isOptOut = await db.optout.findOne({ where: { userID: i.user.id } });
|
||||
|
||||
if (isOptOut) {
|
||||
body.shared = false;
|
||||
}
|
||||
|
||||
const fetchParameters = {
|
||||
method: 'post',
|
||||
body: JSON.stringify(body),
|
||||
headers: { 'Content-Type': 'application/json', 'apikey': stableHordeApi },
|
||||
};
|
||||
|
||||
let response = await fetch('https://stablehorde.net/api/v2/generate/async', fetchParameters);
|
||||
|
||||
response = await response.json();
|
||||
let wait_time = 5000;
|
||||
let checkURL = `https://stablehorde.net/api/v2/generate/check/${response.id}`;
|
||||
const checking = setInterval(async () => {
|
||||
const checkResult = await checkGeneration(checkURL);
|
||||
|
||||
if (checkResult === undefined) return;
|
||||
if (!checkResult.done) {
|
||||
if (checkResult.wait_time < 0) {
|
||||
console.log(checkResult);
|
||||
clearInterval(checking);
|
||||
return i.editReply({ content: 'No servers are currently available to fulfill your request, please try again later.' });
|
||||
}
|
||||
if (checkResult.wait_time === 0) {
|
||||
checkURL = `https://stablehorde.net/api/v2/generate/status/${response.id}`;
|
||||
}
|
||||
wait_time = checkResult.wait_time;
|
||||
}
|
||||
else if (checkResult.done && checkResult.image) {
|
||||
clearInterval(checking);
|
||||
let creditResponse = await fetch(`https://stablehorde.net/api/v2/users/${stableHordeID}`);
|
||||
creditResponse = await creditResponse.json();
|
||||
|
||||
const streamPipeline = util.promisify(stream.pipeline);
|
||||
const res = await fetch(checkResult.image);
|
||||
if (!res.ok) return i.editReply('An error has occured while trying to download your image.');
|
||||
await streamPipeline(res.body, fs.createWriteStream(`${os.tmpdir()}/${i.id}.webp`));
|
||||
|
||||
const generatedImg = new AttachmentBuilder(`${os.tmpdir()}/${i.id}.webp`);
|
||||
|
||||
const stableEmbed = new EmbedBuilder()
|
||||
.setColor(i.member ? i.member.displayHexColor : 'Navy')
|
||||
.setTitle(prompt)
|
||||
.setURL('https://aqualxx.github.io/stable-ui/')
|
||||
.setImage(`attachment://${i.id}.webp`)
|
||||
.setFooter({ text: `**Credit left: ${creditResponse.kudos}** Seed: ${checkResult.seed} worker ID: ${checkResult.worker_id} worker name: ${checkResult.worker_name}` });
|
||||
|
||||
const row = new ActionRowBuilder()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`regenerate${i.user.id}`)
|
||||
.setLabel('🔄 Regenerate')
|
||||
.setStyle(ButtonStyle.Primary),
|
||||
);
|
||||
|
||||
await i.editReply({ embeds: [stableEmbed], components: [row], files: [generatedImg] });
|
||||
|
||||
client.once('interactionCreate', async (interactionMenu) => {
|
||||
if (i.user !== interactionMenu.user) return;
|
||||
if (!interactionMenu.isButton) return;
|
||||
if (interactionMenu.customId === `regenerate${interactionMenu.user.id}`) {
|
||||
await interactionMenu.deferReply();
|
||||
await generate(interactionMenu, prompt, client);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, wait_time);
|
||||
}
|
||||
|
||||
async function checkGeneration(url) {
|
||||
let check = await fetch(url);
|
||||
check = await check.json();
|
||||
|
||||
if (!check.is_possible) {
|
||||
return { done: false, wait_time: -1 };
|
||||
}
|
||||
|
||||
if (check.done) {
|
||||
if (!check.generations) {
|
||||
return { done: false, wait_time: check.wait_time * 1000 };
|
||||
}
|
||||
|
||||
return { done: true, image: check.generations[0].img, seed: check.generations[0].seed, worker_id: check.generations[0].worker_id, worker_name: check.generations[0].worker_name };
|
||||
}
|
||||
}
|
|
@ -1,16 +1,8 @@
|
|||
/* TODO
|
||||
*
|
||||
* To be merged with commands/AI/img2img.js
|
||||
*
|
||||
*/
|
||||
import { SlashCommandBuilder, EmbedBuilder, AttachmentBuilder, ButtonBuilder, ActionRowBuilder, ButtonStyle } from 'discord.js';
|
||||
import fetch from 'node-fetch';
|
||||
import os from 'node:os';
|
||||
import fs from 'node:fs';
|
||||
import stream from 'node:stream';
|
||||
import util from 'node:util';
|
||||
|
||||
import db from '../../models/index.js';
|
||||
|
||||
const { stableHordeApi, stableHordeID } = process.env;
|
||||
|
||||
|
@ -45,15 +37,8 @@ async function generate(i, prompt, client) {
|
|||
steps: 50,
|
||||
nsfw: i.channel.nsfw ? true : false,
|
||||
censor_nsfw: i.channel.nsfw ? true : false,
|
||||
shared: true,
|
||||
};
|
||||
|
||||
const isOptOut = await db.optout.findOne({ where: { userID: i.user.id } });
|
||||
|
||||
if (isOptOut) {
|
||||
body.shared = false;
|
||||
}
|
||||
|
||||
const fetchParameters = {
|
||||
method: 'post',
|
||||
body: JSON.stringify(body),
|
||||
|
@ -84,10 +69,8 @@ async function generate(i, prompt, client) {
|
|||
let creditResponse = await fetch(`https://stablehorde.net/api/v2/users/${stableHordeID}`);
|
||||
creditResponse = await creditResponse.json();
|
||||
|
||||
const streamPipeline = util.promisify(stream.pipeline);
|
||||
const res = await fetch(checkResult.image);
|
||||
if (!res.ok) return i.editReply('An error has occured while trying to download your image.');
|
||||
await streamPipeline(res.body, fs.createWriteStream(`${os.tmpdir()}/${i.id}.webp`));
|
||||
await fetch(checkResult.image)
|
||||
.then(res => res.body.pipe(fs.createWriteStream(`${os.tmpdir()}/${i.id}.webp`)));
|
||||
|
||||
const generatedImg = new AttachmentBuilder(`${os.tmpdir()}/${i.id}.webp`);
|
||||
|
||||
|
|
|
@ -1,269 +0,0 @@
|
|||
import { SlashCommandBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder, PermissionFlagsBits } from 'discord.js';
|
||||
import os from 'node:os';
|
||||
import fs from 'node:fs';
|
||||
|
||||
import db from '../../models/index.js';
|
||||
|
||||
const { ownerId } = process.env;
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('tag')
|
||||
.setDescription('Create custom autoresponse')
|
||||
.addStringOption(option =>
|
||||
option.setName('trigger')
|
||||
.setDescription('The strings that will trigger the tag')
|
||||
.setRequired(false))
|
||||
.addStringOption(option =>
|
||||
option.setName('response')
|
||||
.setDescription('What it will answer back')
|
||||
.setRequired(false))
|
||||
.addBooleanOption(option =>
|
||||
option.setName('remove')
|
||||
.setDescription('(ADMIN ONLY!) Remove the tag')
|
||||
.setRequired(false))
|
||||
.addBooleanOption(option =>
|
||||
option.setName('list')
|
||||
.setDescription('List all the tags for the server')
|
||||
.setRequired(false)),
|
||||
category: 'admin',
|
||||
userPermissions: [PermissionFlagsBits.ManageChannels],
|
||||
async execute(interaction, args, client) {
|
||||
await interaction.deferReply();
|
||||
if (args.list) {
|
||||
let tagList = await db.Tag.findAll({ attributes: ['trigger', 'response', 'ownerID'], where: { serverID: interaction.guild.id } });
|
||||
|
||||
if (args.trigger) {
|
||||
tagList = await db.Tag.findOne({ attributes: ['trigger', 'response', 'ownerID'], where: { trigger: args.trigger, serverID: interaction.guild.id } });
|
||||
}
|
||||
|
||||
if (!tagList) return interaction.editReply('It looks like the server has no tags.');
|
||||
|
||||
const path = `${os.tmpdir()}/${interaction.guild.id}.json`;
|
||||
fs.writeFile(path, JSON.stringify(tagList, null, 2), function(err) {
|
||||
if (err) return console.error(err);
|
||||
});
|
||||
return interaction.editReply({ files: [path] });
|
||||
}
|
||||
|
||||
const tag = await db.Tag.findOne({ where: { trigger: args.trigger, serverID: interaction.guild.id } });
|
||||
|
||||
if (args.remove) {
|
||||
if (tag) {
|
||||
if (tag.get('ownerID') == interaction.user.id || interaction.member.hasPermission('ADMINISTRATOR') || interaction.user.id == ownerId) {
|
||||
db.Tag.destroy({ where: { trigger: args.trigger, serverID: interaction.guild.id } });
|
||||
return interaction.editReply('successfully deleted the following tag: ' + args.trigger);
|
||||
}
|
||||
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`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return interaction.editReply('Did not find the specified tag, are you sure it exist?');
|
||||
}
|
||||
}
|
||||
|
||||
if (!args.trigger) return interaction.editReply('You need to specify what you want me to respond to.');
|
||||
if (!args.response) return interaction.editReply('You need to specify what you want me to answer with.');
|
||||
|
||||
if (!tag) {
|
||||
const body = { trigger: args.trigger, response: args.response, ownerID: interaction.user.id, serverID: interaction.guild.id };
|
||||
await db.Tag.create(body);
|
||||
return interaction.editReply(`tag have been set to ${args.trigger} : ${args.response}`);
|
||||
}
|
||||
else if (tag.get('ownerID') == interaction.user.id || interaction.member.hasPermission('ADMINISTRATOR') || interaction.user.id == ownerId) {
|
||||
|
||||
const row = new ActionRowBuilder()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`edit${interaction.user.id}`)
|
||||
.setLabel('Edit')
|
||||
.setStyle(ButtonStyle.Primary),
|
||||
)
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`remove${interaction.user.id}`)
|
||||
.setLabel('Remove')
|
||||
.setStyle(ButtonStyle.Danger),
|
||||
)
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`nothing${interaction.user.id}`)
|
||||
.setLabel('Do nothing')
|
||||
.setStyle(ButtonStyle.Secondary),
|
||||
);
|
||||
|
||||
await interaction.editReply({ content: 'This tag already exist, do you want to update it, remove it or do nothing?', components: [row], ephemeral: true });
|
||||
|
||||
client.on('interactionCreate', async (interactionMenu) => {
|
||||
if (interaction.user !== interactionMenu.user) return;
|
||||
if (!interactionMenu.isButton) return;
|
||||
interactionMenu.update({ components: [] });
|
||||
if (interactionMenu.customId === `edit${interaction.user.id}`) {
|
||||
const body = { trigger: args.trigger, response: args.response, ownerID: interaction.user.id, serverID: interaction.guild.id };
|
||||
await db.joinChannel.update(body, { where: { guildID: interaction.guild.id } });
|
||||
return interaction.editReply({ content: `The tag ${args.trigger} has been set to ${args.response}`, ephemeral: true });
|
||||
}
|
||||
else if (interactionMenu.customId === `remove${interaction.user.id}`) {
|
||||
db.Tag.destroy({ where: { trigger: args.trigger, serverID: interaction.guild.id } });
|
||||
return interaction.editReply({ content: `The tag ${args.trigger} has been deleted`, ephemeral: true });
|
||||
}
|
||||
else {
|
||||
return interaction.editReply({ content: 'Nothing has been changed.', ephemeral: true });
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
const filter = m => m.content && m.author.id == interaction.user.id;
|
||||
message.channel.awaitMessages(filter, { time: 5000, max: 1, errors: ['time'] })
|
||||
.then(async messages => {
|
||||
let messageContent = messages.map(messages => messages.content.toLowerCase());
|
||||
if (messageContent[0] === 'y' || messageContent[0] === 'yes') {
|
||||
const body = { trigger: args.trigger, response: args.response, ownerID: interaction.user.id, serverID: message.guild.id };
|
||||
await Tag.update(body, { where: { trigger: args.trigger, serverID: message.guild.id } });
|
||||
return interaction.editReply(`tag have been set to ${args.trigger} : ${args.response}`);
|
||||
}
|
||||
else {
|
||||
return interaction.editReply('Not updating.');
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
return interaction.editReply('Took too long to answer. didin\'t update anything.');
|
||||
});
|
||||
*/
|
||||
}
|
||||
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`);
|
||||
}
|
||||
|
||||
const join = await db.joinChannel.findOne({ where: { guildID: interaction.guild.id } });
|
||||
|
||||
if (!join && !args.message) {
|
||||
return interaction.editReply({ content: 'You need a message for me to say anything!', ephemeral: true });
|
||||
}
|
||||
else if (!join) {
|
||||
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args.message };
|
||||
await db.joinChannel.create(body);
|
||||
return interaction.editReply({ content: `The join message have been set with ${args.message}`, ephemeral: true });
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
const { Command } = require('discord-akairo');
|
||||
const Tag = require('../../models').Tag;
|
||||
|
||||
class TagCommand extends Command {
|
||||
constructor() {
|
||||
super('tag', {
|
||||
aliases: ['tag'],
|
||||
category: 'admin',
|
||||
userPermissions: ['MANAGE_MESSAGES'],
|
||||
args: [
|
||||
{
|
||||
id: 'trigger',
|
||||
type: 'string',
|
||||
},
|
||||
{
|
||||
id: 'remove',
|
||||
match: 'flag',
|
||||
flag: '--remove'
|
||||
},
|
||||
{
|
||||
id: 'reset',
|
||||
match: 'flag',
|
||||
flag: '--reset'
|
||||
},
|
||||
{
|
||||
id: 'response',
|
||||
type: 'string',
|
||||
match: 'rest',
|
||||
}
|
||||
],
|
||||
channel: 'guild',
|
||||
description: {
|
||||
content: 'Create custom autoresponse (--remove to delete a tag, --reset to delete EVERY tag on the server) [Click here to see the complete list of "tag"](https://cdn.discordapp.com/attachments/502198809355354133/561043193949585418/unknown.png) (Need "" if the trigger contains spaces)',
|
||||
usage: '[trigger] [response]',
|
||||
examples: ['"do you know da wea" Fuck off dead meme', 'hello Hello [author], how are you today?', 'hello --remove']
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async exec(message, args) {
|
||||
const tag = await Tag.findOne({where: {trigger: args.trigger, serverID: message.guild.id}});
|
||||
const ownerID = this.client.ownerID;
|
||||
|
||||
if (args.reset) {
|
||||
if (message.member.hasPermission('ADMINISTRATOR')) {
|
||||
interaction.editReply('Are you sure you want to delete EVERY tag? There is no way to recover them. y/n');
|
||||
|
||||
const filter = m => m.content && m.author.id == interaction.user.id;
|
||||
return message.channel.awaitMessages(filter, {time: 5000, max: 1, errors: ['time'] })
|
||||
.then(async messages => {
|
||||
let messageContent = messages.map(messages => messages.content.toLowerCase());
|
||||
if (messageContent[0] === 'y' || messageContent[0] === 'yes') {
|
||||
Tag.destroy({where: {serverID: message.guild.id}});
|
||||
return interaction.editReply('Tags have been reset.');
|
||||
} else {
|
||||
return interaction.editReply('Not reseting.');
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
return interaction.editReply('Took too long to answer. didin\'t update anything.');
|
||||
});
|
||||
} else {
|
||||
return interaction.editReply('Only person with the `ADMINISTRATOR` rank can reset tags.');
|
||||
}
|
||||
}
|
||||
|
||||
if (args.remove) {
|
||||
if (tag) {
|
||||
if (tag.get('ownerID') == interaction.user.id || message.member.hasPermission('ADMINISTRATOR') || interaction.user.id == ownerID) {
|
||||
Tag.destroy({where: {trigger: args.trigger, serverID: message.guild.id}});
|
||||
return interaction.editReply('successfully deleted the following tag: ' + args.trigger);
|
||||
} 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`);
|
||||
}
|
||||
} else {
|
||||
return interaction.editReply('Did not find the specified tag, are you sure it exist?');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!args.trigger) return interaction.editReply('Please provide a trigger in order to create a tag.');
|
||||
|
||||
if (!args.response) return interaction.editReply('Please provide the response for that tag');
|
||||
|
||||
if (!tag) {
|
||||
const body = {trigger: args.trigger, response: args.response, ownerID: interaction.user.id, serverID: message.guild.id};
|
||||
await Tag.create(body);
|
||||
return interaction.editReply(`tag have been set to ${args.trigger} : ${args.response}`);
|
||||
} else if (tag.get('ownerID') == interaction.user.id || message.member.hasPermission('ADMINISTRATOR') || interaction.user.id == ownerID) {
|
||||
interaction.editReply('This tag already exist, do you want to update it? y/n');
|
||||
const filter = m => m.content && m.author.id == interaction.user.id;
|
||||
message.channel.awaitMessages(filter, {time: 5000, max: 1, errors: ['time'] })
|
||||
.then(async messages => {
|
||||
let messageContent = messages.map(messages => messages.content.toLowerCase());
|
||||
if (messageContent[0] === 'y' || messageContent[0] === 'yes') {
|
||||
const body = {trigger: args.trigger, response: args.response, ownerID: interaction.user.id, serverID: message.guild.id};
|
||||
await Tag.update(body, {where: {trigger: args.trigger, serverID: message.guild.id}});
|
||||
return interaction.editReply(`tag have been set to ${args.trigger} : ${args.response}`);
|
||||
} else {
|
||||
return interaction.editReply('Not updating.');
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
return interaction.editReply('Took too long to answer. didin\'t update anything.');
|
||||
});
|
||||
} 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`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TagCommand;
|
||||
*/
|
|
@ -4,8 +4,6 @@ import Twit from 'twit';
|
|||
import fetch from 'node-fetch';
|
||||
import os from 'node:os';
|
||||
import fs from 'node:fs';
|
||||
import util from 'node:util';
|
||||
import stream from 'node:stream';
|
||||
|
||||
import db from '../../models/index.js';
|
||||
import wordToCensor from '../../json/censor.json' assert {type: 'json'};
|
||||
|
@ -31,7 +29,8 @@ export default {
|
|||
async execute(interaction, args, client) {
|
||||
const content = args.content;
|
||||
const attachment = args.image;
|
||||
|
||||
console.log(args);
|
||||
console.log(attachment);
|
||||
if (!content && !attachment) {
|
||||
return interaction.reply({ content: 'Uh oh! You are missing any content for me to tweet!', ephemeral: true });
|
||||
}
|
||||
|
@ -92,32 +91,34 @@ export default {
|
|||
// Make sure there is an attachment and if its an image
|
||||
if (attachment) {
|
||||
if (attachment.name.toLowerCase().endsWith('.jpg') || attachment.name.toLowerCase().endsWith('.png') || attachment.name.toLowerCase().endsWith('.gif')) {
|
||||
const streamPipeline = util.promisify(stream.pipeline);
|
||||
const res = await fetch(attachment.url);
|
||||
if (!res.ok) return interaction.editReply('An error has occured while trying to download your image.');
|
||||
await streamPipeline(res.body, fs.createWriteStream(`${os.tmpdir()}/${attachment.name}`));
|
||||
fetch(attachment.url)
|
||||
.then(res => {
|
||||
const dest = fs.createWriteStream(`${os.tmpdir()}/${attachment.name}`);
|
||||
res.body.pipe(dest);
|
||||
dest.on('finish', () => {
|
||||
const file = fs.statSync(`${os.tmpdir()}/${attachment.name}`);
|
||||
const fileSize = file.size / 1000000.0;
|
||||
|
||||
const file = fs.statSync(`${os.tmpdir()}/${attachment.name}`);
|
||||
const fileSize = file.size / 1000000.0;
|
||||
if ((attachment.name.toLowerCase().endsWith('.jpg') || attachment.name.toLowerCase().endsWith('.png')) && fileSize > 5) {
|
||||
return interaction.editReply({ content: 'Images can\'t be larger than 5 MB!' });
|
||||
}
|
||||
else if (attachment.name.toLowerCase().endsWith('.gif') && fileSize > 15) {
|
||||
return interaction.editReply({ content: 'Gifs can\'t be larger than 15 MB!' });
|
||||
}
|
||||
|
||||
if ((attachment.name.toLowerCase().endsWith('.jpg') || attachment.name.toLowerCase().endsWith('.png')) && fileSize > 5) {
|
||||
return interaction.editReply({ content: 'Images can\'t be larger than 5 MB!' });
|
||||
}
|
||||
else if (attachment.name.toLowerCase().endsWith('.gif') && fileSize > 15) {
|
||||
return interaction.editReply({ content: 'Gifs can\'t be larger than 15 MB!' });
|
||||
}
|
||||
|
||||
const b64Image = fs.readFileSync(`${os.tmpdir()}/${attachment.name}`, { encoding: 'base64' });
|
||||
T.post('media/upload', { media_data: b64Image }, function(err, data) {
|
||||
if (err) {
|
||||
console.log('OH NO AN ERROR!!!!!!!');
|
||||
console.error(err);
|
||||
return interaction.editReply({ content: 'OH NO!!! AN ERROR HAS occurred!!! please hold on while i find what\'s causing this issue! ' });
|
||||
}
|
||||
else {
|
||||
Tweet(data);
|
||||
}
|
||||
});
|
||||
const b64Image = fs.readFileSync(`${os.tmpdir()}/${attachment.name}`, { encoding: 'base64' });
|
||||
T.post('media/upload', { media_data: b64Image }, function(err, data) {
|
||||
if (err) {
|
||||
console.log('OH NO AN ERROR!!!!!!!');
|
||||
console.error(err);
|
||||
return interaction.editReply({ content: 'OH NO!!! AN ERROR HAS occurred!!! please hold on while i find what\'s causing this issue! ' });
|
||||
}
|
||||
else {
|
||||
Tweet(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
else {
|
||||
await interaction.editReply({ content: 'File type not supported, you can only send jpg/png/gif' });
|
||||
|
@ -167,7 +168,7 @@ export default {
|
|||
}
|
||||
|
||||
const tweetid = response.id_str;
|
||||
const FunnyWords = ['oppaGangnamStyle', '69', '420', 'cum', 'funnyMan', 'GUCCISmartToilet', 'TwitterForClowns', 'fart', 'ok', 'hi', 'howAreYou', 'WhatsNinePlusTen', '21'];
|
||||
const FunnyWords = ['oppaGangnamStyle', '69', '420', 'cum', 'funnyMan', 'GUCCISmartToilet', 'TwitterForClowns', 'fart', 'mcDotnamejeffDotxyz', 'ok', 'hi', 'howAreYou', 'WhatsNinePlusTen', '21'];
|
||||
const TweetLink = `https://twitter.com/${FunnyWords[Math.floor((Math.random() * FunnyWords.length))]}/status/${tweetid}`;
|
||||
|
||||
// Im too lazy for now to make an entry in config.json
|
||||
|
|
|
@ -4,7 +4,7 @@ import db from '../../models/index.js';
|
|||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('optout')
|
||||
.setDescription('Opt out of the non commands features and arguments logging (for debugging purposes)'),
|
||||
.setDescription('Opt out of the non commands features.'),
|
||||
category: 'utility',
|
||||
async execute(interaction, args, client) {
|
||||
const isOptOut = await db.optout.findOne({ where: { userID: interaction.user.id } });
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
{
|
||||
"development": {
|
||||
"dialect": "sqlite",
|
||||
"storage": "./database.sqlite3"
|
||||
},
|
||||
"test": {
|
||||
"dialect": "sqlite",
|
||||
"storage": ":memory"
|
||||
},
|
||||
"production": {
|
||||
"dialect": "sqlite",
|
||||
"storage": "./database.sqlite3"
|
||||
}
|
||||
}
|
|
@ -9,18 +9,6 @@ export default {
|
|||
async execute(guild, client) {
|
||||
const guildOwner = await client.users.fetch(guild.ownerId);
|
||||
|
||||
const isOptOut = await db.optout.findOne({ where: { userID: guildOwner.id } });
|
||||
|
||||
if (isOptOut) {
|
||||
console.log(`A guild\n${guild.memberCount} users`);
|
||||
if (statusChannel && NODE_ENV !== 'development') {
|
||||
const channel = client.channels.resolve(statusChannel);
|
||||
|
||||
channel.send({ content: `An anonymous guild just added me.\nI'm now in ${client.guilds.cache.size} servers!` });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`${guild.name}\n${guild.memberCount} users\nOwner: ${guildOwner.username}\nOwner ID: ${guild.ownerId}`);
|
||||
|
||||
const blacklist = await guildBlacklist.findOne({ where: { guildID:guild.id } });
|
||||
|
|
|
@ -9,18 +9,6 @@ export default {
|
|||
async execute(guild, client) {
|
||||
const guildOwner = await client.users.fetch(guild.ownerId);
|
||||
|
||||
const isOptOut = await db.optout.findOne({ where: { userID: guildOwner.id } });
|
||||
|
||||
if (isOptOut) {
|
||||
console.log(`***BOT KICKED***A guild\n${guild.memberCount} users\n***BOT KICKED***`);
|
||||
if (statusChannel && NODE_ENV !== 'development') {
|
||||
const channel = client.channels.resolve(statusChannel);
|
||||
|
||||
channel.send({ content: `An anonymous guild just removed me.\nI'm now in ${client.guilds.cache.size} servers!` });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`***BOT KICKED***\n${guild.name}\n${guild.memberCount} users\nOwner: ${guildOwner.username}\nOwner ID: ${guild.ownerId}\n***BOT KICKED***`);
|
||||
|
||||
const blacklist = await guildBlacklist.findOne({ where: { guildID:guild.id } });
|
||||
|
|
|
@ -4,10 +4,6 @@ import { rand } from '../../utils/rand.js';
|
|||
export default {
|
||||
name: 'guildMemberAdd',
|
||||
async execute(member, client) {
|
||||
const isOptOut = await db.optout.findOne({ where: { userID: member.user.id } });
|
||||
|
||||
if (isOptOut) return;
|
||||
|
||||
const join = await db.joinChannel.findOne({ where: { guildID: member.guild.id } });
|
||||
|
||||
if (join) {
|
||||
|
|
|
@ -4,10 +4,6 @@ import { rand } from '../../utils/rand.js';
|
|||
export default {
|
||||
name: 'guildMemberRemove',
|
||||
async execute(member, client) {
|
||||
const isOptOut = await db.optout.findOne({ where: { userID: member.user.id } });
|
||||
|
||||
if (isOptOut) return;
|
||||
|
||||
const leave = await db.leaveChannel.findOne({ where: { guildID: member.guild.id } });
|
||||
|
||||
if (leave) {
|
||||
|
|
|
@ -27,15 +27,7 @@ export default {
|
|||
|
||||
if (!command) return;
|
||||
|
||||
const isOptOut = await db.optout.findOne({ where: { userID: interaction.user.id } });
|
||||
|
||||
if (isOptOut) {
|
||||
console.log(`A user launched command \x1b[33m${commandName}\x1b[0m with slash`);
|
||||
}
|
||||
else {
|
||||
console.log(`\x1b[33m${userTag} (${userID})\x1b[0m launched command \x1b[33m${commandName}\x1b[0m with slash`);
|
||||
}
|
||||
|
||||
console.log(`\x1b[33m${userTag} (${userID})\x1b[0m launched command \x1b[33m${commandName}\x1b[0m with slash`);
|
||||
|
||||
// Owner only check
|
||||
if (command.ownerOnly && interaction.user.id !== ownerId) {
|
||||
|
@ -82,10 +74,6 @@ export default {
|
|||
args[arg.name] = payload;
|
||||
});
|
||||
|
||||
if (!isOptOut) {
|
||||
console.log(`\x1b[33m${commandName}\x1b[0m with args ${JSON.stringify(args)}`);
|
||||
}
|
||||
|
||||
await command.execute(interaction, args, client);
|
||||
}
|
||||
catch (error) {
|
||||
|
|
|
@ -66,16 +66,13 @@ export default {
|
|||
if (tag) {
|
||||
db.Tag.findOne({ where: { trigger: message.content.toLowerCase(), serverID: message.guild.id } });
|
||||
let text = tag.get('response');
|
||||
/*
|
||||
if (text.includes('[ban]')) {
|
||||
message.member.ban('Tag ban :^)');
|
||||
}
|
||||
else if (text.includes('[kick]')) {
|
||||
message.member.kick('Tag kick :^)');
|
||||
}
|
||||
else
|
||||
*/
|
||||
if (text.includes('[delete]')) {
|
||||
else if (text.includes('[delete]')) {
|
||||
message.delete();
|
||||
}
|
||||
|
||||
|
@ -293,14 +290,7 @@ export default {
|
|||
const userTag = message.author.tag;
|
||||
const userID = message.author.id;
|
||||
|
||||
const isOptOut = await db.optout.findOne({ where: { userID: message.author.id } });
|
||||
|
||||
if (isOptOut) {
|
||||
console.log(`A user launched command \x1b[33m${commandName}\x1b[0m with prefix`);
|
||||
}
|
||||
else {
|
||||
console.log(`\x1b[33m${userTag} (${userID})\x1b[0m launched command \x1b[33m${commandName}\x1b[0m with prefix`);
|
||||
}
|
||||
console.log(`\x1b[33m${userTag} (${userID})\x1b[0m launched command \x1b[33m${commandName}\x1b[0m with prefix`);
|
||||
|
||||
// Owner only check
|
||||
if (command.ownerOnly && message.author.id !== ownerId) {
|
||||
|
@ -404,11 +394,6 @@ export default {
|
|||
|
||||
args[payloadName] = payload;
|
||||
}
|
||||
|
||||
if (!isOptOut) {
|
||||
console.log(`\x1b[33m${commandName}\x1b[0m with args ${JSON.stringify(args)}`);
|
||||
}
|
||||
|
||||
await command.execute(message, args, client);
|
||||
}
|
||||
catch (error) {
|
||||
|
|
14
index.js
14
index.js
|
@ -18,19 +18,15 @@ const client = new Client({
|
|||
// Load commands
|
||||
client.commands = new Collection();
|
||||
|
||||
fs.readdir(`${__dirname}/commands`, (err, categoryPath) => {
|
||||
if (err) {
|
||||
return console.error(err);
|
||||
}
|
||||
categoryPath.forEach(category => {
|
||||
loadCommandFromDir(category);
|
||||
});
|
||||
const categoryPath = fs.readdirSync(`${__dirname}/commands`);
|
||||
categoryPath.forEach(category => {
|
||||
loadCommandFromDir(category);
|
||||
});
|
||||
|
||||
// Load events
|
||||
loadEventFromDir('client', client);
|
||||
await loadEventFromDir('client', client);
|
||||
if (NODE_ENV !== 'development') {
|
||||
loadEventFromDir('process', process);
|
||||
await loadEventFromDir('process', process);
|
||||
}
|
||||
|
||||
client.login(token);
|
||||
|
|
7871
package-lock.json
generated
7871
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -19,7 +19,7 @@
|
|||
"dependencies": {
|
||||
"@discordjs/rest": "^0.4.1",
|
||||
"discord-api-types": "^0.33.5",
|
||||
"discord.js": "^14.9.0",
|
||||
"discord.js": "^14.3.0",
|
||||
"dotenv": "^16.0.1",
|
||||
"mariadb": "^3.0.1",
|
||||
"mysql2": "^2.3.3",
|
||||
|
@ -27,7 +27,7 @@
|
|||
"safe-regex": "github:davisjam/safe-regex",
|
||||
"sequelize": "^6.21.3",
|
||||
"turndown": "^7.1.1",
|
||||
"twit": "^1.1.20",
|
||||
"twit": "^2.2.11",
|
||||
"ytpplus-node": "github:Supositware/ytpplus-node"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -35,7 +35,6 @@
|
|||
"@babel/plugin-syntax-import-assertions": "^7.18.6",
|
||||
"@types/node": "^18.7.3",
|
||||
"eslint": "^8.16.0",
|
||||
"sequelize-cli": "^6.4.1",
|
||||
"sqlite3": "^5.1.6"
|
||||
"sequelize-cli": "^6.4.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,11 +46,11 @@ export function rand(text, interaction) {
|
|||
},
|
||||
{
|
||||
name: /\[kick\]/,
|
||||
value: '[This used to kick you but no more!]',
|
||||
value: '',
|
||||
},
|
||||
{
|
||||
name: /\[ban\]/,
|
||||
value: '[This used to ban you but no more!]',
|
||||
value: '',
|
||||
},
|
||||
{
|
||||
name: /\[delete\]/,
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const ratelimit = {};
|
||||
import db from '../models/index.js';
|
||||
|
||||
export default {
|
||||
check,
|
||||
|
@ -26,14 +25,7 @@ function check(user, commandName, commands) {
|
|||
const minutes = Math.floor(seconds / 60);
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const dateString = `${hours > 0 ? ` ${Math.floor(hours)} hours` : ''}${minutes > 0 ? ` ${Math.floor(minutes % 60)} minutes` : ''}${seconds > 0 ? ` ${Math.floor(seconds % 60)} seconds` : ''}`;
|
||||
|
||||
const isOptOut = db.optout.findOne({ where: { userID: userID } });
|
||||
if (isOptOut) {
|
||||
console.log(`A user is rate limited on \x1b[33m${commandName}\x1b[0m for${dateString}.`);
|
||||
}
|
||||
else {
|
||||
console.log(`\x1b[33m${userTag} (${userID})\x1b[0m is rate limited on \x1b[33m${commandName}\x1b[0m for${dateString}.`);
|
||||
}
|
||||
console.log(`\x1b[33m${userTag} (${userID})\x1b[0m is rate limited on \x1b[33m${commandName}\x1b[0m for${dateString}.`);
|
||||
return `You are being rate limited. You can try again in${dateString}.`;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue