diff --git a/.gitignore b/.gitignore index ffaf5f2..68c2752 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .env config.json -node_modules \ No newline at end of file +node_modules +keyfile.json \ No newline at end of file diff --git a/calendarpulltest.js b/calendarpulltest.js index 164dd5d..9d0b3c4 100644 --- a/calendarpulltest.js +++ b/calendarpulltest.js @@ -17,8 +17,14 @@ async function main() { auth: jwtClient, }); - const response = calendar.calendarList.list({}); - console.log('Output: ' + response.data); + calendar.calendarList.list({}, (err, res) => { + if (err) { + console.log('[ERROR]'); + console.log(err.errors); + return; + } + console.log(res.data.items.map(x => x.summary)); + }); } main().catch(e => { diff --git a/commands/googlecalendar/addcalendar.js b/commands/googlecalendar/addcalendar.js index f2baad9..a39ec3f 100644 --- a/commands/googlecalendar/addcalendar.js +++ b/commands/googlecalendar/addcalendar.js @@ -1,6 +1,7 @@ const { SlashCommandBuilder } = 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 = { @@ -20,11 +21,10 @@ module.exports = { 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, + './keyfile.json', googlePrivateKey, SCOPES, ); @@ -35,11 +35,21 @@ module.exports = { auth: jwtClient, }); - calendar.calendarList.insert({ - 'summary': name, - 'description': description, - }); - - await interaction.editReply('New Calendar ' + name + ' Created'); + calendar.calendars.insert({ + resource: { + summary: name, + }, + }, + // 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'); + stdout.write('[ERROR]: '); + console.log(err.errors); + return; + } + await interaction.editReply('New Calendar ' + name + ' Created'); + }, + ); }, }; \ No newline at end of file diff --git a/commands/googlecalendar/addevent.js b/commands/googlecalendar/addevent.js new file mode 100644 index 0000000..e69de29 diff --git a/commands/googlecalendar/deletecalendar.js b/commands/googlecalendar/deletecalendar.js new file mode 100644 index 0000000..e69de29 diff --git a/commands/googlecalendar/deleteevent.js b/commands/googlecalendar/deleteevent.js new file mode 100644 index 0000000..e69de29 diff --git a/commands/googlecalendar/listcalendar.js b/commands/googlecalendar/listcalendar.js new file mode 100644 index 0000000..e69de29 diff --git a/commands/googlecalendar/listevents.js b/commands/googlecalendar/listevents.js new file mode 100644 index 0000000..e69de29 diff --git a/commands/googlecalendar/modifyevent.js b/commands/googlecalendar/modifyevent.js new file mode 100644 index 0000000..e69de29