Skip to content

Commit

Permalink
resolved implement partials
Browse files Browse the repository at this point in the history
  • Loading branch information
Fire-Swan committed Mar 7, 2025
1 parent 938c916 commit 0ac0056
Show file tree
Hide file tree
Showing 4 changed files with 1,295 additions and 692 deletions.
26 changes: 13 additions & 13 deletions commands/request.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-undef */
const {SlashCommandBuilder} = require('@discordjs/builders');
const {ActionRowBuilder, StringSelectMenuBuilder, ButtonBuilder, Collection} = require('discord.js');
const {ButtonStyle} = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');
const { ActionRowBuilder, StringSelectMenuBuilder, ButtonBuilder, Collection } = require('discord.js');
const { ButtonStyle } = require('discord.js');
const fetch = require('node-fetch');
const Discord = require('discord.js');
const ombiIP = process.env.ombiip;
Expand Down Expand Up @@ -97,7 +97,7 @@ module.exports = {
} else {
try {
console.log('No results found for "' + searchTerm + '"');
interaction.reply({content: 'No results available for: "' + searchTerm + '". Please try searching again.', ephemeral: true});
interaction.reply({ content: 'No results available for: "' + searchTerm + '". Please try searching again.', ephemeral: true });
} catch (err) {
console.log(err);
}
Expand Down Expand Up @@ -157,7 +157,7 @@ module.exports = {
object.available = info.available;
object.requested = info.requested;

const {member} = interaction;
const { member } = interaction;

function showBuilder() {
try {
Expand All @@ -174,11 +174,11 @@ module.exports = {
});

if (object.available) {
embed.addFields([{name: '__Available__', value: '✅', inline: true}]);
embed.addFields([{ name: '__Available__', value: '✅', inline: true }]);
}

if (object.requested) {
embed.addFields([{name: '__Requested__', value: '✅', inline: true}]);
embed.addFields([{ name: '__Requested__', value: '✅', inline: true }]);
}

return embed;
Expand All @@ -195,7 +195,7 @@ module.exports = {
const timer = setTimeout(() => {
try {
console.log('Search for ' + info.title + ' timed out');
interaction.followUp({content: 'Your request for ' + info.title + ' timed out', ephemeral: true});
interaction.followUp({ content: 'Your request for ' + info.title + ' timed out', ephemeral: true });
interaction.deleteReply();
} catch (err) {
console.log(err);
Expand Down Expand Up @@ -229,20 +229,20 @@ module.exports = {
try {
if (interaction.message === undefined) {
if (object.requested || object.available) {
interaction.reply({embeds: [embedMessage], components: [selectMenu, new ActionRowBuilder().addComponents(availableButton)]}).then(() => {
interaction.reply({ embeds: [embedMessage], components: [selectMenu, new ActionRowBuilder().addComponents(availableButton)] }).then(() => {
timeOut(interaction, messageId);
});
} else {
interaction.reply({embeds: [embedMessage], components: [selectMenu, row]}).then(() => {
interaction.reply({ embeds: [embedMessage], components: [selectMenu, row] }).then(() => {
timeOut(interaction, messageId);
});
}
} else if (object.requested || object.available) {
interaction.update({embeds: [embedMessage], components: [selectMenu, new ActionRowBuilder().addComponents(availableButton)]}).then(() => {
interaction.update({ embeds: [embedMessage], components: [selectMenu, new ActionRowBuilder().addComponents(availableButton)] }).then(() => {
timeOut(interaction, messageId);
});
} else {
interaction.update({embeds: [embedMessage], components: [selectMenu, row]}).then(() => {
interaction.update({ embeds: [embedMessage], components: [selectMenu, row] }).then(() => {
timeOut(interaction, messageId);
});
}
Expand All @@ -265,7 +265,7 @@ module.exports = {
components: [processing],
});
clearTimeout(timerManager.get(messageId));
const {member} = interaction;
const { member } = interaction;
console.log(member.user.username + ' sent a request to Ombi');
if (mediaType === 'movie') {
try {
Expand Down
81 changes: 44 additions & 37 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
console.log('Initializing shrekbot');
const fs = require('node:fs');
const path = require('node:path');
const {Client, Collection, GatewayIntentBits} = require('discord.js');
const { Client, Collection, GatewayIntentBits } = require('discord.js');
const request = require('./commands/request.js');
const {token} = process.env;
const { token } = process.env;
const channelFeed = process.env.channelfeed;
const client = new Client({intents: [GatewayIntentBits.Guilds]});
const client = new Client({
intents: [GatewayIntentBits.Guilds],
partials: ['CHANNEL']
});
require('child_process').fork('deploy-commands.js');
client.commands = new Collection();
const commandsPath = path.join(__dirname, 'commands');
Expand Down Expand Up @@ -46,7 +49,7 @@ client.on('interactionCreate', async interaction => {
await command.execute(interaction, generateId());
} catch (error) {
console.error(error);
await interaction.reply({content: 'There was an error while executing this command!', ephemeral: true});
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
} else if (interaction.isStringSelectMenu()) {
if (interaction.customId === 'media_selector') {
Expand Down Expand Up @@ -77,39 +80,43 @@ const app = express();

app.use(express.json());

app.post('/webhook', (req, res) => {
console.log('Received webhook:', req.body);
const payload = req.body;

try {
// Extract relevant data from the payload
const { requestedByAlias, title, userName, requestStatus } = payload;

if (requestStatus === 'Available') {
let userId = '';
if (requestedByAlias) {
if (requestedByAlias.includes(',')) {
userId = '<@' + requestedByAlias.split(',')[1] + '>';
} else {
userId = requestedByAlias;
}
} else {
userId = userName;
}

// Compose the Discord webhook message
const discordMessage = `${userId}, ${title} is now available!`;
client.channels.cache.get(channelFeed).send(discordMessage);

res.sendStatus(200);
} else {
console.log(`Request status is not 'Available', it is: '${requestStatus}'`);
res.sendStatus(200); // You might want to send a different status if the request is not processed
}
} catch (error) {
console.error('Error processing webhook:', error);
res.status(500).send('Internal Server Error');
}
app.post('/webhook', async (req, res) => {
console.log('Received webhook:', req.body);
const payload = req.body;

try {
// Extract relevant data from the payload
const { requestedByAlias, title, userName, requestStatus } = payload;

if (requestStatus === 'Available') {
let userId = '';
if (requestedByAlias) {
if (requestedByAlias.includes(',')) {
userId = '<@' + requestedByAlias.split(',')[1] + '>';
} else {
userId = requestedByAlias;
}
} else {
userId = userName;
}

// Compose the Discord webhook message
const discordMessage = `${userId}, ${title} is now available!`;
const channel = client.channels.cache.get(channelFeed);
if (channel.partial) {
await channel.fetch();
}
channel.send(discordMessage);

res.sendStatus(200);
} else {
console.log(`Request status is not 'Available', it is: '${requestStatus}'`);
res.sendStatus(200); // You might want to send a different status if the request is not processed
}
} catch (error) {
console.error('Error processing webhook:', error);
res.status(500).send('Internal Server Error');
}
});

app.listen(8154, () => {
Expand Down
Loading

0 comments on commit 0ac0056

Please # to comment.