Implement basic actions #1

This commit is contained in:
FoxxMD
2021-06-01 23:39:18 -04:00
parent 69eea271cb
commit c6857999bc
4 changed files with 17 additions and 5 deletions

View File

@@ -5,6 +5,10 @@ import Snoowrap, {Comment, Submission} from "snoowrap";
export class LockAction extends Action {
name?: string = 'Lock';
async handle(item: Comment|Submission, client: Snoowrap): Promise<void> {
if (item instanceof Submission) {
// @ts-ignore
await item.lock();
}
}
}

View File

@@ -5,6 +5,8 @@ import Snoowrap, {Comment, Submission} from "snoowrap";
export class RemoveAction extends Action {
name?: string = 'Remove';
async handle(item: Comment|Submission, client: Snoowrap): Promise<void> {
// @ts-ignore
await item.remove();
}
}

View File

@@ -11,7 +11,9 @@ export class ReportAction extends Action {
this.content = options.content;
}
async handle(item: Comment|Submission, client: Snoowrap): Promise<void> {
async handle(item: Comment | Submission, client: Snoowrap): Promise<void> {
// @ts-ignore
await item.report({reason: content});
}
}

View File

@@ -3,8 +3,8 @@ import Action, {ActionJSONConfig} from "../index";
import Snoowrap, {Comment, Submission} from "snoowrap";
export class FlairAction extends Action {
text?: string;
css?: string;
text: string;
css: string;
name?: string = 'Flair';
constructor(options: FlairActionOptions) {
@@ -12,11 +12,15 @@ export class FlairAction extends Action {
if (options.text === undefined && options.css === undefined) {
throw new Error('Must define either text or css on FlairAction');
}
this.text = options.text;
this.css = options.css;
this.text = options.text || '';
this.css = options.css || '';
}
async handle(item: Comment | Submission, client: Snoowrap): Promise<void> {
if (item instanceof Submission) {
// @ts-ignore
await item.assignFlair({text: this.text, cssClass: this.css})
}
}
}