-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.js
90 lines (68 loc) · 2.16 KB
/
main.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
const CONFIG = require('./config.js');
const { client, logAuth } = require('./module/client');
const { Telegram } = require('./Library/telegram');
require('console-stamp')(console, 'HH:MM:ss.l');
const updateNewMessage = require('./update/updateNewMessage')
/*
HSUbot
Hasanudin H Syafaat
@hasanudinhs
banghasan@gmail.com
Support Grup Telegram @botindonesia
*/
// variable tg aku samakan dengan library di GAS
const tg = new Telegram(client)
client
.on('error', err => {
console.error('Got error:', JSON.stringify(err, null, 2))
})
.on('destroy', () => {
console.log('Destroy event')
})
client.on('update', update => {
// handle debugging
let debugLog = false
if (CONFIG.debug.level == 0) {
// minimalis
} else if (CONFIG.debug.level == 1) {
debugLog = '📥 ' + update['_']
} else if (CONFIG.debug.level == 2) {
debugLog = update
} else if (CONFIG.debug.level == 3) {
debugLog = update
} else {
CONFIG.debug.active = false
}
if (CONFIG.debug.active && debugLog)
console.log(JSON.stringify(debugLog, null, 1))
// tangkap event
switch (update['_']) {
case 'updateOption' :
// dapetin ID dari sini aja
if (update.name == 'my_id') tg.id = update.value.value
break;
case 'updateNewMessage':
if (!CONFIG.BOT_API && CONFIG.terbaca) tg.viewMessages(update.message.chat_id, update.message.id, true)
updateNewMessage(tg, update)
break;
case 'updateMessageSendSucceeded':
client.emit('message'+update.old_message_id, update.message)
break;
case 'updateFile':
// sekadar buat dev
// console.log('RAW',update)
// console.log(tg.tasks)
// client.emit('updateFile', update)
// if (CONFIG.debug.active) console.log('receive updateFile file_id=' + update.file.id, update);
break
case 'updateConnectionState':
break;
default:
break;
}
})
async function main() {
await client.connect()
await client.login(() => logAuth);
}
main()