kook-client 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +15 -21
- package/lib/constans.js +7 -10
- package/lib/core/baseClient.js +31 -53
- package/lib/core/receiver.js +12 -16
- package/lib/core/receivers/index.js +2 -7
- package/lib/core/receivers/webhook.js +3 -7
- package/lib/core/receivers/websocket.js +17 -20
- package/lib/elements.js +31 -33
- package/lib/entries/channel.js +9 -13
- package/lib/entries/channelMember.js +3 -7
- package/lib/entries/contact.js +1 -5
- package/lib/entries/guild.js +8 -12
- package/lib/entries/guildMember.js +3 -7
- package/lib/entries/user.js +9 -13
- package/lib/event/index.js +1 -17
- package/lib/event/message.js +6 -11
- package/lib/index.d.ts +8 -20
- package/lib/index.js +7 -23
- package/lib/message.js +16 -20
- package/lib/tsconfig.build.tsbuildinfo +1 -1
- package/lib/types.js +1 -2
- package/lib/utils.js +13 -61
- package/package.json +2 -1
package/lib/utils.js
CHANGED
|
@@ -1,53 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.md5 = exports.toObject = void 0;
|
|
40
|
-
exports.isEmpty = isEmpty;
|
|
41
|
-
exports.genGroupId = genGroupId;
|
|
42
|
-
exports.parseGroupId = parseGroupId;
|
|
43
|
-
exports.remove = remove;
|
|
44
|
-
exports.createLocalFileStream = createLocalFileStream;
|
|
45
|
-
exports.createRemoteFileStream = createRemoteFileStream;
|
|
46
|
-
exports.getFile = getFile;
|
|
47
|
-
const crypto_1 = require("crypto");
|
|
48
|
-
const fs = __importStar(require("fs"));
|
|
49
|
-
const axios_1 = __importDefault(require("axios"));
|
|
50
|
-
const toObject = (data) => {
|
|
1
|
+
import { createHash } from "crypto";
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
export const toObject = (data) => {
|
|
51
5
|
if (Buffer.isBuffer(data))
|
|
52
6
|
return JSON.parse(data.toString());
|
|
53
7
|
if (typeof data === 'object')
|
|
@@ -56,30 +10,28 @@ const toObject = (data) => {
|
|
|
56
10
|
return JSON.parse(data);
|
|
57
11
|
// return String(data);
|
|
58
12
|
};
|
|
59
|
-
exports.toObject = toObject;
|
|
60
13
|
/** md5 hash */
|
|
61
|
-
const md5 = (data) =>
|
|
62
|
-
|
|
63
|
-
function isEmpty(data) {
|
|
14
|
+
export const md5 = (data) => createHash("md5").update(data).digest().toString('hex');
|
|
15
|
+
export function isEmpty(data) {
|
|
64
16
|
if (!data)
|
|
65
17
|
return true;
|
|
66
18
|
if (typeof data !== "object")
|
|
67
19
|
return false;
|
|
68
20
|
return Reflect.ownKeys(data).length === 0;
|
|
69
21
|
}
|
|
70
|
-
function genGroupId(guild_id, channel_id) {
|
|
22
|
+
export function genGroupId(guild_id, channel_id) {
|
|
71
23
|
return Buffer.from(`${guild_id}${channel_id}`, 'utf8')
|
|
72
24
|
.toString('base64')
|
|
73
25
|
.slice(0, -1);
|
|
74
26
|
}
|
|
75
|
-
function parseGroupId(group_id) {
|
|
27
|
+
export function parseGroupId(group_id) {
|
|
76
28
|
const decoded = Buffer.from(group_id + '=', 'base64').toString('utf8');
|
|
77
29
|
return {
|
|
78
30
|
guild_id: decoded.slice(0, 16),
|
|
79
31
|
channel_id: decoded.slice(16)
|
|
80
32
|
};
|
|
81
33
|
}
|
|
82
|
-
function remove(list, item) {
|
|
34
|
+
export function remove(list, item) {
|
|
83
35
|
const index = list.indexOf(item);
|
|
84
36
|
if (index !== -1)
|
|
85
37
|
list.splice(index, 1);
|
|
@@ -88,17 +40,17 @@ function remove(list, item) {
|
|
|
88
40
|
* create stream from local file
|
|
89
41
|
* @param filepath {string} filepath
|
|
90
42
|
*/
|
|
91
|
-
async function createLocalFileStream(filepath) {
|
|
43
|
+
export async function createLocalFileStream(filepath) {
|
|
92
44
|
return fs.createReadStream(filepath.replace('^file://', ''));
|
|
93
45
|
}
|
|
94
46
|
/**
|
|
95
47
|
* create stream from remote url
|
|
96
48
|
* @param url {string} remote url
|
|
97
49
|
*/
|
|
98
|
-
async function createRemoteFileStream(url) {
|
|
99
|
-
return (await
|
|
50
|
+
export async function createRemoteFileStream(url) {
|
|
51
|
+
return (await axios.get(url, { responseType: 'stream' })).data;
|
|
100
52
|
}
|
|
101
|
-
async function getFile(file) {
|
|
53
|
+
export async function getFile(file) {
|
|
102
54
|
if (Buffer.isBuffer(file))
|
|
103
55
|
return file;
|
|
104
56
|
if (file.match(/^https?:\/\//))
|