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({
|
||||
client: 'sqlite3', // or 'better-sqlite3'
|
||||
connection: {
|
||||
filename: "data/database"
|
||||
//filename: "data/database-testing"
|
||||
//filename: "data/database"
|
||||
filename: "data/database-testing"
|
||||
},
|
||||
useNullAsDefault: true
|
||||
})
|
||||
|
@ -103,9 +103,11 @@ export const tableIsNotEmpty = async (table) => {
|
|||
export const getPromptFromBuffer = async () => {
|
||||
logger.trace("getting prompt from buffer")
|
||||
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 {
|
||||
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]
|
||||
} catch (error) {
|
||||
logger.error("getPromptFromBuffer failed!")
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import logger from "../logger.mjs"
|
||||
import { isoDate } from "../utilities.mjs"
|
||||
import { timestamp } from "../utilities.mjs"
|
||||
import Note from "./Note.mjs"
|
||||
import createNote from "../firefish-calls/createNote.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)
|
||||
return { code: "RARITY" }
|
||||
} else {
|
||||
await insertIntoBuffer(word,isoDate())
|
||||
await insertIntoBuffer(word,timestamp())
|
||||
await createNote(`OK!`,note.id)
|
||||
return { code: "OK" }
|
||||
}
|
||||
|
|
|
@ -4,4 +4,8 @@ export function isoDate(date=Date.now()){
|
|||
|
||||
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, '')
|
||||
}
|
||||
|
||||
export function timestamp(){
|
||||
return Date.now()
|
||||
}
|
Loading…
Reference in New Issue