Some mild changes, added list calendar
This commit is contained in:
parent
30a2114ff4
commit
7ebdb84c98
@ -43,7 +43,7 @@ module.exports = {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
async (err, res) => {
|
||||
if (err) {
|
||||
await interaction.editReply('Failed to create calendar ' + name + '\nAsk an Admin to check Breadbot console');
|
||||
await interaction.editReply('Failed to create calendar ' + name + '\nAsk Bradley to check Breadbot console');
|
||||
stdout.write('[ERROR]: ');
|
||||
console.log(err.errors);
|
||||
return;
|
||||
|
@ -0,0 +1,48 @@
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { google } = require('googleapis');
|
||||
const { googlePrivateKey, googleClientEmail, googleProjectNumber } = require('../../config.json');
|
||||
const { stdout } = require('node:process');
|
||||
const SCOPES = ['https://www.googleapis.com/auth/calendar'];
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('listcalendars')
|
||||
.setDescription('Lists the currently available calendars'),
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
|
||||
const jwtClient = new google.auth.JWT(
|
||||
googleClientEmail,
|
||||
'./keyfile.json',
|
||||
googlePrivateKey,
|
||||
SCOPES,
|
||||
);
|
||||
|
||||
const calendar = new google.calendar({
|
||||
version: 'v3',
|
||||
project: googleProjectNumber,
|
||||
auth: jwtClient,
|
||||
});
|
||||
|
||||
calendar.calendarList.list({}, async (err, res) => {
|
||||
if (err) {
|
||||
const errorEmbed = new EmbedBuilder()
|
||||
.setColor(0xFF0000)
|
||||
.setTitle('Failed to get a list of calendars')
|
||||
.setDescription('Ask Bradley to check Breadbot console');
|
||||
|
||||
await interaction.editReply({ embeds: errorEmbed });
|
||||
stdout.write('[ERROR]: ');
|
||||
console.log(err.errors);
|
||||
return;
|
||||
}
|
||||
|
||||
const successEmbed = new EmbedBuilder()
|
||||
.setColor(0x00FF00)
|
||||
.setTitle('Calendar List')
|
||||
.setDescription(res.data.items.map((x) => x.summary).join('\n'));
|
||||
|
||||
await interaction.editReply({ embeds: [ successEmbed ] });
|
||||
});
|
||||
},
|
||||
};
|
@ -32,7 +32,12 @@ const commandFiles = allFiles.filter(file => file.endsWith('.js'));
|
||||
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
|
||||
for (const file of commandFiles) {
|
||||
const command = require(`${file}`);
|
||||
commands.push(command.data.toJSON());
|
||||
if ('data' in command && 'execute' in command) {
|
||||
commands.push(command.data.toJSON());
|
||||
}
|
||||
else {
|
||||
console.log(`Skipping ${file} as it is missing one or more required exported fields`);
|
||||
}
|
||||
}
|
||||
|
||||
// Construct and prepare an instance of the REST module
|
||||
|
Loading…
Reference in New Issue
Block a user