Last active
March 6, 2021 05:12
-
-
Save u9g/e71c18d28259283f71a23697b3a47b86 to your computer and use it in GitHub Desktop.
logs chat but good
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { escapeMarkdown, sendDiscordMessage } = require('./util') | |
const fs = require('fs') | |
const path = require('path') | |
const fileName = path.join('logs', `${new Date(Date.now()).toLocaleDateString().replace(/\//g, '_')}.json`) | |
let data = {} | |
function start (bot, client) { | |
bot.once('spawn', async () => { | |
data = await getData() | |
setInterval(write, 10000) | |
}) | |
bot.on('message', async (msg) => { | |
const text = msg.toString() | |
if (text.trim() === '') return | |
const index = new Date(Date.now()).toLocaleString() | |
data[index] = text | |
}) | |
} | |
async function getData () { | |
if (!fs.existsSync(fileName)) await fs.promises.writeFile(fileName, '{\n}') | |
return require(path.join(__dirname, fileName)) | |
} | |
async function write () { | |
if (!fs.existsSync(fileName)) await fs.promises.writeFile(fileName, '{\n}') | |
await fs.promises.writeFile(fileName, JSON.stringify(data, null, 2)) | |
} | |
module.exports = start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment