remove try/catches from inner layer
This commit is contained in:
parent
53c1635e65
commit
fa3c37627b
|
@ -12,8 +12,7 @@ export default async function checkAndPublish () {
|
|||
if(!await todaysPromptAlreadyPublished()){
|
||||
try {
|
||||
const prompt = await tableIsNotEmpty('buffer') ? await getPromptFromBuffer() : await getNewPrompt()
|
||||
|
||||
logger.trace("prompt acquired successfully!")
|
||||
logger.trace({prompt:prompt},"prompt acquired successfully!")
|
||||
try {
|
||||
const text = makeText(prompt)
|
||||
try {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
export default {
|
||||
maxCount : 30000000,
|
||||
minCount : 200000,
|
||||
minCount : 0,
|
||||
rarityBias: 0.7,
|
||||
spamMode : false
|
||||
}
|
Binary file not shown.
|
@ -7,20 +7,11 @@ const words = await getWords(db)
|
|||
console.dir(words)
|
||||
for (const element of words) {
|
||||
if(isMisspelled(element.word)){
|
||||
try {
|
||||
await db('dictionary')
|
||||
.where('word', element.word)
|
||||
.del()
|
||||
console.log("deleted non-word " + element.word)
|
||||
} catch (error) {
|
||||
console.error(error.message)
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
db.destroy()
|
||||
} catch (error) {
|
||||
console.error(error.message)
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ const blocklist = db.union([
|
|||
|
||||
export const getAcceptablePrompts = async (word) => {
|
||||
logger.trace("getAcceptablePrompt called")
|
||||
try {
|
||||
return db('dictionary')
|
||||
.select('*')
|
||||
.where({
|
||||
|
@ -35,10 +34,6 @@ export const getAcceptablePrompts = async (word) => {
|
|||
.whereRaw('length(word) > 3')
|
||||
.whereNotNull('pronunciation')
|
||||
.orderByRaw('count desc')
|
||||
} catch (error) {
|
||||
logger.error("getAcceptablePrompts failed!")
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -51,31 +46,21 @@ export const getWords = async () => {
|
|||
}
|
||||
|
||||
export const insertIntoBuffer = async (word,timestamp) => {
|
||||
try {
|
||||
return db('buffer')
|
||||
.insert({
|
||||
word:word,
|
||||
timestamp:timestamp
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error("buffer insert failed!")
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const valueExistsInColumn = async (table, column, value) => {
|
||||
try {
|
||||
|
||||
const number = await db(table)
|
||||
.count('* as count')
|
||||
.where(column, value)
|
||||
return number[0].count > 0
|
||||
} catch (error) {
|
||||
logger.error("valueExistsInColumn failed!")
|
||||
throw error
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const wordExistsInDictionary = async (word) => {
|
||||
|
@ -91,13 +76,9 @@ export const wordIsAlreadyInBuffer = async (word) => {
|
|||
}
|
||||
|
||||
export const tableIsNotEmpty = async (table) => {
|
||||
try {
|
||||
const number = await db(table)
|
||||
.count('* as count')
|
||||
return number[0].count > 0
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export const getPromptFromBuffer = async () => {
|
||||
|
@ -105,34 +86,21 @@ export const getPromptFromBuffer = async () => {
|
|||
const oldestWordInBuffer = await db('buffer').select('word').orderBy('timestamp', 'asc').limit(1)
|
||||
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(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!")
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export const deleteFromBuffer = async (word) => {
|
||||
logger.trace(`deleteFromBuffer called for word ${word}!`)
|
||||
try {
|
||||
return db('buffer')
|
||||
.where('word', word)
|
||||
.del()
|
||||
} catch (error) {
|
||||
logger.error("deleteFromBuffer failed!")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const getDatePublished = async (word) => {
|
||||
try {
|
||||
return db('published')
|
||||
.select('date')
|
||||
.where('word',word)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,16 +47,11 @@ const sampleRes = {
|
|||
|
||||
export default async function insertPublished(res, word) {
|
||||
logger.trace("insertPublished called")
|
||||
try {
|
||||
return db('published')
|
||||
.insert({
|
||||
id: res.createdNote.id,
|
||||
word,
|
||||
date: isoDate(sampleRes.createdNote.createdAt)
|
||||
})
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
|
||||
}
|
||||
//console.log(await insertPublished(sampleRes,'marmalade'))
|
|
@ -19,7 +19,6 @@ export default async function createNote(text,replyId) {
|
|||
cw:"Today's #micro365 prompt is:"
|
||||
}
|
||||
if(replyId){body.replyId=replyId}
|
||||
try {
|
||||
const response = await firefish.post("notes/create",body)
|
||||
logger.info({
|
||||
status: response.status,
|
||||
|
@ -27,9 +26,6 @@ export default async function createNote(text,replyId) {
|
|||
data: response.data
|
||||
})
|
||||
return response.data
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ const __dirname = path.dirname(__filename);
|
|||
// })
|
||||
export default pino(
|
||||
{
|
||||
level: 'info',
|
||||
level: 'trace',
|
||||
formatters: {
|
||||
level: (label) => {
|
||||
return { level: label.toUpperCase() };
|
||||
|
|
|
@ -21,8 +21,7 @@ export default async function handleMentions(body) {
|
|||
}
|
||||
const isRealWord = await note.isRealWord
|
||||
if (!isRealWord) {
|
||||
createNote(`I'm afraid I can't do that, ${note.author}. That's not a 'real' word, at least as far as I'm aware! Have you checked the spelling?
|
||||
You might just be too cool for me.`,note.id)
|
||||
createNote(`I'm afraid I can't do that, ${note.author}. That's not a 'real' word, at least as far as I'm aware! Have you checked the spelling?`,note.id)
|
||||
return { code: "NOTREAL" }
|
||||
}
|
||||
if (await wordIsAlreadyInBuffer(word)) {
|
||||
|
@ -33,7 +32,7 @@ export default async function handleMentions(body) {
|
|||
unacceptable = unacceptable.length===0
|
||||
if (unacceptable) {
|
||||
if (await valueExistsInColumn('medical_dictionary', 'word', word)) {
|
||||
createNote("I'm afraid I can't use any word that appears in my medical dictionary. I know this delivers some false positives, but it was the only way to avoid accidentally triggering people!",note.id)
|
||||
createNote("I'm afraid I can't use any word that appears in my medical dictionary. I know this delivers some false positives, but it was the only way.",note.id)
|
||||
return { code: "MEDICAL" }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue