-
Notifications
You must be signed in to change notification settings - Fork 1
/
👩💻 CacheManager.js
188 lines (131 loc) · 3.73 KB
/
👩💻 CacheManager.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
function CacheStarter() {
let _obj_ = { status: _G.Data.callback_data }
let _toJson_ = JSON.stringify(_obj_)
CacheService.getScriptCache()
.put(_G.Data.id, _toJson_)
return true
}
function CacheItemSaver() {
let _chatId_ = _G.Data.id
let cache = CacheService.getScriptCache().get(_chatId_)
let _toJson = JSON.parse(cache)
_toJson['state'] = _G.Data.callback_data
_toJson['obj'] = _G.Data.callback_data
let _toJson_ = JSON.stringify(_toJson)
CacheService.getScriptCache()
.put(_chatId_, _toJson_)
return true
}
function IdCacheSaver() {
let _chatId_ = _G.Data.id
let _Id_ = _G.Data.text
//validating << must match / and length less than 15
if (String(_Id_).match('/') && _Id_.length >= 10 && _Id_.length < 15) {
let cache = _G.cache
cache['ID'] = _Id_
cache['state'] = 'photo'
let _toJson_ = JSON.stringify(cache)
CacheService.getScriptCache()
.put(_chatId_, _toJson_)
return true
}
let _Msg_ = Validity().ID
Bot.sendMessage(_chatId_, _Msg_)
return false
}
function PhotoCacheSaver() {
_G.Data = Bot.PhotoContents(_G.contents)
let _chatId_ = _G.Data.id
let cache = CacheService.getScriptCache().get(_chatId_)
let _toJson = JSON.parse(cache)
if (cache && (_toJson['ID'] || _toJson['ATM'] || _toJson['ITEM'])) {
let photo = _G.Data.photo
_toJson['photo'] = photo
_toJson['state'] = 'phone'
let _toJson_ = JSON.stringify(_toJson)
CacheService.getScriptCache()
.put(_chatId_, _toJson_)
return true
}
//if not send Invalid message
}
function PhoneCacheSaver() {
_G.Data = Bot.ContactContents(_G.contents)
let _chatId_ = _G.Data.id
let cache = CacheService.getScriptCache().get(_chatId_)
let _toJson = JSON.parse(cache)
if (cache && _toJson['state'] == 'phone') {
let contact = _G.Data.contact
_toJson['phone'] = contact
_toJson['date'] = new Date().toLocaleDateString("en-US")
_G.cache = _toJson
return true
}
//if not send invalid message
}
function PhoneTextCacheSaver() {
let contact = _G.Data.text
let _toJson = _G.cache
if (_toJson['state'] == 'phone' && contact.length > 9 && contact.length < 13 && Number(contact)) {
_toJson['phone'] = contact
_toJson['date'] = new Date().toLocaleDateString("en-US")
_G.cache = _toJson
return true
}
let _chatId_ = _G.Data.id
let _Msg_ = Validity().PHONE
Bot.sendMessage(_chatId_, _Msg_)
return false
}
function AtmCacheSaver() {
let _chatId_ = _G.Data.id
let _ATM_ = _G.Data.text
//validating << must match / and length less than 15
if (_ATM_.split(" ")[1]) {
let cache = _G.cache
cache['ATM'] = _ATM_
cache['state'] = 'photo'
let _toJson_ = JSON.stringify(cache)
CacheService.getScriptCache()
.put(_chatId_, _toJson_)
return true
}
let _Msg_ = Validity().ATM
Bot.sendMessage(_chatId_, _Msg_)
return false
}
function ItemCacheSaver() {
let _chatId_ = _G.Data.id
let _Item_ = _G.Data.text
//validating << must match / and length less than 15
if (!Number(_Item_)) {
let cache = _G.cache
cache['ITEM'] = _Item_
cache['state'] = 'photo'
let _toJson_ = JSON.stringify(cache)
CacheService.getScriptCache()
.put(_chatId_, _toJson_)
return true
}
let _Msg_ = Validity().ITEM
Bot.sendMessage(_chatId_, _Msg_)
return false
}
function RestartCache() {
let _chatId_ = _G.Data.id
let cache = _G.cache
let item = cache['obj']
cache['state'] = item
let _toJson_ = JSON.stringify(cache)
CacheService.getScriptCache()
.put(_chatId_, _toJson_)
return true
}
function SkipCache() {
let cache = _G.cache
cache['state'] = 'phone'
let _toJson_ = JSON.stringify(cache)
CacheService.getScriptCache()
.put(_G.Data.id, _toJson_)
return true
}