This repository has been archived by the owner on Jan 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 142
/
index.js
145 lines (142 loc) · 6.78 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const {
WAConnection,
MessageType,
Presence,
MessageOptions,
Mimetype,
WALocationMessage,
WA_MESSAGE_STUB_TYPES,
messageStubType,
ReconnectMode,
ProxyAgent,
waChatKey,
WAMessageProto,
prepareMessageFromContent,
relayWAMessage,
} = require("@adiwajshing/baileys");
const fs = require('fs');
const moment = require('moment-timezone');
const afkJs = require('./lib/afk')
const yargs = require('yargs/yargs')
const vn = JSON.parse(fs.readFileSync('./lib/json/vn.json'))
const ClientJs = require('./lib/client');
const cron = require('node-cron');
global.configs = JSON.parse(fs.readFileSync('./config.json'));
let dataUser = JSON.parse(fs.readFileSync('./lib/json/dataUser.json'))
global.vn = JSON.parse(fs.readFileSync('./lib/json/vn.json'))
global.tebakgambar = {}
moment.tz.setDefault('Asia/Jakarta').locale('id');
const { color } = require('./lib/func')
const Crypto = require('crypto')
const starts = async (sesName) => {
try {
const Client = new ClientJs(global.configs, sesName || global.configs.defaultSessionName)
const client = Client.mainClient
require("./lib/http-server")(client)
Client.starts()
detectChange('./handler.js', (mdl) =>{
try{
Client.cmd.removeAllListeners()
Client.handlerStick.removeAllListeners()
require('./handler')(client, Client)
console.log(color('[ INFO ]', 'cyan'), `${mdl} auto updated!`)
} catch (err) {
console.error(err)
}
})
require('./handler')(client, Client)
client.on('CB:Presence', asd => {
asd = asd[1]
if (!asd.id.endsWith('@g.us')) return
if((asd.type == 'composing' || asd.type == 'recording') && afkJs.detectingAfk(asd.id, asd.participant)) {
Client.sendText(asd.id, `@${asd.participant.split('@')[0]} terdeteksi melakukan aktivitas!, status afkMu telah dihapus`)
}
})
client.on('CB:Call', json => {
client.query({json: ["action","call",["call",{"from":client.user.jid,"to":json[1].from,"id":generateMessageID()},[["reject",{"call-id":json[1].id,"call-creator":json[1].from,"count":"0"},null]]]]}).then(() =>{
setTimeout(async () =>{
if (Client.blocklist.includes(json[1].from)) return
client.blockUser(json[1].from, 'add')
}, 3000)
}).catch()
})
client.on('new-msg', (message) => {
if(message.key && message.key.remoteJid == 'status@broadcast') return
if(message.key.fromMe && !Client.self || !message.key.fromMe && Client.self) return
let dataGc = JSON.parse(fs.readFileSync('./lib/json/dataGc.json'))
const body = message.body
const from = message.key.remoteJid
const isGroup = from.endsWith('@g.us')
const sender = isGroup ? message.participant : from
if (global.tebakgambar[from] && global.tebakgambar[from].id && global.tebakgambar[from].jawaban.toLowerCase() == body.toLowerCase()) Client.reply(from, `YES TEBAK GAMBAR BERHASIL DIJAWAB OLEH @${sender.split("@")[0]}`, message).then(() => global.tebakgambar[from] = {})
if (global.vn.includes(body)) Client.sendPtt(from, `./lib/vn/${body}.mp3`, message)
if (isGroup && !dataGc[from]){
dataGc[from] = {afk:{}}
fs.writeFileSync('./lib/json/dataGc.json', JSON.stringify(dataGc, null, 2))
}
if (isGroup && dataGc[from].antitagall && !message.isAdmin && (message.mentionedJidList.length == message.groupMembers.length || message.mentionedJidList.length-1 == message.groupMembers.length)){
Client.reply(from, 'Tagall detected', message)
client.groupRemove(from, [sender]).catch(() => Client.reply(from, `Jadikan bot admin agar bisa menggunakan fitur antitagall`, message))
}
if (isGroup && dataGc[from].antiviewonce && message.type == 'viewOnceMessage'){
var msg = {...message}
msg.message = message.message.viewOnceMessage.message
msg.message[Object.keys(msg.message)[0]].viewOnce = false
Client.reply(from, 'ViewOnce detected!', message)
client.forwardMessage(from, msg)
}
if (isGroup && !message.isAdmin && dataGc[from].antilink && /chat\.whatsapp\.com/gi.test(body)){
let dtclink = body.match(/chat.whatsapp.com\/(?:invite\/)?([0-9A-Za-z]{18,26})/gi) || []
dtclink.forEach(async l => {
checks = await Client.checkInviteLink(l)
if(checks.status == 200){
Client.reply(from, `Group link detected!`, message)
client.groupRemove(from, [sender]).catch(() => Client.reply(from, `Jadikan bot admin agar bisa menggunakan fitur antilink`, message))
}
})
}
if (!dataUser[sender]){
dataUser[sender] = {limit: 0, premium: false}
fs.writeFileSync('./lib/json/dataUser.json', JSON.stringify(dataUser))
}
if(isGroup) {
if(afkJs.detectingAfk(from, sender)) Client.sendText(from, `@${sender.split('@')[0]} sekarang tidak afk!`)
if(message.message.extendedTextMessage && message.message.extendedTextMessage.contextInfo && message.message.extendedTextMessage.contextInfo.mentionedJid) {
jids = message.message.extendedTextMessage.contextInfo.mentionedJid
jids.forEach(jid => {
takeData = afkJs.tagDetect(from, jid)
if(!takeData) return
duration = moment.duration(moment(takeData.time).diff(moment()))
Client.reply(from, `@${jid.split('@')[0]} sedang afk\nReason: ${takeData.reason}\nTime: ${duration.days()} Hari ${duration.hours()} Jam ${duration.minutes()} Menit ${duration.seconds()} detik`)
})
}
}
})
client.on('group-participants-update', (jdgn) => require('./lib/greet.js')(jdgn, Client, client))
} catch (e) {
console.error(e)
}
}
cron.schedule('0 0 * * *', () => {
for (users in dataUser){
dataUser[users].limit = 0
}
fs.writeFileSync('./lib/json/dataUser.json', JSON.stringify(dataUser))
console.log(color('[ INFO ]', 'cyan'), 'LIMIT RESETED!')
});
detectChange('./lib/text.js', (mdl) => console.log(color('[ INFO ]', 'cyan'), `${mdl} change is detected!`))
detectChange('./lib/greet.js', (mdl) => console.log(color('[ INFO ]', 'cyan'), `${mdl} change is detected!`))
function detectChange(module, cb){
fs.watchFile(require.resolve(module), () => {
delete require.cache[require.resolve(module)]
if (cb) cb(module)
})
}
const randomBytes = (length) => {
return Crypto.randomBytes(length)
}
global.generateMessageID = () => {
return '3EB0' + randomBytes(7).toString('hex').toUpperCase()
}
global.optn = yargs(process.argv.slice(2)).exitProcess(false).parse()
starts(process.argv[2])