-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtes
More file actions
76 lines (65 loc) · 2.11 KB
/
Copy pathtes
File metadata and controls
76 lines (65 loc) · 2.11 KB
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
const LineAPI = require('./api');
class LineConnect extends LineAPI {
constructor(options) {
super();
if (typeof options !== 'undefined') {
this.authToken = options.authToken;
this.certificate = options.certificate;
this.config.Headers['X-Line-Access'] = options.authToken;
}
}
getQrFirst() {
return new Promise((resolve,reject) => {
this._qrCodeLogin().then(async (res) => {
this.authToken = res.authToken;
this.certificate = res.certificate;
console.info(`[*] Token: ${this.authToken}`);
console.info(`[*] Certificate: ${res.certificate}\n`);
let { mid, displayName } = await this._client.getProfile();
console.info(`[*] mid: ${mid}\n`);
console.info(`[*] Name: ${displayName}\n`);
console.info(`NOTE: Dont forget , put your mid and admin on variable 'myBot' in main.js \n`);
console.info(`Regrads Alfathdirk and thx for TCR Team \n`);
console.info(`=======BOT RUNNING======\n`);
await this._tokenLogin(this.authToken, this.certificate);
resolve();
});
});
}
async startx () {
if (typeof this.authToken != 'undefined'){
await this._tokenLogin(this.authToken, this.certificate);
return this.longpoll();
} else {
return new Promise((resolve, reject) => {
this.getQrFirst().then(async (res) => {
resolve(this.longpoll());
});
})
}
}
fetchOps(rev) {
return this._fetchOps(rev, 1);
}
fetchOperations(rev) {
return this._fetchOperations(rev, 5);
}
longpoll() {
return new Promise((resolve, reject) => {
this._fetchOps(this.revision, 1).then((operations) => {
if (!operations) {
console.log('No operations');
reject('No operations');
return;
}
return operations.map((operation) => {
if(operation.revision.toString() != -1) {
let revisionNum = operation.revision.toString();
resolve({ revisionNum, operation });
}
});
});
});
}
}
module.exports = LineConnect;