Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions nodecg-io-reddit/extension/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { NodeCG } from "nodecg/types/server";
import { ServiceClient } from "nodecg-io-core/extension/types";
import { emptySuccess, success, Result } from "nodecg-io-core/extension/utils/result";
import { ServiceBundle } from "nodecg-io-core/extension/serviceBundle";
import RedditAPI from "reddit-ts";

interface RedditServiceConfig {
clientId: string;
clientSecret: string;
username: string;
password: string;
}

export type RedditServiceClient = ServiceClient<RedditAPI>;

module.exports = (nodecg: NodeCG) => {
new RedditService(nodecg, "reddit", __dirname, "../reddit-schema.json").register();
};

class RedditService extends ServiceBundle<RedditServiceConfig, RedditServiceClient> {
async validateConfig(config: RedditServiceConfig): Promise<Result<void>> {
const credentials = {
user_agent: "nodecg-io",
o2a: {
client_id: config.clientId,
client_secret: config.clientSecret,
username: config.username,
password: config.password,
},
};
const client = new RedditAPI(credentials);
await client.me();
return emptySuccess();
}

async createClient(config: RedditServiceConfig): Promise<Result<RedditServiceClient>> {
const credentials = {
user_agent: "nodecg-io",
o2a: {
client_id: config.clientId,
client_secret: config.clientSecret,
username: config.username,
password: config.password,
},
};
const client = new RedditAPI(credentials);
await client.me();
this.nodecg.log.info("Successfully connected to reddit.");
return success({
getNativeClient() {
return client;
},
});
}

stopClient(_client: RedditServiceClient): void {
// Nothing to do.
}
}
14 changes: 14 additions & 0 deletions nodecg-io-reddit/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions nodecg-io-reddit/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "nodecg-io-reddit",
"version": "0.1.0",
"description": "Provides aninterface to the Reddit-API.",
"homepage": "",
"author": {
"name": "noeppi_noeppi",
"url": "https://github.com/noeppi-noeppi"
},
"scripts": {
"build": "tsc -b",
"watch": "tsc -b -w",
"clean": "tsc -b --clean"
},
"keywords": [
"",
"nodecg-bundle"
],
"nodecg": {
"compatibleRange": "^1.1.1",
"bundleDependencies": {
"nodecg-io-core": "0.1.0"
}
},
"license": "MIT",
"devDependencies": {
"@types/node": "^14.6.4",
"nodecg": "^1.6.1",
"typescript": "^4.0.2"
},
"dependencies": {
"nodecg-io-core": "0.1.0",
"reddit-ts": "noeppi-noeppi/npm-reddit-ts#build"
}
}
24 changes: 24 additions & 0 deletions nodecg-io-reddit/reddit-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"properties": {
"clientId": {
"type": "string",
"description": "The client id of the reddit app."
},
"clientSecret": {
"type": "string",
"description": "The client secret of the reddit app."
},
"username": {
"type": "string",
"description": "The username of the user who registered the app."
},
"password": {
"type": "string",
"description": "The password of the user who registered the app."
}
},
"required": ["clientId", "clientSecret", "username", "password"]
}
3 changes: 3 additions & 0 deletions nodecg-io-reddit/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../tsconfig.common.json"
}
Loading