-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
2065 lines (1525 loc) · 59.9 KB
/
bot.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import TelegramBot from 'node-telegram-bot-api'
import assert from 'assert';
import dotenv from 'dotenv'
dotenv.config()
import * as database from './db.js'
import * as privateBot from './bot_private.js'
import * as groupBot from './bot_group.js'
import * as afx from './global.js'
import * as callHistory from './call_history.js'
import {md5} from './md5.js'
const token = process.env.BOT_TOKEN
export const bot = new TelegramBot(token,
{
polling: true
})
export const myInfo = await bot.getMe();
export const sessions = new Map()
export const stateMap = new Map()
export const MIN_COMUNITY_TOKEN_AMOUNT = process.env.MIN_COMUNITY_TOKEN_AMOUNT
export const COMMAND_START = 'start'
export const COMMAND_LOGIN = 'login'
export const COMMAND_CURRENT_SETTING = 'currentsettings'
export const COMMAND_SET_SETTING = 'setsettings'
export const COMMAND_CANCEL = 'cancel'
export const COMMAND_DIRECT = 'direct'
export const COMMAND_DIRECTALL = 'directall'
export const COMMAND_DIRECTNONLOGIN = 'directnon'
export const COMMAND_GAINER = 'topgainer'
export const COMMAND_TEST_LP = 'test_lp'
export const COMMAND_TEST_HP = 'test_hp'
export const COMMAND_TEST_TOKENDEPLOYDATE = 'test_tokendeploydate'
export const COMMAND_STARTKICK = 'startkick'
export const COMMAND_STOPKICK = 'stopkick'
export const COMMAND_MYACCOUNT = 'myaccount'
export const OPTION_MAIN_SETTING = 0
export const OPTION_SET_FRESH_WALLET_SETTING = 1
export const OPTION_SET_FRESH_WALLET_TURN_ON = 2
export const OPTION_SET_FRESH_WALLET_TURN_OFF = 3
export const OPTION_SET_WHALE_WALLET_SETTING = 4
export const OPTION_SET_WHALE_WALLET_TURN_ON = 5
export const OPTION_SET_WHALE_WALLET_TURN_OFF = 6
export const OPTION_SET_KYC_WALLET_SETTING = 7
export const OPTION_SET_KYC_WALLET_TURN_ON = 8
export const OPTION_SET_KYC_WALLET_TURN_OFF = 9
export const OPTION_SET_INIT_LIQUIDITY = 10
export const OPTION_SET_INIT_LIQUIDITY_ETH = 11
export const OPTION_SET_INIT_LIQUIDITY_USD = 12
export const OPTION_SET_DTGS = 13
export const OPTION_DTGS_SELECT_DEX = 14
export const OPTION_DTGS_INPUT_TOKEN_ADDRESS = 15
export const OPTION_DTGS_SHOW_TOKENS = 16
export const OPTION_DTGS_DELETE_TOKEN = 17
export const OPTION_DTGS_DELETE_ALL_TOKEN = 18
export const OPTION_SET_DEFAULT = 19
export const OPTION_GET_ALL_SETTING = 20
export const OPTION_SET_LPLOCK = 21
export const OPTION_SET_LPLOCK_TURN_OFF = 22
export const OPTION_SET_LPLOCK_TURN_ON = 23
export const OPTION_SET_HONEYPOT = 24
export const OPTION_SET_HONEYPOT_TURN_OFF = 25
export const OPTION_SET_HONEYPOT_TURN_ON = 26
export const OPTION_SET_CONTRACT_AGE = 27
export const OPTION_SET_CONTRACT_AGE_PLUS0_1DAY = 28
export const OPTION_SET_CONTRACT_AGE_PLUS1DAY = 29
export const OPTION_SET_CONTRACT_AGE_PLUS1MONTH = 30
export const OPTION_SET_CONTRACT_AGE_PLUS1YEAR = 31
export const OPTION_SET_CONTRACT_AGE_PLUSNUMBERDAYS = 32
export const OPTION_SET_CONTRACT_AGE_TURN_OFF = 33
export const OPTION_SET_DORMANT = 34
export const OPTION_SET_DORMANT_PLUS1MONTH = 35
export const OPTION_SET_DORMANT_PLUS3MONTH = 36
export const OPTION_SET_DORMANT_PLUS6MONTH = 37
export const OPTION_SET_DORMANT_PLUS1YEAR = 38
export const OPTION_SET_DORMANT_TURN_OFF = 39
export const OPTION_SET_SNIPER_DETECTOR = 40
export const OPTION_SET_SNIPER_DETECTOR_TURN_ON = 41
export const OPTION_SET_SNIPER_DETECTOR_TURN_OFF = 42
export const OPTION_SET_USER_WALLET_SETTING = 43
export const OPTION_SET_USER_WALLET_ON = 44
export const OPTION_SET_USER_WALLET_OFF = 45
export const OPTION_SET_USER_SLIPPAGE = 46
export const OPTION_SET_USER_SELL_SETTING = 47
export const OPTION_SET_USER_BUY_SETTING = 48
export const OPTION_SET_USER_BUY_AUTO = 49
export const OPTION_SET_USER_SELL_AUTO = 50
export const OPTION_SET_USER_SELL_HI = 51
export const OPTION_SET_USER_SELL_LO = 52
export const OPTION_SET_USER_SELL_HI_DELETE = 53
export const OPTION_SET_USER_SELL_LO_DELETE = 54
export const OPTION_SET_USER_SELL_HI_AMOUNT = 55
export const OPTION_SET_USER_SELL_LO_AMOUNT = 56
export const OPTION_SET_USER_SELL_HI_AMOUNT_DELETE = 57
export const OPTION_SET_USER_SELL_LO_AMOUNT_DELETE = 58
export const OPTION_SET_USER_WALLET_GENERATE = 59
export const OPTION_SET_USER_BUY_AMOUNT = 60
export const OPTION_SET_USER_BUY_AMOUNT_DELETE = 61
export const OPTION_SET_USER_SELL_TOKEN_ADD = 62
export const OPTION_SET_USER_SELL_TOKEN_SHOW = 63
export const OPTION_SET_USER_SELL_TOKEN_REMOVE = 64
export const OPTION_SET_USER_SELL_TOKEN_REMOVEALL = 65
export const OPTION_BACK = -1
export const OPTION_MSG_COPY_ADDRESS = 100
export const OPTION_MSG_MORE_INFO = 101
export const OPTION_MSG_BACK_INFO = 102
export const OPTION_MSG_BUY_ETH_0_05 = 110
export const OPTION_MSG_BUY_ETH_0_1 = 111
export const OPTION_MSG_BUY_ETH_0_5 = 112
export const OPTION_MSG_BUY_ETH_X = 113
export const OPTION_MSG_SELL_ETH_0_25 = 114
export const OPTION_MSG_SELL_ETH_0_50 = 115
export const OPTION_MSG_SELL_ETH_0_100 = 116
export const OPTION_MSG_SELL_ETH_X = 117
export const STATE_IDLE = 0
export const STATE_WAIT_FRESH_WALLET_MAX_TRANSACTION_COUNT = 1
export const STATE_WAIT_MIN_FRESH_WALLET_COUNT = 2
export const STATE_WAIT_WHALE_WALLET_MIN_BALANCE = 3
export const STATE_WAIT_MIN_WHALE_WALLET_COUNT = 4
export const STATE_WAIT_MIN_KYC_WALLET_COUNT = 5
export const STATE_WAIT_INIT_ETH = 6
export const STATE_WAIT_INIT_USDT_USDC = 7
export const STATE_WAIT_DAILY_STATISTIC_TOKEN_ADDRESS = 8
export const STATE_WAIT_MIN_DORMANT_WALLET_COUNT = 9
export const STATE_WAIT_SET_DEFAULT = 10
export const STATE_WAIT_MIN_SNIPER_COUNT = 11
export const STATE_WAIT_MIN_CONTRACT_AGE = 12
export const STATE_WAIT_SET_USER_WALLET_PRIVATEKEY = 13
export const STATE_WAIT_SET_USER_SLIPPAGE = 14
export const STATE_WAIT_SET_ETH_X_SWAP = 15
export const STATE_WAIT_SET_TOKEN_X_SWAP = 16
export const STATE_WAIT_SET_USER_SELL_HI = 17
export const STATE_WAIT_SET_USER_SELL_LO = 18
export const STATE_WAIT_SET_USER_SELL_HI_AMOUNT = 19
export const STATE_WAIT_SET_USER_SELL_LO_AMOUNT = 20
export const STATE_WAIT_SET_USER_BUY_AMOUNT = 21
export const STATE_WAIT_ADD_AUTOTRADETOKEN = 22
export const stateMap_set = (chatid, state, data = {}) => {
stateMap.set(chatid, {state, data})
}
export const stateMap_get = (chatid) => {
return stateMap.get(chatid)
}
export const stateMap_remove = (chatid) => {
stateMap.delete(chatid)
}
export const stateMap_clear = () => {
stateMap.clear()
}
const json_buttonItem = (key, cmd, text) => {
return {
text: text,
callback_data: JSON.stringify({ k: key, c: cmd }),
}
}
export const json_msgOption = (sessionId, tokenAddress, poolAddress, poolId, isMoreInfo) => {
const hashCode = md5(poolAddress)
let json = [
[
json_buttonItem(tokenAddress, OPTION_MSG_COPY_ADDRESS, 'Copy Address'),
isMoreInfo ? json_buttonItem(`${sessionId}:${hashCode}`, OPTION_MSG_MORE_INFO, 'More Info') : json_buttonItem(`${sessionId}:${hashCode}`, OPTION_MSG_BACK_INFO, 'Back')
// json_buttonItem(sessionId + ':' + poolAddress, OPTION_MSG_MORE_INFO, 'More Info')
],
]
json.push([
json_buttonItem(`${sessionId}:${poolId}`, OPTION_MSG_BUY_ETH_0_05, 'Buy 0.05 Eth'),
json_buttonItem(`${sessionId}:${poolId}`, OPTION_MSG_BUY_ETH_0_1, 'Buy 0.1 Eth'),
json_buttonItem(`${sessionId}:${poolId}`, OPTION_MSG_BUY_ETH_0_5, 'Buy 0.5 Eth'),
json_buttonItem(`${sessionId}:${poolId}`, OPTION_MSG_BUY_ETH_X, 'Buy X Eth'),
])
json.push([
json_buttonItem(`${sessionId}:${poolId}`, OPTION_MSG_SELL_ETH_0_25, 'Sell 25 %'),
json_buttonItem(`${sessionId}:${poolId}`, OPTION_MSG_SELL_ETH_0_50, 'Sell 50 %'),
json_buttonItem(`${sessionId}:${poolId}`, OPTION_MSG_SELL_ETH_0_100, 'Sell 100 %'),
json_buttonItem(`${sessionId}:${poolId}`, OPTION_MSG_SELL_ETH_X, 'Sell X %'),
])
return { title: '', options: json };
}
export const json_botSettings = (sessionId) => {
const json = [
[
json_buttonItem(sessionId, OPTION_SET_INIT_LIQUIDITY, '💧 Initial Liquidty Threshold')
],
[
json_buttonItem(sessionId, OPTION_SET_FRESH_WALLET_SETTING, '☘️ Fresh Wallets Threshold')
],
[
json_buttonItem(sessionId, OPTION_SET_WHALE_WALLET_SETTING, '🐋 Whale Wallets Threshold')
],
[
json_buttonItem(sessionId, OPTION_SET_KYC_WALLET_SETTING, '📝 KYC Wallets Threshold')
],
[
json_buttonItem(sessionId, OPTION_SET_DORMANT, '👴 Dormant Wallets Filter')
],
[
json_buttonItem(sessionId, OPTION_SET_LPLOCK, '🔒 LP Lock Filter')
],
[
json_buttonItem(sessionId, OPTION_SET_HONEYPOT, '🍯 Honeypot Filter')
],
[
json_buttonItem(sessionId, OPTION_SET_CONTRACT_AGE, '⌛ Contract Age Filter')
],
[
json_buttonItem(sessionId, OPTION_SET_DTGS, '📈 ROI Statistics')
],
[
json_buttonItem(sessionId, OPTION_SET_SNIPER_DETECTOR, '🔎 Snipe Volume Detector')
],
[
json_buttonItem(sessionId, OPTION_SET_USER_WALLET_SETTING, '🕋 Swap Setting')
],
[
json_buttonItem(sessionId, OPTION_SET_DEFAULT, '🔁 Reset back to default')
],
]
return { title: '', options: json };
}
async function switchMenu(chatId, messageId, json_buttons) {
const keyboard = {
inline_keyboard: json_buttons,
resize_keyboard: true,
one_time_keyboard: true,
force_reply: true
};
await bot.editMessageReplyMarkup(keyboard, { chat_id: chatId, message_id: messageId })
}
async function switchMenuWithTitle(chatId, messageId, title, json_buttons) {
const keyboard = {
inline_keyboard: json_buttons,
resize_keyboard: true,
one_time_keyboard: true,
force_reply: true
};
try {
await bot.editMessageText(title, {chat_id: chatId, message_id: messageId, reply_markup: keyboard })
} catch (error) {
afx.error_log('[switchMenuWithTitle]', error)
}
}
async function editAnimationMessageCaption(chatId, messageId, title, json_buttons) {
const keyboard = {
inline_keyboard: json_buttons,
resize_keyboard: true,
one_time_keyboard: true,
force_reply: true
};
try {
//protect_content: true,
await bot.editMessageCaption(title, {chat_id: chatId, message_id: messageId, parse_mode: 'HTML', disable_web_page_preview :true, reply_markup: keyboard })
} catch (error) {
afx.error_log('[switchMenuWithTitle]', error)
}
}
export async function openMenu(chatId, menuTitle, json_buttons) {
const keyboard = {
inline_keyboard: json_buttons,
resize_keyboard: true,
one_time_keyboard: true,
force_reply: true
};
await bot.sendMessage(chatId, menuTitle, {reply_markup: keyboard});
}
export const get_menuTitle = (sessionId, subTitle) => {
const session = sessions.get(sessionId)
if (!session) {
return ''
}
let result = session.type === 'private' ? `@${session.username}'s configuration setup` : `@${session.username} group's configuration setup`
if (subTitle && subTitle !== '') {
//subTitle = subTitle.replace('%username%', `@${session.username}`)
result += `\n${subTitle}`
}
return result
}
const json_setDTGS = (sessionId) => {
const json = [
[
// json_buttonItem(sessionId, OPTION_DTGS_SELECT_DEX, 'Add a token address')
json_buttonItem(sessionId, OPTION_DTGS_INPUT_TOKEN_ADDRESS, 'Add a token address')
],
[
json_buttonItem(sessionId, OPTION_DTGS_SHOW_TOKENS, 'Remove token addresses')
],
[
json_buttonItem(sessionId, OPTION_MAIN_SETTING, 'Back')
],
]
return { title: '⬇️ Choose one for daily top gainer statistics setup', options: json };
}
const json_showAutoTradeTokensOption = async (sessionId) => {
const tokens = await database.getAutoTradeTokens(sessionId)
let json = [];
for (const token of tokens) {
json.push([json_buttonItem(`${sessionId}:${token._id.toString()}`, OPTION_SET_USER_SELL_TOKEN_REMOVE, `${token.address} [${token.symbol}]`)])
}
json.push([json_buttonItem(sessionId, OPTION_SET_USER_SELL_TOKEN_REMOVEALL, 'Remove All Tokens')])
json.push([json_buttonItem(sessionId, OPTION_SET_USER_SELL_SETTING, 'Back')])
return { title: '⬇️ Click any item to remove the token address you want to remove', options: json };
}
// const json_selectDexOption = (sessionId) => {
// let json = [];
// for (const dex of afx.dexList) {
// json.push([json_buttonItem(`${sessionId}:${dex.id}`, OPTION_DTGS_INPUT_TOKEN_ADDRESS, dex.title)])
// }
// json.push([json_buttonItem(`${sessionId}`, OPTION_SET_DTGS, 'Back')])
// return { title: '⬇️ Please choose one of below DEXs', options: json };
// }
const json_sellOption = async (sessionId) => {
const session = sessions.get(sessionId)
if (!session) {
return null
}
let json = [];
json.push([json_buttonItem(sessionId, OPTION_SET_USER_SELL_AUTO, session.autosell ? '✅ Auto Sell' : '❌ Auto Sell')])
json.push([
json_buttonItem(sessionId, OPTION_SET_USER_SELL_HI, '✏️ Sell-Hi'),
json_buttonItem(sessionId, OPTION_SET_USER_SELL_HI_DELETE, '⌫ Sell-Hi')
])
json.push([
json_buttonItem(sessionId, OPTION_SET_USER_SELL_LO, '✏️ Sell-Lo'),
json_buttonItem(sessionId, OPTION_SET_USER_SELL_LO_DELETE, '⌫ Sell-Lo')
])
json.push([
json_buttonItem(sessionId, OPTION_SET_USER_SELL_HI_AMOUNT, '✏️ Sell-Hi Amount'),
json_buttonItem(sessionId, OPTION_SET_USER_SELL_HI_AMOUNT_DELETE, '⌫ Sell-Hi Amount')
])
json.push([
json_buttonItem(sessionId, OPTION_SET_USER_SELL_LO_AMOUNT, '✏️ Sell-Lo Amount'),
json_buttonItem(sessionId, OPTION_SET_USER_SELL_LO_AMOUNT_DELETE, '⌫ Sell-Lo Amount')
])
json.push([
json_buttonItem(sessionId, OPTION_SET_USER_SELL_TOKEN_ADD, 'Add Contract address'),
json_buttonItem(sessionId, OPTION_SET_USER_SELL_TOKEN_SHOW, 'Remove Contract address')
])
json.push([json_buttonItem(sessionId, OPTION_SET_USER_WALLET_SETTING, 'Back')])
return { title: '⬇️ Click the button for sell options', options: json };
}
const json_buyOption = async (sessionId) => {
const session = sessions.get(sessionId)
if (!session) {
return null
}
let json = [];
json.push([json_buttonItem(sessionId, OPTION_SET_USER_BUY_AUTO, session.autobuy ? '✅ Auto Buy' : '❌ Auto Buy')])
json.push([
json_buttonItem(sessionId, OPTION_SET_USER_BUY_AMOUNT, '✏️ Buy ETH Amount'),
json_buttonItem(sessionId, OPTION_SET_USER_BUY_AMOUNT_DELETE, '⌫ Buy ETH Amount'),
])
json.push([json_buttonItem(sessionId, OPTION_SET_USER_WALLET_SETTING, 'Back')])
return { title: '⬇️ Click the button for buy options', options: json };
}
const json_showTokensOption = async (sessionId) => {
const tokens = await database.getTokens(sessionId)
let json = [];
for (const token of tokens) {
json.push([json_buttonItem(token._id.toString(), OPTION_DTGS_DELETE_TOKEN, `${token.address} [${token.symbol}]`)])
}
json.push([json_buttonItem(sessionId, OPTION_DTGS_DELETE_ALL_TOKEN, 'Remove All Tokens')])
json.push([json_buttonItem(sessionId, OPTION_SET_DTGS, 'Back')])
return { title: '⬇️ Click the button to remove the token you want', options: json };
}
const json_setFresh = (sessionId) => {
const session = sessions.get(sessionId)
if (!session) {
return null
}
// const json = [
// [
// json_buttonItem(sessionId, OPTION_SET_FRESH_WALLET_TURN_ON, 'Turn on')
// ],
// [
// json_buttonItem(sessionId, OPTION_SET_FRESH_WALLET_TURN_OFF, 'Turn off')
// ],
// [
// json_buttonItem(sessionId, OPTION_MAIN_SETTING, 'Back')
// ],
// ]
let json = []
if (session.min_fresh_wallet_count) {
json.push([
json_buttonItem(sessionId, OPTION_SET_FRESH_WALLET_TURN_OFF, 'Turn off')
])
} else {
json.push([
json_buttonItem(sessionId, OPTION_SET_FRESH_WALLET_TURN_ON, 'Turn on')
])
}
json.push([
json_buttonItem(sessionId, OPTION_MAIN_SETTING, 'Back')
])
return { title: `⬇️ Choose below option for fresh wallets ${(session.min_fresh_wallet_count ? '[Turned on: Wallet count >= ' + session.min_fresh_wallet_count + ', Transansaction count <= ' + session.max_fresh_transaction_count + ']' :'[Turned Off]')}`, options: json };
}
const json_setInitLiquidity = (sessionId) => {
const json = [
[
json_buttonItem(sessionId, OPTION_SET_INIT_LIQUIDITY_ETH, 'Set the minimum ETH balance')
],
[
json_buttonItem(sessionId, OPTION_SET_INIT_LIQUIDITY_USD, 'Set the minimum USDT or USDC balance')
],
[
json_buttonItem(sessionId, OPTION_MAIN_SETTING, 'Back')
],
]
return { title: '⬇️ Choose below options for initial liquidity', options: json };
}
const json_setLPLock = (sessionId) => {
const session = sessions.get(sessionId)
if (!session) {
return null
}
const json = [
[
json_buttonItem(sessionId, session.lp_lock ? OPTION_SET_LPLOCK_TURN_OFF : OPTION_SET_LPLOCK_TURN_ON, session.lp_lock ? 'Turn off LP Lock Filter' :'Turn on LP Lock Filter' )
],
[
json_buttonItem(sessionId, OPTION_MAIN_SETTING, 'Back')
],
]
return { title: `⬇️ Choose below option for LP lock filter. ${(session.lp_lock ? '[LP = Locked]' :'[LP = All]')}`, options: json };
}
const json_setHoneypot = (sessionId) => {
const session = sessions.get(sessionId)
if (!session) {
return null
}
const json = [
[
json_buttonItem(sessionId, session.honeypot ? OPTION_SET_HONEYPOT_TURN_OFF : OPTION_SET_HONEYPOT_TURN_ON, session.honeypot ? 'Turn off Honeypot Filter' :'Turn on Honeypot Filter' )
],
[
json_buttonItem(sessionId, OPTION_MAIN_SETTING, 'Back')
],
]
return { title: `⬇️ Choose below option for Honeypot filter. ${(session.honeypot ? '[Honeypot = No]' :'[Honeypot = All]')}`, options: json };
}
const json_setContractAge = (sessionId) => {
const session = sessions.get(sessionId)
if (!session) {
return null
}
let json = []
let desc = ''
if (session.contract_age && session.contract_age !== 0) {
// const vY = session.contract_age / 365
// const vM = (session.contract_age % 365 ) / session.contract_age / 30
// const vD = (session.contract_age % 30 )
// desc = 'More than '
// if (vY > 0) {
// desc += `${vY} year`
// }
// if (vM > 0) {
// desc += `${vM} month`
// }
// if (vD > 0) {
// desc += `${vD} day`
// }
desc = `${session.contract_age}+ days`
json.push([json_buttonItem(sessionId, OPTION_SET_CONTRACT_AGE_TURN_OFF, 'Turn off Contract Age Filter')])
} else {
desc = 'Off'
json.push([json_buttonItem(sessionId, OPTION_SET_CONTRACT_AGE_PLUS0_1DAY, '0.1+ Day')])
json.push([json_buttonItem(sessionId, OPTION_SET_CONTRACT_AGE_PLUS1DAY, '1+ Day')])
json.push([json_buttonItem(sessionId, OPTION_SET_CONTRACT_AGE_PLUS1MONTH, '1+ Month')])
json.push([json_buttonItem(sessionId, OPTION_SET_CONTRACT_AGE_PLUS1YEAR, '1+ Year')])
json.push([json_buttonItem(sessionId, OPTION_SET_CONTRACT_AGE_PLUSNUMBERDAYS, 'Custom')])
}
json.push([json_buttonItem(sessionId, OPTION_MAIN_SETTING, 'Back')])
return { title: `⬇️ Choose below option for Contract Age filter. [${desc}]`, options: json };
}
const json_setDormant = (sessionId) => {
const session = sessions.get(sessionId)
if (!session) {
return null
}
let json = []
let desc = ''
if (session.min_dormant_wallet_count > 0) {
desc = `${session.min_dormant_duration}+ months, ${session.min_dormant_wallet_count} wallets`
json.push([json_buttonItem(sessionId, OPTION_SET_DORMANT_TURN_OFF, 'Turn off Dormant wallet Filter')])
} else {
desc = 'Off'
json.push([json_buttonItem(sessionId, OPTION_SET_DORMANT_PLUS1MONTH, '1+ Month')])
json.push([json_buttonItem(sessionId, OPTION_SET_DORMANT_PLUS3MONTH, '3+ Months')])
json.push([json_buttonItem(sessionId, OPTION_SET_DORMANT_PLUS6MONTH, '6+ Months')])
json.push([json_buttonItem(sessionId, OPTION_SET_DORMANT_PLUS1YEAR, '1+ Year')])
}
json.push([json_buttonItem(sessionId, OPTION_MAIN_SETTING, 'Back')])
return { title: `⬇️ Choose below option for Dormant wallet filter. [${desc}]`, options: json };
}
const json_setSniperDetector = (sessionId) => {
const session = sessions.get(sessionId)
if (!session) {
return null
}
let json = []
let desc = ''
if (session.min_sniper_count > 0) {
desc = `More than ${session.min_sniper_count} snipers`
json.push([json_buttonItem(sessionId, OPTION_SET_SNIPER_DETECTOR_TURN_OFF, 'Turn off')])
} else {
desc = 'Off'
json.push([json_buttonItem(sessionId, OPTION_SET_SNIPER_DETECTOR_TURN_ON, 'Turn on')])
}
json.push([json_buttonItem(sessionId, OPTION_MAIN_SETTING, 'Back')])
return { title: `⬇️ Choose below option for Sniper Detector. [${desc}]`, options: json };
}
const json_setWhale = (sessionId) => {
const session = sessions.get(sessionId)
if (!session) {
return null
}
// const json = [
// [
// json_buttonItem(sessionId, OPTION_SET_WHALE_WALLET_TURN_ON, 'Turn on')
// ],
// [
// json_buttonItem(sessionId, OPTION_SET_WHALE_WALLET_TURN_OFF, 'Turn off')
// ],
// [
// json_buttonItem(sessionId, OPTION_MAIN_SETTING, 'Back')
// ],
// ]
let json = []
if (session.min_whale_wallet_count) {
json.push([
json_buttonItem(sessionId, OPTION_SET_WHALE_WALLET_TURN_OFF, 'Turn off')
])
} else {
json.push([
json_buttonItem(sessionId, OPTION_SET_WHALE_WALLET_TURN_ON, 'Turn on')
])
}
json.push([
json_buttonItem(sessionId, OPTION_MAIN_SETTING, 'Back')
])
return { title: `⬇️ Choose below option for whale wallets ${(session.min_whale_wallet_count ? '[Turned on: Wallet count >= ' + session.min_whale_wallet_count + ', balance >= ' + session.min_whale_balance + ']' :'[Turned Off]')}`, options: json };
}
const json_setKyc = (sessionId) => {
const session = sessions.get(sessionId)
if (!session) {
return null
}
let json = []
if (session.min_kyc_wallet_count) {
json.push([
json_buttonItem(sessionId, OPTION_SET_KYC_WALLET_TURN_OFF, 'Turn off')
])
} else {
json.push([
json_buttonItem(sessionId, OPTION_SET_KYC_WALLET_TURN_ON, 'Turn on')
])
}
json.push([
json_buttonItem(sessionId, OPTION_MAIN_SETTING, 'Back')
])
return { title: `⬇️ Choose below option for kyc wallet filter ${(session.min_kyc_wallet_count ? '[Turned on: Wallet count >= ' + session.min_kyc_wallet_count + ']' :'[Turned Off]')}`, options: json };
}
const json_setUserwallet = (sessionId) => {
const session = sessions.get(sessionId)
if (!session) {
return null
}
let json = []
if (session.pkey) {
json.push([
json_buttonItem(sessionId, OPTION_SET_USER_WALLET_OFF, 'Remove user wallet')
])
} else {
json.push([
json_buttonItem(sessionId, OPTION_SET_USER_WALLET_ON, 'Set / Change user wallet')
])
json.push([
json_buttonItem(sessionId, OPTION_SET_USER_WALLET_GENERATE, 'Generate new wallet')
])
}
json.push([
json_buttonItem(sessionId, OPTION_SET_USER_SLIPPAGE, 'Set Slippage')
])
json.push([
json_buttonItem(sessionId, OPTION_SET_USER_BUY_SETTING, '⚙️ Buy')
])
json.push([
json_buttonItem(sessionId, OPTION_SET_USER_SELL_SETTING, '⚙️ Sell')
])
json.push([
json_buttonItem(sessionId, OPTION_MAIN_SETTING, 'Back')
])
return { title: `⬇️ Choose below option for buy bot.\nUser wallet: ${(session.pkey ? session.account : 'Not set')}\nSlippage: ${session.slippage ? session.slippage : 'Not Set'}`, options: json };
}
export function sendMessage(chatid, message, enableLinkPreview = true) {
try {
let data = { parse_mode: 'HTML' }
if (enableLinkPreview)
data.disable_web_page_preview = false
else
data.disable_web_page_preview = true
data.disable_forward = true
bot.sendMessage(chatid, message, data)
return true
} catch (error) {
afx.error_log('sendMessage', error)
return false
}
}
export async function sendMessageSync(chatid, message, info = {}) {
try {
let data = { parse_mode: 'HTML' }
data.disable_web_page_preview = false
data.disable_forward = true
await bot.sendMessage(chatid, message, data)
return true
} catch (error) {
if (error?.response?.body?.error_code === 403 ){
info.blocked = true
}
console.log(error?.response?.body)
afx.error_log('sendMessage', error)
return false
}
}
export function sendOptionMessage(chatid, message, option) {
try {
bot.sendMessage(chatid, message, option);
} catch (error) {
afx.error_log('sendMessage', error)
}
}
export function sendMessageToAuthorizedAllUsers(message) {
for (const [chatid, session] of sessions) {
sendMessageToAuthorizedUser(session, message)
}
}
export function sendMessageToAuthorizedUser(session, message, menu = null) {
return new Promise(async (resolve, reject) => {
if (session.wallet || session.vip === 1) {
const fileId = 'CgACAgEAAxkBAALA8mSJ8fqLFP7iWN2llAJZM69Up6riAAIYAwACUmxQRCNXq-ljLrcOLwQ'
sendAnimation(session.chatid, fileId, message, menu).then((res) => {
console.log(`Notification has been sent to @${session.username} (${session.chatid})`)
resolve(true)
}).catch(() => {
resolve(false)
})
} else {
resolve(false)
}
})
}
export async function sendCallToAuthorizedUser(session, filteredInfo, tokenInfo, poolId) {
const menu = json_msgOption(session.chatid, tokenInfo.primaryAddress, tokenInfo.poolAddress, poolId, true);
const message = filteredInfo.content0 + filteredInfo.tag
sendMessageToAuthorizedUser(session, message, menu).then(res => {
if (res) {
const hashCode = md5(tokenInfo.poolAddress)
callHistory.storeMsgData(session.chatid, tokenInfo.poolAddress, tokenInfo.primaryAddress, poolId, hashCode, filteredInfo)
}
})
}
export async function sendAnimation(chatid, file_id, message, json_buttons = null) {
//, protect_content: true
let option = { caption: message, parse_mode: 'HTML', disable_web_page_preview :true }
if (json_buttons) {
const keyboard = {
inline_keyboard: json_buttons.options,
resize_keyboard: true,
one_time_keyboard: true,
force_reply: true
};
option.reply_markup = keyboard
}
return new Promise(async (resolve, reject) => {
bot.sendAnimation(chatid, file_id, option).catch((err) => {
console.log('\x1b[31m%s\x1b[0m', `sendAnimation Error: ${chatid} ${err.response.body.description}`);
}).then((msg) => {
resolve(true)
});
})
}
export function sendPhoto(chatid, file_id, message) {
bot.sendPhoto(chatid, file_id, { caption: message, parse_mode: 'HTML', disable_web_page_preview :true }).catch((err) => {
console.log('\x1b[31m%s\x1b[0m', `sendPhoto Error: ${chatid} ${err.response.body.description}`);
});
}
export function sendLoginSuccessMessage(session) {
if (session.type === 'private') {
sendMessage(session.chatid, `You have successfully logged in with your wallet. From this point forward, you will receive calls based on the settings that you adjusted. If you have any questions, please feel free to contact developer team @PurpleDragon999. Thank you!`)
console.log(`@${session.username} user has successfully logged in with the wallet ${session.wallet}`);
} else if (session.type === 'group') {
sendMessage(session.from_chatid, `@${session.username} group has been successfully logged in with your wallet`)
console.log(`@${session.username} group has successfully logged in with the owner's wallet ${session.wallet}`);
} else if (session.type === 'channel') {
sendMessage(session.chatid, `@${session.username} channel has been successfully logged in with your wallet`)
console.log(`@${session.username} channel has successfully logged in with the creator's wallet ${session.wallet}`);
}
}
export function showSessionLog(session) {
if (session.type === 'private') {
console.log(`@${session.username} user${session.wallet ? ' joined' : '\'s session has been created (' + session.chatid + ')'}`)
} else if (session.type === 'group') {
console.log(`@${session.username} group${session.wallet ? ' joined' : '\'s session has been created (' + session.chatid + ')'}`)
} else if (session.type === 'channel') {
console.log(`@${session.username} channel${session.wallet ? ' joined' : '\'s session has been created'}`)
}
}
export const createSession = (chatid, username, type) => {
let session = {
chatid: chatid,
username: username,
// init_eth: Number(process.env.MIN_POOL_ETH),
// init_usd: Number(process.env.MIN_POOL_USDT_USDC),
// block_threshold: Number(process.env.BLOCK_THRESHOLD),
// max_fresh_transaction_count: Number(process.env.MAX_FRESH_TRANSACTION_COUNT),
// min_fresh_wallet_count: Number(process.env.MIN_FRESH_WALLET_COUNT),
// min_whale_balance: Number(process.env.MIN_WHALE_BALANCE),
// min_whale_wallet_count: Number(process.env.MIN_WHALE_WALLET_COUNT),
// min_kyc_wallet_count: Number(process.env.MIN_KYC_WALLET_COUNT),
// min_dormant_duration: Number(process.env.MIN_DORMANT_DURATION),
// min_dormant_wallet_count: 0,
// lp_lock: 0,
// honeypot:1,
// contract_age:0,
wallet: null,
permit: 0,
type: type
}
setDefaultSettings(session)
sessions.set(session.chatid, session)
showSessionLog(session)
return session;
}
export const updateSession = async (user) => {
let session = sessions.get(user.chatid);
if (session) {
session.chatid = user.chatid
session.username = user.username
session.init_eth = user.init_eth
session.init_usd = user.init_usd
session.block_threshold = user.block_threshold
session.max_fresh_transaction_count = user.max_fresh_transaction_count
session.min_fresh_wallet_count = user.min_fresh_wallet_count
session.min_whale_balance = user.min_whale_balance
session.min_whale_wallet_count = user.min_whale_wallet_count
session.min_kyc_wallet_count = user.min_kyc_wallet_count
session.min_dormant_wallet_count = user.min_dormant_wallet_count
session.min_dormant_duration = user.min_dormant_duration
session.min_sniper_count = user.min_sniper_count
session.lp_lock = user.lp_lock
session.honeypot = user.honeypot
session.contract_age = user.contract_age
session.wallet = user.wallet;
session.from_chatid = user.from_chatid;
session.type = user.type;
session.vip = user.vip;
}
}
export const setDefaultSettings = (session) => {
session.init_eth = 1
session.init_usd = 1000
session.block_threshold = 20
session.max_fresh_transaction_count = 10
session.min_fresh_wallet_count = 2
session.min_whale_balance = 10000
session.min_whale_wallet_count = 2
session.min_kyc_wallet_count = 1
session.min_dormant_duration = 0
session.min_sniper_count = 25
session.min_dormant_wallet_count = 0
session.lp_lock = 0
session.honeypot = 1
session.contract_age = 0
session.pkey = null
session.account = null
session.slippage = 5
session.autobuy = 0
session.autosell = 0
session.autosell_hi = 100
session.autosell_lo = -101
session.autosell_hi_amount = 100
session.autosell_lo_amount = 100
session.autobuy_amount = 0.01
}
export let _command_proc = null
export let _callback_proc = null