mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 22:21:51 +00:00
post: use content as raw embed source in !post_embed with --raw/-r switch
This commit is contained in:
parent
cbcd2bd67d
commit
279a8fe7ae
1 changed files with 25 additions and 2 deletions
|
@ -13,6 +13,7 @@ import {
|
||||||
deactivateMentions,
|
deactivateMentions,
|
||||||
createChunkedMessage,
|
createChunkedMessage,
|
||||||
stripObjectToScalars,
|
stripObjectToScalars,
|
||||||
|
isValidEmbed,
|
||||||
} from "../utils";
|
} from "../utils";
|
||||||
import { GuildSavedMessages } from "../data/GuildSavedMessages";
|
import { GuildSavedMessages } from "../data/GuildSavedMessages";
|
||||||
import { ZeppelinPlugin } from "./ZeppelinPlugin";
|
import { ZeppelinPlugin } from "./ZeppelinPlugin";
|
||||||
|
@ -278,6 +279,7 @@ export class PostPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
{ name: "content", type: "string" },
|
{ name: "content", type: "string" },
|
||||||
{ name: "color", type: "string" },
|
{ name: "color", type: "string" },
|
||||||
{ name: "schedule", type: "string" },
|
{ name: "schedule", type: "string" },
|
||||||
|
{ name: "raw", isSwitch: true, shortcut: "r" },
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
@d.permission("can_post")
|
@d.permission("can_post")
|
||||||
|
@ -290,6 +292,7 @@ export class PostPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
content?: string;
|
content?: string;
|
||||||
color?: string;
|
color?: string;
|
||||||
schedule?: string;
|
schedule?: string;
|
||||||
|
raw?: boolean;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
if (!(args.channel instanceof TextChannel)) {
|
if (!(args.channel instanceof TextChannel)) {
|
||||||
|
@ -315,11 +318,31 @@ export class PostPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
color = parseInt(colorMatch[1], 16);
|
color = parseInt(colorMatch[1], 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
const embed: EmbedBase = {};
|
let embed: EmbedBase = {};
|
||||||
if (args.title) embed.title = args.title;
|
if (args.title) embed.title = args.title;
|
||||||
if (content) embed.description = this.formatContent(content);
|
|
||||||
if (color) embed.color = color;
|
if (color) embed.color = color;
|
||||||
|
|
||||||
|
if (content) {
|
||||||
|
if (args.raw) {
|
||||||
|
let parsed;
|
||||||
|
try {
|
||||||
|
parsed = JSON.parse(content);
|
||||||
|
} catch (e) {
|
||||||
|
this.sendErrorMessage(msg.channel, "Syntax error in embed JSON");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isValidEmbed(parsed)) {
|
||||||
|
this.sendErrorMessage(msg.channel, "Embed is not valid");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
embed = Object.assign({}, embed, parsed);
|
||||||
|
} else {
|
||||||
|
embed.description = this.formatContent(content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (args.schedule) {
|
if (args.schedule) {
|
||||||
// Schedule the post to be posted later
|
// Schedule the post to be posted later
|
||||||
const postAt = this.parseScheduleTime(args.schedule);
|
const postAt = this.parseScheduleTime(args.schedule);
|
||||||
|
|
Loading…
Add table
Reference in a new issue