first commit
This commit is contained in:
26
events/InteractionCreate/interactionCreate.js
Normal file
26
events/InteractionCreate/interactionCreate.js
Normal file
@ -0,0 +1,26 @@
|
||||
const { Events } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: Events.InteractionCreate,
|
||||
async execute(interaction) {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
const command = interaction.client.commands.get(interaction.commandName);
|
||||
|
||||
if (!command) {
|
||||
console.error(`No command matching ${interaction.commandName} was found.`);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await command.execute(interaction);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
if (interaction.replied || interaction.deferred) {
|
||||
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
|
||||
} else {
|
||||
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
33
events/guildBanAdd/chatlog.js
Normal file
33
events/guildBanAdd/chatlog.js
Normal file
@ -0,0 +1,33 @@
|
||||
const { Events, GuildMember } = require("discord.js");
|
||||
const { modLogEmbed } = require("../../embeds/modLogs");
|
||||
|
||||
|
||||
|
||||
module.exports = {
|
||||
name: Events.GuildBanAdd,
|
||||
async execute(member) {
|
||||
try {
|
||||
const auditLogs = await member.guild.fetchAuditLogs({ type: 22 });
|
||||
const banEntry = auditLogs.entries.first();
|
||||
const modLogsChannel = member.guild.channels.cache.find(channel => channel.name === 'mod-logs');
|
||||
|
||||
if (!banEntry) return;
|
||||
|
||||
const { target, executor, reason } = banEntry;
|
||||
|
||||
if (!modLogsChannel) return;
|
||||
|
||||
// Call modLogEmbed and send the embed
|
||||
const embed = modLogEmbed("ban", member, reason || "No reason provided");
|
||||
|
||||
if (embed) {
|
||||
await modLogsChannel.send({ embeds: [embed] });
|
||||
//console.log(`Ban logged: ${target.tag} banned by ${executor.tag}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
};
|
||||
48
events/guildBanAdd/logtodb.js
Normal file
48
events/guildBanAdd/logtodb.js
Normal file
@ -0,0 +1,48 @@
|
||||
const { Events, GuildMember } = require("discord.js");
|
||||
const db = require("../../db");
|
||||
|
||||
/**
|
||||
* @param {Client} client
|
||||
* @param {GuildMember} member
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
name: Events.GuildBanAdd,
|
||||
async execute(member) {
|
||||
const auditLogs = await member.guild.fetchAuditLogs({ type: 22 });
|
||||
const banEntry = auditLogs.entries.first();
|
||||
|
||||
try {
|
||||
if (banEntry) {
|
||||
const { reason, executor, target, createdAt } = banEntry;
|
||||
|
||||
const guildID = member.guild.id;
|
||||
const guildName = member.guild.name;
|
||||
const userID = target.id;
|
||||
const userName = target.username;
|
||||
const userTag = target.tag;
|
||||
const avatarURL = target.displayAvatarURL({ dynamic: true });
|
||||
const banDate = createdAt.toISOString();
|
||||
const banReason = reason || "No reason provided";
|
||||
const banExecutor = executor.tag;
|
||||
|
||||
await db.query(
|
||||
"INSERT INTO bans (guild_ID, guild_Name, user_ID, username, user_Tag, avatar_URL, ban_Date, ban_Reason, ban_Executor) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
[
|
||||
guildID,
|
||||
guildName,
|
||||
userID,
|
||||
userName,
|
||||
userTag,
|
||||
avatarURL,
|
||||
banDate,
|
||||
banReason,
|
||||
banExecutor,
|
||||
]
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("There was an error", error);
|
||||
}
|
||||
},
|
||||
};
|
||||
33
events/guildBanRemove/chatlog.js
Normal file
33
events/guildBanRemove/chatlog.js
Normal file
@ -0,0 +1,33 @@
|
||||
const { Events, GuildMember } = require("discord.js");
|
||||
const { modLogEmbed } = require("../../embeds/modLogs");
|
||||
|
||||
|
||||
|
||||
module.exports = {
|
||||
name: Events.GuildBanRemove,
|
||||
async execute(member) {
|
||||
try {
|
||||
const auditLogs = await member.guild.fetchAuditLogs({ type: 23 });
|
||||
const banEntry = auditLogs.entries.first();
|
||||
const modLogsChannel = member.guild.channels.cache.find(channel => channel.name === 'mod-logs');
|
||||
|
||||
if (!banEntry) return;
|
||||
|
||||
const { target, executor, reason } = banEntry;
|
||||
|
||||
if (!modLogsChannel) return;
|
||||
|
||||
// Call modLogEmbed and send the embed
|
||||
const embed = modLogEmbed("unban", member, reason || "No reason provided");
|
||||
|
||||
if (embed) {
|
||||
await modLogsChannel.send({ embeds: [embed] });
|
||||
//console.log(`Ban logged: ${target.tag} banned by ${executor.tag}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
};
|
||||
21
events/guildCreate/addGuildToDB.js
Normal file
21
events/guildCreate/addGuildToDB.js
Normal file
@ -0,0 +1,21 @@
|
||||
const { Guild, Events } = require('discord.js');
|
||||
|
||||
const db = require('../../db');
|
||||
|
||||
module.exports = {
|
||||
name: Events.GuildCreate,
|
||||
async execute(guild) {
|
||||
try {
|
||||
await db.query('CREATE TABLE IF NOT EXISTS guilds (guild_id VARCHAR PRIMARY KEY, guild_name VARCHAR, created_at TIMESTAMP, guild_owner_id VARCHAR)');
|
||||
const result = await db.query('SELECT * FROM guilds WHERE guild_id = $1', [guild.id]);
|
||||
if (result.rows.length === 0) {
|
||||
await db.query('INSERT INTO guilds (guild_id, guild_name, created_at, guild_owner_id) VALUES ($1, $2, $3, $4)', [guild.id, guild.name, guild.createdAt, guild.ownerId]);
|
||||
console.log(`Added new guild to the database: ${guild.name}`);
|
||||
} else {
|
||||
console.log(`Guild already exists in the database: ${guild.name}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error adding guild to the database:', error);
|
||||
}
|
||||
},
|
||||
};
|
||||
34
events/guildCreate/createChannel.js
Normal file
34
events/guildCreate/createChannel.js
Normal file
@ -0,0 +1,34 @@
|
||||
const { Guild, Events, PermissionFlagsBits } = require('discord.js');
|
||||
|
||||
const db = require('../../db');
|
||||
|
||||
module.exports = {
|
||||
name: Events.GuildCreate,
|
||||
async execute(guild) {
|
||||
try {
|
||||
await db.query('CREATE TABLE IF NOT EXISTS bot_channel (guild_id VARCHAR PRIMARY KEY, guild_name VARCHAR, channel_id VARCHAR, channel_name VARCHAR)');
|
||||
const result = await db.query('SELECT * FROM bot_channel WHERE guild_id = $1', [guild.id]);
|
||||
if (result.rows.length === 0) {
|
||||
// Create Channel then add to database
|
||||
const channel = await guild.channels.create({
|
||||
name: 'BluBot',
|
||||
type: 0,
|
||||
permissionOverwrites: [
|
||||
{
|
||||
id: guild.id,
|
||||
allow: [PermissionFlagsBits.ViewChannel],
|
||||
},
|
||||
],
|
||||
});
|
||||
await db.query('INSERT INTO bot_channel (guild_id, guild_name, channel_id, channel_name) VALUES ($1, $2, $3, $4)', [guild.id, guild.name, channel.id, channel.name]);
|
||||
//await db.query('INSERT INTO bot_channel (guild_id, guild_name, channel_id, channel_name) VALUES ($1, $2, $3, $4)', [guild.id, guild.name, guild.channels.id, guild.channels.name]);
|
||||
console.log(`Added new guild to the database: ${guild.name}`);
|
||||
} else {
|
||||
console.log(`Guild already exists in the database: ${guild.name}`);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Error creating channel or adding to database:', error);
|
||||
}
|
||||
}
|
||||
};
|
||||
26
events/guildMemberAdd/logToDB.js
Normal file
26
events/guildMemberAdd/logToDB.js
Normal file
@ -0,0 +1,26 @@
|
||||
const { Events, GuildMember } = require("discord.js");
|
||||
const db = require("../../db");
|
||||
|
||||
/**
|
||||
* @param {Client} client
|
||||
* @param {GuildMember} member
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
name: Events.GuildMemberAdd,
|
||||
async execute(member) {
|
||||
try {
|
||||
const userID = member.id;
|
||||
const userName = member.user.username;
|
||||
const userTag = member.user.tag;
|
||||
const avatarURL = member.displayAvatarURL({ dynamic: true });
|
||||
|
||||
await db.query(
|
||||
"INSERT INTO members (user_ID, username, user_Tag, avatar_URL) VALUES ($1, $2, $3, $4) ON CONFLICT (user_ID) DO NOTHING",
|
||||
[userID, userName, userTag, avatarURL]
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("There was an error", error);
|
||||
}
|
||||
},
|
||||
};
|
||||
34
events/guildMemberAdd/sendWelcome.js
Normal file
34
events/guildMemberAdd/sendWelcome.js
Normal file
@ -0,0 +1,34 @@
|
||||
const { GuildMember, Events } = require('discord.js')
|
||||
const db = require('../../db')
|
||||
const { welcomeEmbed } = require('../../embeds/welcomeMember')
|
||||
|
||||
/**
|
||||
* @param {Client} client
|
||||
* @param {GuildMember} member
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
name: Events.GuildMemberAdd,
|
||||
async execute(member) {
|
||||
|
||||
try {
|
||||
const embed = welcomeEmbed(member)
|
||||
const result = await db.query(`SELECT channel_id, enabled FROM auto_welcome WHERE guild_id = $1`,
|
||||
[member.guild.id])
|
||||
|
||||
const welcomeData = result.rows[0]
|
||||
|
||||
if (welcomeData && welcomeData.enabled) {
|
||||
const welcomeChannel = member.guild.channels.cache.get(welcomeData.channel_id)
|
||||
|
||||
if (welcomeChannel) {
|
||||
welcomeChannel.send({ embeds: [embed]})
|
||||
} else {
|
||||
console.error('Invalid channel id')
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('There was an error in sendWelcome:', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
26
events/messageCreate/messageCreate.js
Normal file
26
events/messageCreate/messageCreate.js
Normal file
@ -0,0 +1,26 @@
|
||||
const { Events, Message } = require('discord.js');
|
||||
const db = require('../../db')
|
||||
|
||||
/**
|
||||
* @param { Message } message
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
name: Events.MessageCreate,
|
||||
async execute(message) {
|
||||
const messageContent = message.content
|
||||
const author = message.author.tag
|
||||
const guildID = message.guild.id
|
||||
if (!message.inGuild() || message.author.bot) return;
|
||||
|
||||
try {
|
||||
await db.query("INSERT INTO messages (message, author, guild_ID) VALUES ($1, $2, $3)", [
|
||||
messageContent,
|
||||
author,
|
||||
guildID,
|
||||
]);
|
||||
} catch (error) {
|
||||
console.error("Error saving message: ", error)
|
||||
}
|
||||
}
|
||||
}
|
||||
47
events/presenceUpdate/checktwitchPres.js
Normal file
47
events/presenceUpdate/checktwitchPres.js
Normal file
@ -0,0 +1,47 @@
|
||||
const { Guild, GuildMember, Events } = require('discord.js')
|
||||
const db = require('../../db')
|
||||
|
||||
const { userStreamingEmbed } = require('../../embeds/userStreaming')
|
||||
|
||||
|
||||
module.exports = {
|
||||
name: Events.PresenceUpdate,
|
||||
async execute(oldPresence, newPresence) {
|
||||
|
||||
//console.log('Presence Update:', newPresence);
|
||||
|
||||
|
||||
|
||||
// Check if the user is streaming
|
||||
if (!newPresence.activities) return;
|
||||
const streamingActivity = newPresence.activities.find(activity => activity.type === 1);
|
||||
if (!streamingActivity) return;
|
||||
|
||||
const user = newPresence.user;
|
||||
|
||||
if (streamingActivity)
|
||||
{
|
||||
try {
|
||||
for (const [guildId, guild] of newPresence.client.guilds.cache) {
|
||||
const member = await guild.members.fetch(user.id).catch(() => null);
|
||||
if (!member) continue;
|
||||
const result = await db.query("SELECT channel_id FROM bot_channel WHERE guild_id = $1", [guildId]);
|
||||
if (result.rows.length === 0) continue;
|
||||
const channelId = result.rows[0].channel_id;
|
||||
const channel = guild.channels.cache.get(channelId);
|
||||
|
||||
if (channel && channel.isTextBased()) {
|
||||
const { embeds, components } = userStreamingEmbed(user, streamingActivity);
|
||||
await channel.send({
|
||||
embeds,
|
||||
components
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching user:', error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
10
events/ready/ready.js
Normal file
10
events/ready/ready.js
Normal file
@ -0,0 +1,10 @@
|
||||
const { Events, PresenceUpdateStatus } = require('discord.js')
|
||||
|
||||
module.exports = {
|
||||
name: Events.ClientReady,
|
||||
once: true,
|
||||
execute(client) {
|
||||
console.log(`Ready! Logged in as ${client.user.tag}`);
|
||||
client.user.setStatus(PresenceUpdateStatus.Online)
|
||||
},
|
||||
};
|
||||
41
events/ready/setActivity.js
Normal file
41
events/ready/setActivity.js
Normal file
@ -0,0 +1,41 @@
|
||||
const { Client, Guild, Events, ActivityType, PresenceUpdateStatus } = require('discord.js');
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Client} client
|
||||
* @param {Guild} guild
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
name: Events.ClientReady,
|
||||
async execute(client) {
|
||||
const guildsCount = client.guilds.cache.size;
|
||||
|
||||
let status = [
|
||||
{
|
||||
name: "I am Live",
|
||||
type: ActivityType.Watching,
|
||||
},
|
||||
{
|
||||
name: "Choo Choo 🚂",
|
||||
},
|
||||
{
|
||||
name: 'Hippity Hoppity',
|
||||
},
|
||||
{
|
||||
name: `I am in ${guildsCount} Server(s)`,
|
||||
},
|
||||
{
|
||||
name: 'Yippe 🐻'
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
|
||||
|
||||
setInterval(() => {
|
||||
let random = Math.floor(Math.random() * status.length);
|
||||
client.user.setActivity(status[random]);
|
||||
}, 30000);
|
||||
}
|
||||
};
|
||||
0
events/voiceStateUpdate/checkUpdate.js
Normal file
0
events/voiceStateUpdate/checkUpdate.js
Normal file
Reference in New Issue
Block a user