buffered prompts now have timestamp instead of iso
This commit is contained in:
parent
0a98f3a477
commit
53c1635e65
|
@ -6,8 +6,8 @@ import config from "../config.mjs"
|
||||||
export const db = Knex({
|
export const db = Knex({
|
||||||
client: 'sqlite3', // or 'better-sqlite3'
|
client: 'sqlite3', // or 'better-sqlite3'
|
||||||
connection: {
|
connection: {
|
||||||
filename: "data/database"
|
//filename: "data/database"
|
||||||
//filename: "data/database-testing"
|
filename: "data/database-testing"
|
||||||
},
|
},
|
||||||
useNullAsDefault: true
|
useNullAsDefault: true
|
||||||
})
|
})
|
||||||
|
@ -103,9 +103,11 @@ export const tableIsNotEmpty = async (table) => {
|
||||||
export const getPromptFromBuffer = async () => {
|
export const getPromptFromBuffer = async () => {
|
||||||
logger.trace("getting prompt from buffer")
|
logger.trace("getting prompt from buffer")
|
||||||
const oldestWordInBuffer = await db('buffer').select('word').orderBy('timestamp', 'asc').limit(1)
|
const oldestWordInBuffer = await db('buffer').select('word').orderBy('timestamp', 'asc').limit(1)
|
||||||
logger.info(`oldest word in buffer: ${oldestWordInBuffer[0].word}`)
|
const word = oldestWordInBuffer[0].word
|
||||||
|
if(!word){throw new Error("Requested oldest word in buffer but got an empty array! Is buffer empty?")}
|
||||||
try {
|
try {
|
||||||
const prompt = await getAcceptablePrompts(oldestWordInBuffer[0].word)
|
const prompt = await getAcceptablePrompts(word)
|
||||||
|
if(prompt.length===0){throw new Error("Prompt from buffer is not acceptable! Has it already been published? Have the acceptability criteria changed?")}
|
||||||
return prompt[0]
|
return prompt[0]
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("getPromptFromBuffer failed!")
|
logger.error("getPromptFromBuffer failed!")
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import logger from "../logger.mjs"
|
import logger from "../logger.mjs"
|
||||||
import { isoDate } from "../utilities.mjs"
|
import { timestamp } from "../utilities.mjs"
|
||||||
import Note from "./Note.mjs"
|
import Note from "./Note.mjs"
|
||||||
import createNote from "../firefish-calls/createNote.mjs"
|
import createNote from "../firefish-calls/createNote.mjs"
|
||||||
import { getDatePublished, wordIsAlreadyInBuffer, getAcceptablePrompts, valueExistsInColumn, insertIntoBuffer } from "../database-calls/db.mjs"
|
import { getDatePublished, wordIsAlreadyInBuffer, getAcceptablePrompts, valueExistsInColumn, insertIntoBuffer } from "../database-calls/db.mjs"
|
||||||
|
@ -46,7 +46,7 @@ export default async function handleMentions(body) {
|
||||||
createNote(`I'm afraid I can't do that, ${note.author}. The word you've suggested is either too quirky or not quirky enough. Them's the breaks.`,note.id)
|
createNote(`I'm afraid I can't do that, ${note.author}. The word you've suggested is either too quirky or not quirky enough. Them's the breaks.`,note.id)
|
||||||
return { code: "RARITY" }
|
return { code: "RARITY" }
|
||||||
} else {
|
} else {
|
||||||
await insertIntoBuffer(word,isoDate())
|
await insertIntoBuffer(word,timestamp())
|
||||||
await createNote(`OK!`,note.id)
|
await createNote(`OK!`,note.id)
|
||||||
return { code: "OK" }
|
return { code: "OK" }
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,3 +5,7 @@ export function isoDate(date=Date.now()){
|
||||||
export function removeUrls(string) {
|
export function removeUrls(string) {
|
||||||
return string.replace(/(https:\/\/www\.|http:\/\/www\.|https:\/\/|http:\/\/)?[a-zA-Z]{2,}(\.[a-zA-Z]{2,})(\.[a-zA-Z]{2,})?\/[a-zA-Z0-9]{2,}|((https:\/\/www\.|http:\/\/www\.|https:\/\/|http:\/\/)?[a-zA-Z]{2,}(\.[a-zA-Z]{2,})(\.[a-zA-Z]{2,})?)|(https:\/\/www\.|http:\/\/www\.|https:\/\/|http:\/\/)?[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}(\.[a-zA-Z0-9]{2,})?/g, '')
|
return string.replace(/(https:\/\/www\.|http:\/\/www\.|https:\/\/|http:\/\/)?[a-zA-Z]{2,}(\.[a-zA-Z]{2,})(\.[a-zA-Z]{2,})?\/[a-zA-Z0-9]{2,}|((https:\/\/www\.|http:\/\/www\.|https:\/\/|http:\/\/)?[a-zA-Z]{2,}(\.[a-zA-Z]{2,})(\.[a-zA-Z]{2,})?)|(https:\/\/www\.|http:\/\/www\.|https:\/\/|http:\/\/)?[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}(\.[a-zA-Z0-9]{2,})?/g, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function timestamp(){
|
||||||
|
return Date.now()
|
||||||
|
}
|
Loading…
Reference in New Issue