in out user

main
kry008 2024-06-16 10:28:17 +02:00
parent 81b2cbb8a2
commit f0e96dac7e
9 changed files with 428 additions and 35 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ templates.file
node_modules node_modules
package-lock.json package-lock.json
guilds-*.txt guilds-*.txt
guilds/*.json

View File

@ -0,0 +1,95 @@
const fs = require('fs');
module.exports = {
name: 'exitmsg',
description: 'Enable or disable the exit message and edit the exit message. To mention the user, use {{USER}}.',
help: 'Function to edit the message that is sent when a user leaves the server, use {{USER}} to mention the user.',
options: [
{
name: 'enabled',
description: 'Enable or disable the exit message',
type: 5,
required: true,
},
{
name: 'title',
description: 'Title of the exit message',
type: 3,
required: false,
},
{
name: 'description',
description: 'Description of the exit message, use {{USER}} to mention the user',
type: 3,
required: false,
},
{
name: 'channel',
description: 'Channel to send the exit message',
type: 7,
required: false,
}
],
slash: true,
text: true,
admin: true,
requireKick: false,
requireBan: false,
canBeUsedInDm: true,
contexts: ['GUILD_TEXT'],
integration_types: [0],
execute(message, args) {
message.channel.send('This command can only be used as a slash command.');
},
executeSlash(interaction) {
//check if the user has the required permissions
if (!interaction.member.permissions.has('ADMINISTRATOR')) {
interaction.reply('You need to have the administrator permission to use this command.');
return;
}
//check if all the required arguments are provided
if(!interaction.options.getBoolean('enabled') || !interaction.options.getString('title') || !interaction.options.getString('description') || !interaction.options.getChannel('channel')) {
interaction.reply('Please provide all the required information.');
return;
}
const enabled = interaction.options.getBoolean('enabled');
const title = interaction.options.getString('title');
const description = interaction.options.getString('description');
const channel = interaction.options.getChannel('channel');
const filePath = `./guilds/guilds-${interaction.guild.id}.json`;
if(enabled === null || title === null || description === null || channel === null) {
interaction.reply('Please provide all the required information.');
return;
}
if(channel.type !== 0) {
interaction.reply('Please provide a text channel.');
return;
}
if(enabled === false) {
//get data from file
const data = JSON.parse(fs.readFileSync(filePath));
data.goodbyeMessage.title = null;
data.goodbyeMessage.content = null;
data.goodbyeChannel = null;
data.goodbye = false;
fs.writeFileSync(filePath, JSON.stringify(data));
interaction.reply('Exit message disabled.');
return;
}
else
{
const data = JSON.parse(fs.readFileSync(filePath));
data.goodbyeMessage.title = title;
data.goodbyeMessage.content = description;
data.goodbyeChannel = channel.id;
data.goodbye = true;
fs.writeFileSync(filePath, JSON.stringify(data));
interaction.reply('Exit message updated successfully.');
return;
}
},
};

View File

@ -0,0 +1,101 @@
const fs = require('fs');
module.exports = {
name: 'newusermsg',
description: 'Edit the message that is sent when a new user joins the server, use {{USER}} to mention the user.',
help: 'Function to edit the message that is sent when a new user joins the server, use {{USER}} to mention the user.',
//enabled/disabled, title, description, channel
options: [
{
name: 'enabled',
description: 'Enable or disable the welcome message',
type: 5,
required: true,
},
{
name: 'title',
description: 'Title of the welcome message',
type: 3,
required: false,
},
{
name: 'description',
description: 'Description of the welcome message, use {{USER}} to mention the user',
type: 3,
required: false,
},
{
name: 'channel',
description: 'Channel to send the welcome message',
type: 7,
required: false,
}
],
slash: true,
text: true,
admin: true,
requireKick: true,
requireBan: true,
canBeUsedInDm: false,
contexts: ['GUILD_TEXT'],
integration_types: [0, 1],
execute(message, args) {
message.channel.send('This command can only be used as a slash command.');
},
executeSlash(interaction) {
//check if the user has the required permissions
if (!interaction.member.permissions.has('ADMINISTRATOR')) {
interaction.reply('You need to have the administrator permission to use this command.');
return;
}
//check if all the required arguments are provided
if(!interaction.options.getBoolean('enabled') || !interaction.options.getString('title') || !interaction.options.getString('description') || !interaction.options.getChannel('channel')) {
interaction.reply('Please provide all the required information.');
return;
}
const enabled = interaction.options.getBoolean('enabled');
const title = interaction.options.getString('title');
const description = interaction.options.getString('description');
const channel = interaction.options.getChannel('channel');
const filePath = `./guilds/guilds-${interaction.guild.id}.json`;
if(enabled === null || title === null || description === null || channel === null) {
interaction.reply('Please provide all the required information.');
return;
}
//check if the channel is a text channel
if(channel.type !== 0) {
interaction.reply('Please provide a text channel.');
return;
}
if(enabled === false) {
//get data from file
if (fs.existsSync(filePath)) {
const data = JSON.parse(fs.readFileSync(filePath));
data.hello = false;
data.helloChannel = null;
data.welcomeMessage.title = null;
data.welcomeMessage.content = null;
fs.writeFileSync(filePath, JSON.stringify(data));
}
interaction.reply('Welcome message disabled.');
return;
}
else
{
//get data from file
if (fs.existsSync(filePath)) {
const data = JSON.parse(fs.readFileSync(filePath));
data.hello = true;
data.helloChannel = channel.id;
data.welcomeMessage.title = title;
data.welcomeMessage.content = description;
fs.writeFileSync(filePath, JSON.stringify(data));
}
interaction.reply('Welcome message enabled.');
return;
}
},
};

View File

@ -0,0 +1,76 @@
const fs = require('fs');
module.exports = {
name: 'rulesmsg',
description: 'Enable or disable the rules message and edit the rules message.',
help: 'Use {{RULES}} to mention the rules channel',
options: [
{
name: 'enabled',
description: 'Enable or disable the rules message',
type: 5,
required: true,
},
{
name: 'ruleline',
description: 'Description of the rules message, use {{RULES}} to mention the rules channel',
type: 3,
required: false,
},
{
name: 'channel',
description: 'Channel to send the rules message',
type: 7,
required: false,
}
],
slash: true,
text: true,
admin: true,
requireKick: false,
requireBan: false,
canBeUsedInDm: false,
contexts: ['GUILD_TEXT'],
integration_types: [0],
execute(message, args) {
message.channel.send('This command can only be used as a slash command.');
},
executeSlash(interaction) {
//check if the user has the required permissions
if (!interaction.member.permissions.has('ADMINISTRATOR')) {
interaction.reply('You need to have the administrator permission to use this command.');
return;
}
//check if all the required arguments are provided
if(!interaction.options.getBoolean('enabled') || !interaction.options.getString('ruleline') || !interaction.options.getChannel('channel')) {
interaction.reply('Please provide all the required information.');
return;
}
const enabled = interaction.options.getBoolean('enabled');
const ruleline = interaction.options.getString('ruleline');
const channel = interaction.options.getChannel('channel');
const filePath = `./guilds/guilds-${interaction.guild.id}.json`;
if(enabled === null || ruleline === null || channel === null) {
interaction.reply('Please provide all the required information.');
return;
}
if(channel.type !== 0) {
interaction.reply('Please provide a text channel.');
return;
}
if (enabled) {
const data = JSON.parse(fs.readFileSync(filePath));
data.rulesMessage = ruleline;
data.rulesChannel = channel.id;
fs.writeFileSync(filePath, JSON.stringify(data, null, 4));
}
else {
const data = JSON.parse(fs.readFileSync(filePath));
data.rulesMessage = null;
data.rulesChannel = null;
fs.writeFileSync(filePath, JSON.stringify(data, null, 4));
}
interaction.reply('Rules message updated successfully.');
},
};

View File

@ -9,5 +9,18 @@ module.exports = {
const guildPath = `./guilds-${new Date().toISOString().split('T')[0]}.txt`; const guildPath = `./guilds-${new Date().toISOString().split('T')[0]}.txt`;
//save name - id - time of joining //save name - id - time of joining
fs.appendFileSync(guildPath, `JOIN: \`${guild.name}\` - ${guild.id} - ${new Date().toLocaleString()}\n`); fs.appendFileSync(guildPath, `JOIN: \`${guild.name}\` - ${guild.id} - ${new Date().toLocaleString()}\n`);
const guildPath2 = `./guilds/guilds-${guild.id}.json`;
if (!fs.existsSync(guildPath2)) {
fs.writeFileSync(guildPath2, JSON.stringify({ id: guild.id, name: [guild.name], premium: false, prefix: prefix, premium:false, prefix:"^", hello: false, goodbye: true, helloChannel: null, goodbyeChannel: null, rulesChannel: null, welcomeMessage: { title: "Say hello", content: "Hello {{USER}}"}, goodbyeMessage: { title: "Say goodbye", content: "Goodbye {{USER}}"}, rulesMessage: null}));
}
else
{
const data = JSON.parse(fs.readFileSync(guildPath2));
if (!data.name.includes(guild.name))
{
data.name.push(guild.name);
fs.writeFileSync(guildPath2, JSON.stringify(data));
}
}
} }
}; };

View File

@ -1,28 +1,57 @@
const { Events, EmbedBuilder } = require('discord.js'); const { Events, EmbedBuilder } = require('discord.js');
const fs = require('fs');
function randomColor() { function randomColor() {
const r = Math.floor(Math.random() * 200) + 50; const r = Math.floor(Math.random() * 200) + 50;
const g = Math.floor(Math.random() * 200) + 50; const g = Math.floor(Math.random() * 200) + 50;
const b = Math.floor(Math.random() * 200) + 50; const b = Math.floor(Math.random() * 200) + 50;
return `#${r.toString(16)}${g.toString(16)}${b.toString(16)}`; return `#${r.toString(16)}${g.toString(16)}${b.toString(16)}`;
} }
module.exports = {
name: Events.GuildMemberAdd,
once: false,
execute(args) {
const { guild, user } = args;
const channel = guild.channels.cache.find(channel => ['new-member', 'new-users', 'hello', 'welcome'].includes(channel.name));
//find rules channel
const rulesChannel = guild.channels.cache.find(channel => ['rules', 'regulations', 'regulamin'].includes(channel.name));
if (!channel) return;
if(!rulesChannel) var text = 'Please read the rules in rules channel.';
else var text = `Please read the rules in ${rulesChannel} channel.`;
const embed = new EmbedBuilder()
.setTitle(`Welcome ${user.username}!`)
.setDescription(`Welcome to ${guild.name}! \n${text}`)
.setColor(randomColor())
.setThumbnail(user.avatarURL())
.setTimestamp();
channel.send({ embeds: [embed] });
module.exports = {
name: Events.GuildMemberAdd,
once: false,
execute(member) {
const { guild, user } = member;
const filePath = `./guilds/guilds-${guild.id}.json`;
if (fs.existsSync(filePath)) {
const data = JSON.parse(fs.readFileSync(filePath));
if (!data.hello || !data.helloChannel) return;
let title = data.welcomeMessage && data.welcomeMessage.title ? data.welcomeMessage.title : "👋 Welcome!";
let description = data.welcomeMessage && data.welcomeMessage.content ? data.welcomeMessage.content.replace("{{USER}}", user.username) : `Welcome to the server, ${user.username}!`;
if(data.rulesChannel == null || data.rulesMessage == null)
{
}
else
{
//data.rulesMessage + #data.rulesChannel
description += "\n" + data.rulesMessage;
//replace {{RULES}} with the rules channel
description = description.replace("{{RULES}}", `<#${data.rulesChannel}>`);
}
const embed = new EmbedBuilder()
.setTitle(title)
.setDescription(description)
.setColor(randomColor())
.setThumbnail(user.avatarURL())
.setTimestamp();
guild.channels.fetch(data.helloChannel)
.then(channel => {
if (channel) {
channel.send({ embeds: [embed] })
.catch(console.error);
} else {
console.error("Welcome channel not found.");
}
})
.catch(console.error);
} else {
return;
}
} }
}; };

View File

@ -1,11 +1,66 @@
const { Events } = require('discord.js'); const { Events } = require('discord.js');
const { ActivityType } = require('discord.js'); const { ActivityType } = require('discord.js');
const { prefix } = require('../config.json');
const fs = require('fs');
module.exports = { module.exports = {
name: Events.ClientReady, name: Events.ClientReady,
once: true, once: true,
execute(client) { execute(client) {
console.log(`Ready! Logged in as ${client.user.tag}`); console.log(`Ready! Logged in as ${client.user.tag}`);
client.user.setActivity('kry008.xyz/bot/i | To see how to support type /supportbot', { type: ActivityType.PLAYING }); client.user.setActivity('kry008.xyz/bot/i | To see how to support type /supportbot | Type /help to get all commands', { type: ActivityType.PLAYING });
//read all guilds, create files with guildid.json if not exists
client.guilds.cache.forEach(guild => {
const guildPath = `./guilds/guilds-${guild.id}.json`;
if (!fs.existsSync(guildPath)) {
fs.writeFileSync(guildPath, JSON.stringify(({ id: guild.id, name: [guild.name], premium: false, prefix: prefix, premium:false, prefix:"^", modChannel: null, hello: false, goodbye: true, helloChannel: null, goodbyeChannel: null, rulesChannel: null, welcomeMessage: { title: "Say hello", content: "Hello {{USER}}"}, goodbyeMessage: { title: "Say goodbye", content: "Goodbye {{USER}}"}, rulesMessage: null})));
}
else
{
const data = JSON.parse(fs.readFileSync(guildPath));
if (!data.name.includes(guild.name))
{
data.name.push(guild.name);
fs.writeFileSync(guildPath, JSON.stringify(data));
}
if(!data.hello)
{
data.hello = false;
}
if(!data.goodbye)
{
data.goodbye = false;
}
if(!data.helloChannel)
{
data.helloChannel = null;
}
if(!data.goodbyeChannel)
{
data.goodbyeChannel = null;
}
if(!data.rulesChannel)
{
data.rulesChannel = null;
}
if(!data.welcomeMessage)
{
data.welcomeMessage = null;
}
if(!data.goodbyeMessage)
{
data.goodbyeMessage = null;
}
if(!data.rulesMessage)
{
data.rulesMessage = null;
}
if(!data.modChannel)
{
data.modChannel = null;
}
fs.writeFileSync(guildPath, JSON.stringify(data));
}
});
}, },
}; };

View File

@ -1,19 +1,42 @@
//guildMemberRemove
const { Events, EmbedBuilder } = require('discord.js'); const { Events, EmbedBuilder } = require('discord.js');
const fs = require('fs');
module.exports = { module.exports = {
name: Events.GuildMemberRemove, name: Events.GuildMemberRemove,
once: false, once: false,
execute(args) { execute(member) {
const { guild, user } = args; const { guild, user } = member;
const channel = guild.channels.cache.find(channel => ['goodbye', 'bye', 'left', 'leaving', 'wyjścia'].includes(channel.name)); const filePath = `./guilds/guilds-${guild.id}.json`;
if (!channel) return;
const embed = new EmbedBuilder() if (fs.existsSync(filePath)) {
.setTitle(`Goodbye ${user.username}!`) const data = JSON.parse(fs.readFileSync(filePath));
.setDescription(`Goodbye ${user.username}!`)
.setColor('#ff0000') if (!data.goodbye || !data.goodbyeChannel) return;
.setThumbnail(user.avatarURL())
.setTimestamp(); let title = data.goodbyeMessage.title;
channel.send({ embeds: [embed] }); let description = data.goodbyeMessage.content ? data.goodbyeMessage.content.replace("{{USER}}", user.username) : `Goodbye ${user.username}!`;
const embed = new EmbedBuilder()
.setTitle(title)
.setDescription(description)
.setColor("#ff0000")
.setThumbnail(user.avatarURL())
.setTimestamp();
guild.channels.fetch(data.goodbyeChannel)
.then(channel => {
if (channel) {
channel.send({ embeds: [embed] })
.catch(console.error);
} else {
console.error("Goodbye channel not found.");
}
})
.catch(console.error);
}
else
{
return;
}
} }
}; };

View File