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()){
 | 
					    if(!await todaysPromptAlreadyPublished()){
 | 
				
			||||||
        try {            
 | 
					        try {            
 | 
				
			||||||
            const prompt = await tableIsNotEmpty('buffer') ? await getPromptFromBuffer() : await getNewPrompt()
 | 
					            const prompt = await tableIsNotEmpty('buffer') ? await getPromptFromBuffer() : await getNewPrompt()
 | 
				
			||||||
 | 
					            logger.trace({prompt:prompt},"prompt acquired successfully!")
 | 
				
			||||||
            logger.trace("prompt acquired successfully!")
 | 
					 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                const text = makeText(prompt)
 | 
					                const text = makeText(prompt)
 | 
				
			||||||
                try {
 | 
					                try {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,5 @@
 | 
				
			||||||
export default {
 | 
					export default {
 | 
				
			||||||
 maxCount : 30000000,
 | 
					 maxCount : 30000000,
 | 
				
			||||||
 minCount : 200000,
 | 
					 minCount : 0,
 | 
				
			||||||
 rarityBias: 0.7,
 | 
					 rarityBias: 0.7,
 | 
				
			||||||
 spamMode : false
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -7,20 +7,11 @@ const words = await getWords(db)
 | 
				
			||||||
console.dir(words)
 | 
					console.dir(words)
 | 
				
			||||||
for (const element of words) {
 | 
					for (const element of words) {
 | 
				
			||||||
  if(isMisspelled(element.word)){
 | 
					  if(isMisspelled(element.word)){
 | 
				
			||||||
    try {
 | 
					 | 
				
			||||||
      await db('dictionary')
 | 
					      await db('dictionary')
 | 
				
			||||||
      .where('word', element.word)
 | 
					      .where('word', element.word)
 | 
				
			||||||
      .del()
 | 
					      .del()
 | 
				
			||||||
      console.log("deleted non-word " + element.word)
 | 
					      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) => {
 | 
					export const getAcceptablePrompts = async (word) => {
 | 
				
			||||||
  logger.trace("getAcceptablePrompt called")
 | 
					  logger.trace("getAcceptablePrompt called")
 | 
				
			||||||
  try {
 | 
					 | 
				
			||||||
    return db('dictionary')
 | 
					    return db('dictionary')
 | 
				
			||||||
      .select('*')
 | 
					      .select('*')
 | 
				
			||||||
      .where({
 | 
					      .where({
 | 
				
			||||||
| 
						 | 
					@ -35,10 +34,6 @@ export const getAcceptablePrompts = async (word) => {
 | 
				
			||||||
      .whereRaw('length(word) > 3')
 | 
					      .whereRaw('length(word) > 3')
 | 
				
			||||||
      .whereNotNull('pronunciation')
 | 
					      .whereNotNull('pronunciation')
 | 
				
			||||||
      .orderByRaw('count desc')
 | 
					      .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) => {
 | 
					export const insertIntoBuffer = async (word,timestamp) => {
 | 
				
			||||||
  try {
 | 
					 | 
				
			||||||
    return db('buffer')
 | 
					    return db('buffer')
 | 
				
			||||||
    .insert({
 | 
					    .insert({
 | 
				
			||||||
      word:word,
 | 
					      word:word,
 | 
				
			||||||
      timestamp:timestamp
 | 
					      timestamp:timestamp
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
  } catch (error) {
 | 
					 | 
				
			||||||
    logger.error("buffer insert failed!")
 | 
					 | 
				
			||||||
    throw error
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const valueExistsInColumn = async (table, column, value) => {
 | 
					export const valueExistsInColumn = async (table, column, value) => {
 | 
				
			||||||
  try {
 | 
					
 | 
				
			||||||
    const number = await db(table)
 | 
					    const number = await db(table)
 | 
				
			||||||
      .count('* as count')
 | 
					      .count('* as count')
 | 
				
			||||||
      .where(column, value)
 | 
					      .where(column, value)
 | 
				
			||||||
    return number[0].count > 0
 | 
					    return number[0].count > 0
 | 
				
			||||||
  } catch (error) {
 | 
					 | 
				
			||||||
    logger.error("valueExistsInColumn failed!")
 | 
					 | 
				
			||||||
    throw error
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const wordExistsInDictionary = async (word) => {
 | 
					export const wordExistsInDictionary = async (word) => {
 | 
				
			||||||
| 
						 | 
					@ -91,13 +76,9 @@ export const wordIsAlreadyInBuffer = async (word) => {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const tableIsNotEmpty = async (table) => {
 | 
					export const tableIsNotEmpty = async (table) => {
 | 
				
			||||||
  try {
 | 
					 | 
				
			||||||
    const number = await db(table)
 | 
					    const number = await db(table)
 | 
				
			||||||
      .count('* as count')
 | 
					      .count('* as count')
 | 
				
			||||||
    return number[0].count > 0
 | 
					    return number[0].count > 0
 | 
				
			||||||
  } catch (error) {
 | 
					 | 
				
			||||||
    throw error
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const getPromptFromBuffer = async () => {
 | 
					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 oldestWordInBuffer = await db('buffer').select('word').orderBy('timestamp', 'asc').limit(1)
 | 
				
			||||||
  const word = 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?")}
 | 
					  if(!word){throw new Error("Requested oldest word in buffer but got an empty array! Is buffer empty?")}
 | 
				
			||||||
  try {
 | 
					 | 
				
			||||||
    const prompt = await getAcceptablePrompts(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?")}
 | 
					    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) {
 | 
					 | 
				
			||||||
    logger.error("getPromptFromBuffer failed!")
 | 
					 | 
				
			||||||
    throw error
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const deleteFromBuffer = async (word) => {
 | 
					export const deleteFromBuffer = async (word) => {
 | 
				
			||||||
  logger.trace(`deleteFromBuffer called for word ${word}!`)
 | 
					  logger.trace(`deleteFromBuffer called for word ${word}!`)
 | 
				
			||||||
  try {
 | 
					 | 
				
			||||||
    return db('buffer')
 | 
					    return db('buffer')
 | 
				
			||||||
    .where('word', word)
 | 
					    .where('word', word)
 | 
				
			||||||
    .del()
 | 
					    .del()
 | 
				
			||||||
  } catch (error) {
 | 
					 | 
				
			||||||
    logger.error("deleteFromBuffer failed!")
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const getDatePublished = async (word) => {
 | 
					export const getDatePublished = async (word) => {
 | 
				
			||||||
  try {
 | 
					 | 
				
			||||||
    return db('published')
 | 
					    return db('published')
 | 
				
			||||||
    .select('date')
 | 
					    .select('date')
 | 
				
			||||||
    .where('word',word)
 | 
					    .where('word',word)
 | 
				
			||||||
  } catch (error) {
 | 
					 | 
				
			||||||
    throw error
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -47,16 +47,11 @@ const sampleRes = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default async function insertPublished(res, word) {
 | 
					export default async function insertPublished(res, word) {
 | 
				
			||||||
  logger.trace("insertPublished called")
 | 
					  logger.trace("insertPublished called")
 | 
				
			||||||
  try {
 | 
					 | 
				
			||||||
    return db('published')
 | 
					    return db('published')
 | 
				
			||||||
      .insert({
 | 
					      .insert({
 | 
				
			||||||
        id: res.createdNote.id,
 | 
					        id: res.createdNote.id,
 | 
				
			||||||
        word,
 | 
					        word,
 | 
				
			||||||
        date: isoDate(sampleRes.createdNote.createdAt)
 | 
					        date: isoDate(sampleRes.createdNote.createdAt)
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
  } catch (error) {
 | 
					 | 
				
			||||||
    throw error
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
//console.log(await insertPublished(sampleRes,'marmalade'))
 | 
					//console.log(await insertPublished(sampleRes,'marmalade'))
 | 
				
			||||||
| 
						 | 
					@ -19,7 +19,6 @@ export default async function createNote(text,replyId) {
 | 
				
			||||||
    cw:"Today's #micro365 prompt is:"
 | 
					    cw:"Today's #micro365 prompt is:"
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if(replyId){body.replyId=replyId}
 | 
					  if(replyId){body.replyId=replyId}
 | 
				
			||||||
  try {
 | 
					 | 
				
			||||||
    const response = await firefish.post("notes/create",body)
 | 
					    const response = await firefish.post("notes/create",body)
 | 
				
			||||||
    logger.info({
 | 
					    logger.info({
 | 
				
			||||||
      status: response.status,
 | 
					      status: response.status,
 | 
				
			||||||
| 
						 | 
					@ -27,9 +26,6 @@ export default async function createNote(text,replyId) {
 | 
				
			||||||
      data: response.data
 | 
					      data: response.data
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    return response.data
 | 
					    return response.data
 | 
				
			||||||
  } catch (error) {
 | 
					 | 
				
			||||||
    throw error
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,7 +16,7 @@ const __dirname = path.dirname(__filename);
 | 
				
			||||||
// })
 | 
					// })
 | 
				
			||||||
export default pino(
 | 
					export default pino(
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      level: 'info',
 | 
					      level: 'trace',
 | 
				
			||||||
      formatters: {
 | 
					      formatters: {
 | 
				
			||||||
        level: (label) => {
 | 
					        level: (label) => {
 | 
				
			||||||
          return { level: label.toUpperCase() };
 | 
					          return { level: label.toUpperCase() };
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,8 +21,7 @@ export default async function handleMentions(body) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    const isRealWord = await note.isRealWord
 | 
					    const isRealWord = await note.isRealWord
 | 
				
			||||||
    if (!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? 
 | 
					        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)
 | 
				
			||||||
        You might just be too cool for me.`,note.id)
 | 
					 | 
				
			||||||
        return { code: "NOTREAL" }
 | 
					        return { code: "NOTREAL" }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (await wordIsAlreadyInBuffer(word)) {
 | 
					    if (await wordIsAlreadyInBuffer(word)) {
 | 
				
			||||||
| 
						 | 
					@ -33,7 +32,7 @@ export default async function handleMentions(body) {
 | 
				
			||||||
    unacceptable = unacceptable.length===0
 | 
					    unacceptable = unacceptable.length===0
 | 
				
			||||||
    if (unacceptable) {
 | 
					    if (unacceptable) {
 | 
				
			||||||
        if (await valueExistsInColumn('medical_dictionary', 'word', word)) {
 | 
					        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" }
 | 
					            return { code: "MEDICAL" }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue