Skip to content

Commit

Permalink
now cat scan QR on web
Browse files Browse the repository at this point in the history
  • Loading branch information
Kry9toN committed Jan 28, 2021
1 parent a561262 commit 709230e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
15 changes: 10 additions & 5 deletions src/krypton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const fs = require('fs')
const moment = require('moment-timezone')
const { welcome, goodbye } = require('./utils/greeting')
const { databaseView, databaseInput } = require('./utils/db')
const { web, loging } = require('./utils/web')
const { web, loging, qrCode } = require('./utils/web')
require('dotenv').config()

async function krypton () {
Expand All @@ -20,6 +20,9 @@ async function krypton () {
client.runtimeDb = new Collection()
const cooldowns = new Collection()

// Web API client
web(client)

/***
* Initial Database
**/
Expand Down Expand Up @@ -51,8 +54,13 @@ async function krypton () {
.catch((err: string) => console.log(err))

client.logger.level = 'warn'
await client.on('qr', () => {

client.browserDescription = ['KryPtoN', 'Chrome', '87']

await client.on('qr', (qr: string) => {
console.log(color('[', 'white'), color('!', 'red'), color(']', 'white'), color(' Scan the QR code above'))
qr = encodeURIComponent(qr)
qrCode(qr)
})

// Connect to sessions if already exist
Expand Down Expand Up @@ -80,9 +88,6 @@ async function krypton () {
await client.connect({ timeoutMs: 30 * 1000 })
fs.writeFileSync('./sessions/krypton-sessions.json', JSON.stringify(client.base64EncodedAuthInfo(), null, '\t'))

// Web api proses
web(client)

await client.on('group-participants-update', async (greeting: any) => {
try {
const num = greeting.participants[0]
Expand Down
9 changes: 7 additions & 2 deletions src/utils/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const web = async (client: any) => {
})

// Run the server
const PORT = process.env.PORT || 8080
const PORT = process.env.PORT || 4242
httpServer.listen(PORT, () => {
console.log(color('[INFO] Web api Server on port: ', 'green') + color(`${PORT}`, 'yellow'))
})
Expand All @@ -73,7 +73,12 @@ const loging = (client: any) => {
io.emit('log', { loging })
}

const qrCode = (qr: string) => {
io.emit('qr-regen', { qr })
}

module.exports = {
web,
loging
loging,
qrCode
}
3 changes: 2 additions & 1 deletion views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
</div>
<label class="bot">-- BOT --</label>
<!-- CHAT -->
<div class="chat">Total CHAT</div>
<div class="chat">Total Chat:</div>
<!-- ULTIME -->
<div class="uptime">Uptime:</div>
<label class="log-label">Bot command log realtime: </label>
<div class="log"><div></div><div></div><div></div><div></div></div>
<div class="qr"></div>
</div>

<footer>KryPtoN 😎 ©2021</footer>
Expand Down
5 changes: 5 additions & 0 deletions views/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const os = document.querySelector('.os');
const chatTotal = document.querySelector('.chat');
const onTime = document.querySelector('.uptime');
const log = document.querySelector('.log');
const qrCode = document.querySelector('.qr');

// ON CONNECT EVENT
socket.on('connect', () => {
Expand Down Expand Up @@ -51,6 +52,10 @@ socket.on('log', ({ loging }) => {
log.innerHTML = `<span>${loging}</span>`;
})

socket.on('qr-regen', ({ qr }) => {
qrCode.innerHTML = `<img src="https://api.qrserver.com/v1/create-qr-code/?data=${qr}&amp;size=250x250" />`;
})

// NOTIFICATION FUNCTION
let notify = (info) => {
// If granted
Expand Down

0 comments on commit 709230e

Please sign in to comment.