forked from ikkygganzBotz/Riych-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathriych.js
More file actions
151 lines (141 loc) · 5.99 KB
/
Copy pathriych.js
File metadata and controls
151 lines (141 loc) · 5.99 KB
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
146
147
148
149
150
151
require('./settings/config.js')
const
{
WAConnection,
MessageType,
Presence,
MessageOptions,
Mimetype,
WALocationMessage,
WA_MESSAGE_STUB_TYPES,
WA_DEFAULT_EPHEMERAL,
ReconnectMode,
ProxyAgent,
GroupSettingChange,
waChatKey,
mentionedJid,
processTime,
} = require("@adiwajshing/baileys")
const fs = require('fs')
const { banner, getBuffer, start, success } = require('./lib/functions')
const { color } = require('./lib/color')
const CFonts = require('cfonts')
const { uploadImages } = require('./lib/uploadimage')
require('./command/case.js')
nocache('./command/case.js', module => console.log(`${module} is now updated!`))
const starts = async (haruka = new WAConnection()) => {
haruka.logger.level = 'warn'
haruka.version = [2, 2143, 3]
haruka.browserDescription = [ 'Haruka-Bot', 'Chrome', '3.0' ]
CFonts.say('Riychbot', {
font: 'block',
color: ['#ff9c00'],
align: 'center',
})
CFonts.say(`Bot WhatsApp Created By Riych-Uhuy`, {
font: 'console',
align: 'center',
gradient: ['red', 'magenta']
})
haruka.on('qr', () => {
console.log(color('[','white'), color('!','red'), color(']','white'), color(' Scan qr maks 20 detik sebelum qr expired'))
})
fs.existsSync('./session.json') && haruka.loadAuthInfo('./session.json')
haruka.on('connecting', () => {
start('2', 'Connecting...')
})
haruka.on('open', () => {
success('2', 'Connected')
})
await haruka.connect({timeoutMs: 30*1000})
fs.writeFileSync('./session.json', JSON.stringify(haruka.base64EncodedAuthInfo(), null, '\t'))
haruka.on('chat-update', async (message) => {
require('./command/case.js')(haruka, message)
})
haruka.on('group-participants-update', async (anu) => {
console.log(anu)
try {
const sendButLoc = async (id, text1, desc1, gam1, but = [], options = {}) => {
const mediaxxaaaa = await haruka.prepareMessage(id, gam1, MessageType.location, {thumbnail: gam1})
var mhan = mediaxxaaaa.message["ephemeralMessage"] ? mediaxxaaaa.message.ephemeralMessage : mediaxxaaaa
const buttonMessages = {
locationMessage: mhan.message.locationMessage,
contentText: text1,
footerText: desc1,
buttons: but,
headerType: 6
}
haruka.sendMessage(id, buttonMessages, MessageType.buttonsMessage, options)
}
const mdata = await haruka.groupMetadata(anu.jid)
num = anu.participants[0]
let v = haruka.contacts[num] || { notify: num.replace(/@.+/, "") };
anu_user = v.vname || v.notify || num.split("@")[0];
try {
ppmem = await haruka.getProfilePicture(num);
} catch (e) {
ppmem = 'https://telegra.ph/file/f8df36078279304745bae.png'
}
try {
ppgc = await haruka.getProfilePicture(anu.jid);
} catch (e) {
ppgc = 'https://telegra.ph/file/d4c05638fa7886a1d8060.jpg'
}
let ppmem2 = await getBuffer(ppmem)
let ppmem3 = await uploadImages(ppmem2)
let ppgc2 = await getBuffer(ppgc)
let ppgc3 = await uploadImages(ppgc2)
let gakloo = [{
"buttonId": `.owner`,
"buttonText": {
"displayText": "Welcome 👋"
},
"type": "RESPONSE"
}]
if (anu.action == 'add' && !num.includes(haruka.user.jid)) {
welcome = await getBuffer(`https://api-alphabot.herokuapp.com/api/greetings/welcome2?name=${encodeURI(anu_user)}&member=${encodeURI(mdata.participants.length)}&groupName=${encodeURI(mdata.subject)}&ppuser=${ppmem3}&bgurl=${background}&apikey=Alphabot`)
try{
await sendButLoc(mdata.id, `Welcome @${num.split('@')[0]} to ${mdata.subject}` + '\n' + lang.welcome(), `Welcome Message By ${ownername}`,welcome, [{"buttonId": `.owner`,"buttonText": {"displayText": "Welcome"},"type": "RESPONSE"}], {contextInfo: { mentionedJid: [num]}})
} catch {
await sendButLoc(mdata.id, `Welcome @${num.split('@')[0]} to ${mdata.subject}` + '\n' + lang.welcome(), `Welcome Message By ${ownername}`,ppmem2, [{"buttonId": `.owner`,"buttonText": {"displayText": "Welcome"},"type": "RESPONSE"}], {contextInfo: { mentionedJid: [num]}})
}
} else if (anu.action == 'remove' && !num.includes(haruka.user.jid)) {
goodbye = await getBuffer(`https://api-alphabot.herokuapp.com/api/greetings/goodbye2?name=${encodeURI(anu_user)}&member=${encodeURI(mdata.participants.length)}&groupName=${encodeURI(mdata.subject)}&ppuser=${ppmem3}&bgurl=${background}&apikey=Alphabot`)
try{
await sendButLoc(mdata.id, `Goodbye @${num.split('@')[0]}\n⌯ָ ֙Leave from group:\n${mdata.subject}` + '\n' + lang.leave(), `Leave Message By ${ownername}`,goodbye, [{"buttonId": `.owner`,"buttonText": {"displayText": "Bye"},"type": "RESPONSE"}], {contextInfo: { mentionedJid: [num]}})
} catch {
await sendButLoc(mdata.id, `Goodbye @${num.split('@')[0]}\n⌯ָ ֙Leave from group:\n${mdata.subject}` + '\n' + lang.leave(), `Leave Message By ${ownername}`,ppmem2, [{"buttonId": `.owner`,"buttonText": {"displayText": "Bye"},"type": "RESPONSE"}], {contextInfo: { mentionedJid: [num]}})
}
}
} catch (e) {
console.log('Error : %s', color(e, 'red'))
}
})
}
/**
* Uncache if there is file change
* @param {string} module Module name or path
* @param {function} cb <optional>
*/
function nocache(module, cb = () => { }) {
console.log('Module', `'${module}'`, 'is now being watched for changes')
fs.watchFile(require.resolve(module), async () => {
await uncache(require.resolve(module))
cb(module)
})
}
/**
* Uncache a module
* @param {string} module Module name or path
*/
function uncache(module = '.') {
return new Promise((resolve, reject) => {
try {
delete require.cache[require.resolve(module)]
resolve()
} catch (e) {
reject(e)
}
})
}
starts()