added new things
This commit is contained in:
2
functions/.gitignore
vendored
Normal file
2
functions/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
*.local
|
||||
44
functions/index.js
Normal file
44
functions/index.js
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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!");
|
||||
// });
|
||||
5859
functions/package-lock.json
generated
Normal file
5859
functions/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
24
functions/package.json
Normal file
24
functions/package.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "functions",
|
||||
"description": "Cloud Functions for Firebase",
|
||||
"scripts": {
|
||||
"serve": "firebase emulators:start --only functions",
|
||||
"shell": "firebase functions:shell",
|
||||
"start": "npm run shell",
|
||||
"deploy": "firebase deploy --only functions",
|
||||
"logs": "firebase functions:log"
|
||||
},
|
||||
"engines": {
|
||||
"node": "22"
|
||||
},
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"bad-words": "^4.0.0",
|
||||
"firebase-admin": "^12.6.0",
|
||||
"firebase-functions": "^6.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"firebase-functions-test": "^3.1.0"
|
||||
},
|
||||
"private": true
|
||||
}
|
||||
Reference in New Issue
Block a user