Refactor: convert to const exports

This commit is contained in:
Manuel 2022-08-07 18:26:55 +02:00
parent 6c34025dae
commit d645509aaa
3 changed files with 32 additions and 29 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
node_modules node_modules
package-lock.json package-lock.json
config.json config.json
.prettierrc

View File

@ -3,7 +3,7 @@ const CONFIG = require("../config.json");
const { secondsToHms, ticksToSeconds } = require("./util"); const { secondsToHms, ticksToSeconds } = require("./util");
const log = require("loglevel"); const log = require("loglevel");
function getProgressString(percent) { const getProgressString = (percent) => {
// the min with of the discord window allows for this many chars // the min with of the discord window allows for this many chars
const NUMBER_OF_CHARS = 12; const NUMBER_OF_CHARS = 12;
let string = ""; let string = "";
@ -15,20 +15,21 @@ function getProgressString(percent) {
} }
} }
return string; return string;
} };
/** /**
* *
* @param {String} string * @param {String} string
* @returns {String} * @returns {String}
*/ */
// TODO do this with something like wcwidth // TODO do this with something like wcwidth
function getMaxWidthString(string) { function getMaxWidthString = (string) => {
const NUMBER_OF_CHARS = 12; const NUMBER_OF_CHARS = 12;
if (string.length > NUMBER_OF_CHARS) { if (string.length > NUMBER_OF_CHARS) {
return string.slice(0, NUMBER_OF_CHARS - 3) + "..."; return string.slice(0, NUMBER_OF_CHARS - 3) + "...";
} }
return string; return string;
} };
class InterActivePlayMessage { class InterActivePlayMessage {
// musicplayermessage // musicplayermessage

View File

@ -3,11 +3,11 @@ const CONFIG = require("../config.json");
const log = require("loglevel"); const log = require("loglevel");
var iapm; var interactivePlayMessage;
var updateInterval; var updateInterval;
function init( const init = (
message, message,
title, title,
artist, artist,
@ -20,11 +20,11 @@ function init(
onNext, onNext,
onRepeat, onRepeat,
playlistLenth playlistLenth
) { ) => {
if (typeof iapm !== "undefined") { if (typeof interactivePlayMessage !== "undefined") {
destroy(); destroy();
} }
iapm = new InterActivePlayMessage( interactivePlayMessage = new InterActivePlayMessage(
message, message,
title, title,
artist, artist,
@ -38,12 +38,12 @@ function init(
onRepeat, onRepeat,
playlistLenth playlistLenth
); );
} };
function destroy() { const destroy = () => {
if (typeof iapm !== "undefined") { if (typeof interactivePlayMessage !== "undefined") {
iapm.destroy(); interactivePlayMessage.destroy();
iapm = undefined; interactivePlayMessage = undefined;
} else { } else {
throw Error("No Interactive Message Found"); throw Error("No Interactive Message Found");
} }
@ -52,31 +52,32 @@ function destroy() {
clearInterval(updateInterval); clearInterval(updateInterval);
updateInterval = undefined; updateInterval = undefined;
} }
} };
function hasMessage() { const hasMessage = () => {
if (typeof iapm === "undefined") { if (typeof interactivePlayMessage === "undefined") {
return false; return false;
} else { } else {
return true; return true;
} }
} };
/** /**
* *
* @param {Function} callback function to retrieve current ticks * @param {Function} callback function to retrieve current ticks
*/ */
function startUpate(callback) { const startUpate = (callback) => {
if ( if (
typeof CONFIG["interactive-seek-bar-update-intervall"] === "number" && typeof CONFIG["interactive-seek-bar-update-intervall"] === "number" &&
CONFIG["interactive-seek-bar-update-intervall"] > 0 CONFIG["interactive-seek-bar-update-intervall"] > 0
) { ) {
updateInterval = setInterval(() => { updateInterval = setInterval(() => {
iapm.updateProgress(callback()); interactivePlayMessage.updateProgress(callback());
}, CONFIG["interactive-seek-bar-update-intervall"]); }, CONFIG["interactive-seek-bar-update-intervall"]);
} }
} };
function updateCurrentSongMessage( const updateCurrentSongMessage = (
title, title,
artist, artist,
imageURL, imageURL,
@ -84,11 +85,11 @@ function updateCurrentSongMessage(
ticksLength, ticksLength,
playlistIndex, playlistIndex,
playlistLenth playlistLenth
) { ) => {
log.log(iapm); log.log(interactivePlayMessage);
if (typeof iapm !== "undefined") { if (typeof interactivePlayMessage !== "undefined") {
iapm.updateCurrentSongMessage( interactivePlayMessage.updateCurrentSongMessage(
title, title,
artist, artist,
imageURL, imageURL,
@ -100,12 +101,12 @@ function updateCurrentSongMessage(
} else { } else {
throw Error("No Interactive Message Found"); throw Error("No Interactive Message Found");
} }
} };
module.exports = { module.exports = {
init, init,
destroy, destroy,
hasMessage, hasMessage,
startUpate, startUpate,
updateCurrentSongMessage, updateCurrentSongMessage
}; };