This repository was archived by the owner on Apr 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Add a reddit service #137
Merged
Merged
Add a reddit service #137
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "../tsconfig.common.json" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.