Skip to content

Commit

Permalink
🧩 Separate from the main processing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maseshi committed Jan 15, 2022
1 parent e8ede05 commit 092f948
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
14 changes: 14 additions & 0 deletions source/handlers/monitor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { info } = require("log-symbols");
const express = require("express");
const app = express();
const port = 8080;

module.exports = (client) => {
app.get("/", (req, res) => {
res.send("Copyright (c) 2020-2022 Maseshi(Chaiwat Suwannarat). All rights reserved.")
});

app.listen(port, () => {
console.log(info + " Remote monitoring is now available at http://localhost:" + port);
});
};
73 changes: 73 additions & 0 deletions source/handlers/music.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
module.exports = (client) => {
client.music.on("playSong", (queue, song) => {
queue.textChannel.send(client.translate.main.distube.playSong.playing_song.replace("%s1", song.name).replace("%s2", song.formattedDuration));
});

client.music.on("addSong", (queue, song) => {
queue.textChannel.send(client.translate.main.distube.addSong.added_song.replace("%s1", song.name).replace("%s2", song.formattedDuration));
});

client.music.on("addList", (queue, playlist) => {
const list = playlist.map((songs, index) => "**" + index + "**. " + songs.name);

queue.textChannel.send({
"embeds": [
{
"title": playlist.name,
"description": client.translate.main.distube.addList.timer_choose.replace("%s", list),
"color": 16296490,
"timestamp": new Date(),
"footer": {
"icon_url": queue.member.user.displayAvatarURL(),
"text": queue.member.user.username
}
}
]
});
});

client.music.on("searchResult", (message, result) => {
let index = 0;
const search = result.map(song => "**" + (++index) + "**. " + song.name + " - `" + song.formattedDuration + "`").join("\n");

message.channel.send({
"embeds": [
{
"title": client.translate.main.distube.searchResult.searching.replace("%s", search),
"description": client.translate.main.distube.addList.timer_choose.replace("%s", search),
"color": 16296490,
"timestamp": new Date(),
"footer": {
"icon_url": message.author.displayAvatarURL(),
"text": message.author.username
}
}
]
});
client.music.options.searchSongs = false;
});

client.music.on("searchCancel", (message, query) => {
message.reply(client.translate.main.distube.searchCancel.search_cancelled);
client.music.options.searchSongs = false;
});

client.music.on("initQueue", (queue) => {
queue.autoplay = false;
queue.volume = 100;
queue.filter = "clear";
queue.createdTimestamp = new Date();
});

client.music.on("empty", (queue) => {
queue.textChannel.send(client.translate.main.distube.empty.no_user_in_channel);
});

client.music.on("finish", (queue) => {
queue.textChannel.send(client.translate.main.distube.finish.queue_is_empty);
});

client.music.on("error", (channel, error) => {
console.error(error);
});
};

0 comments on commit 092f948

Please sign in to comment.