remove mojang-api-js package

This commit is contained in:
kdh8219 2023-04-28 23:38:58 +09:00
parent 7e079b90bf
commit d978933936
4 changed files with 63 additions and 22 deletions

View file

@ -1,9 +1,9 @@
{
"dependencies": {
"axios": "^1.4.0",
"discord.js": "^14.6.0",
"dotenv": "^16.0.3",
"firebase-admin": "^11.2.0",
"mojang-api-js": "^1.0.1",
"nodemon": "^2.0.20",
"typescritp": "^1.0.0"
},

View file

@ -1,10 +1,14 @@
import { Collection, SlashCommandBuilder } from "discord.js";
import {
Collection,
SlashCommandBuilder,
ChatInputCommandInteraction,
} from "discord.js";
import commands from "./command/commands.js";
export type TCommand = {
data: SlashCommandBuilder;
execute: Function;
execute: (interaction: ChatInputCommandInteraction) => void;
};
export function getCommands(): Collection<string, TCommand> {
const commandColection = new Collection<string, TCommand>();

View file

@ -1,16 +1,18 @@
import Client from "mojang-api-js";
import axios from "axios";
import TwoWayMmap from "../utils/two-way-map.js";
class MojangAPI {
private mojangAPI: Client = new Client();
private cached: TwoWayMmap<string, string> = new TwoWayMmap<string, string>(); // uuid, id
async getIdFromUUID(minecraft_uuid: string): Promise<string> {
let id = this.cached.get_by_first(minecraft_uuid);
if (id) return id;
let mcid = await this.mojangAPI.uuidToName(minecraft_uuid);
id = mcid.id;
const request = await axios.get(
`https://api.mojang.com/user/profile/${minecraft_uuid}`
);
id = JSON.parse(request.data).name;
if (!id) throw new Error("Failed to get minecraft id from api");
@ -21,8 +23,10 @@ class MojangAPI {
let uuid = this.cached.get_by_second(minecraft_id);
if (uuid) return uuid;
let mcid = await this.mojangAPI.nameToUuid(minecraft_id);
uuid = mcid.id;
const request = await axios.get(
`https://api.mojang.com/users/profiles/minecraft/${minecraft_id}`
);
uuid = JSON.parse(request.data).id;
if (!uuid) throw new Error("Failed to get minecraft id from api");
this.cached.remove_by_first(uuid);

View file

@ -440,6 +440,20 @@ async-retry@^1.3.3:
dependencies:
retry "0.13.1"
asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==
axios@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.4.0.tgz#38a7bf1224cd308de271146038b551d725f0be1f"
integrity sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==
dependencies:
follow-redirects "^1.15.0"
form-data "^4.0.0"
proxy-from-env "^1.1.0"
balanced-match@^1.0.0:
version "1.0.2"
resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz"
@ -506,11 +520,6 @@ catharsis@^0.9.0:
dependencies:
lodash "^4.17.15"
centra@^2.4.2:
version "2.5.0"
resolved "https://registry.npmjs.org/centra/-/centra-2.5.0.tgz"
integrity sha512-CnSF1HD8vOOgNbE4P2fZEhdhfAohvpcF3DSdSvEcSHDAZvr+Xfw73isT8SXJJc3VMBqSwjXhr29/ikHUgFcypg==
chalk@^4.0.0:
version "4.1.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
@ -555,6 +564,13 @@ color-name@~1.1.4:
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
combined-stream@^1.0.8:
version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
dependencies:
delayed-stream "~1.0.0"
compressible@^2.0.12:
version "2.0.18"
resolved "https://registry.yarnpkg.com/compressible/-/compressible-2.0.18.tgz#af53cca6b070d4c3c0750fbd77286a6d7cc46fba"
@ -586,6 +602,11 @@ deep-is@~0.1.3:
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.4.tgz#a6f2dce612fadd2ef1f519b73551f17e85199831"
integrity sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==
delayed-stream@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==
discord-api-types@^0.37.12:
version "0.37.14"
resolved "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.14.tgz"
@ -774,6 +795,20 @@ firebase-admin@^11.2.0:
"@google-cloud/firestore" "^6.4.0"
"@google-cloud/storage" "^6.5.2"
follow-redirects@^1.15.0:
version "1.15.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==
form-data@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"
fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@ -1247,7 +1282,7 @@ mime-db@1.52.0, "mime-db@>= 1.43.0 < 2":
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==
mime-types@^2.0.8:
mime-types@^2.0.8, mime-types@^2.1.12:
version "2.1.35"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"
integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==
@ -1283,13 +1318,6 @@ mkdirp@^1.0.4:
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==
mojang-api-js@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/mojang-api-js/-/mojang-api-js-1.0.1.tgz"
integrity sha512-E15UGkbAU16U4SaWrYSdqBwiTM1kkxRiiaK/lS6S4oInWcxIrd0hzU+ITh+1DMYwUgTbKDZ//U77cF+fb0jf9w==
dependencies:
centra "^2.4.2"
ms@2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
@ -1432,6 +1460,11 @@ protobufjs@7.1.2, protobufjs@^7.0.0:
"@types/node" ">=13.7.0"
long "^5.0.0"
proxy-from-env@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==
pseudomap@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"