Created
December 20, 2022 05:36
-
-
Save micahlt/febb58d5abaab91b9ef26bb7f55caef6 to your computer and use it in GitHub Desktop.
TheCaf.me Memo CLI
This file contains hidden or 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
| require("dotenv").config(); | |
| const MongoClient = require("mongodb").MongoClient; | |
| const prompts = require("prompts"); | |
| (async () => { | |
| const client = new MongoClient(process.env.CAFMONGO); | |
| const dbName = "info"; | |
| await client.connect(); | |
| const db = client.db(dbName); | |
| const collection = db.collection("db-meta"); | |
| const memos = await collection.find({ last_id: { $exists: true } }).toArray(); | |
| const memo_id = memos[0].last_id; | |
| console.log("Let's get started making an announcment."); | |
| const memo_title = await prompts({ | |
| type: "text", | |
| message: "What's the title?", | |
| }); | |
| const memo_text = await prompts({ | |
| type: "text", | |
| message: "What's the description?", | |
| }); | |
| const expiresAt = await prompts({ | |
| type: "date", | |
| initial: new Date(), | |
| mask: "MM/DD/YYYY HH:mm", | |
| message: "What's the expiry date?", | |
| }); | |
| await collection.updateOne( | |
| { last_id: memo_id }, | |
| { $set: { last_id: memo_id + 1 } } | |
| ); | |
| await collection.insertOne({ | |
| memo_id: memo_id + 1, | |
| memo_title: memo_title.undefined, | |
| memo_text: memo_text.undefined, | |
| expiresAt: expiresAt.undefined, | |
| }); | |
| console.log( | |
| "Message published successfully! It should be visible on TheCaf.me in under 2 minutes." | |
| ); | |
| })(); |
This file contains hidden or 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
| { | |
| "name": "cafinfo-messager", | |
| "version": "1.0.0", | |
| "description": "", | |
| "main": "cli.js", | |
| "scripts": { | |
| "start": "node cli.js" | |
| }, | |
| "author": "Micah Lindley", | |
| "license": "MIT", | |
| "dependencies": { | |
| "dotenv": "^16.0.3", | |
| "mongodb": "^4.13.0", | |
| "prompts": "^2.4.2" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment