Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Ningoje authored Sep 20, 2022
1 parent f79b64c commit 23e5b9d
Show file tree
Hide file tree
Showing 59 changed files with 2,214 additions and 0 deletions.
Empty file added lib/AlienAlfa
Empty file.
18 changes: 18 additions & 0 deletions lib/antispam.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

const usedCommandRecently = new Set();

const isFiltered = (from) => {
return !!usedCommandRecently.has(from);
};

const addFilter = (from) => {
usedCommandRecently.add(from);
setTimeout(() => {
return usedCommandRecently.delete(from);
}, 1500);// slow commands cmd filtered
};
module.exports = {
msgFilter: {
isFiltered,
addFilter
}};
26 changes: 26 additions & 0 deletions lib/binary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//═══════════════════════════════════════════════════════//
//If you want to recode, reupload
//or copy the codes/script,
//pls give credit
//no credit? i will take action immediately
//© 2022 Xeon Bot Inc. Cheems Bot MD
//Thank you to Lord Buddha, Family and Myself
//════════════════════════════//
async function dBinary(str) {
var newBin = str.split(" ")
var binCode = []
for (i = 0; i < newBin.length; i++) {
binCode.push(String.fromCharCode(parseInt(newBin[i], 2)))
}
return binCode.join("")
}

async function eBinary(str = ''){
let res = ''
res = str.split('').map(char => {
return char.charCodeAt(0).toString(2);
}).join(' ')
return res
}

module.exports = { dBinary, eBinary }
66 changes: 66 additions & 0 deletions lib/cloudDBAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//═══════════════════════════════════════════════════════//
//If you want to recode, reupload
//or copy the codes/script,
//pls give credit
//no credit? i will take action immediately
//© 2022 Xeon Bot Inc. Cheems Bot MD
//Thank you to Lord Buddha, Family and Myself
//════════════════════════════//
const got = require('got')

const stringify = obj => JSON.stringify(obj, null, 2)
const parse = str => JSON.parse(str, (_, v) => {
if (
v !== null &&
typeof v === 'object' &&
'type' in v &&
v.type === 'Buffer' &&
'data' in v &&
Array.isArray(v.data)) {
return Buffer.from(v.data)
}
return v
})
class CloudDBAdapter {
constructor(url, {
serialize = stringify,
deserialize = parse,
fetchOptions = {}
} = {}) {
this.url = url
this.serialize = serialize
this.deserialize = deserialize
this.fetchOptions = fetchOptions
}

async read() {
try {
let res = await got(this.url, {
method: 'GET',
headers: {
'Accept': 'application/json;q=0.9,text/plain'
},
...this.fetchOptions
})
if (res.statusCode !== 200) throw res.statusMessage
return this.deserialize(res.body)
} catch (e) {
return null
}
}

async write(obj) {
let res = await got(this.url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
...this.fetchOptions,
body: this.serialize(obj)
})
if (res.statusCode !== 200) throw res.statusMessage
return res.body
}
}

module.exports = CloudDBAdapter
Empty file added lib/color.js
Empty file.
93 changes: 93 additions & 0 deletions lib/converter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//═══════════════════════════════════════════════════════//
//If you want to recode, reupload
//or copy the codes/script,
//pls give credit
//no credit? i will take action immediately
//© 2022 Xeon Bot Inc. Cheems Bot MD
//Thank you to Lord Buddha, Family and Myself
//════════════════════════════//
const fs = require('fs')
const path = require('path')
const { spawn } = require('child_process')

function ffmpeg(buffer, args = [], ext = '', ext2 = '') {
return new Promise(async (resolve, reject) => {
try {
let tmp = path.join(__dirname, '../src', + new Date + '.' + ext)
let out = tmp + '.' + ext2
await fs.promises.writeFile(tmp, buffer)
spawn('ffmpeg', [
'-y',
'-i', tmp,
...args,
out
])
.on('error', reject)
.on('close', async (code) => {
try {
await fs.promises.unlink(tmp)
if (code !== 0) return reject(code)
resolve(await fs.promises.readFile(out))
await fs.promises.unlink(out)
} catch (e) {
reject(e)
}
})
} catch (e) {
reject(e)
}
})
}

/**
* Convert Audio to Playable WhatsApp Audio
* @param {Buffer} buffer Audio Buffer
* @param {String} ext File Extension
*/
function toAudio(buffer, ext) {
return ffmpeg(buffer, [
'-vn',
'-ac', '2',
'-b:a', '128k',
'-ar', '44100',
'-f', 'mp3'
], ext, 'mp3')
}

/**
* Convert Audio to Playable WhatsApp PTT
* @param {Buffer} buffer Audio Buffer
* @param {String} ext File Extension
*/
function toPTT(buffer, ext) {
return ffmpeg(buffer, [
'-vn',
'-c:a', 'libopus',
'-b:a', '128k',
'-vbr', 'on',
'-compression_level', '10'
], ext, 'opus')
}

/**
* Convert Audio to Playable WhatsApp Video
* @param {Buffer} buffer Video Buffer
* @param {String} ext File Extension
*/
function toVideo(buffer, ext) {
return ffmpeg(buffer, [
'-c:v', 'libx264',
'-c:a', 'aac',
'-ab', '128k',
'-ar', '44100',
'-crf', '32',
'-preset', 'slow'
], ext, 'mp4')
}

module.exports = {
toAudio,
toPTT,
toVideo,
ffmpeg,
}
79 changes: 79 additions & 0 deletions lib/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//═══════════════════════════════════════════════════════//
//If you want to recode, reupload
//or copy the codes/script,
//pls give credit
//no credit? i will take action immediately
//© 2022 Xeon Bot Inc. Cheems Bot MD
//Thank you to Lord Buddha, Family and Myself
//════════════════════════════//
const path = require('path')
const _fs = require('fs')
const { promises: fs } = _fs

class Database {
/**
* Create new Database
* @param {String} filepath Path to specified json database
* @param {...any} args JSON.stringify arguments
*/
constructor(filepath, ...args) {
this.file = path.resolve(filepath)
this.logger = console

this._load()

this._jsonargs = args
this._state = false
this._queue = []
this._interval = setInterval(async () => {
if (!this._state && this._queue && this._queue[0]) {
this._state = true
await this[this._queue.shift()]().catch(this.logger.error)
this._state = false
}
}, 1000)

}

get data() {
return this._data
}

set data(value) {
this._data = value
this.save()
}

/**
* Queue Load
*/
load() {
this._queue.push('_load')
}

/**
* Queue Save
*/
save() {
this._queue.push('_save')
}

_load() {
try {
return this._data = _fs.existsSync(this.file) ? JSON.parse(_fs.readFileSync(this.file)) : {}
} catch (e) {
this.logger.error(e)
return this._data = {}
}
}

async _save() {
let dirname = path.dirname(this.file)
if (!_fs.existsSync(dirname)) await fs.mkdir(dirname, { recursive: true })
await fs.writeFile(this.file, JSON.stringify(this._data, ...this._jsonargs))
return this.file
}
}

module.exports = Database

Loading

0 comments on commit 23e5b9d

Please sign in to comment.