-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconversion.js
378 lines (289 loc) Β· 10.2 KB
/
conversion.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
const { Sticker, createSticker, StickerTypes } = require('wa-sticker-formatter');
const { zokou } = require("../framework/zokou");
const traduire = require("../framework/traduction");
const { downloadMediaMessage,downloadContentFromMessage } = require('@whiskeysockets/baileys');
const fs =require("fs-extra") ;
const axios = require('axios');
const FormData = require('form-data');
const { exec } = require("child_process");
async function uploadToTelegraph(Path) {
if (!fs.existsSync(Path)) {
throw new Error("Fichier non existant");
}
try {
const form = new FormData();
form.append("file", fs.createReadStream(Path));
const { data } = await axios.post("https://telegra.ph/upload", form, {
headers: {
...form.getHeaders(),
},
});
if (data && data[0] && data[0].src) {
return "https://telegra.ph" + data[0].src;
} else {
throw new Error("Erreur lors de la rΓ©cupΓ©ration du lien de la vidΓ©o");
}
} catch (err) {
throw new Error(String(err));
}
}
zokou({nomCom:"sticker",categorie: "Conversion", reaction: "π¨πΏβπ»"},async(origineMessage,zk,commandeOptions)=>{
let {ms,mtype,arg,repondre,nomAuteurMessage}=commandeOptions
var txt=JSON.stringify(ms.message)
var mime=mtype === "imageMessage" || mtype === "videoMessage";
var tagImage = mtype==="extendedTextMessage" && txt.includes("imageMessage")
var tagVideo = mtype==="extendedTextMessage" && txt.includes("videoMessage")
const alea = (ext) => {
return `${Math.floor(Math.random() * 10000)}${ext}`;};
const stickerFileName = alea(".webp");
// image
if (mtype === "imageMessage" ||tagImage) {
let downloadFilePath;
if (ms.message.imageMessage) {
downloadFilePath = ms.message.imageMessage;
} else {
// picture mentioned
downloadFilePath =
ms.message.extendedTextMessage.contextInfo.quotedMessage.imageMessage;
}
// picture
const media = await downloadContentFromMessage(downloadFilePath, "image");
let buffer = Buffer.from([]);
for await (const elm of media) {
buffer = Buffer.concat([buffer, elm]);
}
sticker = new Sticker(buffer, {
pack:"Baraka-Md" ,
author: nomAuteurMessage,
type:
arg.includes("crop") || arg.includes("c")
? StickerTypes.CROPPED
: StickerTypes.FULL,
quality: 100,
});
} else if (mtype === "videoMessage" || tagVideo) {
// videos
let downloadFilePath;
if (ms.message.videoMessage) {
downloadFilePath = ms.message.videoMessage;
} else {
downloadFilePath =
ms.message.extendedTextMessage.contextInfo.quotedMessage.videoMessage;
}
const stream = await downloadContentFromMessage(downloadFilePath, "video");
let buffer = Buffer.from([]);
for await (const elm of stream) {
buffer = Buffer.concat([buffer, elm]);
}
sticker = new Sticker(buffer, {
pack:"Beltah-Md", // pack stick
author: nomAuteurMessage, // name of the author of the stick
type:
arg.includes("-r") || arg.includes("-c")
? StickerTypes.CROPPED
: StickerTypes.FULL,
quality: 40,
});
} else {
repondre("Please mention an image or video!");
return;
}
await sticker.toFile(stickerFileName);
await zk.sendMessage(
origineMessage,
{
sticker: fs.readFileSync(stickerFileName),
},
{ quoted: ms }
);
try{
fs.unlinkSync(stickerFileName)
}catch(e){console.log(e)}
});
zokou({nomCom:"scrop",categorie: "Conversion", reaction: "π¨πΏβπ»"},async(origineMessage,zk,commandeOptions)=>{
const {ms , msgRepondu,arg,repondre,nomAuteurMessage} = commandeOptions ;
if(!msgRepondu) { repondre( 'make sure to mention the media' ) ; return } ;
if(!(arg[0])) {
pack = nomAuteurMessage
} else {
pack = arg.join(' ')
} ;
if (msgRepondu.imageMessage) {
mediamsg = msgRepondu.imageMessage
} else if(msgRepondu.videoMessage) {
mediamsg = msgRepondu.videoMessage
}
else if (msgRepondu.stickerMessage) {
mediamsg = msgRepondu.stickerMessage ;
} else {
repondre('Uh media please'); return
} ;
var stick = await zk.downloadAndSaveMediaMessage(mediamsg)
let stickerMess = new Sticker(stick, {
pack: pack,
type: StickerTypes.CROPPED,
categories: ["π€©", "π"],
id: "12345",
quality: 70,
background: "transparent",
});
const stickerBuffer2 = await stickerMess.toBuffer();
zk.sendMessage(origineMessage, { sticker: stickerBuffer2 }, { quoted: ms });
});
zokou({nomCom:"take",categorie: "Conversion", reaction: "π¨πΏβπ»"},async(origineMessage,zk,commandeOptions)=>{
const {ms , msgRepondu,arg,repondre,nomAuteurMessage} = commandeOptions ;
if(!msgRepondu) { repondre( 'make sure to mention the media' ) ; return } ;
if(!(arg[0])) {
pack = nomAuteurMessage
} else {
pack = arg.join(' ')
} ;
if (msgRepondu.imageMessage) {
mediamsg = msgRepondu.imageMessage
} else if(msgRepondu.videoMessage) {
mediamsg = msgRepondu.videoMessage
}
else if (msgRepondu.stickerMessage) {
mediamsg = msgRepondu.stickerMessage ;
} else {
repondre('Uh a media please'); return
} ;
var stick = await zk.downloadAndSaveMediaMessage(mediamsg)
let stickerMess = new Sticker(stick, {
pack: pack,
type: StickerTypes.FULL,
categories: ["π€©", "π"],
id: "12345",
quality: 70,
background: "transparent",
});
const stickerBuffer2 = await stickerMess.toBuffer();
zk.sendMessage(origineMessage, { sticker: stickerBuffer2 }, { quoted: ms });
});
zokou({ nomCom: "write", categorie: "Conversion", reaction: "π¨πΏβπ»" }, async (origineMessage, zk, commandeOptions) => {
const { ms, msgRepondu, arg, repondre, nomAuteurMessage } = commandeOptions;
if (!msgRepondu) {
repondre('Please mention an image');
return;
}
if (!msgRepondu.imageMessage) {
repondre('The command only works with images');
return;
} ;
text = arg.join(' ') ;
if(!text || text === null) {repondre('Make sure to insert text') ; return } ;
const mediamsg = msgRepondu.imageMessage;
const image = await zk.downloadAndSaveMediaMessage(mediamsg);
//Create a FormData object
const data = new FormData();
data.append('image', fs.createReadStream(image));
//Configure headers
const clientId = 'b40a1820d63cd4e'; // Replace with your Imgur client ID
const headers = {
'Authorization': `Client-ID ${clientId}`,
...data.getHeaders()
};
// Configure the query
const config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.imgur.com/3/image',
headers: headers,
data: data
};
try {
const response = await axios(config);
const imageUrl = response.data.data.link;
console.log(imageUrl)
//Use imageUrl however you want (meme creation, etc.)
const meme = `https://api.memegen.link/images/custom/-/${text}.png?background=${imageUrl}`;
// Create the sticker
const stickerMess = new Sticker(meme, {
pack: nomAuteurMessage,
author: 'anyway-Md',
type: StickerTypes.FULL,
categories: ["π€©", "π"],
id: "12345",
quality: 70,
background: "transparent",
});
const stickerBuffer2 = await stickerMess.toBuffer();
zk.sendMessage(
origineMessage,
{ sticker: stickerBuffer2 },
{ quoted: ms }
);
} catch (error) {
console.error('Error uploading to Imgur :', error);
repondre('An error occurred while creating the meme.');
}
});
zokou({nomCom:"photo",categorie: "Conversion", reaction: "π¨πΏβπ»"},async(dest,zk,commandeOptions)=>{
const {ms , msgRepondu,arg,repondre,nomAuteurMessage} = commandeOptions ;
if(!msgRepondu) { repondre( 'make sure to mention the media' ) ; return } ;
if (!msgRepondu.stickerMessage) {
repondre('Um mention a non-animated sticker'); return
} ;
let mediaMess = await zk.downloadAndSaveMediaMessage(msgRepondu.stickerMessage);
const alea = (ext) => {
return `${Math.floor(Math.random() * 10000)}${ext}`;};
let ran = await alea(".png");
exec(`ffmpeg -i ${mediaMess} ${ran}`, (err) => {
fs.unlinkSync(mediaMess);
if (err) {
zk.sendMessage(
dest,
{
text: 'A non-animated sticker please',
},
{ quoted: ms }
);
return;
}
let buffer = fs.readFileSync(ran);
zk.sendMessage(
dest,
{ image: buffer },
{ quoted: ms }
);
fs.unlinkSync(ran);
});
});
zokou({ nomCom: "trt", categorie: "Conversion", reaction: "π¨πΏβπ»" }, async (dest, zk, commandeOptions) => {
const { msgRepondu, repondre , arg } = commandeOptions;
if(msgRepondu) {
try {
if(!arg || !arg[0]) { repondre('(eg : trt en)') ; return }
let texttraduit = await traduire(msgRepondu.conversation , {to : arg[0]}) ;
repondre(texttraduit)
} catch (error) {
repondre('Mention a texte Message') ;
}
} else {
repondre('Mention a texte Message')
}
}) ;
zokou({ nomCom: "url", categorie: "Conversion", reaction: "π¨πΏβπ»" }, async (origineMessage, zk, commandeOptions) => {
const { msgRepondu, repondre } = commandeOptions;
if (!msgRepondu) {
repondre('mention a image or video');
return;
}
let mediaPath;
if (msgRepondu.videoMessage) {
mediaPath = await zk.downloadAndSaveMediaMessage(msgRepondu.videoMessage);
} else if (msgRepondu.imageMessage) {
mediaPath = await zk.downloadAndSaveMediaMessage(msgRepondu.imageMessage);
} else {
repondre('mention a image or video');
return;
}
try {
const telegraphUrl = await uploadToTelegraph(mediaPath);
fs.unlinkSync(mediaPath); // Supprime le fichier après utilisation
repondre(telegraphUrl);
} catch (error) {
console.error('Erreur lors de la crΓ©ation du lien Telegraph :', error);
repondre('Opps error');
}
});