Spaces:
Paused
Paused
Upload 3 files
Browse files- Dockerfile (1).txt +11 -0
- server.js +60 -0
- silva.js +131 -0
Dockerfile (1).txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM quay.io/gurusensei/gurubhay:latest
|
| 2 |
+
|
| 3 |
+
RUN git clone https://github.com/SilvaTechB/silva-md-bot /root/sylivanus
|
| 4 |
+
|
| 5 |
+
WORKDIR /root/sylivanus/
|
| 6 |
+
|
| 7 |
+
RUN npm install --platform=linuxmusl
|
| 8 |
+
|
| 9 |
+
EXPOSE 5000
|
| 10 |
+
|
| 11 |
+
CMD ["npm", "start"]
|
server.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import express from 'express'
|
| 2 |
+
import { createServer } from 'http'
|
| 3 |
+
import path from 'path'
|
| 4 |
+
import { Socket } from 'socket.io'
|
| 5 |
+
import { toBuffer } from 'qrcode'
|
| 6 |
+
import fetch from 'node-fetch'
|
| 7 |
+
|
| 8 |
+
function connect(conn, PORT) {
|
| 9 |
+
let app = (global.app = express())
|
| 10 |
+
console.log(app)
|
| 11 |
+
let server = (global.server = createServer(app))
|
| 12 |
+
// app.use(express.static(path.join(__dirname, 'views')))
|
| 13 |
+
let _qr = 'invalid'
|
| 14 |
+
|
| 15 |
+
conn.ev.on('connection.update', function appQR({ qr }) {
|
| 16 |
+
if (qr) _qr = qr
|
| 17 |
+
})
|
| 18 |
+
|
| 19 |
+
app.use(async (req, res) => {
|
| 20 |
+
res.setHeader('content-type', 'image/png')
|
| 21 |
+
res.end(await toBuffer(_qr))
|
| 22 |
+
})
|
| 23 |
+
|
| 24 |
+
// let io = new Socket(server)
|
| 25 |
+
// io.on('connection', socket => {
|
| 26 |
+
// let { unpipeEmit } = pipeEmit(conn, socket, 'conn-')
|
| 27 |
+
// socket.on('disconnect', unpipeEmit)
|
| 28 |
+
// })
|
| 29 |
+
|
| 30 |
+
server.listen(PORT, () => {
|
| 31 |
+
console.log('App listened on port', PORT)
|
| 32 |
+
if (opts['keepalive']) keepAlive()
|
| 33 |
+
})
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
function pipeEmit(event, event2, prefix = '') {
|
| 37 |
+
let old = event.emit
|
| 38 |
+
event.emit = function (event, ...args) {
|
| 39 |
+
old.emit(event, ...args)
|
| 40 |
+
event2.emit(prefix + event, ...args)
|
| 41 |
+
}
|
| 42 |
+
return {
|
| 43 |
+
unpipeEmit() {
|
| 44 |
+
event.emit = old
|
| 45 |
+
},
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
function keepAlive() {
|
| 50 |
+
const url = `https://${process.env.REPL_SLUG}.${process.env.REPL_OWNER}.repl.co`
|
| 51 |
+
if (/(\/\/|\.)undefined\./.test(url)) return
|
| 52 |
+
setInterval(
|
| 53 |
+
() => {
|
| 54 |
+
fetch(url).catch(console.error)
|
| 55 |
+
},
|
| 56 |
+
5 * 1000 * 60
|
| 57 |
+
)
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
export default connect
|
silva.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import chalk from 'chalk'
|
| 2 |
+
import { spawn } from 'child_process'
|
| 3 |
+
import express from 'express'
|
| 4 |
+
import figlet from 'figlet'
|
| 5 |
+
import fs from 'fs'
|
| 6 |
+
import path from 'path'
|
| 7 |
+
import { fileURLToPath } from 'url';
|
| 8 |
+
|
| 9 |
+
figlet(
|
| 10 |
+
'SILVA MD',
|
| 11 |
+
{
|
| 12 |
+
font: 'Ghost',
|
| 13 |
+
horizontalLayout: 'default',
|
| 14 |
+
verticalLayout: 'default',
|
| 15 |
+
},
|
| 16 |
+
(err, data) => {
|
| 17 |
+
if (err) {
|
| 18 |
+
console.error(chalk.red('Figlet error:', err))
|
| 19 |
+
return
|
| 20 |
+
}
|
| 21 |
+
console.log(chalk.yellow(data))
|
| 22 |
+
}
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
figlet(
|
| 26 |
+
'Silva Bot',
|
| 27 |
+
{
|
| 28 |
+
horizontalLayout: 'default',
|
| 29 |
+
verticalLayout: 'default',
|
| 30 |
+
},
|
| 31 |
+
(err, data) => {
|
| 32 |
+
if (err) {
|
| 33 |
+
console.error(chalk.red('Figlet error:', err))
|
| 34 |
+
return
|
| 35 |
+
}
|
| 36 |
+
console.log(chalk.magenta(data))
|
| 37 |
+
}
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
const app = express()
|
| 41 |
+
const port = process.env.PORT || 5000
|
| 42 |
+
|
| 43 |
+
const __filename = fileURLToPath(import.meta.url);
|
| 44 |
+
const __dirname = path.dirname(__filename);
|
| 45 |
+
|
| 46 |
+
app.use(express.static(path.join(__dirname, 'jusorts')));
|
| 47 |
+
|
| 48 |
+
app.get('/', (req, res) => {
|
| 49 |
+
res.redirect('/silva.html');
|
| 50 |
+
});
|
| 51 |
+
|
| 52 |
+
app.listen(port, () => {
|
| 53 |
+
console.log(chalk.green(`Port ${port} is open`))
|
| 54 |
+
})
|
| 55 |
+
|
| 56 |
+
let isRunning = false
|
| 57 |
+
|
| 58 |
+
async function start(file) {
|
| 59 |
+
if (isRunning) return
|
| 60 |
+
isRunning = true
|
| 61 |
+
|
| 62 |
+
const currentFilePath = new URL(import.meta.url).pathname
|
| 63 |
+
const args = [path.join(path.dirname(currentFilePath), file), ...process.argv.slice(2)]
|
| 64 |
+
const p = spawn(process.argv[0], args, {
|
| 65 |
+
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
| 66 |
+
})
|
| 67 |
+
|
| 68 |
+
p.on('message', data => {
|
| 69 |
+
console.log(chalk.cyan(`✔️RECEIVED ${data}`))
|
| 70 |
+
switch (data) {
|
| 71 |
+
case 'reset':
|
| 72 |
+
p.kill()
|
| 73 |
+
isRunning = false
|
| 74 |
+
start.apply(this, arguments)
|
| 75 |
+
break
|
| 76 |
+
case 'uptime':
|
| 77 |
+
p.send(process.uptime())
|
| 78 |
+
break
|
| 79 |
+
}
|
| 80 |
+
})
|
| 81 |
+
|
| 82 |
+
p.on('exit', code => {
|
| 83 |
+
isRunning = false
|
| 84 |
+
console.error(chalk.red(`❌Exited with code: ${code}`))
|
| 85 |
+
|
| 86 |
+
if (code === 0) return
|
| 87 |
+
|
| 88 |
+
fs.watchFile(args[0], () => {
|
| 89 |
+
fs.unwatchFile(args[0])
|
| 90 |
+
start('sylivanus.js')
|
| 91 |
+
})
|
| 92 |
+
})
|
| 93 |
+
|
| 94 |
+
p.on('error', err => {
|
| 95 |
+
console.error(chalk.red(`Error: ${err}`))
|
| 96 |
+
p.kill()
|
| 97 |
+
isRunning = false
|
| 98 |
+
start('sylivanus.js')
|
| 99 |
+
})
|
| 100 |
+
|
| 101 |
+
const pluginsFolder = path.join(path.dirname(currentFilePath), 'lazackcmds')
|
| 102 |
+
|
| 103 |
+
fs.readdir(pluginsFolder, async (err, files) => {
|
| 104 |
+
if (err) {
|
| 105 |
+
console.error(chalk.red(`Error reading lazackcmds folder: ${err}`))
|
| 106 |
+
return
|
| 107 |
+
}
|
| 108 |
+
console.log(chalk.yellow(`Installed ${files.length} plugins`))
|
| 109 |
+
|
| 110 |
+
try {
|
| 111 |
+
const { default: baileys } = await import('@whiskeysockets/baileys')
|
| 112 |
+
const version = (await baileys.fetchLatestBaileysVersion()).version
|
| 113 |
+
console.log(chalk.yellow(`Using Baileys version ${version}`))
|
| 114 |
+
} catch (e) {
|
| 115 |
+
console.error(chalk.red(' Baileys library is not installed'))
|
| 116 |
+
}
|
| 117 |
+
})
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
start('sylivanus.js')
|
| 121 |
+
|
| 122 |
+
process.on('unhandledRejection', () => {
|
| 123 |
+
console.error(chalk.red(`Unhandled promise rejection. Bot will restart...`))
|
| 124 |
+
start('sylivanus.js')
|
| 125 |
+
})
|
| 126 |
+
|
| 127 |
+
process.on('exit', code => {
|
| 128 |
+
console.error(chalk.red(`Exited with code: ${code}`))
|
| 129 |
+
console.error(chalk.red(`Bot will restart...`))
|
| 130 |
+
start('sylivanus.js')
|
| 131 |
+
})
|