Skip to content

Commit

Permalink
Format Code
Browse files Browse the repository at this point in the history
  • Loading branch information
AlenVelocity committed Apr 14, 2021
1 parent 34398cd commit 11045d6
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 38 deletions.
3 changes: 1 addition & 2 deletions src/Client/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { IGroupinfo } from '../Typings'
import { Client as Base } from './ML'

export class Client extends Base {

group = new GroupEx(this)

async getGroupInfo(jid: string): Promise<IGroupinfo> {
Expand All @@ -14,4 +13,4 @@ export class Client extends Base {
if (!data) data = await new this.GroupModel({ jid }).save()
return { metadata, admins, data }
}
}
}
3 changes: 1 addition & 2 deletions src/Client/ML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { MlNsfw } from '../lib'
import { Client as Base } from './Utils'

export class Client extends Base {

ML = {
nsfw: new MlNsfw()
}
}
}
2 changes: 1 addition & 1 deletion src/Client/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class Client extends WAConnection {
constructor(
public GroupModel: Model<IGroupModel>,
public UserModel: Model<IUserModel>,
public SessionModel: Model<ISessionModel>,
public SessionModel: Model<ISessionModel>
) {
super()
if (this.config.cron) this.clearCycle(this.config.cron)
Expand Down
37 changes: 18 additions & 19 deletions src/Handler/Message.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { MessageType, proto, WAGroupMetadata, WAMessage } from '@adiwajshing/baileys'
import chalk from 'chalk'
import { Client } from '../Client'
import {
createSticker,
help,
toggleableGroupActions,
getWById,
wSearch,
ytSreach,
getYTMediaFromUrl
} from '../lib'
import { createSticker, help, toggleableGroupActions, getWById, wSearch, ytSreach, getYTMediaFromUrl } from '../lib'
import moment from 'moment-timezone'
import responses from '../lib/responses.json'
import Utils from '../Utils'
Expand All @@ -21,24 +13,22 @@ export class Message {
handleGroupMessage = async (M: WAMessage): Promise<void> => {
const from = M.key.remoteJid
if (!from) return

const { message } = M
if (!message) return

const sender = M.participant

const mod = this.client._config.admins.includes(sender)
const group = await this.client.getGroupInfo(from)

const { user, data: userData } = await this.client.getUser(sender)
const [admin, iAdmin] = [group.admins.includes(sender), group.admins.includes(this.client.user.jid)]
const username = user?.notify || user?.vname || user?.name || ''
if (group.data.safe && !admin && iAdmin && (await this.checkMessageForNSFWandAct(M, username, group.metadata))) return void null
if (group.data.safe && !admin && iAdmin && (await this.checkMessageForNSFWandAct(M, username, group.metadata)))
return void null
const { body, media } = this.getBase(M, message)
if (!body) return
const opt = this.parseArgs(body)
if (!opt) return
const { args, flags } = opt

if (!args[0].startsWith(this.client._config.prefix)) return this.freeText(body, M)
const command = args[0].slice(1).toLowerCase()
if (!command)
Expand All @@ -60,8 +50,6 @@ export class Message {
? [message.extendedTextMessage.contextInfo.participant]
: []


const mod = this.client._config.admins.includes(sender)
console.log(
chalk.green('[EXEC]'),
chalk.blue(moment(Number(M.messageTimestamp) * 1000).format('DD/MM HH:mm:ss')),
Expand Down Expand Up @@ -107,7 +95,11 @@ export class Message {
case 'promote':
case 'demote':
case 'remove':
this.client.reply(from, await this.client.group.toggleEvent(from, mentioned || [], admin, iAdmin, command), M)
this.client.reply(
from,
await this.client.group.toggleEvent(from, mentioned || [], admin, iAdmin, command),
M
)
break
case 'help':
this.client.reply(from, { body: help(this.client, slicedJoinedArgs.toLowerCase().trim()) }, M)
Expand Down Expand Up @@ -310,9 +302,16 @@ export class Message {
checkMessageForNSFWandAct = async (M: WAMessage, username: string, metadata: WAGroupMetadata): Promise<boolean> => {
if (!M.message?.imageMessage) return false
if (await this.client.ML.nsfw.check(await this.client.downloadMediaMessage(M))) {
await this.client.reply(metadata.id, { body: responses['nsfw-detected']}, M)
await this.client.reply(metadata.id, { body: responses['nsfw-detected'] }, M)
await this.client.group.toggleEvent(metadata.id, [M.participant], true, true, 'remove')
console.log(chalk.redBright('[NSFW]'), chalk.yellow(moment((M.messageTimestamp as number * 1000)).format('DD/MM HH:mm:ss')), 'By', chalk.red(username), 'in', chalk.red(metadata.subject))
console.log(
chalk.redBright('[NSFW]'),
chalk.yellow(moment((M.messageTimestamp as number) * 1000).format('DD/MM HH:mm:ss')),
'By',
chalk.red(username),
'in',
chalk.red(metadata.subject)
)
return true
}
return false
Expand Down
14 changes: 7 additions & 7 deletions src/Web/Routes/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class BaseRoutes {

constructor(public client: Client, public web: Web) {
this.web.app.use('/client', this.clientRouter)
this.web.app.get('/', (req, res) => res.json({ message: 'Hi there'}))
this.web.app.get('/', (req, res) => res.json({ message: 'Hi there' }))
this.web.app.get('/wakemydyno.txt', async (req, res) => {
res.setHeader('Content-disposition', 'attachment; filename=wakemydyno.txt')
res.setHeader('Content-type', 'text/plain')
Expand Down Expand Up @@ -43,23 +43,23 @@ export class BaseRoutes {
})
res.end(this.web.QR)
})

this.clientRouter.get('/state', (req, res) => {
res.json({ state: this.client.state })
})
this.web.app.get('/endpoints', (req, res) => {
res.json(endpoints)
})

this.clientRouter.get('/config', (req, res) => {
res.json(this.client._config)
})

this.clientRouter.get('/user', (req, res) => {
const json = req.query.jid ? this.client.contacts[String(req.query.jid)] || {} : this.client.user
res.json(json)
})

this.clientRouter.get('/wa', async (req, res) => {
const query = req.query
if (query?.state === this.connectionOptions[1]) {
Expand All @@ -84,7 +84,7 @@ export class BaseRoutes {
}
return res.json({ message: 'Invalid Query' })
})

this.clientRouter.get('/session', async (req, res) => {
if (req.query.delete) {
const ID = process.env.SESSION_ID || 'PROD'
Expand All @@ -94,7 +94,7 @@ export class BaseRoutes {
}
return res.json(this.client.base64EncodedAuthInfo())
})

this.clientRouter.get('/pfp', async (req, res) => {
const auth = this.auth(req)
if (typeof auth === 'object') return res.json(auth)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ML/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './nsfw'
export * from './nsfw'
5 changes: 2 additions & 3 deletions src/lib/ML/nsfw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import * as tf from '@tensorflow/tfjs-node'
import * as nsfw from 'nsfwjs'

export class MlNsfw {

nsfwModel!: nsfw.NSFWJS

constructor() {
nsfw.load().then((m) => {
this.nsfwModel = m
Expand All @@ -18,4 +17,4 @@ export class MlNsfw {
if (pre[0].className === 'Hentai' || pre[0].className === 'Porn') return true
return false
}
}
}
11 changes: 9 additions & 2 deletions src/lib/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ export class GroupEx {

simplifiedGroupInfo = async (info: IGroupinfo): Promise<IReply> => {
const { metadata, data } = info
const [safe, events, NSFW, icon] = [data?.safe || false, data?.events || false, data?.nsfw || false, await this.client.getPfp(metadata.id)]
const [safe, events, NSFW, icon] = [
data?.safe || false,
data?.events || false,
data?.nsfw || false,
await this.client.getPfp(metadata.id)
]
const owner = this.client.contacts[metadata.owner]
return {
body: icon ? await Utils.download(icon) : Utils.yui404,
Expand All @@ -100,7 +105,9 @@ export class GroupEx {
metadata.participants.length
}\n\n🏅 *Admins:* ${
metadata.participants.filter((participiant) => participiant.isAdmin).length
}\n\n🔮 *Events:* ${events}\n\n🌟 *Safe:* ${safe}\n\n🔞 *NSFW:* ${NSFW}\n\n〽 *Description:* ${metadata.desc}`,
}\n\n🔮 *Events:* ${events}\n\n🌟 *Safe:* ${safe}\n\n🔞 *NSFW:* ${NSFW}\n\n〽 *Description:* ${
metadata.desc
}`,
type: MessageType.image
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export * from './help'
export * from './anime'
export * from './YT'
export * from './sticker'
export * from './ML'
export * from './ML'

0 comments on commit 11045d6

Please sign in to comment.