Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"WELCOME": {
"NEW_MEMBER_CHANNEL_ID": "xxxxxxxxxxx"
},
"guildId": "xxxxxxxxxx"

"guildId": "xxxxxxxxxx",
"PARKING_CHANNEL_ID": "xxxxxxxx"
}
3 changes: 3 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ const startBot = async () => {
// calling them on the reactionHandler object
const reactionHandler = new ReactionHandler();
const scamDetector = new ScamDetector();
const parkingScraper = require('./src/util/ParkingScraper');

client.once('ready', () => {
messageHandler.initialize();
parkingScraper.initialize(client);
client.user.setPresence({
activity: {
name: `${prefix}help`,
Expand Down
Empty file added src/commands/parking.js
Empty file.
81 changes: 81 additions & 0 deletions src/commands/util/parking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const Command = require('../Command');
const parkingScraper = require('../../util/ParkingScraper');
const { EmbedBuilder } = require('discord.js');
const { PARKING_CHANNEL_ID } = require('../../../config.json');

module.exports = new Command({
name: 'parking',
description: 'Get SJSU parking garage status (uses cached data)',
aliases: ['park', 'garages'],
example: 'parking',
category: 'Util',
execute: async function(message, args) {
try {
const result = await parkingScraper.fetchParkingData();

if (!result.success) {
message.channel.send(`❌ Failed to fetch parking data: ${result.error}`);
return;
}

const { data, websiteTimestamp, fromCache } = result;

if (!data || data.length === 0) {
message.channel.send('❌ No parking data available');
return;
}

// Check if user wants chart format
const wantsChart = args.includes('chart') || args.includes('graph');

if (wantsChart) {
// Create text chart
const chart = parkingScraper.createChart(data, websiteTimestamp);

const embed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle('🚗 SJSU Parking Status')
.setDescription('```\n' + chart + '\n```')
.setFooter({
text: fromCache ? 'Data from cache' : 'Fresh data'
})
.setTimestamp();

message.channel.send({ embeds: [embed] });
return;
}
// down here, no need for else
// Simple format with link to auto-updating channel
const simpleText = parkingScraper.formatSimple(data);

const embed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle('🚗 SJSU Parking Status')
.setDescription(simpleText)
.addFields({
name: 'Last Updated',
value: websiteTimestamp,
inline: true
});

// Add link to auto-updating channel if it exists
if (PARKING_CHANNEL_ID) {
embed.addFields({
name: '📊 Live Updates',
value: `Check <#${PARKING_CHANNEL_ID}> for parking status`,
inline: false
});
}

embed.setFooter({
text: 'Cached data • Use "parking chart" for visual chart'
})
.setTimestamp();

message.channel.send({ embeds: [embed] });

} catch (error) {
message.channel.send(`❌ An error occurred: ${error.message}`);
}
}
});
Loading