renamed channel.channel to channel.name for better readability

This commit is contained in:
DeSqBlocki
2024-12-21 19:27:58 +01:00
parent 1040a08712
commit d50364275d
+9 -11
View File
@@ -10,7 +10,7 @@ async function SubscribeChannel(interaction) {
const channelName = encodeURI(await interaction.options.getString('channel')).toLowerCase() const channelName = encodeURI(await interaction.options.getString('channel')).toLowerCase()
const userID = interaction.user.id const userID = interaction.user.id
try { try {
let streamData = await tClient.getStreams({ channel: channelName }) let streamData = await tClient.getStreams({ name: channelName })
//console.log(await tClient.searchChannels({query: `${channelName}`})) // returns too many results and not exact match first //console.log(await tClient.searchChannels({query: `${channelName}`})) // returns too many results and not exact match first
} catch (error) { } catch (error) {
return interaction.reply({ return interaction.reply({
@@ -24,7 +24,7 @@ async function SubscribeChannel(interaction) {
const db = mClient.db('notifyme') const db = mClient.db('notifyme')
const channelsColl = db.collection('channels') const channelsColl = db.collection('channels')
const find = await channelsColl.find({ channel: channelName }).toArray() const find = await channelsColl.find({ name: channelName }).toArray()
if (find[0]) { if (find[0]) {
if (find[0].subscribers.includes(userID)) { if (find[0].subscribers.includes(userID)) {
@@ -39,10 +39,10 @@ async function SubscribeChannel(interaction) {
try { try {
const res = await channelsColl.findOneAndUpdate({ const res = await channelsColl.findOneAndUpdate({
channel: channelName name: channelName
}, { }, {
$set: { $set: {
channel: channelName, name: channelName,
}, },
$push: { $push: {
subscribers: userID subscribers: userID
@@ -75,7 +75,7 @@ async function UnsubscribeChannel(interaction) {
const db = mClient.db('notifyme') const db = mClient.db('notifyme')
const channelsColl = db.collection('channels') const channelsColl = db.collection('channels')
const find = await channelsColl.find({ channel: channelName }).toArray() const find = await channelsColl.find({ name: channelName }).toArray()
if (find[0]) { if (find[0]) {
if (!find[0].subscribers.includes(userID)) { if (!find[0].subscribers.includes(userID)) {
@@ -90,10 +90,10 @@ async function UnsubscribeChannel(interaction) {
try { try {
const res = await channelsColl.findOneAndUpdate({ const res = await channelsColl.findOneAndUpdate({
channel: channelName name: channelName
}, { }, {
$set: { $set: {
channel: channelName, name: channelName,
}, },
$pull: { $pull: {
subscribers: userID subscribers: userID
@@ -104,7 +104,7 @@ async function UnsubscribeChannel(interaction) {
}) })
if(!res.subscribers[0]){ if(!res.subscribers[0]){
const newRes = await channelsColl.findOneAndDelete({ const newRes = await channelsColl.findOneAndDelete({
channel: channelName name: channelName
}) })
} }
} catch (error) { } catch (error) {
@@ -143,7 +143,7 @@ async function ListChannel(interaction) {
} }
var channelList = [] var channelList = []
find.forEach((document) => { find.forEach((document) => {
channelList.push(escapeMarkdown(document.channel)) channelList.push(escapeMarkdown(document.name))
}) })
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setTitle('List of Subscribed Channels:') .setTitle('List of Subscribed Channels:')
@@ -200,8 +200,6 @@ async function InfoChannel(interaction) {
ephemeral: true ephemeral: true
}) })
} }
//streamData = streamData.
//console.log(await tClient.searchChannels({query: `${channelName}`})) // returns too many results and not exact match first
} catch (error) { } catch (error) {
console.error(error) console.error(error)
return interaction.reply({ return interaction.reply({