mirror of
				https://github.com/warengroup/eximiabots-radiox.git
				synced 2025-10-31 11:01:36 +00:00 
			
		
		
		
	removed stations memory leak
This commit is contained in:
		| @@ -2,6 +2,7 @@ const { Client, Collection } = require('discord.js'); | |||||||
| const Discord = require('discord.js'); | const Discord = require('discord.js'); | ||||||
| const fs = require('fs'); | const fs = require('fs'); | ||||||
| const path = require('path'); | const path = require('path'); | ||||||
|  | const fetch = require('node-fetch'); | ||||||
| const events = '../events/'; | const events = '../events/'; | ||||||
|  |  | ||||||
| module.exports = class extends Client { | module.exports = class extends Client { | ||||||
| @@ -29,6 +30,9 @@ module.exports = class extends Client { | |||||||
|             this.commandAliases.set(command.alias, command); |             this.commandAliases.set(command.alias, command); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         client.stations = fetch('https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json') | ||||||
|  |             .then(res => res.json()); | ||||||
|  |  | ||||||
|         this.on('ready', () => { |         this.on('ready', () => { | ||||||
|             require(`${events}ready`).execute(this, Discord); |             require(`${events}ready`).execute(this, Discord); | ||||||
|         }); |         }); | ||||||
|   | |||||||
| @@ -1,22 +1,21 @@ | |||||||
| module.exports = async function (guild, client, station) { | module.exports = async function (guild, client, station) { | ||||||
|  |  | ||||||
|     const radio = client.radio.get(guild.id); |     const radio = client.radio.get(guild.id); | ||||||
|     const stations = await client.funcs.radiostations(); |  | ||||||
|     let url = ""; |     let url = ""; | ||||||
|      |  | ||||||
|     if(isNaN(station)){ |     if (isNaN(station)) { | ||||||
|         radio.voiceChannel.leave(); |         radio.voiceChannel.leave(); | ||||||
|         return radio.textChannel.send('<:redx:674263474704220182> An error has occured while playing radio!'); |         return radio.textChannel.send('<:redx:674263474704220182> An error has occured while playing radio!'); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if(station-1 > stations.length-1){ |     if (station - 1 > client.stations.length - 1) { | ||||||
|         radio.voiceChannel.leave(); |         radio.voiceChannel.leave(); | ||||||
|         return radio.textChannel.send('<:redx:674263474704220182> An error has occured while playing radio!'); |         return radio.textChannel.send('<:redx:674263474704220182> An error has occured while playing radio!'); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     url = stations[station-1].stream[stations[station-1].stream.default]; |     url = client.stations[station - 1].stream[client.stations[station - 1].stream.default]; | ||||||
|      |  | ||||||
|     if(!url) { |     if (!url) { | ||||||
|         radio.voiceChannel.leave(); |         radio.voiceChannel.leave(); | ||||||
|         return radio.textChannel.send('<:redx:674263474704220182> An error has occured while playing radio!'); |         return radio.textChannel.send('<:redx:674263474704220182> An error has occured while playing radio!'); | ||||||
|     } |     } | ||||||
| @@ -32,16 +31,16 @@ module.exports = async function (guild, client, station) { | |||||||
|     dispatcher.on('start', () => { |     dispatcher.on('start', () => { | ||||||
|         dispatcher.player.streamingData.pausedTime = 0; |         dispatcher.player.streamingData.pausedTime = 0; | ||||||
|     }); |     }); | ||||||
|          |  | ||||||
|     dispatcher.on('error', error => { |     dispatcher.on('error', error => { | ||||||
|         console.error(error); |         console.error(error); | ||||||
|         radio.voiceChannel.leave(); |         radio.voiceChannel.leave(); | ||||||
|         client.radio.delete(guild.id); |         client.radio.delete(guild.id); | ||||||
|         return radio.textChannel.send('<:redx:674263474704220182> An error has occured while playing radio!'); |         return radio.textChannel.send('<:redx:674263474704220182> An error has occured while playing radio!'); | ||||||
|     }); |     }); | ||||||
|          |  | ||||||
|     dispatcher.setVolume(radio.volume / 10); |     dispatcher.setVolume(radio.volume / 10); | ||||||
|      |  | ||||||
|     radio.textChannel.send('Start playing'); |     radio.textChannel.send('Start playing'); | ||||||
|     radio.playing = true; |     radio.playing = true; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,9 +0,0 @@ | |||||||
| module.exports = async function () { |  | ||||||
|  |  | ||||||
|     const fetch = require('node-fetch'); |  | ||||||
|  |  | ||||||
|     let data = fetch('https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json') |  | ||||||
|                 .then(res => res.json()); |  | ||||||
|  |  | ||||||
|     return data; |  | ||||||
| } |  | ||||||
		Reference in New Issue
	
	Block a user
	 MatteZ02
					MatteZ02