Skip to content

Instantly share code, notes, and snippets.

@micahlt
Created December 20, 2022 05:36
Show Gist options
  • Select an option

  • Save micahlt/febb58d5abaab91b9ef26bb7f55caef6 to your computer and use it in GitHub Desktop.

Select an option

Save micahlt/febb58d5abaab91b9ef26bb7f55caef6 to your computer and use it in GitHub Desktop.
TheCaf.me Memo CLI
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."
);
})();
{
"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