forked from dvishal485/price-tracker-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotification.js
110 lines (97 loc) · 4.44 KB
/
Notification.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
function updateNotice(user, data, msg) {
var ssNew = SpreadsheetApp.openById(sheetID)
var products = ssNew.getSheets()[0].getDataRange().getValues().length - 1
var s = ssNew.getSheets()[1].getDataRange().getValues()
var s = String(s[1][2])
var subscribers = s.split(';')
var after = Math.ceil(products / batchSize) * trackAfter
if (data != 'inform service' && data != 'clear clutter') {
var keyboardButtons = [
{ "text": '☕ Buy dev a coffee', "callback_data": '/donate' }
]
var message = `⚠️ Bot will no longer be maintained
(from November 18, 2021)
Trackings and currently <b>active feature will work normally</b>!
No more features will be added further.
<b>No more help message from developer</b> will be provided as well.
In case, the bot start to fail identification of product, <b>no fix will be issued</b>.
The normal tracking will remain <i>free to use and open-source</i> as well.
To obtain the working report of bot send :
/status
<b>Reason for Project Shutdown :</b>
Lack of funds to keep project active
☕ If my work ever helped you consider buying me a coffee.
`
} else { var message = msg }
if (user) {
var keyboardButtons = [
{ "text": "ℹ️ Contact Developer", "callback_data": `/r` },
{ "text": '☕ Buy me a coffee', "callback_data": '/donate' }
]
sendButtonMessage(message, data, null, keyboardButtons)
} else {
sendReport(`Running messaging service...\n\nUser Count : ${subscribers.length}`)
for (var i = 0; i < subscribers.length; i++) {
if (subscribers[i] != '') {
try {
var temp = sendButtonMessage(message, null, subscribers[i], keyboardButtons)
Logger.log(temp)
if (data == 'clear clutter' && temp != null) {
deleteMessage(temp)
}
} catch (e) {
if (Error(e).message.split('blocked').length > 1 || Error(e).message.split('deactivated').length > 1) {
unsubscribe(subscribers[i])
}
sendReport(Error(e).message)
}
}
}
sendReport(`Finished running messaging service...`)
}
return after
}
function workingReport(data) {
try {
var ssNew = SpreadsheetApp.openById(sheetID)
var products = ssNew.getSheets()[0].getDataRange().getValues().length - 1
var pproducts = ssNew.getSheets()[2].getDataRange().getValues().length - 1
var s = ssNew.getSheets()[1].getDataRange().getValues()
var fromSub = s[1][0]
var toSub = s[1][1]
var pfromSub = s[2][0]
var ptoSub = s[2][1]
s = String(s[1][2])
var subscribers = s.split(';')
var numberOfSubs = subscribers.length - 1
var batches = Math.ceil(products / batchSize)
var pbatches = Math.ceil(pproducts / pincodeBatchSize)
var timeTaken = batches * trackAfter
var reportMessage = `Spreadsheet File : <a href='https://docs.google.com/spreadsheets/d/${sheetID}'>Open spreadsheet file</a> (OWNER ONLY)
Number of products tracking :
- Normal Mode : <code>${products}</code>
- Pincode Mode : <code>${pproducts}</code>
Total time taken for tracking :
- Normal Mode : <code>${timeTaken} minutes</code>
- Pincode Mode : <code>${pbatches * pincodeTrackAfter} minutes</code>
Batch information :
- Normal Mode : (${batches} batches)
<code>${batchSize}</code> products after every <code>${trackAfter} minutes</code>
- Pincode Mode : (${pbatches} batches)
<code>${pincodeBatchSize}</code> products after every <code>${pincodeTrackAfter} minutes</code>
Tracking Rate :
<code>${Math.round((batchSize / trackAfter + pincodeBatchSize / pincodeTrackAfter) * 100) / 100} products per minute</code>
Current Batch :
- Normal Mode : <code>Product ${fromSub} to ${toSub}</code>
- Pincode Mode : <code>Product ${pfromSub} to ${ptoSub}</code>
Number of subscribers : <code>${numberOfSubs}</code>
~ Generated by ${botName}`
var keyboardButtons = [
{ "text": "Report a problem", "callback_data": `/r` },
{ "text": "Buy developer a coffee", "callback_data": `/donate` }
]
sendButtonMessage(reportMessage, data, null, keyboardButtons)
} catch (e) {
sendReport(e.message)
}
}