Post: allow adding linebreaks with \n
This commit is contained in:
parent
de05352f18
commit
28bf7ecf67
1 changed files with 24 additions and 12 deletions
|
@ -21,7 +21,7 @@ export class PostPlugin extends Plugin {
|
||||||
return {
|
return {
|
||||||
permissions: {
|
permissions: {
|
||||||
post: false,
|
post: false,
|
||||||
edit: false
|
edit: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
overrides: [
|
overrides: [
|
||||||
|
@ -29,13 +29,17 @@ export class PostPlugin extends Plugin {
|
||||||
level: ">=100",
|
level: ">=100",
|
||||||
permissions: {
|
permissions: {
|
||||||
post: true,
|
post: true,
|
||||||
edit: true
|
edit: true,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected formatContent(str) {
|
||||||
|
return str.replace(/\\n/g, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* COMMAND: Post a message as the bot to the specified channel
|
* COMMAND: Post a message as the bot to the specified channel
|
||||||
*/
|
*/
|
||||||
|
@ -47,7 +51,7 @@ export class PostPlugin extends Plugin {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = args.content || undefined;
|
const content = (args.content && this.formatContent(args.content)) || undefined;
|
||||||
let downloadedAttachment;
|
let downloadedAttachment;
|
||||||
let file;
|
let file;
|
||||||
|
|
||||||
|
@ -55,7 +59,7 @@ export class PostPlugin extends Plugin {
|
||||||
downloadedAttachment = await downloadFile(msg.attachments[0].url);
|
downloadedAttachment = await downloadFile(msg.attachments[0].url);
|
||||||
file = {
|
file = {
|
||||||
name: msg.attachments[0].filename,
|
name: msg.attachments[0].filename,
|
||||||
file: await fsp.readFile(downloadedAttachment.path)
|
file: await fsp.readFile(downloadedAttachment.path),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +80,11 @@ export class PostPlugin extends Plugin {
|
||||||
* COMMAND: Post a message with an embed as the bot to the specified channel
|
* COMMAND: Post a message with an embed as the bot to the specified channel
|
||||||
*/
|
*/
|
||||||
@d.command("post_embed", "<channel:channel>", {
|
@d.command("post_embed", "<channel:channel>", {
|
||||||
options: [{ name: "title", type: "string" }, { name: "content", type: "string" }, { name: "color", type: "string" }]
|
options: [
|
||||||
|
{ name: "title", type: "string" },
|
||||||
|
{ name: "content", type: "string" },
|
||||||
|
{ name: "color", type: "string" },
|
||||||
|
],
|
||||||
})
|
})
|
||||||
@d.permission("post")
|
@d.permission("post")
|
||||||
async postEmbedCmd(msg: Message, args: { channel: Channel; title?: string; content?: string; color?: string }) {
|
async postEmbedCmd(msg: Message, args: { channel: Channel; title?: string; content?: string; color?: string }) {
|
||||||
|
@ -103,7 +111,7 @@ export class PostPlugin extends Plugin {
|
||||||
|
|
||||||
const embed: EmbedBase = {};
|
const embed: EmbedBase = {};
|
||||||
if (args.title) embed.title = args.title;
|
if (args.title) embed.title = args.title;
|
||||||
if (args.content) embed.description = args.content;
|
if (args.content) embed.description = this.formatContent(args.content);
|
||||||
if (color) embed.color = color;
|
if (color) embed.color = color;
|
||||||
|
|
||||||
const createdMsg = await args.channel.createMessage({ embed });
|
const createdMsg = await args.channel.createMessage({ embed });
|
||||||
|
@ -127,14 +135,18 @@ export class PostPlugin extends Plugin {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.bot.editMessage(savedMessage.channel_id, savedMessage.id, args.content);
|
await this.bot.editMessage(savedMessage.channel_id, savedMessage.id, this.formatContent(args.content));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* COMMAND: Edit the specified message with an embed posted by the bot
|
* COMMAND: Edit the specified message with an embed posted by the bot
|
||||||
*/
|
*/
|
||||||
@d.command("edit_embed", "<messageId:string>", {
|
@d.command("edit_embed", "<messageId:string>", {
|
||||||
options: [{ name: "title", type: "string" }, { name: "content", type: "string" }, { name: "color", type: "string" }]
|
options: [
|
||||||
|
{ name: "title", type: "string" },
|
||||||
|
{ name: "content", type: "string" },
|
||||||
|
{ name: "color", type: "string" },
|
||||||
|
],
|
||||||
})
|
})
|
||||||
@d.permission("edit")
|
@d.permission("edit")
|
||||||
async editEmbedCmd(msg: Message, args: { messageId: string; title?: string; content?: string; color?: string }) {
|
async editEmbedCmd(msg: Message, args: { messageId: string; title?: string; content?: string; color?: string }) {
|
||||||
|
@ -162,7 +174,7 @@ export class PostPlugin extends Plugin {
|
||||||
|
|
||||||
const embed: EmbedBase = savedMessage.data.embeds[0];
|
const embed: EmbedBase = savedMessage.data.embeds[0];
|
||||||
if (args.title) embed.title = args.title;
|
if (args.title) embed.title = args.title;
|
||||||
if (args.content) embed.description = args.content;
|
if (args.content) embed.description = this.formatContent(args.content);
|
||||||
if (color) embed.color = color;
|
if (color) embed.color = color;
|
||||||
|
|
||||||
await this.bot.editMessage(savedMessage.channel_id, savedMessage.id, { embed });
|
await this.bot.editMessage(savedMessage.channel_id, savedMessage.id, { embed });
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue