Skip to content

Commit 20acc12

Browse files
committed
Add footer to comment/ban content
Closes #5
1 parent 60c0569 commit 20acc12

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/Action/BanAction.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Action from "./index";
33
import Snoowrap, {Comment, Submission} from "snoowrap";
44
import {RuleResult} from "../Rule";
55
import {renderContent} from "../Utils/SnoowrapUtils";
6+
import {generateFooter} from "../util";
67

78
export class BanAction extends Action {
89

@@ -32,6 +33,9 @@ export class BanAction extends Action {
3233
async process(item: Comment | Submission, ruleResults: RuleResult[]): Promise<void> {
3334
const content = this.message === undefined ? undefined : await this.resources.getContent(this.message, item.subreddit);
3435
const renderedContent = content === undefined ? undefined : await renderContent(content, item, ruleResults);
36+
37+
const footer = await generateFooter(item);
38+
3539
let banPieces = [];
3640
banPieces.push(`Message: ${renderedContent === undefined ? 'None' : `${renderedContent.length > 100 ? `\r\n${renderedContent}` : renderedContent}`}`);
3741
banPieces.push(`Reason: ${this.reason || 'None'}`);
@@ -42,7 +46,7 @@ export class BanAction extends Action {
4246
// @ts-ignore
4347
await item.subreddit.banUser({
4448
name: item.author.id,
45-
banMessage: renderedContent,
49+
banMessage: renderedContent === undefined ? undefined : `${renderedContent}${footer}`,
4650
banReason: this.reason,
4751
banNote: this.note,
4852
duration: this.duration

src/Action/CommentAction.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Submission from "snoowrap/dist/objects/Submission";
44
import {renderContent} from "../Utils/SnoowrapUtils";
55
import {RequiredRichContent, RichContent} from "../Common/interfaces";
66
import {RuleResult} from "../Rule";
7+
import {generateFooter} from "../util";
78

89
export class CommentAction extends Action {
910
content: string;
@@ -39,8 +40,10 @@ export class CommentAction extends Action {
3940
return;
4041
}
4142

43+
const footer = await generateFooter(item);
44+
4245
// @ts-ignore
43-
const reply: Comment = await item.reply(renderedContent);
46+
const reply: Comment = await item.reply(`${renderedContent}${footer}`);
4447
if (this.lock) {
4548
if (!this.dryRun) {
4649
// snoopwrap typing issue, thinks comments can't be locked

src/util.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,3 +388,11 @@ export const parseFromJsonOrYamlToObject = (content: string): [object?, Error?,
388388
}
389389
return [obj, jsonErr, yamlErr];
390390
}
391+
392+
export const generateFooter = async (item: Submission | Comment) => {
393+
const subName = await item.subreddit.display_name;
394+
// TODO customize modmail message based on action being peformed
395+
const modmailLink = `https://www.reddit.com/message/compose?to=%2Fr%2F${subName}&message=Reminder:%20If+you+are+messaging+about+a+post+removal+,+please+include+the%20post%20URL%20somewhere%20in%20the%20message.`
396+
397+
return `\r\n*****\r\nThis action was performed by [a bot.](https://www.reddit.com/r/ContextModBot/comments/o1dugk/introduction_to_contextmodbot_and_rcb/) Mention a moderator or [send a modmail](${modmailLink}) if you any ideas, questions , or concerns about this action.`
398+
}

0 commit comments

Comments
 (0)