Compare commits
No commits in common. "8d8bd0fbb85244cd1c9c5c80cdbdd8c82a4ec31c" and "fb0022d24725c704f9f59f61ad4ba1b34f19ac27" have entirely different histories.
8d8bd0fbb8
...
fb0022d247
5 changed files with 11 additions and 96 deletions
10
action.yml
10
action.yml
|
@ -8,24 +8,14 @@ inputs:
|
||||||
webhook:
|
webhook:
|
||||||
description: "Discord webhook url to use"
|
description: "Discord webhook url to use"
|
||||||
required: true
|
required: true
|
||||||
outputFileLocation:
|
|
||||||
description: "Where to write a file containing current message ids for this run"
|
|
||||||
default: "./messageIDs.txt"
|
|
||||||
storageMethod:
|
storageMethod:
|
||||||
description: |-
|
description: |-
|
||||||
Method of storing old message ids to delete
|
Method of storing old message ids to delete
|
||||||
one of:
|
one of:
|
||||||
- none - doesn't store ids of sent messages
|
- none - doesn't store ids of sent messages
|
||||||
- git - stores ids in git repository
|
- git - stores ids in git repository
|
||||||
- webhook - stores in message sent by another webhook
|
|
||||||
default: none
|
default: none
|
||||||
required: true
|
required: true
|
||||||
storegeGitFileLocation:
|
|
||||||
description: "Where in git repository file should be saved"
|
|
||||||
storageWebhookUrl:
|
|
||||||
description: "Webhook url used to send and read message containing messageIDs"
|
|
||||||
storageWebhookMessageID:
|
|
||||||
description: "Message ID to read and edit"
|
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: node20
|
using: node20
|
||||||
|
|
44
dist/index.js
vendored
44
dist/index.js
vendored
|
@ -129058,7 +129058,6 @@ async function main() {
|
||||||
if (presentMessages.length !== messageBlocks.length) {
|
if (presentMessages.length !== messageBlocks.length) {
|
||||||
core.info("number of message blocks is different, sending messages");
|
core.info("number of message blocks is different, sending messages");
|
||||||
core.debug(`read "blocks": ${messageBlocks.length}, number of read messages: ${presentMessages.length}`);
|
core.debug(`read "blocks": ${messageBlocks.length}, number of read messages: ${presentMessages.length}`);
|
||||||
shouldPostMessages = true;
|
|
||||||
}
|
}
|
||||||
if (!shouldPostMessages)
|
if (!shouldPostMessages)
|
||||||
for (let i = 0; i < messageBlocks.length; i++) {
|
for (let i = 0; i < messageBlocks.length; i++) {
|
||||||
|
@ -129104,9 +129103,9 @@ async function main() {
|
||||||
}
|
}
|
||||||
const messageIDsConcatenated = messageIDs.join("\n");
|
const messageIDsConcatenated = messageIDs.join("\n");
|
||||||
core.info(`Messages sent! IDs:\n${messageIDsConcatenated}`);
|
core.info(`Messages sent! IDs:\n${messageIDsConcatenated}`);
|
||||||
await promises_1.default.writeFile(core.getInput("outputFileLocation"), messageIDsConcatenated);
|
await promises_1.default.writeFile("./messageIDs.txt", messageIDsConcatenated);
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
storage_1.default.pushMessageIDs(messageIDs),
|
storage_1.default.pushMessageIDs(),
|
||||||
presentMessageIds.map(v => client.deleteMessage(v)),
|
presentMessageIds.map(v => client.deleteMessage(v)),
|
||||||
].flat());
|
].flat());
|
||||||
}
|
}
|
||||||
|
@ -129154,7 +129153,6 @@ exports.pushMessageIDs = exports.getMessageIDs = void 0;
|
||||||
const promises_1 = __importDefault(__nccwpck_require__(93977));
|
const promises_1 = __importDefault(__nccwpck_require__(93977));
|
||||||
const core = __importStar(__nccwpck_require__(42186));
|
const core = __importStar(__nccwpck_require__(42186));
|
||||||
const exec_1 = __nccwpck_require__(71514);
|
const exec_1 = __nccwpck_require__(71514);
|
||||||
const discord_js_1 = __nccwpck_require__(85973);
|
|
||||||
function exec(command, options) {
|
function exec(command, options) {
|
||||||
const splitted = command.trim().split(/ +/g);
|
const splitted = command.trim().split(/ +/g);
|
||||||
if (splitted.length === 0)
|
if (splitted.length === 0)
|
||||||
|
@ -129164,11 +129162,6 @@ function exec(command, options) {
|
||||||
function getStorageMethod() {
|
function getStorageMethod() {
|
||||||
return core.getInput("storageMethod", { required: true });
|
return core.getInput("storageMethod", { required: true });
|
||||||
}
|
}
|
||||||
function getStorageWebhook() {
|
|
||||||
return new discord_js_1.WebhookClient({
|
|
||||||
url: core.getInput("storageWebhookUrl", { required: true }),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/** @returns array of messageIDs */
|
/** @returns array of messageIDs */
|
||||||
async function getMessageIDs() {
|
async function getMessageIDs() {
|
||||||
const method = getStorageMethod();
|
const method = getStorageMethod();
|
||||||
|
@ -129176,7 +129169,7 @@ async function getMessageIDs() {
|
||||||
case "none":
|
case "none":
|
||||||
return [];
|
return [];
|
||||||
case "git":
|
case "git":
|
||||||
return promises_1.default.readFile(core.getInput("storageGitFileLocation"))
|
return promises_1.default.readFile("./messageIDs.txt")
|
||||||
.then(v => v.toString().trim().split("\n"))
|
.then(v => v.toString().trim().split("\n"))
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
core.warning("Couldn't read messageIDs");
|
core.warning("Couldn't read messageIDs");
|
||||||
|
@ -129184,50 +129177,23 @@ async function getMessageIDs() {
|
||||||
core.warning("Continuing anyway");
|
core.warning("Continuing anyway");
|
||||||
return [];
|
return [];
|
||||||
});
|
});
|
||||||
case "webhook":
|
|
||||||
return getStorageWebhook()
|
|
||||||
.fetchMessage(core.getInput("storageWebhookMessageID"))
|
|
||||||
.then(v => v.content.split(", "))
|
|
||||||
.catch(e => {
|
|
||||||
core.warning("Couldn't read messageIDs");
|
|
||||||
return [];
|
|
||||||
});
|
|
||||||
default:
|
default:
|
||||||
throw new Error(`Storage method is unknown: ${method}`);
|
throw new Error(`Storage method is unknown: ${method}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.getMessageIDs = getMessageIDs;
|
exports.getMessageIDs = getMessageIDs;
|
||||||
async function pushMessageIDs(messageIDs) {
|
async function pushMessageIDs() {
|
||||||
const method = getStorageMethod();
|
const method = getStorageMethod();
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case "git":
|
case "git":
|
||||||
const gitFileLocation = core.getInput("storageGitFileLocation", { required: true });
|
|
||||||
await promises_1.default.copyFile(core.getInput("outputFileLocation"), gitFileLocation);
|
|
||||||
await exec("git config --global user.name \"Actions\"");
|
await exec("git config --global user.name \"Actions\"");
|
||||||
await exec("git config --global user.email \"noreply@users.noreply.github.com\"");
|
await exec("git config --global user.email \"noreply@users.noreply.github.com\"");
|
||||||
await exec(`git add ${gitFileLocation}`);
|
await exec("git add ./messageIDs.txt");
|
||||||
await (0, exec_1.exec)("git", ["commit", "-m", "Update stored messageIDs"]);
|
await (0, exec_1.exec)("git", ["commit", "-m", "Update stored messageIDs"]);
|
||||||
await exec("git push");
|
await exec("git push");
|
||||||
return true;
|
return true;
|
||||||
case "none":
|
case "none":
|
||||||
return false;
|
return false;
|
||||||
case "webhook":
|
|
||||||
const content = messageIDs.join(", ");
|
|
||||||
try {
|
|
||||||
const id = core.getInput("storageWebhookMessageID");
|
|
||||||
if (id === "" || isNaN(Number(id)))
|
|
||||||
throw new Error("Invalid argument provided for storageWebhookMessageID");
|
|
||||||
await getStorageWebhook().editMessage(core.getInput("storageWebhookMessageID"), content);
|
|
||||||
core.info("Message for storage edited!");
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
core.warning("Couldn't edit storage message");
|
|
||||||
core.warning(e);
|
|
||||||
core.warning("Sending a new storage message");
|
|
||||||
const message = await getStorageWebhook().send(messageIDs.join(", "));
|
|
||||||
core.info(`Message for storage sent! ID: ${message.id}`);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
default:
|
default:
|
||||||
throw new Error(`Storage method is unknown: ${method}`);
|
throw new Error(`Storage method is unknown: ${method}`);
|
||||||
}
|
}
|
||||||
|
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
@ -49,7 +49,6 @@ async function main() {
|
||||||
if (presentMessages.length !== messageBlocks.length) {
|
if (presentMessages.length !== messageBlocks.length) {
|
||||||
core.info("number of message blocks is different, sending messages");
|
core.info("number of message blocks is different, sending messages");
|
||||||
core.debug(`read "blocks": ${messageBlocks.length}, number of read messages: ${presentMessages.length}`);
|
core.debug(`read "blocks": ${messageBlocks.length}, number of read messages: ${presentMessages.length}`);
|
||||||
shouldPostMessages = true;
|
|
||||||
}
|
}
|
||||||
if (!shouldPostMessages) for (let i = 0; i < messageBlocks.length; i++) {
|
if (!shouldPostMessages) for (let i = 0; i < messageBlocks.length; i++) {
|
||||||
// FIXME: discord may strip special unicode characters, making strings different
|
// FIXME: discord may strip special unicode characters, making strings different
|
||||||
|
@ -99,10 +98,10 @@ async function main() {
|
||||||
|
|
||||||
const messageIDsConcatenated = messageIDs.join("\n");
|
const messageIDsConcatenated = messageIDs.join("\n");
|
||||||
core.info(`Messages sent! IDs:\n${messageIDsConcatenated}`);
|
core.info(`Messages sent! IDs:\n${messageIDsConcatenated}`);
|
||||||
await fs.writeFile(core.getInput("outputFileLocation"), messageIDsConcatenated);
|
await fs.writeFile("./messageIDs.txt", messageIDsConcatenated);
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
storage.pushMessageIDs(messageIDs),
|
storage.pushMessageIDs(),
|
||||||
presentMessageIds.map(v => client.deleteMessage(v)),
|
presentMessageIds.map(v => client.deleteMessage(v)),
|
||||||
].flat()
|
].flat()
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,7 +2,6 @@ import fs from "node:fs/promises";
|
||||||
|
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import { exec as _exec, type ExecOptions } from "@actions/exec";
|
import { exec as _exec, type ExecOptions } from "@actions/exec";
|
||||||
import { WebhookClient } from "discord.js";
|
|
||||||
|
|
||||||
function exec(command: string, options?: ExecOptions) {
|
function exec(command: string, options?: ExecOptions) {
|
||||||
const splitted = command.trim().split(/ +/g);
|
const splitted = command.trim().split(/ +/g);
|
||||||
|
@ -15,12 +14,6 @@ function getStorageMethod(): string {
|
||||||
return core.getInput("storageMethod", {required: true})
|
return core.getInput("storageMethod", {required: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getStorageWebhook(): WebhookClient {
|
|
||||||
return new WebhookClient({
|
|
||||||
url: core.getInput("storageWebhookUrl", { required: true }),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @returns array of messageIDs */
|
/** @returns array of messageIDs */
|
||||||
export async function getMessageIDs(): Promise<string[]> {
|
export async function getMessageIDs(): Promise<string[]> {
|
||||||
const method = getStorageMethod();
|
const method = getStorageMethod();
|
||||||
|
@ -28,7 +21,7 @@ export async function getMessageIDs(): Promise<string[]> {
|
||||||
case "none":
|
case "none":
|
||||||
return [];
|
return [];
|
||||||
case "git":
|
case "git":
|
||||||
return fs.readFile(core.getInput("storageGitFileLocation"))
|
return fs.readFile("./messageIDs.txt")
|
||||||
.then(v => v.toString().trim().split("\n"))
|
.then(v => v.toString().trim().split("\n"))
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
core.warning("Couldn't read messageIDs");
|
core.warning("Couldn't read messageIDs");
|
||||||
|
@ -36,56 +29,23 @@ export async function getMessageIDs(): Promise<string[]> {
|
||||||
core.warning("Continuing anyway");
|
core.warning("Continuing anyway");
|
||||||
return [];
|
return [];
|
||||||
})
|
})
|
||||||
case "webhook":
|
|
||||||
return getStorageWebhook()
|
|
||||||
.fetchMessage(core.getInput("storageWebhookMessageID"))
|
|
||||||
.then(v => v.content.split(", "))
|
|
||||||
.catch(e => {
|
|
||||||
core.warning("Couldn't read messageIDs");
|
|
||||||
return [];
|
|
||||||
});
|
|
||||||
default:
|
default:
|
||||||
throw new Error(`Storage method is unknown: ${method}`);
|
throw new Error(`Storage method is unknown: ${method}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function pushMessageIDs(messageIDs: string[]) {
|
export async function pushMessageIDs() {
|
||||||
const method = getStorageMethod();
|
const method = getStorageMethod();
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case "git":
|
case "git":
|
||||||
const gitFileLocation = core.getInput("storageGitFileLocation", { required: true });
|
|
||||||
await fs.copyFile(
|
|
||||||
core.getInput("outputFileLocation"),
|
|
||||||
gitFileLocation
|
|
||||||
);
|
|
||||||
await exec("git config --global user.name \"Actions\"")
|
await exec("git config --global user.name \"Actions\"")
|
||||||
await exec("git config --global user.email \"noreply@users.noreply.github.com\"")
|
await exec("git config --global user.email \"noreply@users.noreply.github.com\"")
|
||||||
await exec(`git add ${gitFileLocation}`);
|
await exec("git add ./messageIDs.txt")
|
||||||
await _exec("git", ["commit", "-m", "Update stored messageIDs"])
|
await _exec("git", ["commit", "-m", "Update stored messageIDs"])
|
||||||
await exec("git push");
|
await exec("git push");
|
||||||
return true;
|
return true;
|
||||||
case "none":
|
case "none":
|
||||||
return false;
|
return false;
|
||||||
case "webhook":
|
|
||||||
const content = messageIDs.join(", ");
|
|
||||||
try {
|
|
||||||
const id = core.getInput("storageWebhookMessageID");
|
|
||||||
if (id === "" || isNaN(Number(id)))
|
|
||||||
throw new Error("Invalid argument provided for storageWebhookMessageID");
|
|
||||||
await getStorageWebhook().editMessage(
|
|
||||||
core.getInput("storageWebhookMessageID"),
|
|
||||||
content
|
|
||||||
)
|
|
||||||
core.info("Message for storage edited!")
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
core.warning("Couldn't edit storage message");
|
|
||||||
core.warning(e as Error);
|
|
||||||
core.warning("Sending a new storage message");
|
|
||||||
const message = await getStorageWebhook().send(messageIDs.join(", "));
|
|
||||||
core.info(`Message for storage sent! ID: ${message.id}`);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
default:
|
default:
|
||||||
throw new Error(`Storage method is unknown: ${method}`);
|
throw new Error(`Storage method is unknown: ${method}`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue