@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
@@ -0,0 +1,19 @@
|
|
1
|
+
const { TextFile } = require('./TextFile.js');
|
2
|
+
class JSONFile {
|
3
|
+
constructor(filename) {
|
4
|
+
this.adapter = new TextFile(filename);
|
5
|
+
}
|
6
|
+
async read() {
|
7
|
+
const data = await this.adapter.read();
|
8
|
+
if (data === null) {
|
9
|
+
return null;
|
10
|
+
}
|
11
|
+
else {
|
12
|
+
return JSON.parse(data);
|
13
|
+
}
|
14
|
+
}
|
15
|
+
write(obj) {
|
16
|
+
return this.adapter.write(JSON.stringify(obj, null, 2));
|
17
|
+
}
|
18
|
+
}
|
19
|
+
module.exports = { JSONFile };
|
@@ -0,0 +1,19 @@
|
|
1
|
+
const { TextFileSync } = require('./TextFileSync.js');
|
2
|
+
class JSONFileSync {
|
3
|
+
constructor(filename) {
|
4
|
+
this.adapter = new TextFileSync(filename);
|
5
|
+
}
|
6
|
+
read() {
|
7
|
+
const data = this.adapter.read();
|
8
|
+
if (data === null) {
|
9
|
+
return null;
|
10
|
+
}
|
11
|
+
else {
|
12
|
+
return JSON.parse(data);
|
13
|
+
}
|
14
|
+
}
|
15
|
+
write(obj) {
|
16
|
+
this.adapter.write(JSON.stringify(obj, null, 2));
|
17
|
+
}
|
18
|
+
}
|
19
|
+
module.exports = { JSONFileSync };
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class LocalStorage {
|
2
|
+
constructor(key) {
|
3
|
+
this.key = key;
|
4
|
+
}
|
5
|
+
read() {
|
6
|
+
const value = localStorage.getItem(this.key);
|
7
|
+
if (value === null) {
|
8
|
+
return null;
|
9
|
+
}
|
10
|
+
return JSON.parse(value);
|
11
|
+
}
|
12
|
+
write(obj) {
|
13
|
+
localStorage.setItem(this.key, JSON.stringify(obj));
|
14
|
+
}
|
15
|
+
}
|
16
|
+
module.exports = { LocalStorage };
|
@@ -0,0 +1,25 @@
|
|
1
|
+
const fs = require('fs');
|
2
|
+
const { Writer } = require('steno');
|
3
|
+
class TextFile {
|
4
|
+
constructor(filename) {
|
5
|
+
this.filename = filename;
|
6
|
+
this.writer = new Writer(filename);
|
7
|
+
}
|
8
|
+
async read() {
|
9
|
+
let data;
|
10
|
+
try {
|
11
|
+
data = await fs.promises.readFile(this.filename, 'utf-8');
|
12
|
+
}
|
13
|
+
catch (e) {
|
14
|
+
if (e.code === 'ENOENT') {
|
15
|
+
return null;
|
16
|
+
}
|
17
|
+
throw e;
|
18
|
+
}
|
19
|
+
return data;
|
20
|
+
}
|
21
|
+
write(str) {
|
22
|
+
return this.writer.write(str);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
module.exports = { TextFile };
|
@@ -0,0 +1,26 @@
|
|
1
|
+
const fs = require('fs');
|
2
|
+
const path = require('path');
|
3
|
+
class TextFileSync {
|
4
|
+
constructor(filename) {
|
5
|
+
this.filename = filename;
|
6
|
+
this.tempFilename = path.join(path.dirname(filename), `.${path.basename(filename)}.tmp`);
|
7
|
+
}
|
8
|
+
read() {
|
9
|
+
let data;
|
10
|
+
try {
|
11
|
+
data = fs.readFileSync(this.filename, 'utf-8');
|
12
|
+
}
|
13
|
+
catch (e) {
|
14
|
+
if (e.code === 'ENOENT') {
|
15
|
+
return null;
|
16
|
+
}
|
17
|
+
throw e;
|
18
|
+
}
|
19
|
+
return data;
|
20
|
+
}
|
21
|
+
write(str) {
|
22
|
+
fs.writeFileSync(this.tempFilename, str);
|
23
|
+
fs.renameSync(this.tempFilename, this.filename);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
module.exports = { TextFileSync };
|
@@ -0,0 +1,9 @@
|
|
1
|
+
export * from './adapters/JSONFile.js';
|
2
|
+
export * from './adapters/JSONFileSync.js';
|
3
|
+
export * from './adapters/LocalStorage.js';
|
4
|
+
export * from './adapters/Memory.js';
|
5
|
+
export * from './adapters/MemorySync.js';
|
6
|
+
export * from './adapters/TextFile.js';
|
7
|
+
export * from './adapters/TextFileSync.js';
|
8
|
+
export * from './Low.js';
|
9
|
+
export * from './LowSync.js';
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module.exports = {
|
2
|
+
...require('./adapters/JSONFile.js'),
|
3
|
+
...require('./adapters/JSONFileSync.js'),
|
4
|
+
...require('./adapters/LocalStorage.js'),
|
5
|
+
...require('./adapters/Memory.js'),
|
6
|
+
...require('./adapters/MemorySync.js'),
|
7
|
+
...require('./adapters/TextFile.js'),
|
8
|
+
...require('./adapters/TextFileSync.js'),
|
9
|
+
...require('./Low.js'),
|
10
|
+
...require('./LowSync.js'),
|
11
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
const mongoose = require('mongoose')
|
2
|
+
const { Schema } = mongoose
|
3
|
+
|
4
|
+
module.exports = class mongoDB {
|
5
|
+
constructor(url, options = { useNewUrlParser: true, useUnifiedTopology: true }) {
|
6
|
+
this.url = url
|
7
|
+
this.data = this._data = this._schema = this._model = {}
|
8
|
+
this.db
|
9
|
+
this.options = options
|
10
|
+
}
|
11
|
+
async read() {
|
12
|
+
this.db = await mongoose.connect(this.url, { ...this.options })
|
13
|
+
this.connection = mongoose.connection
|
14
|
+
let schema = this._schema = new Schema({
|
15
|
+
data: {
|
16
|
+
type: Object,
|
17
|
+
required: true, //depends on whether the field is mandatory or not
|
18
|
+
default: {}
|
19
|
+
}
|
20
|
+
})
|
21
|
+
// this._model = mongoose.model('data', schema)
|
22
|
+
try { this._model = mongoose.model('data', schema) } catch { this._model = mongoose.model('data') }
|
23
|
+
this._data = await this._model.findOne({})
|
24
|
+
if (!this._data) {
|
25
|
+
this.data = {}
|
26
|
+
await this.write(this.data)
|
27
|
+
this._data = await this._model.findOne({})
|
28
|
+
} else this.data = this._data.data
|
29
|
+
return this.data
|
30
|
+
}
|
31
|
+
|
32
|
+
|
33
|
+
async write(data) {
|
34
|
+
if (!data) return data
|
35
|
+
if (!this._data) return (new this._model({ data })).save()
|
36
|
+
this._model.findById(this._data._id, (err, docs) => {
|
37
|
+
if (!err) {
|
38
|
+
if (!docs.data) docs.data = {}
|
39
|
+
docs.data = data
|
40
|
+
return docs.save()
|
41
|
+
}
|
42
|
+
})
|
43
|
+
}
|
44
|
+
}
|
package/system/print.js
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
let { WAMessageStubType } = require('@whiskeysockets/baileys')
|
2
|
+
let urlRegex = require('url-regex-safe')({ strict: false })
|
3
|
+
let PhoneNumber = require('awesome-phonenumber')
|
4
|
+
let chalk = require('chalk')
|
5
|
+
|
6
|
+
module.exports = async function (m, conn = { user: {} }) {
|
7
|
+
let _name = await conn.getName(m.sender)
|
8
|
+
let sender = PhoneNumber('+' + m.sender.replace('@s.whatsapp.net', '')).getNumber('international') + (_name ? ' ~' + _name : '')
|
9
|
+
let chat = await conn.getName(m.chat)
|
10
|
+
let filesize = (m.msg ? m.msg.vcard ? m.msg.vcard.length : m.msg.fileLength ? m.msg.fileLength.low || m.msg.fileLength : m.msg.axolotlSenderKeyDistributionMessage ? m.msg.axolotlSenderKeyDistributionMessage.length : m.text ? m.text.length : 0 : m.text ? m.text.length : 0) || 0
|
11
|
+
let user = global.DATABASE.data.users[m.sender]
|
12
|
+
let me = PhoneNumber('+' + (conn.user && conn.user.jid).replace('@s.whatsapp.net', '')).getNumber('international')
|
13
|
+
|
14
|
+
console.log(`${chalk.redBright('%s')} ${chalk.black(chalk.bgYellow('%s'))} ${chalk.black(chalk.bgGreen('%s'))} ${chalk.magenta('%s [%s %sB]')} ${chalk.green('%s')} ${chalk.yellow('%s%s')} ${chalk.blueBright('to')} ${chalk.green('%s')} ${chalk.black(chalk.bgYellow('%s'))}`.trim(), me + ' ~' + conn.user.name, (m.messageTimestamp ? new Date(1000 * (m.messageTimestamp.low || m.messageTimestamp)) : new Date).toTimeString(), m.messageStubType ? WAMessageStubType[m.messageStubType] : '', filesize, filesize === 0 ? 0 : (filesize / 1009 ** Math.floor(Math.log(filesize) / Math.log(1000))).toFixed(1), ['', ...'KMGTP'][Math.floor(Math.log(filesize) / Math.log(1000))] || '', sender, m ? m.exp : '?', user ? '|' + user.exp + '|' + user.limit : '' + ('|' + user.level), m.chat + (chat ? ' ~' + chat : ''), m.mtype ? m.mtype.replace(/message$/i, '').replace('audio', m.msg.ptt ? 'PTT' : 'audio').replace(/^./, v => v.toUpperCase()) : '')
|
15
|
+
|
16
|
+
if (typeof m.text === 'string' && m.text) {
|
17
|
+
let log = m.text.replace(/\u200e+/g, '')
|
18
|
+
let mdRegex = /(?<=(?:^|[\s\n])\S?)(?:([*_~])(.+?)\1|```((?:.||[\n\r])+?)```)(?=\S?(?:[\s\n]|$))/g
|
19
|
+
let mdFormat = (depth = 4) => (_, type, text, monospace) => {
|
20
|
+
let types = {
|
21
|
+
_: 'italic',
|
22
|
+
'*': 'bold',
|
23
|
+
'~': 'strikethrough'
|
24
|
+
}
|
25
|
+
text = text || monospace
|
26
|
+
let formatted = !types[type] || depth < 1 ? text : chalk[types[type]](text.replace(mdRegex, mdFormat(depth - 1)))
|
27
|
+
// console.log({ depth, type, formatted, text, monospace }, formatted)
|
28
|
+
return formatted
|
29
|
+
}
|
30
|
+
if (log.length < 4096)
|
31
|
+
log = log.replace(urlRegex, (url, i, text) => {
|
32
|
+
let end = url.length + i
|
33
|
+
return i === 0 || end === text.length || (/^\s$/.test(text[end]) && /^\s$/.test(text[i - 1])) ? chalk.blueBright(url) : url
|
34
|
+
})
|
35
|
+
log = log.replace(mdRegex, mdFormat(4))
|
36
|
+
if (m.mentionedJid) for (let user of m.mentionedJid) log = log.replace('@' + user.split`@`[0], chalk.blueBright('@' + await conn.getName(user)))
|
37
|
+
console.log(m.error != null ? chalk.red(log) : m.isCommand ? chalk.yellow(log) : log)
|
38
|
+
}
|
39
|
+
if (m.messageStubParameters) console.log(m.messageStubParameters.map(jid => {
|
40
|
+
jid = conn.decodeJid(jid)
|
41
|
+
let name = conn.getName(jid)
|
42
|
+
return chalk.gray(PhoneNumber('+' + jid.replace('@s.whatsapp.net', '')).getNumber('international') + (name ? ' ~' + name : ''))
|
43
|
+
}).join(', '))
|
44
|
+
|
45
|
+
if (/document/i.test(m.mtype)) console.log(`📄 ${m.msg.filename || m.msg.displayName || 'Document'}`)
|
46
|
+
else if (/ContactsArray/i.test(m.mtype)) console.log(`👨👩👧👦 ${' ' || ''}`)
|
47
|
+
else if (/contact/i.test(m.mtype)) console.log(`👨 ${m.msg.displayName || ''}`)
|
48
|
+
else if (/audio/i.test(m.mtype)) (s = m.msg.seconds, console.log(`${m.msg.ptt ? '🎤 (PTT ' : '🎵 ('}AUDIO) ${Math.floor(s / 60).toString().padStart(2, 0)}:${(s % 60).toString().padStart(2, 0)}`))
|
49
|
+
|
50
|
+
console.log()
|
51
|
+
// if (m.quoted) console.log(m.msg.contextInfo)
|
52
|
+
}
|
@@ -0,0 +1,184 @@
|
|
1
|
+
const axios = require('axios')
|
2
|
+
const FormData = require('form-data')
|
3
|
+
const parse = require('file-type').fromBuffer
|
4
|
+
const cheerio = require('cheerio')
|
5
|
+
const Func = new (require('./functions'))
|
6
|
+
|
7
|
+
module.exports = class Scraper {
|
8
|
+
uploader = (i, extension, time = 60) => new Promise(async resolve => {
|
9
|
+
try {
|
10
|
+
if (!Buffer.isBuffer(i) && !Func.isUrl(i)) return resolve({
|
11
|
+
creator: global.creator,
|
12
|
+
status: false,
|
13
|
+
msg: 'only buffer and url formats are allowed'
|
14
|
+
})
|
15
|
+
const file = Buffer.isBuffer(i) ? i : Func.isUrl(i) ? await (await axios.get(i, {
|
16
|
+
responseType: 'arraybuffer'
|
17
|
+
})).data : null
|
18
|
+
const parse = await axios.get('https://tmpfiles.org')
|
19
|
+
const cookie = parse.headers['set-cookie'].join('; ')
|
20
|
+
const token = cheerio.load(parse.data)('input[name="_token"]').attr('value')
|
21
|
+
try {
|
22
|
+
var { ext } = await parse(file)
|
23
|
+
} catch (e) {
|
24
|
+
var ext = 'txt'
|
25
|
+
}
|
26
|
+
let form = new FormData
|
27
|
+
form.append('_token', token)
|
28
|
+
form.append('file', Buffer.from(file), Func.makeId(10) + '.' + (extension || ext))
|
29
|
+
form.append('max_views', 0)
|
30
|
+
form.append('max_time', time)
|
31
|
+
form.append('upload', 'Upload')
|
32
|
+
const html = await (await axios.post('https://tmpfiles.org', form, {
|
33
|
+
headers: {
|
34
|
+
cookie,
|
35
|
+
...form.getHeaders()
|
36
|
+
}
|
37
|
+
})).data
|
38
|
+
const $ = cheerio.load(html)
|
39
|
+
const component = []
|
40
|
+
$('td').each((i, e) => component.push($(e).text()))
|
41
|
+
if (!component[2]) return resolve({
|
42
|
+
creator: global.creator,
|
43
|
+
status: false,
|
44
|
+
msg: `upload failed`
|
45
|
+
})
|
46
|
+
resolve({
|
47
|
+
creator: global.creator,
|
48
|
+
status: true,
|
49
|
+
data: {
|
50
|
+
filename: component[0],
|
51
|
+
size: component[1],
|
52
|
+
expired: component[3],
|
53
|
+
url: component[2]
|
54
|
+
}
|
55
|
+
})
|
56
|
+
} catch (e) {
|
57
|
+
resolve({
|
58
|
+
creator: global.creator,
|
59
|
+
status: false,
|
60
|
+
msg: e.message
|
61
|
+
})
|
62
|
+
}
|
63
|
+
})
|
64
|
+
|
65
|
+
telegraph = i => new Promise(async (resolve, reject) => {
|
66
|
+
try {
|
67
|
+
if (!Buffer.isBuffer(i) && !Func.isUrl(i)) return resolve({
|
68
|
+
creator: global.creator,
|
69
|
+
status: false,
|
70
|
+
msg: 'only buffer and url formats are allowed'
|
71
|
+
})
|
72
|
+
const file = Buffer.isBuffer(i) ? i : Func.isUrl(i) ? await (await axios.get(i, {
|
73
|
+
responseType: 'arraybuffer'
|
74
|
+
})).data : null
|
75
|
+
try {
|
76
|
+
var { ext } = await parse(file)
|
77
|
+
} catch (e) {
|
78
|
+
var ext = 'jpg'
|
79
|
+
}
|
80
|
+
let form = new FormData
|
81
|
+
form.append('file', Buffer.from(file), 'image.' + ext)
|
82
|
+
const json = await (await axios.post('https://telegra.ph/upload', form, {
|
83
|
+
headers: {
|
84
|
+
"Accept": "*/*",
|
85
|
+
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0.1; SM-J500G) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Mobile Safari/537.36",
|
86
|
+
"Origin": "https://telegra.ph",
|
87
|
+
"Referer": "https://telegra.ph",
|
88
|
+
"Referrer-Policy": "strict-origin-when-cross-origin",
|
89
|
+
"sec-ch-ua": '"Chromium";v="107", "Not=A?Brand";v="24"',
|
90
|
+
"sec-ch-ua-platform": "Android",
|
91
|
+
"sec-fetch-dest": "empty",
|
92
|
+
"sec-fetch-mode": "cors",
|
93
|
+
"sec-fetch-site": "same-origin",
|
94
|
+
"x-requested-with": "XMLHttpRequest",
|
95
|
+
...form.getHeaders()
|
96
|
+
}
|
97
|
+
})).data
|
98
|
+
if (!json || json.length < 1) return resolve({
|
99
|
+
creator: global.creator,
|
100
|
+
status: false,
|
101
|
+
msg: 'Failed to upload!'
|
102
|
+
})
|
103
|
+
resolve({
|
104
|
+
creator: global.creator,
|
105
|
+
status: true,
|
106
|
+
data: {
|
107
|
+
url: 'https://telegra.ph' + json[0].src
|
108
|
+
}
|
109
|
+
})
|
110
|
+
} catch (e) {
|
111
|
+
resolve({
|
112
|
+
creator: global.creator,
|
113
|
+
status: false,
|
114
|
+
msg: e.message
|
115
|
+
})
|
116
|
+
}
|
117
|
+
})
|
118
|
+
|
119
|
+
uploadImage = i => new Promise(async (resolve, reject) => {
|
120
|
+
try {
|
121
|
+
if (!Buffer.isBuffer(i) && !Func.isUrl(i)) return resolve({
|
122
|
+
creator: global.creator,
|
123
|
+
status: false,
|
124
|
+
msg: 'only buffer and url formats are allowed'
|
125
|
+
})
|
126
|
+
const parse = await (await axios.get('https://imgbb.com', {
|
127
|
+
headers: {
|
128
|
+
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0.1; SM-J500G) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Mobile Safari/537.36"
|
129
|
+
}
|
130
|
+
}))
|
131
|
+
const token = parse.data.match(/PF\.obj\.config\.auth_token="([^"]*)/)[1]
|
132
|
+
const cookie = parse.headers['set-cookie'].join(', ')
|
133
|
+
const file = Buffer.isBuffer(i) ? i : Func.isUrl(i) ? await (await axios.get(i, {
|
134
|
+
responseType: 'arraybuffer'
|
135
|
+
})).data : null
|
136
|
+
try {
|
137
|
+
var { ext } = await parse(file)
|
138
|
+
} catch (e) {
|
139
|
+
var ext = 'jpg'
|
140
|
+
}
|
141
|
+
let form = new FormData
|
142
|
+
form.append('source', Buffer.from(file), 'image.' + ext)
|
143
|
+
form.append('type', 'file')
|
144
|
+
form.append('action', 'upload')
|
145
|
+
form.append('timestamp', (new Date() * 1))
|
146
|
+
form.append('auth_token', token)
|
147
|
+
const json = await (await axios.post('https://imgbb.com/json', form, {
|
148
|
+
headers: {
|
149
|
+
"Accept": "*/*",
|
150
|
+
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0.1; SM-J500G) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Mobile Safari/537.36",
|
151
|
+
"Origin": "https://imgbb.com",
|
152
|
+
"Referer": "https://imgbb.com/upload",
|
153
|
+
"Referrer-Policy": "strict-origin-when-cross-origin",
|
154
|
+
cookie,
|
155
|
+
...form.getHeaders()
|
156
|
+
}
|
157
|
+
})).data
|
158
|
+
if (json.status_code != 200) return resolve({
|
159
|
+
creator: global.creator,
|
160
|
+
status: false,
|
161
|
+
msg: `Failed to Upload!`
|
162
|
+
})
|
163
|
+
resolve({
|
164
|
+
creator: global.creator,
|
165
|
+
status: true,
|
166
|
+
original: json,
|
167
|
+
data: {
|
168
|
+
url: json.image.display_url
|
169
|
+
}
|
170
|
+
})
|
171
|
+
} catch (e) {
|
172
|
+
resolve({
|
173
|
+
creator: global.creator,
|
174
|
+
status: false,
|
175
|
+
msg: e.message
|
176
|
+
})
|
177
|
+
}
|
178
|
+
})
|
179
|
+
|
180
|
+
shorten = async (url) => {
|
181
|
+
let isurl = /https?:\/\//.test(url)
|
182
|
+
return isurl ? (await require('axios').get('https://tinyurl.com/api-create.php?url=' + encodeURIComponent(url))).data : ''
|
183
|
+
}
|
184
|
+
}
|