Yapper/functions/index.js

45 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2025-01-03 15:36:56 +00:00
/**
* Import function triggers from their respective submodules:
*
* const {onCall} = require("firebase-functions/v2/https");
* const {onDocumentWritten} = require("firebase-functions/v2/firestore");
*
* See a full list of supported triggers at https://firebase.google.com/docs/functions
*/
//const {onRequest} = require("firebase-functions/v2/https");
//const logger = require("firebase-functions/logger");
const functions = require('firebase-functions');
const Filter = require('bad-words');
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
exports.detectEvilUsers = functions.firestore
.document('messages/{msgId}')
.onCreate(async (doc, ctx) => {
const filter = new Filter();
const {text, uid} = doc.data();
if (filter.isProfane(text)) {
const cleaned = filter.clean(text);
await doc.ref.update({text: `Got banned for saying ${cleaned}`});
await db.collection('banned').doc('uid').set({});
}
});
// Create and deploy your first functions
// https://firebase.google.com/docs/functions/get-started
// exports.helloWorld = onRequest((request, response) => {
// logger.info("Hello logs!", {structuredData: true});
// response.send("Hello from Firebase!");
// });