Skip to content

Commit

Permalink
Merge pull request #524 from aternosorg/safe-search
Browse files Browse the repository at this point in the history
catch no data being returned from the safe search api
  • Loading branch information
JulianVennen authored Nov 2, 2022
2 parents 98bfdab + f14c7f6 commit 0f5ace9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "modbot",
"version": "3.0.9",
"version": "3.0.10",
"description": "Discord Bot for the Aternos Discord server",
"main": "index.js",
"type": "module",
Expand Down
10 changes: 8 additions & 2 deletions src/automod/SafeSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export default class SafeSearch {
let maxType = null, maxValue = null;
for (const image of images.values()) {
const safeSearchAnnotation = await this.request(image);
if (!safeSearchAnnotation) {
continue;
}

for (const type of ['adult', 'medical', 'violence', 'racy']) {
const likelihood = this.getLikelihoodAsNumber(safeSearchAnnotation[type]);
if (!maxValue || likelihood > maxValue) {
Expand All @@ -76,8 +80,10 @@ export default class SafeSearch {
}

const [{safeSearchAnnotation}] = await this.annotatorClient.safeSearchDetection(image.url);
this.#cache.set(hash, safeSearchAnnotation, CACHE_DURATION);
await database.query('INSERT INTO safeSearch (hash, data) VALUES (?, ?)', hash, JSON.stringify(safeSearchAnnotation));
if (safeSearchAnnotation) {
this.#cache.set(hash, safeSearchAnnotation, CACHE_DURATION);
await database.query('INSERT INTO safeSearch (hash, data) VALUES (?, ?)', hash, JSON.stringify(safeSearchAnnotation));
}
return safeSearchAnnotation;
}

Expand Down

0 comments on commit 0f5ace9

Please sign in to comment.