-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
195 lines (179 loc) · 7.95 KB
/
app.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
const { Client, LocalAuth, MessageMedia} = require('whatsapp-web.js');
const qrcode = require('qrcode-terminal');
const fs = require('fs');
const axios = require('axios');
const FormData = require('form-data');
const path = require('path');
const client = new Client({
authStrategy: new LocalAuth()
});
client.on('qr', (qr) => {
qrcode.generate(qr, {small:true});
});
client.on('authenticated', () => {
console.log('authenticad')
});
client.on('auth_failure', msg => {
// Fired if session restore was unsuccessful
console.error('AUTHENTICATION FAILURE', msg);
});
client.on('ready', () => {
console.log('Client is ready!');
});
client.initialize();
client.on('message', msg => {
if(msg.body === '$menu') {
const weekday = ["Minggu","Senin","Selasa","Rabu","Kamis","Jum'at","Sabtu"];
const d = new Date();
let day = weekday[d.getDay()];
msg.reply(
` Tahu Genjot
Serasa Digenjot Tobrut
Server Time : ${day} ${d.toLocaleTimeString()} ${ d.toLocaleDateString() }
*List Menu*
*->* $sticker
*->* $change<spasi>Change Group Name
*->* $gacha-waifu
*->* $all
*->* $cuaca<spasi>kota
*->* $removebg
ASEDE
`);
}
});
client.on('message', async(msg)=> {
if(msg.body.startsWith('$sticker') && msg.type === 'image'){
const media = await msg.downloadMedia();
msg.reply(media, msg.from, {
sendMediaAsSticker:true,
stickerName: "Tahu Genjot",
stickerAuthor: "Serasa digenjot Tobrut"
})
} else if (msg.body.startsWith('$change ')) {
// Change the group subject
let chat = await msg.getChat();
if (chat.isGroup) {
let newSubject = msg.body.slice(8);
chat.setSubject(newSubject);
} else {
msg.reply('This command can only be used in a group!');
}
} else if (msg.body === '$gacha-waifulokal') {
const waifu = ['Alice-Nakiri.jpeg', 'Belldandy.jpeg', 'KOCHO-SHINOBU.jpeg', 'Lenalee-Lee.jpeg', 'mai.jpeg', 'Megumi-Tadokoro.jpeg', 'Miku-nakano.jpeg', 'ram.jpeg', 'selee.jpeg', 'TATSUMAKI.png', 'Teletha.png'];
const random = Math.floor(Math.random() * waifu.length);
const media = MessageMedia.fromFilePath(`./waifu/${waifu[random]}`);
msg.reply(media, msg.from, {
caption:"Gacha terus dan dapatkan waifu favoritmu"
});
} else if(msg.body === '$all') {
const chat = await msg.getChat();
if(!chat.isGroup){
msg.reply('this command can only used in a group!')
}
// GET TIME ZONE
const time = new Date().getHours();
let timezone = '';
if( time >= 3 && time < 11 ){
timezone = 'Selamat Pagi';
} else if(time >= 11 && time < 15 ){
timezone = 'selamat siang';
} else if (time >= 15 && time < 18){
timezone = 'selamat sore';
} else {
timezone = 'selamat malam';
}
// LAST GET TIME ZONE
let text = timezone + " " + "Member" + " " + chat.name;
let mentions = [];
for(let participant of chat.participants) {
const contact = await client.getContactById(participant.id._serialized);
mentions.push(contact);
text += `@${participant.id.user} `;
}
await msg.reply(text, msg.from, {mentions});
} else if(msg.body.startsWith('$cuaca ')){
let weather = msg.body.slice(7);
const yourapi = ''
axios.get(`https://api.openweathermap.org/data/2.5/weather?appid=${yourapi}&units=metric&q=${weather}`)
.then(function (response) {
const res = response.data;
cuaca(res);
})
.catch(function (error) {
console.log(error);
// const err = error.data;
cuacaMiss(error)
})
function cuaca (res){
msg.reply(`
Kota : ${res.name}, ${res.sys.country}
Cuaca : ${res.weather[0].main}, ${res.weather[0].description}
Suhu : ${res.main.temp}°C
Angin : ${res.wind.speed} Speed, ${res.wind.deg} Deg,
Source : openweathermap.org
`)
}
function cuacaMiss(res){
msg.reply(` Nama Kota tidak ditemukan
${res.message}`)
}
} else if (msg.body === '$gacha-waifu'){
axios.get('https://api.waifu.pics/sfw/waifu')
.then(function(res){
console.log(res);
waif(res.data)
})
.catch(function(err){
console.log(err)
})
const waif = async(res) => {
const media = await MessageMedia.fromUrl(res.url)
msg.reply(media, msg.from, {
caption: "gacha terus dan dapatkan waifu favoritmu"
});
}
} else if(msg.body.startsWith('$removebg') && msg.type === 'image'){
msg.downloadMedia()
.then((res) => {
const random = Math.floor(Math.random() * 24123143123142).toString();
const pathImg = `./upload/${random}.png`;
fs.writeFileSync(pathImg, res.data, {encoding:'base64'});
removeBgApi(pathImg);
})
.catch((err) => {
console.log(err)
})
function removeBgApi(rdm){
const formData = new FormData();
formData.append('size', 'auto');
formData.append('image_file', fs.createReadStream(rdm), path.basename(rdm));
axios({
method: 'post',
url: 'https://api.remove.bg/v1.0/removebg',
data: formData,
responseType: 'arraybuffer',
headers: {
...formData.getHeaders(),
'X-Api-Key': 'Your Api key',
},
encoding: null
})
.then((response) => {
if(response.status != 200) return console.error('Error:', response.status, response.statusText);
const random = Math.floor(Math.random() * 24123143123142).toString();
const urlGmbr = `./result/${random}.png`;
fs.writeFileSync(urlGmbr, response.data);
urlGm(urlGmbr);
})
.catch((error) => {
return console.error('Request failed:', error);
});
function urlGm(pat){
const media = MessageMedia.fromFilePath(pat)
msg.reply(media , msg.from, {
sendMediaAsDocument:true
})
}
}
}
})