Skip to content

Commit 9766bea

Browse files
Replace master with main (#7)
* Replace master with main * Update djs command's description Co-authored-by: Ben <BenjammingKirby@users.noreply.github.com>
1 parent b26a5ae commit 9766bea

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "tph_docs_bot",
33
"version": "1.0.0",
44
"description": "A bot made for TPH (The Programmers Hangout - discord.gg/programming) ",
5-
"main": "index.js",
5+
"main": "dist/bot.js",
66
"scripts": {
77
"tsc": "tsc",
88
"test": "echo \"Error: no test specified\" && exit 1"
@@ -12,6 +12,7 @@
1212
"dependencies": {
1313
"discord-akairo": "^8.1.0",
1414
"discord.js": "^12.5.1",
15+
"discord.js-docs": "BenjammingKirby/discord.js-docs#types",
1516
"dotenv": "^8.2.0",
1617
"pm2": "^4.5.1"
1718
},
@@ -27,4 +28,4 @@
2728
"ts-node-dev": "^1.1.1",
2829
"typescript": "^4.1.3"
2930
}
30-
}
31+
}

src/commands/docs/djs.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
import { Message } from "discord.js";
1+
import type { Message } from "discord.js";
22
import { Command } from "discord-akairo";
3-
import fetch from "node-fetch";
4-
import { stringify } from "querystring";
5-
3+
import Doc from "discord.js-docs";
64
export default class DiscordCommand extends Command {
75
public constructor() {
86
super("djs-docs", {
97
aliases: ["djs", "d.js", "djsdocs", "discordjs", "discord.js"],
108
description: {
11-
content: "Searches discord.js documentation for what it thinks you mean. Defaults to using the master branch",
9+
content: "Searches discord.js documentation for what it thinks you mean. Defaults to using the main branch",
1210
usage: "<query> <optional branch>",
13-
examples: ["Guild#Members", "Guild#Members master"],
11+
examples: ["Guild#Members", "Guild#Members main"],
1412
},
1513
channel: "guild",
1614
clientPermissions: ["EMBED_LINKS"],
@@ -27,7 +25,7 @@ export default class DiscordCommand extends Command {
2725
},
2826
{
2927
id: "branch",
30-
flag: ["master", "stable"],
28+
flag: ["main", "stable"],
3129
match: "flag",
3230
default: "stable",
3331
},
@@ -38,12 +36,13 @@ export default class DiscordCommand extends Command {
3836
public async exec(message: Message, { query, branch }: { query: string; branch: string }): Promise<Message | Message[]> {
3937
const str = query.split(" ");
4038

41-
const source = branch ? "stable" : "master";
42-
43-
//src and q being the params accepted by the API
44-
const queryString = stringify({ src: source, q: str.join(" ") });
45-
const res = await fetch(`https://djsdocs.sorta.moe/v2/embed?${queryString}`);
46-
const embedObj = await res.json();
39+
const source = branch ? "stable" : "main";
40+
const doc = await Doc.fetch(source, {force: true});
41+
const resultEmbed = doc.resolveEmbed(str.join("#"));
42+
if (!resultEmbed) return;
43+
// For typings of djs' embeds
44+
const timeStampDate = new Date(resultEmbed.timestamp);
45+
const embedObj = {...resultEmbed, timestamp: timeStampDate} ;
4746

4847
if (!embedObj) return;
4948

yarn.lock

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,11 @@ commander@2.15.1:
592592
resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f"
593593
integrity sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==
594594

595+
common-tags@^1.8.0:
596+
version "1.8.0"
597+
resolved "https://registry.yarnpkg.com/common-tags/-/common-tags-1.8.0.tgz#8e3153e542d4a39e9b10554434afaaf98956a937"
598+
integrity sha512-6P6g0uetGpW/sdyUy/iQQCbFF0kWVMSIVSyYz7Zgjcgh8mgw8PQzDNZeyZ5DQ2gM7LBoZPHmnjz8rUthkBG5tw==
599+
595600
concat-map@0.0.1:
596601
version "0.0.1"
597602
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
@@ -737,6 +742,14 @@ discord-akairo@^8.1.0:
737742
resolved "https://registry.yarnpkg.com/discord-akairo/-/discord-akairo-8.1.0.tgz#9f3d910e12c197d40d3522a3a93679e2a746a6ca"
738743
integrity sha512-INWYmHo6NgyYx1ZKGSCmgznVfvkXpWGj4fGCGjO8IPkZ06Bidb9YKr4rXy2lwG0kprCjvqY0qbbhcw6N050abQ==
739744

745+
discord.js-docs@BenjammingKirby/discord.js-docs#types:
746+
version "0.1.2"
747+
resolved "https://codeload.github.com/BenjammingKirby/discord.js-docs/tar.gz/f8a89e4f2ae9adff2104a79e501e59aadc8e9dbe"
748+
dependencies:
749+
common-tags "^1.8.0"
750+
fuse.js "^3.4.6"
751+
node-fetch "^2.6.0"
752+
740753
discord.js@^12.5.1:
741754
version "12.5.1"
742755
resolved "https://registry.yarnpkg.com/discord.js/-/discord.js-12.5.1.tgz#992b45753e3815526a279914ccc281d3496f5990"
@@ -1097,6 +1110,11 @@ functional-red-black-tree@^1.0.1:
10971110
resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327"
10981111
integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=
10991112

1113+
fuse.js@^3.4.6:
1114+
version "3.6.1"
1115+
resolved "https://registry.yarnpkg.com/fuse.js/-/fuse.js-3.6.1.tgz#7de85fdd6e1b3377c23ce010892656385fd9b10c"
1116+
integrity sha512-hT9yh/tiinkmirKrlv4KWOjztdoZo1mx9Qh4KvWqC7isoXwdUY3PNWUxceF4/qO9R6riA2C29jdTOeQOIROjgw==
1117+
11001118
get-stdin@^4.0.1:
11011119
version "4.0.1"
11021120
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe"
@@ -1543,7 +1561,7 @@ netmask@^1.0.6:
15431561
resolved "https://registry.yarnpkg.com/netmask/-/netmask-1.0.6.tgz#20297e89d86f6f6400f250d9f4f6b4c1945fcd35"
15441562
integrity sha1-ICl+idhvb2QA8lDZ9Pa0wZRfzTU=
15451563

1546-
node-fetch@^2.6.1:
1564+
node-fetch@^2.6.0, node-fetch@^2.6.1:
15471565
version "2.6.1"
15481566
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
15491567
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==

0 commit comments

Comments
 (0)