Skip to content

Commit

Permalink
move private methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisd committed Jul 12, 2024
1 parent 03eacfb commit c817063
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
29 changes: 29 additions & 0 deletions handlers/ban.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}


Expand Down
29 changes: 0 additions & 29 deletions handlers/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
}
Expand Down

0 comments on commit c817063

Please sign in to comment.