Browse Source

refactored adding Webster 1828 definitions for readability

master
nerdy-sam 1 year ago
parent
commit
594e9976ac
No known key found for this signature in database GPG Key ID: 8A814BCF72590007
1 changed files with 20 additions and 12 deletions
  1. +20
    -12
      bot.js

+ 20
- 12
bot.js View File

@@ -24,6 +24,10 @@ import KJV from './bibles/english_kjv.js'

'use strict'

const oneMinuteMs = 1000 * 60
const oneDayMs = 1000 * 60 * 60 * 24

console.log('Matrix client starting...')
const matrix = new MatrixClient(
...config.matrix,
new SimpleFsStorageProvider('./bot.json')
@@ -33,15 +37,9 @@ matrix.start()
AutojoinRoomsMixin.setupOnClient(matrix)
AutojoinUpgradedRoomsMixin.setupOnClient(matrix)

console.log('Matrix client started!')

console.log('Sending a Proverb every hour on the sevens.')

console.log('Sending a Proverb every hour on the seventh minute...')
const Proverbs = KJV.filter(verse => (verse.book == 'Proverbs'))

const oneMinuteMs = 1000 * 60
const oneDayMs = 1000 * 60 * 60 * 24

schedule.scheduleJob({
rule: '0 7 * * * *' // seven minutes past every hour
}, () => {
@@ -77,24 +75,34 @@ schedule.scheduleJob({
const xrefUrl = `${xrefDomain}/TSK/Proverbs/${chapter}/${verse}`
const xrefLink = `<b><a href="${xrefUrl}">X-REFs</a></b>`

const verseWords = words(Proverbs[verseIndex].text).map(verseWord => {
// take each word from the verse
const verseWords = words(Proverbs[verseIndex].text)
// and see if Noah Webster defined it in 1828
const verseWordsDefined = verseWords.map(verseWord => {
let w1828Scored = []

// find closest match in Websters 1828 Dictionary for verse word
WEB1828.forEach(dictWord => {
// normalize words and then score the match
const jwNum = jw(dictWord.toLowerCase(), verseWord.toLowerCase())
w1828Scored.push({vw: verseWord, dw: dictWord, jw: jwNum})
// require at least a 90% match score
if (jwNum >= 0.9) {
w1828Scored.push({vw: verseWord, dw: dictWord, jw: jwNum})
}
})

// return first result of scored and sorted dictionary words
return w1828Scored.sort((a, b) => b.jw - a.jw)[0]
const closestMatch = w1828Scored.sort((a,b) => b.jw - a.jw)[0]

return (w1828Scored.length) ? closestMatch : false
})

let vHTML = `${vrefLink} ${Proverbs[verseIndex].text} ${xrefLink}`

// replace each word with a link to its definition
verseWords.forEach(word => {
verseWordsDefined.forEach(word => {
const webDomain = 'http://webstersdictionary1828.com/Dictionary'
const vDefined = ` <a href="${webDomain}/${word.dw}">${word.vw}</a>`
const vwRegEx = new RegExp(` ${word.vw}`)
@@ -110,7 +118,7 @@ schedule.scheduleJob({
const delayedDate = new Date(Date.now() + delay)

console.log(
`${vrefLink} scheduled for ${room.name} on ${delayedDate.toTimeString()}`
`${vref} scheduled for ${room.name} on ${delayedDate.toTimeString()}`
)

schedule.scheduleJob(


Loading…
Cancel
Save