Committing a (non-functional) add calendar command
This commit is contained in:
parent
b2b8bccaa6
commit
dce3b6ecc4
29
breadbot.js
29
breadbot.js
@ -3,22 +3,41 @@ const path = require('node:path');
|
|||||||
const { Client, Events, GatewayIntentBits, Collection } = require('discord.js');
|
const { Client, Events, GatewayIntentBits, Collection } = require('discord.js');
|
||||||
const { token } = require('./config.json');
|
const { token } = require('./config.json');
|
||||||
|
|
||||||
|
const getAllFiles = function(directoryPath, arrayOfFiles) {
|
||||||
|
const files = fs.readdirSync(directoryPath);
|
||||||
|
|
||||||
|
arrayOfFiles = arrayOfFiles || [];
|
||||||
|
|
||||||
|
files.forEach(file => {
|
||||||
|
if (fs.statSync(directoryPath + path.sep + file).isDirectory()) {
|
||||||
|
arrayOfFiles = getAllFiles(directoryPath + path.sep + file, arrayOfFiles);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
arrayOfFiles.push(path.join(__dirname, directoryPath, path.sep, file));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return arrayOfFiles;
|
||||||
|
};
|
||||||
|
|
||||||
|
const allFiles = [];
|
||||||
|
getAllFiles('.' + path.sep + 'commands', allFiles);
|
||||||
|
|
||||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||||
|
|
||||||
client.commands = new Collection();
|
client.commands = new Collection();
|
||||||
|
|
||||||
const commandsPath = path.join(__dirname, 'commands');
|
const commandFiles = allFiles.filter(file => file.endsWith('.js'));
|
||||||
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
|
||||||
|
|
||||||
for (const file of commandFiles) {
|
for (const file of commandFiles) {
|
||||||
const filePath = path.join(commandsPath, file);
|
const command = require(file);
|
||||||
const command = require(filePath);
|
|
||||||
|
|
||||||
if ('data' in command && 'execute' in command) {
|
if ('data' in command && 'execute' in command) {
|
||||||
client.commands.set(command.data.name, command);
|
client.commands.set(command.data.name, command);
|
||||||
|
console.log(`[INFO] Loaded command at ${file}`);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
|
console.log(`[WARNING] The command at ${file} is missing a required "data" or "execute" property.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
45
commands/googlecalendar/addcalendar.js
Normal file
45
commands/googlecalendar/addcalendar.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
|
const { google } = require('googleapis');
|
||||||
|
const { googlePrivateKey, googleClientEmail, googleProjectNumber } = require('../../config.json');
|
||||||
|
const SCOPES = ['https://www.googleapis.com/auth/calendar'];
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('addcalendar')
|
||||||
|
.setDescription('Creates a new Google Calendar')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('name')
|
||||||
|
.setDescription('The new name for the calendar')
|
||||||
|
.setRequired(true))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('description')
|
||||||
|
.setDescription('The description of this new calendar')),
|
||||||
|
async execute(interaction) {
|
||||||
|
await interaction.deferReply({ ephemeral: true });
|
||||||
|
|
||||||
|
const name = interaction.options.getString('name');
|
||||||
|
const description = interaction.options.getString('description');
|
||||||
|
|
||||||
|
const jwtClient = new google.auth.JWT(
|
||||||
|
googleClientEmail,
|
||||||
|
null,
|
||||||
|
googlePrivateKey,
|
||||||
|
SCOPES,
|
||||||
|
);
|
||||||
|
|
||||||
|
const calendar = new google.calendar({
|
||||||
|
version: 'v3',
|
||||||
|
project: googleProjectNumber,
|
||||||
|
auth: jwtClient,
|
||||||
|
});
|
||||||
|
|
||||||
|
calendar.calendarList.insert({
|
||||||
|
'summary': name,
|
||||||
|
'description': description,
|
||||||
|
});
|
||||||
|
|
||||||
|
await interaction.editReply('New Calendar ' + name + ' Created');
|
||||||
|
},
|
||||||
|
};
|
@ -1,14 +1,37 @@
|
|||||||
const { REST, Routes } = require('discord.js');
|
const { REST, Routes } = require('discord.js');
|
||||||
const { clientId, guildId, token } = require('./config.json');
|
const { clientId, guildId, token } = require('./config.json');
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
|
const path = require('node:path');
|
||||||
|
|
||||||
|
const getAllFiles = function(directoryPath, arrayOfFiles) {
|
||||||
|
const files = fs.readdirSync(directoryPath);
|
||||||
|
|
||||||
|
arrayOfFiles = arrayOfFiles || [];
|
||||||
|
|
||||||
|
files.forEach(file => {
|
||||||
|
if (fs.statSync(directoryPath + path.sep + file).isDirectory()) {
|
||||||
|
arrayOfFiles = getAllFiles(directoryPath + path.sep + file, arrayOfFiles);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
arrayOfFiles.push(path.join(__dirname, directoryPath, path.sep, file));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return arrayOfFiles;
|
||||||
|
};
|
||||||
|
|
||||||
const commands = [];
|
const commands = [];
|
||||||
|
const allFiles = [];
|
||||||
|
getAllFiles('.' + path.sep + 'commands', allFiles);
|
||||||
|
allFiles.forEach(file => {
|
||||||
|
console.log(file);
|
||||||
|
});
|
||||||
// Grab all the command files from the commands directory you created earlier
|
// Grab all the command files from the commands directory you created earlier
|
||||||
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
|
const commandFiles = allFiles.filter(file => file.endsWith('.js'));
|
||||||
|
|
||||||
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
|
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
|
||||||
for (const file of commandFiles) {
|
for (const file of commandFiles) {
|
||||||
const command = require(`./commands/${file}`);
|
const command = require(`${file}`);
|
||||||
commands.push(command.data.toJSON());
|
commands.push(command.data.toJSON());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user