feat: allow overwriting the message
continuous-integration/drone/push Build is failing Details

Signed-off-by: Sam Therapy <sam@samtherapy.net>
This commit is contained in:
Sam Therapy 2022-11-23 18:37:46 +01:00
parent 7bb1d39096
commit c4427fe5c9
Signed by: sam
GPG Key ID: 4D8B07C18F31ACBD
7 changed files with 31 additions and 19 deletions

View File

@ -1,9 +1,9 @@
#!/usr/bin/env node
import getConfig from "./helpers/getConfig.js"
import { config } from "./helpers/types.js"
import getLocalImage from "./getLocalImage.js"
import getRemoteImage from "./getRemoteImage.js"
import getConfig from "./helpers/getConfig.js"
import { config } from "./helpers/types.js"
/**
* Main function

View File

@ -2,10 +2,10 @@ import { createReadStream, ReadStream } from "node:fs"
import { readdir } from "node:fs/promises"
import { exit } from "node:process"
import postImage from "./postImage.js"
import args from "./helpers/args.js"
import crashHandler from "./helpers/crashHandler.js"
import { config } from "./helpers/types.js"
import postImage from "./postImage.js"
/**
* Get a local image from the filesystem

View File

@ -6,10 +6,11 @@ import { promisify } from "node:util"
import { search, Post } from "booru"
import got from "got-cjs"
import postImage from "./postImage.js"
import args from "./helpers/args.js"
import crashHandler from "./helpers/crashHandler.js"
import { config } from "./helpers/types.js"
import postImage from "./postImage.js"
/**
* Get a remote image from a booru

View File

@ -1,8 +1,8 @@
import { exit } from "node:process"
import { exit } from "node:process";
import commandLineArgs from "command-line-args"
import commandLineUsage from "command-line-usage"
import writeConfig from "./writeconfig.js"
import commandLineArgs from "command-line-args";
import commandLineUsage from "command-line-usage";
import writeConfig from "./writeConfig.js";
const optionDefinitions = [
{
@ -34,9 +34,17 @@ const optionDefinitions = [
description:
"Write a default configuration file to the current directory and exit.",
},
]
{
name: "message",
type: String,
alias: "m",
description: "The message to post with the image.",
defaultValue: "",
typeLabel: "<message>",
},
];
const args = commandLineArgs(optionDefinitions)
const args = commandLineArgs(optionDefinitions);
if (args.help) {
const usage = commandLineUsage([
@ -53,18 +61,18 @@ if (args.help) {
content:
"Project home: {underline https://git.froth.zone/Sam/fediverse-imagebot}",
},
])
console.log(usage)
exit(0)
]);
console.log(usage);
exit(0);
}
if (args.verbose) console.log("Running in verbose mode.\n")
if (args.verbose) console.log("Running in verbose mode.\n");
if (args.writeConfig) {
writeConfig(args.verbose).then(() => {
console.log("Wrote default config file to ./config.jsonc")
exit(0)
})
console.log("Wrote default config file to ./config.jsonc");
exit(0);
});
}
export default args
export default args;

View File

@ -1,6 +1,7 @@
import { readFile } from "node:fs/promises"
import JSON5 from "json5"
import args from "./args.js"
import crashHandler from "./crashHandler.js"
import { config } from "./types.js"

View File

@ -3,6 +3,8 @@ import { Readable } from "node:stream"
import generator, { Entity, Response } from "megalodon"
import pRetry from "p-retry"
import args from "./helpers/args.js"
import crashHandler from "./helpers/crashHandler.js"
import { config } from "./helpers/types.js"
@ -38,7 +40,7 @@ export default async function postImage(
// Make the post
const post = async () =>
client.postStatus(cfg.message, {
client.postStatus(args.message || cfg.message, {
media_ids: [res.data.id],
// Change this to make the post visibility you wish
visibility: cfg.visibility,