|
1 | | -/* eslint-disable @typescript-eslint/naming-convention */ |
2 | | -import { get } from "superagent"; |
3 | | -import { getOwner } from "./api/Bot"; |
4 | | -import ZhycorpError from "./util/ZhycorpError"; |
5 | | -import type { Bot } from "./interfaces"; |
6 | | - |
7 | | -export class ZhycorpWrapper { |
8 | | - private readonly baseURL = "https://bot.zhycorp.com"; |
9 | | - public async getBot(id: string): Promise<Bot> { |
10 | | - const USER_PATTERN = /\d{17,19}/g; |
11 | | - if (!USER_PATTERN.test(id)) throw Error("Invalid user id"); |
12 | | - |
13 | | - const { body: result } = await get(this.baseURL); |
14 | | - if (!result[id]) throw new ZhycorpError("Not Found"); |
15 | | - const bot = result[id]; |
16 | | - const user = await getOwner(id); |
17 | | - return { |
18 | | - approved: bot.approved, |
19 | | - botID: bot.botID, |
20 | | - owner: { |
21 | | - userID: bot.ownerID, |
22 | | - userTag: user |
23 | | - }, |
24 | | - prefix: bot.prefix, |
25 | | - registered: bot.registered |
26 | | - }; |
27 | | - } |
28 | | -} |
| 1 | +/* eslint-disable @typescript-eslint/naming-convention */ |
| 2 | +import { get } from "superagent"; |
| 3 | +import { getOwner } from "./api/Bot"; |
| 4 | +import ZhycorpError from "./util/ZhycorpError"; |
| 5 | +import { Bot } from "./interfaces"; |
| 6 | + |
| 7 | +export class ZhycorpWrapper { |
| 8 | + private readonly baseURL = "https://bot.zhycorp.com"; |
| 9 | + public async getBot(id: string): Promise<Bot> { |
| 10 | + const USER_PATTERN = /\d{17,19}/g; |
| 11 | + if (!USER_PATTERN.test(id)) throw Error("Invalid user id"); |
| 12 | + |
| 13 | + const { body: result } = await get(this.baseURL); |
| 14 | + if (!result[id]) throw new ZhycorpError("Not Found"); |
| 15 | + const bot = result[id]; |
| 16 | + const user = await getOwner(id); |
| 17 | + return { |
| 18 | + approved: bot.approved, |
| 19 | + botID: bot.botID, |
| 20 | + owner: { |
| 21 | + userID: bot.ownerID, |
| 22 | + userTag: user |
| 23 | + }, |
| 24 | + prefix: bot.prefix, |
| 25 | + registered: bot.registered |
| 26 | + }; |
| 27 | + } |
| 28 | +} |
0 commit comments