-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.ts
190 lines (178 loc) · 5.38 KB
/
bot.ts
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
import {
Bot,
Context,
GrammyError,
HttpError,
MemorySessionStorage,
SessionFlavor,
} from "grammy";
import { session } from "grammy";
import { commandsComposer } from "./commands";
import { importTokenConversation } from "./conversations";
import {
ConversationFlavor,
conversations,
createConversation,
} from "@grammyjs/conversations";
import { callbackHandler, listenerComposer, callBackQueryComposer } from "./handlers";
import {
CreateTokenMenu,
initTaxMenu,
finalTaxMenu,
decimalMenu,
menuComposer,
fundContractButton,
TradingMenu,
settingMenu,
returnToMainMenu,
gasPresetMenu,
FaqButton,
} from "./views";
import { accountMenu } from "./views";
import withdrawEthConversation from "./conversations/withdrawEth.conversations";
import { freeStorage } from "@grammyjs/storage-free";
import { distribute, run, sequentialize } from "@grammyjs/runner";
import validate from "./validations/config.validation";
import { I18n } from "@grammyjs/i18n";
import { customBuyAmountConversation } from "./conversations/customBuyAmount.conversation";
import { buyTokenConversation } from "./conversations/BuyToken.conversation";
import { setTradeAmountConversation } from "./conversations/setTradeAmountConversation.conversation";
import { sellTokenConversation } from "./conversations/SellToken.conversation";
import { setSellTradeAmountConversation } from "./conversations/setSellTradeAmount.conversation";
import { CreateWallet } from "./web3";
import { importWalletConversation } from "./conversations/importWallet.conversation";
import { setcustomSlippageConversation } from "./conversations/setCustomSlippage.conversation";
export type MyContext = Context &
SessionFlavor<SessionData> &
ConversationFlavor;
interface SessionData {
walletAddress: string | null;
tokenName: string;
tokenNameIsSet: boolean;
tokenDecimalsSet: boolean;
tokendecimal: number;
privateKey: string;
amountAmountLiqtoAdd: "";
userName: string;
autoBuy: boolean;
autoSell: boolean;
slippage: string;
buyAmount: string;
sellAmount: string;
tokens: string[];
notification: boolean;
customBuyToken: string;
customSellToken: string;
tokenBalance: any;
isSlow: boolean;
isFast: boolean;
isAverage: boolean;
isMaxSpeed: boolean;
}
// Create an instance of the `Bot` class and pass your bot token to it.
const bot = new Bot<MyContext>(process.env.BOT_TOKEN || "not bot token"); // <-- put your bot token between the ""
function initial(): SessionData {
return {
walletAddress: null,
tokenNameIsSet: false,
tokenDecimalsSet: false,
tokendecimal: 0,
tokenName: "",
privateKey: "",
amountAmountLiqtoAdd: "",
userName: "",
autoBuy: false,
autoSell: false,
slippage: "",
buyAmount: "0",
sellAmount: "0",
tokens: [],
notification: false,
customBuyToken: "",
tokenBalance: "",
customSellToken: "",
isAverage: false,
isMaxSpeed: false,
isFast: false,
isSlow: false,
};
}
const i18n = new I18n<MyContext>({
defaultLocale: "en", // see below for more information
directory: "locales", // Load all translation files from locales/.
});
// bot.use(i18n);
const { getDecimals, getSymbol, EthBalance } = new CreateWallet();
// bot.on("msg:text", (ctx) => {
// console.log("jj");
// const address = ctx.msg.text;
// const rpc = process.env.RPC;
// return;
// });
bot.use(session({ initial, storage: new MemorySessionStorage<SessionData>() }));
bot.use(conversations());
bot.use(FaqButton);
bot.use(createConversation(withdrawEthConversation, "withdrawEthConversation"));
bot.use(createConversation(buyTokenConversation, "buyTokenConversation"));
bot.use(createConversation(sellTokenConversation, "sellTokenConversation"));
bot.use(
createConversation(importWalletConversation, "importWalletConversation")
);
bot.use(
createConversation(
setcustomSlippageConversation,
"setcustomSlippageConversation"
)
);
bot.use(
createConversation(
customBuyAmountConversation,
"customBuyAmountConversation"
)
);
bot.use(
createConversation(
setSellTradeAmountConversation,
"setSellTradeAmountConversation"
)
);
// bot.use(accountMenu);
bot.use(
createConversation(setTradeAmountConversation, "setTradeAmountConversation")
);
bot.use(gasPresetMenu);
bot.use(settingMenu);
bot.use(TradingMenu);
bot.use(menuComposer);
bot.api.setMyCommands([
{ command: "help", description: "Help and Support " },
{ command: "start", description: "Start Trading" },
{ command: "config", description: "configure trade settings" },
{ command: "wallet", description: "Wallet details" },
{ command: "orders", description: "checkout pnl and opened Trades" },
{ command: "rewards", description: "See Rewards" },
{ command: "faq", description: "Frequently Asked questions" },
]);
// Handle the /start command.
bot.use(commandsComposer);
bot.use(callBackQueryComposer);
bot.use(callbackHandler);
bot.use(listenerComposer);
bot.catch((err: { ctx: MyContext; error: any }) => {
const ctx = err.ctx;
console.error(`Error while handling update ${ctx.update.update_id}:`);
const e = err.error;
if (e instanceof GrammyError) {
console.error("Error in request:", e.description);
} else if (e instanceof HttpError) {
console.error("Could not contact Telegram:", e);
} else {
console.error("Unknown error:", e);
}
});
// Now that you specified how to handle messages, you can start your bot.
// This will connect to the Telegram servers and wait for messages.
// Start the bot.
bot.use(distribute(__dirname + "./worker", { count: 4 }));
validate();
run(bot);