Skip to content
This repository was archived by the owner on Jul 20, 2023. It is now read-only.
Merged
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
config.json
node_modules/
jsconfig.json
jsconfig.json
database.sqlite
23 changes: 0 additions & 23 deletions Util/Models sequalize.js

This file was deleted.

37 changes: 37 additions & 0 deletions Util/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const Sequelize = require('sequelize');

const sequelize = new Sequelize('database', 'user', 'password', {
host: 'localhost',
dialect: 'sqlite',
logging: false,
storage: 'database.sqlite'
})

const Bans = sequelize.define('bans', {
userID:{
type: Sequelize.NUMBER,
},
reason: {
type: Sequelize.TEXT,
defaultValue: "No reason provided"
},
Executor: Sequelize.STRING,
type: {
type: Sequelize.STRING,
}//,
//ID: Sequelize.NUMBER
});

const Warns = sequelize.define('warns', {
userID:{
type: Sequelize.NUMBER,
},
reason: {
type: Sequelize.TEXT,
defaultValue: "No reason provided"
},
Executor: Sequelize.STRING//,
// ID: Sequelize.NUMBER
});

module.exports = { Bans, Warns }
30 changes: 24 additions & 6 deletions commands/ban.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
Expand All @@ -15,18 +16,35 @@ module.exports = {
.setName("time")
.setDescription("How long to ban this user?")),
async execute(interaction) {
let member = interaction.options.getMember("user")
let member = await interaction.client.users.fetch(interaction.options.getMember("user"))
let reason = interaction.options.getString("reason")

const db = interaction.client.db.Bans
const replyEmbed = new MessageEmbed()
if (!reason) reason = "No reason provided"

if (interaction.options.getNumber("time") !== undefined) {let days = interaction.options.getNumber("time")}
else {let days = null}

if (member.bannable) await member.ban({ days: days, reason: reason }).then(console.log).catch(error => {console.error(error);interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });return});

else if (!user.bannable) {interaction.reply("I can't ban this member");return}
if (reason === String) interaction.reply(`${user.tag} has been banned with the reason ${reason}`)
else if (reason !== String) interaction.reply(`${user.tag} has been banned`)
else if (!member.bannable) {
replyEmbed.setDescription("I can't ban this member")
replyEmbed.setColor("#FF0000")
return
}
if (reason === String) {
replyEmbed.setDescription(`${user.tag} has been banned with the reason ${reason}`)
replyEmbed.setColor("#00FF00")
}
else if (reason !== String) {
replyEmbed.setDescription(`${user.tag} has been banned`)
replyEmbed.setColor("#00FF00")
}
interaction.reply({embeds:[replyEmbed]})
db.create({
reason: reason,
Executor: interaction.member.user.tag,
userID: user.id
})
},
};
8 changes: 5 additions & 3 deletions commands/kick.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { SlashCommandBuilder } = require('@discordjs/builders')
const { guildId } = require('../config.json')
const { MessageEmbed } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
Expand All @@ -19,8 +20,9 @@ module.exports = {
if (!reason) reason = "No reason provided"

if (member.kickable) member.kick({ reason: reason }).then(console.log).catch(error => {console.error(error);interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });return});

if (reason === String) interaction.reply(`${user.tag} has been kicked with the reason ${reason}`)
else if (reason !== String) interaction.reply(`${user.tag} has been kicked`)
const replyEmbed = new MessageEmbed().setColor("#00FF00")
if (reason === String) replyEmbed.setDescription(`${user.tag} has been kicked with the reason ${reason}`)
else if (reason !== String) replyEmbed.setDescription(`${user.tag} has been kicked`)
interaction.reply({embeds:[replyEmbed]})
}
}
10 changes: 9 additions & 1 deletion commands/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ module.exports = {
.addSubcommand(subcommand => subcommand
.setName('warns')
.setDescription('list warns')
.addUserOption(o => o
.setName("user")
.setDescription("The user to list warnings")
.setRequired(true))
),
async execute(interaction) {
const subcommand = interaction.options.getSubcommand()
if (subcommand == "warns") {
interaction.reply("cool it works")
const user = interaction.options.getMember("user")
//interaction.deferReply()
db = interaction.client.db.Warns
list = await db.findAll(/*{where: { userID: user.id }}*/)
interaction.reply(list)
}
}
}
8 changes: 5 additions & 3 deletions commands/lock.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const { guildId } = require("../config.json")
const { MessageEmbed } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
Expand All @@ -15,7 +16,7 @@ module.exports = {
async execute(interaction) {
let channel = interaction.options.getChannel("channel");
let reason = interaction.options.getString("reason")

const replyEmbed = new MessageEmbed()
if (!reason) reason = "No reason provided"

channel.permissionOverwrites.edit(guildId, {
Expand All @@ -24,7 +25,8 @@ module.exports = {
CREATE_PUBLIC_THREADS: false,
CREATE_PRIVATE_THREADS: false,
}, {reason: reason, type: 0})

interaction.reply("Channel locked")
replyEmbed.setColor("#00FF00")
replyEmbed.setDescription("Channel locked")
interaction.reply({embeds:[replyEmbed]})
}
}
18 changes: 14 additions & 4 deletions commands/slowmode.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { SlashCommandBuilder } = require('@discordjs/builders')
const { MessageEmbed } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
Expand All @@ -25,8 +26,9 @@ module.exports = {
const unit = interaction.options.getString('unit');
const RealLen = interaction.options.getInteger('duration');
const reason = interaction.options.getString('reason');
const replyEmbed = new MessageEmbed()
let length = RealLen;

if (channel.available) {

if (unit == "seconds") length = Math.floor(length * 1000);
Expand All @@ -35,12 +37,20 @@ module.exports = {

if (channel.isText) {
channel.setRateLimitPerUser(length, reason);
interaction.reply(`Set **${RealLen} ${unit}** slowmode in ${channel} for "**${reason}**"`)
replyEmbed.setDescription(`Set **${RealLen} ${unit}** slowmode in ${channel} for "**${reason}**"`)
replyEmbed.setColor("#00FF00")
interaction.reply({embeds:[replyEmbed]})
}
else if (!channel.isText) {
replyEmbed.setDescription(`The specified channel (<#${channel.id}>) isn't a text channel, I can't set a slowmode there.`)
replyEmbed.setColor("#FF0000")
interaction.reply({ embeds: [replyEmbed], ephemeral: true })
}
else if (!channel.isText) interaction.reply({ content: `The specified channel (<#${channel.id}>) isn't a text channel, I can't set a slowmode there.`, ephemeral: true })
}
else if (!channel.available) {
interaction.reply({ content: "It seems Discord is having problems, please go to https://discordstatus.com/ to see \"when\" it will be fixed", ephemeral: true})
replyEmbed.setColor("#FF0000")
replyEmbed.setDescription("It seems Discord is having problems, please go to https://discordstatus.com/ to see \"when\" it will be fixed")
interaction.reply({ embeds: [replyEmbed] , ephemeral: true})
}
}
}
18 changes: 13 additions & 5 deletions commands/timeout.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const { Modal } = require('discord.js');
const { Modal, MessageEmbed } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
Expand Down Expand Up @@ -27,7 +27,7 @@ module.exports = {
let length = interaction.options.getInteger('duration')
const unit = interaction.options.getString('unit')
let reason = interaction.options.getString('reason')

const replyEmbed = new MessageEmbed();
if (!reason) reason = "No reason provided"

if (unit == "seconds") {
Expand All @@ -41,14 +41,22 @@ module.exports = {
}

if (length > 2.419e+9) {
await interaction.reply(`**I cannot timeout ${user.tag} for that long! You provided a time longer than 28 days!**`)
replyEmbed.setColor("#FF0000")
replyEmbed.setDescription(`**I cannot timeout ${user.tag} for that long! You provided a time longer than 28 days!**`)
await interaction.reply({embeds:[replyEmbed]})
}
else {
member.timeout(length, reason + " | Timeout by " + interaction.member.user.tag)
.then(async () => {await interaction.reply(`Timedout ${member} for **${RealLen} ${unit}** for **"${reason}".**`)})
.then(async () => {
replyEmbed.setDescription(`Timed out ${member} for **${RealLen} ${unit}** for **"${reason}".**`)
replyEmbed.setColor("#00FF00")
await interaction.reply({embeds:[replyEmbed]})
})
.catch(async error => {
console.log(error)
await interaction.reply({content: `**I cannot timeout ${member.tag}! They have staff permissions!**`, ephemeral: true})
replyEmbed.setDescription(`**I cannot timeout ${member.tag}! They have staff permissions!**`)
replyEmbed.setColor("#FF0000")
await interaction.reply({embeds: [replyEmbed], ephemeral: true})
})
}
},
Expand Down
14 changes: 11 additions & 3 deletions commands/unban.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ module.exports = {
async execute(interaction) {
let member = interaction.options.getMember("user");
let reason = interaction.options.getString("reason");

const replyEmbed = new MessageEmbed()
if (!reason) reason = "No reason provided"

await member.unban();

if (reason === String) interaction.reply(`${user.tag} has been unbanned with the reason ${reason}`);
if (reason === String) {
replyEmbed.setColor("#00FF00")
replyEmbed.setDescription(`${user.tag} has been unbanned with the reason ${reason}`)
}
else if (reason !== String) {
replyEmbed.setDescription(`${user.tag} has been unbanned`);
replyEmbed.setColor("#00FF00")
}

interaction.reply({embeds:[replyEmbed]});

else if (reason !== String) interaction.reply(`${user.tag} has been unbanned`);
},
};
7 changes: 5 additions & 2 deletions commands/unlock.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const { guildId } = require("../config.json")
const { MessageEmbed } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
Expand All @@ -24,7 +25,9 @@ module.exports = {
CREATE_PUBLIC_THREADS: true,
CREATE_PRIVATE_THREADS: true,
}, {reason: reason, type: 0})

interaction.reply("Channel unlocked")
const replyEmbed = new MessageEmbed()
.setDescription("Channel unlocked")
.setColor("#00FF00")
interaction.reply({embeds: [replyEmbed]})
}
}
24 changes: 18 additions & 6 deletions commands/warn.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const { guildId } = require("../config.json")
const { MessageEmbed } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
Expand All @@ -11,13 +12,24 @@ module.exports = {
.setRequired(true))
.addStringOption(o => o
.setName("reason")
.setDescription("Why should this user be warned?")),
.setDescription("Why should this user be warned?")
.setRequired(true))
,
async execute(interaction) {
const user = interaction.options.getUser("user")
const reason = interaction.options.getString("reason")
//interaction.reply({ content: "This command is not out yet!", ephemeral: true})
interaction.reply({ content: `Warned ${user.tag}: ${reason}`})
user.send(`You have been warned for: ${reason}`)
const user = interaction.options.getUser("user")
const reason = interaction.options.getString("reason")
const db = interaction.client.db.Warns
const replyEmbed = new MessageEmbed().setColor("#00FF00")
const dmEmbed = new MessageEmbed().setColor("#FF0000")
replyEmbed.setDescription(`Warned ${user.tag}: ${reason}`)
dmEmbed.setDescription(`You have been warned for: ${reason}`)
interaction.reply({ embeds: [replyEmbed]})
user.send({ embeds: [dmEmbed]})
db.create({
reason: reason,
Executor: interaction.member.user.tag,
userID: user.id
})
//if (!reason) reason = "No reason provided"
}
}
3 changes: 2 additions & 1 deletion config.json.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"token":"",
"clientId":"",
"guildId":""
"guildId":"",
"sqlPass":""
}
13 changes: 12 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
const fs = require('node:fs');
const path = require('node:path');
const Sequelize = require('sequelize')
const { Client, Collection } = require('discord.js');
const { token } = require('./config.json');
const { token, sqlPass } = require('./config.json');

client = new Client({intents: 0});

const sequelize = new Sequelize('database', 'user', sqlPass, {
host: 'localhost',
dialect: 'sqlite',
logging: false,
storage: 'database.sqlite',
});
client.db = require('./Util/database')

client.commands = new Collection();
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
Expand All @@ -17,6 +26,8 @@ for (const file of commandFiles) {


client.once('ready', () => {
client.db.Bans.sync()
client.db.Warns.sync()
console.log(`Login as ${client.user.tag}`);
})

Expand Down