Skip to content

Commit

Permalink
intial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
EhsanFox committed Jul 27, 2021
0 parents commit 8a28568
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 0 deletions.
109 changes: 109 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
dist/
node_modules/
jspm_packages/
package-lock.json

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Executable Files
*.exe
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
worker: node index.js
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Setar-Radio
Setar-Radio Bot, Connects to Setar-Radio Station(private at the moment)

# How does it works?
it just uses ffmpeg and discord.js
and for the music data, it uses websocket

15 changes: 15 additions & 0 deletions helpers/Player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = (con) => {

const Dispatcher = con.play("https://fzbotcs.herokuapp.com/");

Dispatcher.on("finish", () => {
Dispatcher.destroy();
module.exports(con);
});

Dispatcher.on("error", (e) => {
Dispatcher.destroy();
module.exports(con);
});

};
28 changes: 28 additions & 0 deletions helpers/RadioStation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const WebSocket = require("ws");
const { EventEmitter } = require("events");

module.exports = class RadioStation extends EventEmitter {
#Radio;
#ws;
#reconnect = true;
constructor(url, reconnect)
{
super();
if(url)
this.#Radio = `wss://${url}`;
if(reconnect)
this.#reconnect = reconnect;
}

connect() {
this.#ws = new WebSocket(this.#Radio);
this.#ws.on("open", () => this.emit("ready"));
this.#ws.on("message", (msg) => this.emit("music", msg));
this.#ws.on("close", () => {
if(this.#reconnect)
this.connect();
});
}


}
34 changes: 34 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { Client, MessageEmbed } = require("discord.js");
const Player = require("./helpers/Player");
const RadioStation = require("./helpers/RadioStation");
const Radio = new RadioStation(process.env.RADIO_URL, true);

const client = new Client();

client.on("ready", () => {
console.log(`✔ ${client.user.username} now Online.`);
Radio.connect();

const guild = client.guilds.resolve("721126627165077545");
client.SetarGuild = guild;

const VoiceChannel = client.SetarGuild.channels.resolve("869515688941854770");

VoiceChannel.join().then( (connection) => {
connection.voice.setSelfDeaf(true);
Player(connection);
})
});

Radio.once("ready", () => console.log(`✔ Radio Connected.`))
Radio.on("music", (name) => {
const TextChannel = client.SetarGuild.channels.resolve("869515632796893194");
client.user.setActivity({
name,
type: "LISTENING"
});
TextChannel.bulkDelete(10, true);
TextChannel.send(new MessageEmbed().setTitle(`Now Playing ${name}`).setDescription("Playing From **Setar-Radio**"));
});

client.login(process.env.TOKEN);
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "Setar-Radio",
"version": "1.0.0",
"description": "Setar-Radio Station | Server Part",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/SeTar-Bot/Setar-Radio.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/SeTar-Bot/Setar-Radio/issues"
},
"homepage": "https://github.com/SeTar-Bot/Setar-Radio#readme",
"dependencies": {
"discord.js": "^12.5.3",
"@discordjs/opus": "^0.3.2",
"fluent-ffmpeg": "^2.1.2",
"events": "^3.3.0",
"ws": "^7.5.3"
}
}

0 comments on commit 8a28568

Please sign in to comment.