@im-dims/dims-js 0.1.3
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.
Potentially problematic release.
This version of @im-dims/dims-js might be problematic. Click here for more details.
- package/README.md +71 -0
- package/index.js +25 -0
- package/package.json +53 -0
- package/system/cloudDBAdabter.js +49 -0
- package/system/converter.js +80 -0
- package/system/exif.js +129 -0
- package/system/functions.js +558 -0
- package/system/lowdb/Low.d.ts +11 -0
- package/system/lowdb/Low.js +21 -0
- package/system/lowdb/LowSync.d.ts +11 -0
- package/system/lowdb/LowSync.js +21 -0
- package/system/lowdb/MissingAdapterError.d.ts +3 -0
- package/system/lowdb/MissingAdapterError.js +7 -0
- package/system/lowdb/adapters/JSONFile.d.ts +7 -0
- package/system/lowdb/adapters/JSONFile.js +19 -0
- package/system/lowdb/adapters/JSONFileSync.d.ts +7 -0
- package/system/lowdb/adapters/JSONFileSync.js +19 -0
- package/system/lowdb/adapters/LocalStorage.d.ts +7 -0
- package/system/lowdb/adapters/LocalStorage.js +16 -0
- package/system/lowdb/adapters/Memory.d.ts +6 -0
- package/system/lowdb/adapters/Memory.js +13 -0
- package/system/lowdb/adapters/MemorySync.d.ts +6 -0
- package/system/lowdb/adapters/MemorySync.js +12 -0
- package/system/lowdb/adapters/TextFile.d.ts +8 -0
- package/system/lowdb/adapters/TextFile.js +25 -0
- package/system/lowdb/adapters/TextFileSync.d.ts +8 -0
- package/system/lowdb/adapters/TextFileSync.js +26 -0
- package/system/lowdb/index.d.ts +9 -0
- package/system/lowdb/index.js +11 -0
- package/system/mongoDB.js +44 -0
- package/system/print.js +52 -0
- package/system/scraper.js +184 -0
- package/system/simple.js +1 -0
package/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
### simple function for mari-wabot
|
2
|
+
|
3
|
+
> All class functions for mari-wabot
|
4
|
+
|
5
|
+
### Get Started
|
6
|
+
```Javascript
|
7
|
+
const loli = new(require('@fainshe/dims'))
|
8
|
+
console.log(loli)
|
9
|
+
```
|
10
|
+
|
11
|
+
### Event Message
|
12
|
+
```Javascript
|
13
|
+
WebMessageInfo {
|
14
|
+
messageStubParameters: [],
|
15
|
+
labels: [],
|
16
|
+
userReceipt: [],
|
17
|
+
reactions: [],
|
18
|
+
pollUpdates: [],
|
19
|
+
eventResponses: [],
|
20
|
+
key: MessageKey {
|
21
|
+
remoteJid: '6281398274790@s.whatsapp.net',
|
22
|
+
fromMe: false,
|
23
|
+
id: '9BC314A4B10444F9EF'
|
24
|
+
},
|
25
|
+
message: Message {
|
26
|
+
extendedTextMessage: ExtendedTextMessage { text: '=> m', contextInfo: [ContextInfo] },
|
27
|
+
messageContextInfo: MessageContextInfo {
|
28
|
+
deviceListMetadata: [DeviceListMetadata],
|
29
|
+
deviceListMetadataVersion: 2
|
30
|
+
}
|
31
|
+
},
|
32
|
+
messageTimestamp: Long { low: 1720359281, high: 0, unsigned: true },
|
33
|
+
broadcast: false,
|
34
|
+
pushName: 'ItsMeDims',
|
35
|
+
id: '9BC314A4B10444F9EF',
|
36
|
+
isBaileys: false,
|
37
|
+
chat: '6281398274790@s.whatsapp.net',
|
38
|
+
isGroup: false,
|
39
|
+
sender: '6281398274790@s.whatsapp.net',
|
40
|
+
fromMe: false,
|
41
|
+
mtype: 'extendedTextMessage',
|
42
|
+
msg: ExtendedTextMessage {
|
43
|
+
text: '=> m',
|
44
|
+
contextInfo: ContextInfo {
|
45
|
+
mentionedJid: [],
|
46
|
+
groupMentions: [],
|
47
|
+
expiration: 0,
|
48
|
+
ephemeralSettingTimestamp: [Long],
|
49
|
+
disappearingMode: [DisappearingMode]
|
50
|
+
}
|
51
|
+
},
|
52
|
+
text: '=> m',
|
53
|
+
mentionedJid: [],
|
54
|
+
quoted: null,
|
55
|
+
name: 'ItsMeDims',
|
56
|
+
reply: [Function (anonymous)],
|
57
|
+
react: [Function (anonymous)],
|
58
|
+
copy: [Function (anonymous)],
|
59
|
+
forward: [Function (anonymous)],
|
60
|
+
copyNForward: [Function (anonymous)],
|
61
|
+
cMod: [Function (anonymous)],
|
62
|
+
delete: [Function (anonymous)],
|
63
|
+
plugin: 'owner-eval.js',
|
64
|
+
isCommand: true
|
65
|
+
}
|
66
|
+
```
|
67
|
+
|
68
|
+
### Thanks To
|
69
|
+
[](https://github.com/Nurutomo) [](https://github.com/neoxr)
|
70
|
+
[](https://github.com/rifnd) [](https://github.com/alya-tok)
|
71
|
+
[](https://github.com/Im-Dims) [](https://github.com/fainshe)
|
package/index.js
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require('dotenv').config()
|
2
|
+
const { makeWASocket, smsg, logic, protoType } = require('./system/simple')
|
3
|
+
const Functions = new (require('./system/functions'))
|
4
|
+
const Scraper = new (require('./system/scraper'))
|
5
|
+
const Converter = new (require('./system/converter'))
|
6
|
+
const Print = require('./system/print')
|
7
|
+
const Exif = new (require('./system/exif'))
|
8
|
+
const MongoDB = require('./system/mongoDB')
|
9
|
+
const CloudDBAdapter = require('./system/cloudDBAdabter')
|
10
|
+
const lowdb = require('./system/lowdb')
|
11
|
+
|
12
|
+
module.exports = class Component {
|
13
|
+
makeWASocket = makeWASocket
|
14
|
+
smsg = smsg
|
15
|
+
logic = logic
|
16
|
+
protoType = protoType
|
17
|
+
Functions = Functions
|
18
|
+
Scraper = Scraper
|
19
|
+
Converter = Converter
|
20
|
+
Print = Print
|
21
|
+
Exif = Exif
|
22
|
+
MongoDB = MongoDB
|
23
|
+
CloudDBAdapter = CloudDBAdapter
|
24
|
+
lowdb = lowdb
|
25
|
+
}
|
package/package.json
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
{
|
2
|
+
"name": "@im-dims/dims-js",
|
3
|
+
"version": "0.1.3",
|
4
|
+
"description": "simple function for mari-wabot",
|
5
|
+
"main": "index.js",
|
6
|
+
"scripts": {
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
8
|
+
},
|
9
|
+
"repository": {
|
10
|
+
"type": "git",
|
11
|
+
"url": "git+https://github.com/Im-Dims/dims-js.git"
|
12
|
+
},
|
13
|
+
"author": "Im-Dims",
|
14
|
+
"license": "ISC",
|
15
|
+
"bugs": {
|
16
|
+
"url": "https://github.com/Im-Dims/dims-js/issues"
|
17
|
+
},
|
18
|
+
"homepage": "https://github.com/Im-Dims/dims-js#readme",
|
19
|
+
"dependencies": {
|
20
|
+
"awesome-phonenumber": "~2.59.0",
|
21
|
+
"axios": "~0.24.0",
|
22
|
+
"cfonts": "^2.10.1",
|
23
|
+
"chalk": "^4.1.2",
|
24
|
+
"cheerio": "~1.0.0-rc.5",
|
25
|
+
"child_process": "~1.0.2",
|
26
|
+
"cloudscraper": "4.6.0",
|
27
|
+
"dotenv": "^16.0.1",
|
28
|
+
"file-type": "~16.5.2",
|
29
|
+
"fluent-ffmpeg": "npm:fluent-ffmpeg-7",
|
30
|
+
"form-data": "~4.0.0",
|
31
|
+
"fs": "0.0.1-security",
|
32
|
+
"got": "^11.8.6",
|
33
|
+
"html-entities": "~2.3.2",
|
34
|
+
"human-readable": "^0.2.1",
|
35
|
+
"jsdom": "^20.0.3",
|
36
|
+
"lodash": "^4.17.21",
|
37
|
+
"lowdb": "^2.1.0",
|
38
|
+
"moment-timezone": "~0.5.34",
|
39
|
+
"mongoose": "^6.3.3",
|
40
|
+
"node-cache": "^5.1.2",
|
41
|
+
"node-fetch": "^2.6.7",
|
42
|
+
"node-id3": "^0.2.3",
|
43
|
+
"node-webpmux": "^3.1.0",
|
44
|
+
"qrcode": "^1.5.0",
|
45
|
+
"qrcode-terminal": "^0.12.0",
|
46
|
+
"request": "^2.88.2",
|
47
|
+
"rootpath": "^0.1.2",
|
48
|
+
"similarity": "^1.2.1",
|
49
|
+
"syntax-error": "^1.4.0",
|
50
|
+
"url-regex-safe": "^3.0.0",
|
51
|
+
"yargs": "^17.5.1"
|
52
|
+
}
|
53
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
const got = require('got')
|
2
|
+
|
3
|
+
const stringify = obj => JSON.stringify(obj, null, 2)
|
4
|
+
const parse = str => JSON.parse(str, (_, v) => {
|
5
|
+
if (v !== null && typeof v === 'object' && 'type' in v && v.type === 'Buffer' && 'data' in v && Array.isArray(v.data)) {
|
6
|
+
return Buffer.from(v.data)
|
7
|
+
}
|
8
|
+
return v
|
9
|
+
})
|
10
|
+
|
11
|
+
class CloudDBAdapter {
|
12
|
+
constructor(url, { serialize = stringify, deserialize = parse, fetchOptions = {} } = {}) {
|
13
|
+
this.url = url
|
14
|
+
this.serialize = serialize
|
15
|
+
this.deserialize = deserialize
|
16
|
+
this.fetchOptions = fetchOptions
|
17
|
+
}
|
18
|
+
|
19
|
+
async read() {
|
20
|
+
try {
|
21
|
+
let res = await got(this.url, {
|
22
|
+
method: 'GET',
|
23
|
+
headers: {
|
24
|
+
'Accept': 'application/json;q=0.9,text/plain'
|
25
|
+
},
|
26
|
+
...this.fetchOptions
|
27
|
+
})
|
28
|
+
if (res.statusCode !== 200) throw res.statusMessage
|
29
|
+
return this.deserialize(res.body)
|
30
|
+
} catch (e) {
|
31
|
+
return null
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
async write(obj) {
|
36
|
+
let res = await got(this.url, {
|
37
|
+
method: 'POST',
|
38
|
+
headers: {
|
39
|
+
'Content-Type': 'application/json'
|
40
|
+
},
|
41
|
+
...this.fetchOptions,
|
42
|
+
body: this.serialize(obj)
|
43
|
+
})
|
44
|
+
if (res.statusCode !== 200) throw res.statusMessage
|
45
|
+
return res.body
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
module.exports = CloudDBAdapter
|
@@ -0,0 +1,80 @@
|
|
1
|
+
const fs = require('fs')
|
2
|
+
const path = require('path')
|
3
|
+
const { spawn } = require('child_process')
|
4
|
+
|
5
|
+
module.exports = class Converter {
|
6
|
+
ffmpeg = (buffer, args = [], ext = '', ext2 = '') => {
|
7
|
+
return new Promise(async (resolve, reject) => {
|
8
|
+
try {
|
9
|
+
let tmp = 'temp/' + new Date + '.' + ext
|
10
|
+
let out = tmp + '.' + ext2
|
11
|
+
await fs.promises.writeFile(tmp, buffer)
|
12
|
+
spawn('ffmpeg', [
|
13
|
+
'-y',
|
14
|
+
'-i', tmp,
|
15
|
+
...args,
|
16
|
+
out
|
17
|
+
])
|
18
|
+
.on('error', reject)
|
19
|
+
.on('close', async (code) => {
|
20
|
+
try {
|
21
|
+
await fs.promises.unlink(tmp)
|
22
|
+
if (code !== 0) return reject(code)
|
23
|
+
resolve(await fs.promises.readFile(out))
|
24
|
+
await fs.promises.unlink(out)
|
25
|
+
} catch (e) {
|
26
|
+
reject(e)
|
27
|
+
}
|
28
|
+
})
|
29
|
+
} catch (e) {
|
30
|
+
reject(e)
|
31
|
+
}
|
32
|
+
})
|
33
|
+
}
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Convert Audio to Playable WhatsApp Audio
|
37
|
+
* @param {Buffer} buffer Audio Buffer
|
38
|
+
* @param {String} ext File Extension
|
39
|
+
**/
|
40
|
+
toAudio = (buffer, ext) => {
|
41
|
+
return this.ffmpeg(buffer, [
|
42
|
+
'-vn',
|
43
|
+
'-ac', '2',
|
44
|
+
'-b:a', '128k',
|
45
|
+
'-ar', '44100',
|
46
|
+
'-f', 'mp3'
|
47
|
+
], ext, 'mp3')
|
48
|
+
}
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Convert Audio to Playable WhatsApp PTT
|
52
|
+
* @param {Buffer} buffer Audio Buffer
|
53
|
+
* @param {String} ext File Extension
|
54
|
+
**/
|
55
|
+
toPTT = (buffer, ext) => {
|
56
|
+
return this.ffmpeg(buffer, [
|
57
|
+
'-vn',
|
58
|
+
'-c:a', 'libopus',
|
59
|
+
'-b:a', '128k',
|
60
|
+
'-vbr', 'on',
|
61
|
+
'-compression_level', '10'
|
62
|
+
], ext, 'opus')
|
63
|
+
}
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Convert Audio to Playable WhatsApp Video
|
67
|
+
* @param {Buffer} buffer Video Buffer
|
68
|
+
* @param {String} ext File Extension
|
69
|
+
**/
|
70
|
+
toVideo = (buffer, ext) => {
|
71
|
+
return this.ffmpeg(buffer, [
|
72
|
+
'-c:v', 'libx264',
|
73
|
+
'-c:a', 'aac',
|
74
|
+
'-ab', '128k',
|
75
|
+
'-ar', '44100',
|
76
|
+
'-crf', '32',
|
77
|
+
'-preset', 'slow'
|
78
|
+
], ext, 'mp4')
|
79
|
+
}
|
80
|
+
}
|
package/system/exif.js
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
const fs = require('fs')
|
2
|
+
const { tmpdir } = require('os')
|
3
|
+
const Crypto = require('crypto')
|
4
|
+
const ff = require('fluent-ffmpeg')
|
5
|
+
const webp = require('node-webpmux')
|
6
|
+
const path = require('path')
|
7
|
+
|
8
|
+
module.exports = class Exif {
|
9
|
+
async imageToWebp(media) {
|
10
|
+
let tmpFileOut = path.join(tmpdir(), `${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.webp`)
|
11
|
+
let tmpFileIn = path.join(tmpdir(), `${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.jpg`)
|
12
|
+
fs.writeFileSync(tmpFileIn, media)
|
13
|
+
await new Promise((resolve, reject) => {
|
14
|
+
ff(tmpFileIn)
|
15
|
+
.on("error", reject)
|
16
|
+
.on("end", () => resolve(true))
|
17
|
+
.addOutputOptions([
|
18
|
+
"-vcodec",
|
19
|
+
"libwebp",
|
20
|
+
"-vf",
|
21
|
+
"scale=320:320:force_original_aspect_ratio=decrease,pad=320:320:(ow-iw)/2:(oh-ih)/2:color=white@0.0, split [a][b]; [a] palettegen=reserve_transparent=on:transparency_color=ffffff [p]; [b][p] paletteuse"
|
22
|
+
]).toFormat("webp").save(tmpFileOut)
|
23
|
+
})
|
24
|
+
let buff = fs.readFileSync(tmpFileOut)
|
25
|
+
fs.unlinkSync(tmpFileOut)
|
26
|
+
fs.unlinkSync(tmpFileIn)
|
27
|
+
return buff
|
28
|
+
}
|
29
|
+
async videoToWebp(media) {
|
30
|
+
let tmpFileOut = path.join(tmpdir(), `${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.webp`)
|
31
|
+
let tmpFileIn = path.join(tmpdir(), `${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.mp4`)
|
32
|
+
fs.writeFileSync(tmpFileIn, media)
|
33
|
+
await new Promise((resolve, reject) => {
|
34
|
+
ff(tmpFileIn)
|
35
|
+
.on("error", reject)
|
36
|
+
.on("end", () => resolve(true))
|
37
|
+
.addOutputOptions([
|
38
|
+
"-vcodec",
|
39
|
+
"libwebp",
|
40
|
+
"-vf",
|
41
|
+
"scale=320:320:force_original_aspect_ratio=decrease,pad=320:320:(ow-iw)/2:(oh-ih)/2:color=white@0.0, split [a][b]; [a] palettegen=reserve_transparent=on:transparency_color=ffffff [p]; [b][p] paletteuse",
|
42
|
+
"-loop", "0", "-ss", "00:00:00", "-t", "00:00:05",
|
43
|
+
"-preset",
|
44
|
+
"default",
|
45
|
+
"-an",
|
46
|
+
"-vsync",
|
47
|
+
"0"
|
48
|
+
]).toFormat("webp").save(tmpFileOut)
|
49
|
+
})
|
50
|
+
let buff = fs.readFileSync(tmpFileOut)
|
51
|
+
fs.unlinkSync(tmpFileOut)
|
52
|
+
fs.unlinkSync(tmpFileIn)
|
53
|
+
return buff
|
54
|
+
}
|
55
|
+
async writeExifImg(media, metadata) {
|
56
|
+
let wMedia = await this.imageToWebp(media)
|
57
|
+
let tmpFileIn = path.join(tmpdir(), `${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.webp`)
|
58
|
+
let tmpFileOut = path.join(tmpdir(), `${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.webp`)
|
59
|
+
fs.writeFileSync(tmpFileIn, wMedia)
|
60
|
+
if (metadata.packname || metadata.author) {
|
61
|
+
let img = new webp.Image()
|
62
|
+
let json = {
|
63
|
+
"sticker-pack-id": "neoxrbot",
|
64
|
+
"sticker-pack-name": metadata.packname,
|
65
|
+
"sticker-pack-publisher": metadata.author,
|
66
|
+
"emojis": metadata.categories ? metadata.categories : [""],
|
67
|
+
"web-rest-api": "https://api.neoxr.eu.org"
|
68
|
+
}
|
69
|
+
let exifAttr = Buffer.from([0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x41, 0x57, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00])
|
70
|
+
let jsonBuff = Buffer.from(JSON.stringify(json), "utf-8")
|
71
|
+
let exif = Buffer.concat([exifAttr, jsonBuff])
|
72
|
+
exif.writeUIntLE(jsonBuff.length, 14, 4)
|
73
|
+
await img.load(tmpFileIn)
|
74
|
+
fs.unlinkSync(tmpFileIn)
|
75
|
+
img.exif = exif
|
76
|
+
await img.save(tmpFileOut)
|
77
|
+
return tmpFileOut
|
78
|
+
}
|
79
|
+
}
|
80
|
+
async writeExifWebp(media, metadata) {
|
81
|
+
let tmpFileIn = path.join(tmpdir(), `${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.webp`)
|
82
|
+
let tmpFileOut = path.join(tmpdir(), `${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.webp`)
|
83
|
+
fs.writeFileSync(tmpFileIn, media)
|
84
|
+
if (metadata.packname || metadata.author) {
|
85
|
+
let img = new webp.Image()
|
86
|
+
let json = {
|
87
|
+
"sticker-pack-id": "neoxrbot",
|
88
|
+
"sticker-pack-name": metadata.packname,
|
89
|
+
"sticker-pack-publisher": metadata.author,
|
90
|
+
"emojis": metadata.categories ? metadata.categories : [""],
|
91
|
+
"web-rest-api": "https://api.neoxr.eu.org"
|
92
|
+
}
|
93
|
+
let exifAttr = Buffer.from([0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x41, 0x57, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00])
|
94
|
+
let jsonBuff = Buffer.from(JSON.stringify(json), "utf-8")
|
95
|
+
let exif = Buffer.concat([exifAttr, jsonBuff])
|
96
|
+
exif.writeUIntLE(jsonBuff.length, 14, 4)
|
97
|
+
await img.load(tmpFileIn)
|
98
|
+
fs.unlinkSync(tmpFileIn)
|
99
|
+
img.exif = exif
|
100
|
+
await img.save(tmpFileOut)
|
101
|
+
return tmpFileOut
|
102
|
+
}
|
103
|
+
}
|
104
|
+
async writeExifVid(media, metadata) {
|
105
|
+
let wMedia = await this.videoToWebp(media)
|
106
|
+
let tmpFileIn = path.join(tmpdir(), `${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.webp`)
|
107
|
+
let tmpFileOut = path.join(tmpdir(), `${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.webp`)
|
108
|
+
fs.writeFileSync(tmpFileIn, wMedia)
|
109
|
+
if (metadata.packname || metadata.author) {
|
110
|
+
let img = new webp.Image()
|
111
|
+
let json = {
|
112
|
+
"sticker-pack-id": "neoxrbot",
|
113
|
+
"sticker-pack-name": metadata.packname,
|
114
|
+
"sticker-pack-publisher": metadata.author,
|
115
|
+
"emojis": metadata.categories ? metadata.categories : [""],
|
116
|
+
"web-rest-api": "https://api.neoxr.eu.org"
|
117
|
+
}
|
118
|
+
let exifAttr = Buffer.from([0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x41, 0x57, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00])
|
119
|
+
let jsonBuff = Buffer.from(JSON.stringify(json), "utf-8")
|
120
|
+
let exif = Buffer.concat([exifAttr, jsonBuff])
|
121
|
+
exif.writeUIntLE(jsonBuff.length, 14, 4)
|
122
|
+
await img.load(tmpFileIn)
|
123
|
+
fs.unlinkSync(tmpFileIn)
|
124
|
+
img.exif = exif
|
125
|
+
await img.save(tmpFileOut)
|
126
|
+
return tmpFileOut
|
127
|
+
}
|
128
|
+
}
|
129
|
+
}
|