FoxxMD / context-mod

an event-based, reddit moderation bot built on top of snoowrap and written in typescript
https://contextmod.dev
MIT License
49 stars 11 forks source link

Setting post flair action fails #63

Closed rysie closed 2 years ago

rysie commented 2 years ago
2021-12-22T11:27:38+00:00 error : ~u/xxxxxxx~ {r/xxxxxxxxxxxx} [SUB xxxxx] [CHK Flair OF submitters] [Action Flair - Set post flair] Encountered error while running Right-hand side of 'instanceof' is not an object
TypeError: Right-hand side of 'instanceof' is not an object
at FlairAction.process (CWD/src/Action/SubmissionAction/FlairAction.js:32:18)
at FlairAction.handle (CWD/src/Action/index.js:69:40)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SubmissionCheck.runActions (CWD/src/Check/index.js:257:25)
at async Manager.runChecks (CWD/src/Subreddit/Manager.js:478:34)
at async action (CWD/src/Web/Server/routes/authenticated/user/index.js:81:9)
at async wrappedMiddleware (CWD/node_modules/@awaitjs/express/index.js:64:9)

Affected line src/Action/SubmissionAction/FlairAction.ts:35:

        if (item instanceof Submission) {
            .....
FoxxMD commented 2 years ago

👍 this is due to the way Submission is imported (and a general issue with snoowrap's typescript typings...)

import {Submission} from 'snoowrap';

This just imports the Submission typing

To actually import the Submission object (for use with instanceof) the import needs to be

import Submission from "snoowrap/dist/objects/Submission";

I did a big refactor awhile back to fix all of these but my IDE sometimes still auto imports the typing instead of the object. oops. Will get this fixed today (or please send a PR!)

rysie commented 2 years ago

OK I created a PR that fixes it + adds submission flair action.