Browse Source

adding eslint linting

master
nerdy-sam 1 year ago
parent
commit
6b9075aa0d
No known key found for this signature in database GPG Key ID: 8A814BCF72590007
3 changed files with 107 additions and 23 deletions
  1. +5
    -5
      .editorconfig
  2. +82
    -0
      .eslintrc.json
  3. +20
    -18
      bot.js

+ 5
- 5
.editorconfig View File

@@ -5,10 +5,10 @@ root = true

[*]
end_of_line = lf
insert_final_newline = false
max_line_length = 80

insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
tab_width = 2
indent_style = tab
indent_size = 2
indent_size = tab
max_line_length = 80

+ 82
- 0
.eslintrc.json View File

@@ -0,0 +1,82 @@
{
"env": {
"node": true,
"es2021": true
},
"sourceType": "module",
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest",
"ecmaFeatures": {
"impliedStrict": true
}
},
"rules": {
"camelcase": "error",
"max-len": [
"error",
{
"code": 80,
"tabWidth": 2,
"ignoreUrls": true,
"ignoreComments": false,
"ignoreTrailingComments": false,
"ignoreStrings": false,
"ignoreTemplateLiterals": false,
"ignoreRegExpLiterals": false
}
],
"max-lines-per-function": [
"error",
{
"max": 20,
"skipBlankLines": true,
"skipComments": true,
"IIFEs": true
}
],
"indent": [
"error",
"tab"
],
"quotes": [
"error",
"single",
{
"avoidEscape": true,
"allowTemplateLiterals": true
}
],
"semi": [
"error",
"never"
],
"newline-per-chained-call": [
"error",
{"ignoreChainWithDepth": 3}
],
"brace-style": [
"error",
"1tbs",
{"allowSingleLine": true}
],
"object-curly-newline": [
"error",
{
"minProperties": 3,
"multiline": true,
"consistent": true
}
],
"no-var": "error",
"prefer-const": [
"error",
{"destructuring": "all"}
],
"arrow-spacing": "error",
"no-magic-numbers": [
"error",
{"ignore": [-1,0,1]}
]
}
}

+ 20
- 18
bot.js View File

@@ -1,10 +1,10 @@
/**
* @file Eliezer - a Christian matrix bot
* @author nerdy-sam
* @license BlueOak-1.0.0
* @version 0.1.0
* @see {@link http://semver.org}
*/
* @file Eliezer - a Christian matrix bot
* @author nerdy-sam
* @license BlueOak-1.0.0
* @version 0.2.0
* @see {@link http://semver.org}
*/

import {
MatrixClient,
@@ -13,10 +13,10 @@ import {
AutojoinUpgradedRoomsMixin
} from 'matrix-bot-sdk'
import schedule from 'node-schedule'
import { promises as fs } from 'fs'
import {promises as fs} from 'fs'
import jw from 'talisman/metrics/jaro-winkler.js'
import words from 'talisman/tokenizers/words/index.js'
import { similarity } from 'talisman/metrics/prefix.js'
import words from 'talisman/tokenizers/words/index.js'
import {similarity as prefix} from 'talisman/metrics/prefix.js'

import config from './config.js'

@@ -78,7 +78,7 @@ schedule.scheduleJob({

// 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 = []
@@ -89,17 +89,19 @@ schedule.scheduleJob({
const d = dictWord.toLowerCase()
// normalize words and then score the match
const jwNum = jw(d, v)
// require at least a 85% match score and weight matching prefix
// require at least a 85% match score
// NOTE: All false positives I've ran across are longer than verseWord
// and had a more dissimilar prefix than the correct dictionary match
if (jwNum >= 0.85) {
let score = jwNum * similarity(d, v)
// decrease weight of matches by how much of a prefix they share
let score = jwNum * prefix(d, v)

if (v.length < d.length) {
// decrease weight of longer matches by a factor of length
score = score * (verseWord.length / dictWord.length)
}
w1828Scored.push({vw: verseWord, dw: dictWord, sc: score})
}
})
@@ -124,13 +126,13 @@ schedule.scheduleJob({

config.rooms.proverbs.forEach((room, index) => {
// add delay to throttle sending messages to many rooms
const threeSec = 3000
const threeMin = 180_000
const ratio = index + 1
const delay = threeSec * ratio
const delay = threeMin * ratio
const delayedDate = new Date(Date.now() + delay)

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

schedule.scheduleJob(


Loading…
Cancel
Save