Added database
This commit is contained in:
parent
b68cb0b219
commit
cf968f198a
@ -17,7 +17,7 @@
|
||||
"curly": ["error", "multi-line", "consistent"],
|
||||
"dot-location": ["error", "property"],
|
||||
"handle-callback-err": "off",
|
||||
"indent": ["error", "tab"],
|
||||
"indent": ["error", 2],
|
||||
"keyword-spacing": "error",
|
||||
"max-nested-callbacks": ["error", { "max": 4 }],
|
||||
"max-statements-per-line": ["error", { "max": 2 }],
|
||||
|
23
discordbot/commands/clear.js
Normal file
23
discordbot/commands/clear.js
Normal file
@ -0,0 +1,23 @@
|
||||
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
|
||||
const { simpleEmbed } = require('../functions/embeds.js');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('clear')
|
||||
.setDescription('Clear 1-100 messages')
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
|
||||
.addNumberOption(option => option
|
||||
.setName('amount')
|
||||
.setDescription('The amount of messages to clear')
|
||||
.setRequired(true)),
|
||||
|
||||
async execute(interaction) {
|
||||
const amount = interaction.options.getNumber('amount');
|
||||
|
||||
if (amount < 1 || amount > 100) return await interaction.reply({ embeds: [simpleEmbed('The amount must be between 1-100')] });
|
||||
|
||||
interaction.channel.bulkDelete(amount, true);
|
||||
|
||||
await interaction.reply({ embeds: [simpleEmbed(`Cleared **${amount}** messages`)], ephemeral: true });
|
||||
},
|
||||
};
|
BIN
discordbot/database.sqlite
Normal file
BIN
discordbot/database.sqlite
Normal file
Binary file not shown.
25
discordbot/events/guildMemberAdd.js
Normal file
25
discordbot/events/guildMemberAdd.js
Normal file
@ -0,0 +1,25 @@
|
||||
const { Events, EmbedBuilder } = require('discord.js');
|
||||
const { client } = require('../index.js');
|
||||
const { Users } = require('../functions/models');
|
||||
|
||||
module.exports = {
|
||||
name: Events.GuildMemberAdd,
|
||||
async execute(member) {
|
||||
const addMemberEmbed = new EmbedBuilder()
|
||||
.setTitle(`${member.user.globalName} has joined!`)
|
||||
.setDescription(`Welcome ${member} to the **Polarcraft** Discord server!`)
|
||||
.setColor(process.env.EMBED_COLOR)
|
||||
.setThumbnail(member.user.avatarURL());
|
||||
|
||||
const channel = client.channels.cache.get(process.env.LOG_CHANNEL_ID);
|
||||
channel.send({ embeds: [addMemberEmbed] });
|
||||
|
||||
try {
|
||||
await Users.create({
|
||||
id: member.user.id,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
};
|
14
discordbot/events/guildMemberRemove.js
Normal file
14
discordbot/events/guildMemberRemove.js
Normal file
@ -0,0 +1,14 @@
|
||||
const { Events, EmbedBuilder } = require('discord.js');
|
||||
const { client } = require('../index.js');
|
||||
|
||||
module.exports = {
|
||||
name: Events.GuildMemberRemove,
|
||||
async execute(member) {
|
||||
const removeMemberEmbed = new EmbedBuilder()
|
||||
.setTitle(`${member.user.globalName} has left!`)
|
||||
.setColor(process.env.EMBED_COLOR);
|
||||
|
||||
const channel = client.channels.cache.get(process.env.LOG_CHANNEL_ID);
|
||||
channel.send({ embeds: [removeMemberEmbed] });
|
||||
},
|
||||
};
|
@ -1,10 +1,15 @@
|
||||
const { Events } = require('discord.js');
|
||||
const deployCommands = require('../functions/deployCommands');
|
||||
const { Users, Teams, Minecraft } = require('../functions/models');
|
||||
|
||||
module.exports = {
|
||||
name: Events.ClientReady,
|
||||
once: true,
|
||||
execute(client) {
|
||||
Users.sync();
|
||||
Teams.sync();
|
||||
Minecraft.sync();
|
||||
|
||||
console.log(`Ready! Logged in as ${client.user.tag}`);
|
||||
|
||||
deployCommands();
|
||||
|
56
discordbot/functions/models.js
Normal file
56
discordbot/functions/models.js
Normal file
@ -0,0 +1,56 @@
|
||||
const { sequelize } = require('../index');
|
||||
const Sequelize = require('sequelize');
|
||||
|
||||
const Users = sequelize.define('users', {
|
||||
id: {
|
||||
type: Sequelize.STRING,
|
||||
primaryKey: true,
|
||||
unique: true,
|
||||
},
|
||||
teamId: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
moderator: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false,
|
||||
},
|
||||
admin: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false,
|
||||
},
|
||||
});
|
||||
|
||||
const Teams = sequelize.define('teams', {
|
||||
name: {
|
||||
type: Sequelize.STRING,
|
||||
unique: true,
|
||||
validate: {
|
||||
len: [3, 16],
|
||||
isAlphanumeric: true,
|
||||
},
|
||||
},
|
||||
color: {
|
||||
type: Sequelize.STRING,
|
||||
validate: {
|
||||
is: /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const Minecraft = sequelize.define('minecraft', {
|
||||
uuid: {
|
||||
type: Sequelize.UUID,
|
||||
unique: true,
|
||||
primaryKey: true,
|
||||
},
|
||||
whitelisted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false,
|
||||
},
|
||||
code: {
|
||||
type: Sequelize.STRING,
|
||||
unique: true,
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = { Users, Teams, Minecraft };
|
@ -1,12 +1,22 @@
|
||||
const { Client, GatewayIntentBits, Collection } = require('discord.js');
|
||||
const Sequelize = require('sequelize');
|
||||
const dotenv = require('dotenv');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const sequelize = new Sequelize('polarcraft', 'user', process.env.DATABSE_PASSWORD, {
|
||||
host: 'localhost',
|
||||
dialect: 'sqlite',
|
||||
logging: false,
|
||||
// SQLite only
|
||||
storage: 'database.sqlite',
|
||||
});
|
||||
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
exports.sequelize = sequelize;
|
||||
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
|
||||
exports.client = client;
|
||||
|
||||
client.commands = new Collection();
|
||||
@ -39,3 +49,4 @@ for (const file of eventFiles) {
|
||||
}
|
||||
|
||||
client.login(process.env.DISCORD_TOKEN);
|
||||
|
||||
|
1126
discordbot/package-lock.json
generated
1126
discordbot/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -10,7 +10,9 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"discord.js": "^14.12.1",
|
||||
"dotenv": "^16.3.1"
|
||||
"dotenv": "^16.3.1",
|
||||
"sequelize": "^6.32.1",
|
||||
"sqlite3": "^5.1.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^8.46.0"
|
||||
|
Loading…
x
Reference in New Issue
Block a user