forked from tuhinpal/WhatsBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverifyemail.js
60 lines (56 loc) · 1.78 KB
/
verifyemail.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
//jshint esversion:8
const axios = require("axios");
function yesno(status) {
if (status) {
return "Yes";
} else {
return "No";
}
}
async function emailVerifier(email) {
try {
let data = (
await axios({
method: "post",
url: "https://validateemail.projects.thetuhin.com/api",
headers: {
"thank-you": "tuhin",
"Content-Type": "application/json",
},
data: JSON.stringify({ email }),
})
).data;
if (data.status) {
let validitystring = (data.valid) ? `valid with ${data.valid_chance}% chance` : 'invalid';
return `*${data.query}* is ${validitystring}\n\nDisposable: ${yesno(data.disposable)}\nFree Provider: ${yesno(data.free)}`
} else {
throw new Error("error");
}
} catch (error) {
return (
`🙇♂️ *Error*\n\n` +
"```Something Unexpected Happened while validating this email.```"
);
}
}
const execute = async (client, msg, args) => {
msg.delete(true);
let getdata;
if (msg.hasQuotedMsg) {
let quotedMsg = await msg.getQuotedMessage();
getdata = await emailVerifier(quotedMsg.body);
quotedMsg.reply(getdata);
} else {
getdata = await emailVerifier(args[0]);
await client.sendMessage(msg.to, getdata);
}
};
module.exports = {
name: "Verify Email",
description: "Verify the credibility of a given email",
command: "!verifyemail",
commandType: "plugin",
isDependent: false,
help: `*Email Verifier*\n\nTest an Email's validity before it bounce. \n\n*Reply an email with !verifyemail*\nor,\n*!verifyemail [Email Address]*`,
execute,
};