forked from Mooninghnk/UnetworkBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscord.js
223 lines (194 loc) · 6.87 KB
/
discord.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
const rp = require('request-promise');
var request = require("request");
const TelegramBot = require('node-telegram-bot-api');
// Imports the Google Cloud client library
const {Translate} = require('@google-cloud/translate');
const projectId = 'PROJECT ID';
const translate = new Translate({
projectId: projectId,
key: "GOOGLE KEY"
});
const requestOptions = {
method: 'GET',
uri: 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol=UUU',
headers: {
'X-CMC_PRO_API_KEY': 'YOUR CMC API KEY'
},
json: true,
gzip: true
};
function getdata() {
rp(requestOptions).then(response => {
xmo = response;
}).catch((err) => {
console.log('API call error:', err.message);
});
}
// replace the value below with the Telegram token you receive from @BotFather
const token = 'TELEGRAM API TOKEN';
// Create a bot that uses 'polling' to fetch new updates
const bot = new TelegramBot(token, {
polling: true
});
bot.onText(/\/ko (.+)/, (msg, match) => {
const chatId = msg.chat.id; // the captured "whatever"
const toTrans = match[1];
let text = toTrans;
const target = 'ko';
translate
.translate(text, target)
.then(results => {
const translation = results[0];
bot.sendMessage(chatId, `translation from @${msg.from.username} :\n` +translation);
});
});
bot.onText(/\/en (.+)/, (msg, match) => {
const chatId = msg.chat.id; // the captured "whatever"
const toTrans = match[1];
let text = toTrans;
const target = 'en';
translate
.translate(text, target)
.then(results => {
const translation = results[0];
bot.sendMessage(chatId, `translation from @${msg.from.username} :\n` +translation);
});
});
bot.onText(/\/zh (.+)/, (msg, match) => {
const chatId = msg.chat.id; // the captured "whatever"
const toTrans = match[1];
let text = toTrans;
const target = 'zh';
translate
.translate(text, target)
.then(results => {
const translation = results[0];
bot.sendMessage(chatId, `translation from @${msg.from.username} :\n` +translation);
});
});
bot.onText(/\/calc (.+)/, (msg, match) => {
getdata();
const chatId = msg.chat.id; // the captured "whatever"
const number = Number(match[1]);
let result = xmo.data.UUU.quote.USD.price * number;
let res = result.toString().split(".").shift();
setTimeout(() => bot.sendMessage(chatId, res+ "$"), 1000);
});
bot.on('new_chat_members', (ctx) => {
const chatId = ctx.chat.id;
bot.sendMessage(chatId, "Welcome To UUU @" + ctx.new_chat_member.username);
});
//bot.on('left_chat_member', (usr) => {
// const chatID = usr.chat.id;
// bot.sendMessage(chatID, "We will miss you @" + usr.left_chat_member.username);
//});
// Listen for any kind of message. There are different kinds of
// messages.
bot.on('message', (msg) => {
const chatId = msg.chat.id;
if(msg.text === "/rank@Unetworkbot") {
getdata();
setTimeout(() => bot.sendMessage(chatId, "Current Rank: "+xmo.data.UUU.cmc_rank), 1000);
}
else if(msg.text === "/rank") {
getdata();
setTimeout(() => bot.sendMessage(chatId, "Current Rank: "+xmo.data.UUU.cmc_rank), 1000);
}
if(msg.text === "/volume@Unetworkbot" ) {
getdata();
setTimeout(() => bot.sendMessage(chatId, "$"+xmo.data.UUU.quote.USD.volume_24h + " 24/hr"), 1000);
}
else if(msg.text === "/volume" ) {
getdata();
setTimeout(() => bot.sendMessage(chatId, "$"+xmo.data.UUU.quote.USD.volume_24h + " 24/hr"), 1000);
}
if(msg.text === "/tsupply@Unetworkbot") {
getdata();
setTimeout(() => bot.sendMessage(chatId, "Total Supply: "+xmo.data.UUU.total_supply+" UUU"), 1000);
}
else if(msg.text === "/tsupply") {
getdata();
setTimeout(() => bot.sendMessage(chatId, "Total Supply: "+xmo.data.UUU.total_supply+" UUU"), 1000);
}
if(msg.text === "/cmc@Unetworkbot") {
bot.sendMessage(chatId, "https://coinmarketcap.com/currencies/u-network");
}
else if(msg.text === "/cmc") {
bot.sendMessage(chatId, "https://coinmarketcap.com/currencies/u-network");
}
if(msg.text === "/ustart@Unetworkbot") {
bot.sendMessage(chatId, "https://ustart.u.network/");
}
else if(msg.text === "/ustart") {
bot.sendMessage(chatId, "https://ustart.u.network/");
}
if(msg.text === "/twitter@Unetworkbot") {
bot.sendMessage(chatId, "https://twitter.com/UNetworkHQ");
}
else if(msg.text === "/twitter") {
bot.sendMessage(chatId, "https://twitter.com/UNetworkHQ");
}
if(msg.text === "/cap@Unetworkbot") {
getdata();
setTimeout(() => bot.sendMessage(chatId, "Market Cap: $"+xmo.data.UUU.quote.USD.market_cap + " USD"), 1000);
}
else if(msg.text === "/cap") {
getdata();
setTimeout(() => bot.sendMessage(chatId, "Market Cap: $"+xmo.data.UUU.quote.USD.market_cap + " USD"), 1000);
}
if (msg.text === "/buyu@Unetworkbot") {
bot.sendMessage(msg.chat.id, "Buy with ETH: https://www.hbg.com/en-us/exchange/?s=uuu_eth" + "Buy with BTC: https://www.hbg.com/en-us/exchange/?s=uuu_btc");
}
else if (msg.text === "/buyu") {
bot.sendMessage(msg.chat.id, "Buy with ETH: https://www.hbg.com/en-us/exchange/?s=uuu_eth" + "Buy with BTC: https://www.hbg.com/en-us/exchange/?s=uuu_btc");
}
if (msg.text === "/circsup@Unetworkbot") {
getdata();
setTimeout(() => bot.sendMessage(chatId, "Circulating Supply: "+xmo.data.UUU.circulating_supply), 1000);
}
else if(msg.text === "/circsup") {
getdata();
setTimeout(() => bot.sendMessage(chatId, "Circulating Supply: "+xmo.data.UUU.circulating_supply+ " UUU"), 1000);
}
if (msg.text === "/price@Unetworkbot") {
getdata();
setTimeout(() => bot.sendMessage(chatId, "Current Price: "+xmo.data.UUU.quote.USD.price+"$ " +xmo.data.UUU.quote.USD.percent_change_24h+ "%"), 1000);
}
else if(msg.text === "/price") {
getdata();
setTimeout(() => bot.sendMessage(chatId, "Current Price: "+xmo.data.UUU.quote.USD.price+ "$ "+xmo.data.UUU.quote.USD.percent_change_24h+ "%"), 1000);
}
//Intaractions
if(msg.text === "Hi") {
getdata();
setTimeout(() => bot.sendMessage(chatId, "Welcome To The UUU Community"),0);
}
else if(msg.text === "hi") {
getdata();
setTimeout(() => bot.sendMessage(chatId, "Welcome To The UUU Community"), 0);
}
if(msg.text === "Hello") {
getdata();
setTimeout(() => bot.sendMessage(chatId, "Welcome To The UUU Community"), 0);
}
else if(msg.text === "hello") {
getdata();
setTimeout(() => bot.sendMessage(chatId, "Welcome To The UUU Community"), 0);
}
if(msg.text === "hey") {
getdata();
setTimeout(() => bot.sendMessage(chatId, "Welcome To The UUU Community"), 0);
}
else if(msg.text === "Hey") {
getdata();
setTimeout(() => bot.sendMessage(chatId, "Welcome To The UUU Community"), 0);
}
if(msg.text === "Bye") {
getdata();
setTimeout(() => bot.sendMessage(chatId, "Oh no don't leave us :("), 0);
}
else if(msg.text === "bye") {
getdata();
setTimeout(() => bot.sendMessage(chatId, "Oh no don't leave us :("), 0);
}
});