Skip to content

Commit

Permalink
feat: add partial dm channel argument (#288)
Browse files Browse the repository at this point in the history
Co-authored-by: Renovate Bot <bot@renovateapp.com>
  • Loading branch information
favna and renovate-bot committed Sep 28, 2021
1 parent 30ee759 commit c8c74de
Show file tree
Hide file tree
Showing 6 changed files with 543 additions and 401 deletions.
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,30 @@
"tslib": "^2.3.1"
},
"devDependencies": {
"@commitlint/cli": "^13.1.0",
"@commitlint/config-conventional": "^13.1.0",
"@commitlint/cli": "^13.2.0",
"@commitlint/config-conventional": "^13.2.0",
"@favware/npm-deprecate": "^1.0.2",
"@favware/rollup-type-bundler": "^1.0.3",
"@sapphire/eslint-config": "^3.2.3",
"@sapphire/prettier-config": "^1.1.6",
"@sapphire/ts-config": "^3.0.0",
"@types/jest": "^27.0.2",
"@types/node": "^16.9.1",
"@types/ws": "^7.4.7",
"@types/ws": "^8.2.0",
"cz-conventional-changelog": "^3.3.0",
"discord.js": "^13.1.0",
"gen-esm-wrapper": "^1.1.2",
"gen-esm-wrapper": "^1.1.3",
"husky": "^7.0.2",
"jest": "^27.1.0",
"jest-circus": "^27.1.0",
"jest": "^27.2.3",
"jest-circus": "^27.2.3",
"lint-staged": "^11.1.2",
"pretty-quick": "^3.1.1",
"rollup": "^2.56.3",
"rollup": "^2.57.0",
"rollup-plugin-version-injector": "^1.3.3",
"standard-version": "^9.3.1",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1",
"typedoc": "^0.21.9",
"typedoc": "^0.22.4",
"typescript": "^4.4.3"
},
"repository": {
Expand All @@ -72,8 +72,8 @@
"!dist/*.tsbuildinfo"
],
"engines": {
"node": ">=12",
"npm": ">=6"
"node": ">=16.6.0",
"npm": ">=7.24.1"
},
"keywords": [
"bot",
Expand Down Expand Up @@ -105,18 +105,18 @@
"access": "public"
},
"resolutions": {
"acorn": "^8.4.1",
"acorn": "^8.5.0",
"ansi-regex": "^5.0.1",
"minimist": "^1.2.5",
"kind-of": "^6.0.3",
"jest-environment-jsdom": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.1.tgz",
"jest-jasmine2": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.1.tgz",
"dot-prop": "^6.0.1",
"lodash": "^4.17.21",
"marked": "^2.1.3",
"marked": "^3.0.4",
"merge": "^2.1.1",
"trim": "^1.0.1",
"trim-newlines": "^3.0.1"
"trim-newlines": "^4.0.2"
},
"prettier": "@sapphire/prettier-config"
}
21 changes: 21 additions & 0 deletions src/arguments/CorePartialDMChannel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { PieceContext } from '@sapphire/pieces';
import type { DMChannel, PartialDMChannel } from 'discord.js';
import { resolvePartialDMChannel } from '../lib/resolvers';
import { Argument, ArgumentContext, ArgumentResult } from '../lib/structures/Argument';

export class CoreArgument extends Argument<DMChannel | PartialDMChannel> {
public constructor(context: PieceContext) {
super(context, { name: 'partialDMChannel' });
}

public run(parameter: string, context: ArgumentContext): ArgumentResult<DMChannel | PartialDMChannel> {
const resolved = resolvePartialDMChannel(parameter, context.message);
if (resolved.success) return this.ok(resolved.value);
return this.error({
parameter,
identifier: resolved.error,
message: 'The argument did not resolve to a Partial DM channel.',
context
});
}
}
2 changes: 1 addition & 1 deletion src/lib/resolvers/dmChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export function resolveDMChannel(
): Result<DMChannel, Identifiers.ArgumentChannelError | Identifiers.ArgumentDMChannelError> {
const result = resolveChannel(parameter, message);
if (!result.success) return result;
if (isDMChannel(result.value)) return ok(result.value);
if (isDMChannel(result.value) && !result.value.partial) return ok(result.value);
return err(Identifiers.ArgumentDMChannelError);
}
1 change: 1 addition & 0 deletions src/lib/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export * from './integer';
export * from './member';
export * from './message';
export * from './number';
export * from './partialDMChannel';
export * from './role';
export * from './string';
export * from './user';
15 changes: 15 additions & 0 deletions src/lib/resolvers/partialDMChannel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { isDMChannel } from '@sapphire/discord.js-utilities';
import type { DMChannel, Message, PartialDMChannel } from 'discord.js';
import { Identifiers } from '../errors/Identifiers';
import { err, ok, Result } from '../parsers/Result';
import { resolveChannel } from './channel';

export function resolvePartialDMChannel(
parameter: string,
message: Message
): Result<DMChannel | PartialDMChannel, Identifiers.ArgumentChannelError | Identifiers.ArgumentDMChannelError> {
const result = resolveChannel(parameter, message);
if (!result.success) return result;
if (isDMChannel(result.value)) return ok(result.value);
return err(Identifiers.ArgumentDMChannelError);
}
Loading

0 comments on commit c8c74de

Please sign in to comment.