Skip to content

Commit c8c74de

Browse files
favnarenovate-bot
andauthored
feat: add partial dm channel argument (#288)
Co-authored-by: Renovate Bot <[email protected]>
1 parent 30ee759 commit c8c74de

File tree

6 files changed

+543
-401
lines changed

6 files changed

+543
-401
lines changed

package.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,30 @@
3737
"tslib": "^2.3.1"
3838
},
3939
"devDependencies": {
40-
"@commitlint/cli": "^13.1.0",
41-
"@commitlint/config-conventional": "^13.1.0",
40+
"@commitlint/cli": "^13.2.0",
41+
"@commitlint/config-conventional": "^13.2.0",
4242
"@favware/npm-deprecate": "^1.0.2",
4343
"@favware/rollup-type-bundler": "^1.0.3",
4444
"@sapphire/eslint-config": "^3.2.3",
4545
"@sapphire/prettier-config": "^1.1.6",
4646
"@sapphire/ts-config": "^3.0.0",
4747
"@types/jest": "^27.0.2",
4848
"@types/node": "^16.9.1",
49-
"@types/ws": "^7.4.7",
49+
"@types/ws": "^8.2.0",
5050
"cz-conventional-changelog": "^3.3.0",
5151
"discord.js": "^13.1.0",
52-
"gen-esm-wrapper": "^1.1.2",
52+
"gen-esm-wrapper": "^1.1.3",
5353
"husky": "^7.0.2",
54-
"jest": "^27.1.0",
55-
"jest-circus": "^27.1.0",
54+
"jest": "^27.2.3",
55+
"jest-circus": "^27.2.3",
5656
"lint-staged": "^11.1.2",
5757
"pretty-quick": "^3.1.1",
58-
"rollup": "^2.56.3",
58+
"rollup": "^2.57.0",
5959
"rollup-plugin-version-injector": "^1.3.3",
6060
"standard-version": "^9.3.1",
6161
"ts-jest": "^27.0.5",
6262
"ts-node": "^10.2.1",
63-
"typedoc": "^0.21.9",
63+
"typedoc": "^0.22.4",
6464
"typescript": "^4.4.3"
6565
},
6666
"repository": {
@@ -72,8 +72,8 @@
7272
"!dist/*.tsbuildinfo"
7373
],
7474
"engines": {
75-
"node": ">=12",
76-
"npm": ">=6"
75+
"node": ">=16.6.0",
76+
"npm": ">=7.24.1"
7777
},
7878
"keywords": [
7979
"bot",
@@ -105,18 +105,18 @@
105105
"access": "public"
106106
},
107107
"resolutions": {
108-
"acorn": "^8.4.1",
108+
"acorn": "^8.5.0",
109109
"ansi-regex": "^5.0.1",
110110
"minimist": "^1.2.5",
111111
"kind-of": "^6.0.3",
112112
"jest-environment-jsdom": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.1.tgz",
113113
"jest-jasmine2": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.1.tgz",
114114
"dot-prop": "^6.0.1",
115115
"lodash": "^4.17.21",
116-
"marked": "^2.1.3",
116+
"marked": "^3.0.4",
117117
"merge": "^2.1.1",
118118
"trim": "^1.0.1",
119-
"trim-newlines": "^3.0.1"
119+
"trim-newlines": "^4.0.2"
120120
},
121121
"prettier": "@sapphire/prettier-config"
122122
}

src/arguments/CorePartialDMChannel.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { PieceContext } from '@sapphire/pieces';
2+
import type { DMChannel, PartialDMChannel } from 'discord.js';
3+
import { resolvePartialDMChannel } from '../lib/resolvers';
4+
import { Argument, ArgumentContext, ArgumentResult } from '../lib/structures/Argument';
5+
6+
export class CoreArgument extends Argument<DMChannel | PartialDMChannel> {
7+
public constructor(context: PieceContext) {
8+
super(context, { name: 'partialDMChannel' });
9+
}
10+
11+
public run(parameter: string, context: ArgumentContext): ArgumentResult<DMChannel | PartialDMChannel> {
12+
const resolved = resolvePartialDMChannel(parameter, context.message);
13+
if (resolved.success) return this.ok(resolved.value);
14+
return this.error({
15+
parameter,
16+
identifier: resolved.error,
17+
message: 'The argument did not resolve to a Partial DM channel.',
18+
context
19+
});
20+
}
21+
}

src/lib/resolvers/dmChannel.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ export function resolveDMChannel(
1010
): Result<DMChannel, Identifiers.ArgumentChannelError | Identifiers.ArgumentDMChannelError> {
1111
const result = resolveChannel(parameter, message);
1212
if (!result.success) return result;
13-
if (isDMChannel(result.value)) return ok(result.value);
13+
if (isDMChannel(result.value) && !result.value.partial) return ok(result.value);
1414
return err(Identifiers.ArgumentDMChannelError);
1515
}

src/lib/resolvers/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export * from './integer';
1818
export * from './member';
1919
export * from './message';
2020
export * from './number';
21+
export * from './partialDMChannel';
2122
export * from './role';
2223
export * from './string';
2324
export * from './user';

src/lib/resolvers/partialDMChannel.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { isDMChannel } from '@sapphire/discord.js-utilities';
2+
import type { DMChannel, Message, PartialDMChannel } from 'discord.js';
3+
import { Identifiers } from '../errors/Identifiers';
4+
import { err, ok, Result } from '../parsers/Result';
5+
import { resolveChannel } from './channel';
6+
7+
export function resolvePartialDMChannel(
8+
parameter: string,
9+
message: Message
10+
): Result<DMChannel | PartialDMChannel, Identifiers.ArgumentChannelError | Identifiers.ArgumentDMChannelError> {
11+
const result = resolveChannel(parameter, message);
12+
if (!result.success) return result;
13+
if (isDMChannel(result.value)) return ok(result.value);
14+
return err(Identifiers.ArgumentDMChannelError);
15+
}

0 commit comments

Comments
 (0)