From c817063511fdf304d5f3fa5e68243e3962dbbea1 Mon Sep 17 00:00:00 2001 From: Lluis Date: Fri, 12 Jul 2024 17:41:12 +0200 Subject: [PATCH] move private methods --- handlers/ban.js | 29 +++++++++++++++++++++++++++++ handlers/stream.js | 29 ----------------------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/handlers/ban.js b/handlers/ban.js index 9d3fb25..fbb43e2 100644 --- a/handlers/ban.js +++ b/handlers/ban.js @@ -29,6 +29,35 @@ class Ban { await TwitchService.unBanUser(user.id) } } + + _getUserNames (unbanRequests) { + let text + if (unbanRequests.length === 1){ + text = this._maskUserName(unbanRequests[0].user_name) + } else if (unbanRequests.length > 1) { + text = unbanRequests.map(ur => this._maskUserName(ur.user_name)).join(', ').replace(/, ([^,]*)$/, ' y $1') + } + return text + } + + _maskUserName (userName) { + const unmaskedStartLength = 3 + const unmaskedEndLength = 1 + + let unmaskedStart = userName.substring(0, unmaskedStartLength) + let masked = '' + let unmaskedEnd = '' + + const unmaskedLength = unmaskedStartLength + unmaskedEndLength + if (userName.length > unmaskedLength) { + masked = '*'.repeat(userName.length - unmaskedLength) + unmaskedEnd = userName.substring(userName.length - unmaskedEndLength) + } else if (userName.length > unmaskedStartLength) { + masked = '*'.repeat(userName.length - unmaskedStartLength) + } + + return unmaskedStart + masked + unmaskedEnd + } } diff --git a/handlers/stream.js b/handlers/stream.js index e796c94..96a956e 100644 --- a/handlers/stream.js +++ b/handlers/stream.js @@ -15,35 +15,6 @@ class Stream { await BrowserService.refreshPage().catch(() => { console.error('refreshPage on refreshPage')}) } - _getUserNames (unbanRequests) { - let text - if (unbanRequests.length === 1){ - text = this._maskUserName(unbanRequests[0].user_name) - } else if (unbanRequests.length > 1) { - text = unbanRequests.map(ur => this._maskUserName(ur.user_name)).join(', ').replace(/, ([^,]*)$/, ' y $1') - } - return text - } - - _maskUserName (userName) { - const unmaskedStartLength = 3 - const unmaskedEndLength = 1 - - let unmaskedStart = userName.substring(0, unmaskedStartLength) - let masked = '' - let unmaskedEnd = '' - - const unmaskedLength = unmaskedStartLength + unmaskedEndLength - if (userName.length > unmaskedLength) { - masked = '*'.repeat(userName.length - unmaskedLength) - unmaskedEnd = userName.substring(userName.length - unmaskedEndLength) - } else if (userName.length > unmaskedStartLength) { - masked = '*'.repeat(userName.length - unmaskedStartLength) - } - - return unmaskedStart + masked + unmaskedEnd - } - async getScreenshots(target, bot) { bot.say(target, `Fotos del stream ${config.externalUrl}/stream`) }