Add facts

This commit is contained in:
Quentin ANIERE 2022-05-18 10:55:52 +02:00
parent 91e5ae7c73
commit 55528545e9
3 changed files with 174 additions and 122 deletions

View File

@ -1,5 +1,6 @@
const fs = require("fs");
const https = require("https");
const axios = require("axios");
const dotenv = require('dotenv').config();
const express = require("express");
const socketio = require("socket.io");
@ -33,6 +34,14 @@ function log(message) {
console.log(getCurrentTime() + " " + message);
}
function getFact() {
axios.get("https://chuckn.neant.be/api/rand")
.then(response => {
return response.data.joke.replace("Chuck Norris", "Denis");
})
}
const app = express(); //The base http server, use by socketio and https serveur
@ -83,6 +92,9 @@ io.on("connection", (client) => {
io.sockets.emit("fart");
log(`${client.denisFanNumber} : have farted`);
} else if(data.message === "/fact") {
io.sockets.emit("new-message", {author: "DenisFact", message: getFact()});
} else {
client.emit("warning");
log(`${client.denisFanNumber} : ${data.message} (INVALID)`);

View File

@ -4,6 +4,7 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"axios": "^0.27.2",
"dotenv": "^16.0.0",
"express": "^4.17.3",
"express-basic-auth": "^1.2.1",

283
yarn.lock

File diff suppressed because it is too large Load Diff