-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhookHandler.js
83 lines (75 loc) · 1.79 KB
/
hookHandler.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
const getTrackDetails = require('../utils/getTrackDetails');
const trackEmbed = require('../utils/trackEmbed');
const trackerUpdate = async (client, json) => {
const {
carrier,
tracking_code,
est_delivery_date,
tracking_details,
public_url,
} = json;
const {
message,
lastLocation,
lastDateTime,
deliveryEstimate,
} = getTrackDetails.lastArrayElement(
client.moment,
est_delivery_date,
tracking_details
);
// Checks if Tracking Number is unique
const queryExist = function (
query = client.dbSchemas['listExist'],
data = [tracking_code]
) {
return new Promise(function (resolve, reject) {
client.db.all(query, data, (err, rows) => {
if (err) {
reject(err);
} else {
resolve(rows[0].listExist);
}
});
});
};
if ((await queryExist()) === 0) return;
// Get Note of the Watch List Item
const queryHook = function (
query = client.dbSchemas['hook'],
data = [tracking_code]
) {
return new Promise(function (resolve, reject) {
client.db.all(query, data, (err, row) => {
if (err) {
reject(err);
} else {
resolve({ id: row[0].userid, note: row[0].note });
}
});
});
};
const hookResults = await queryHook();
// Send tracker update to channel id and mention user
client.channels.cache
.get(client.channel_id)
.send(
trackEmbed.createEmbed(
carrier,
tracking_code,
hookResults.note,
hookResults.id,
message,
lastLocation,
lastDateTime,
deliveryEstimate,
public_url
)
);
client.channels.cache
.get(client.channel_id)
.send(`Tracker Update for <@${hookResults.id}>`);
};
module.exports = {
trackerUpdate,
};