-
Notifications
You must be signed in to change notification settings - Fork 11
/
App.js
298 lines (259 loc) · 12.7 KB
/
App.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
// [console]
// - scottie
var config = require("./config"); // config file config.js
console.log(config);
var realBotDiscordToken = config.realBotDiscordToken;
var infourl = config.infourl; // url for info and helps stuff, ie: welcome
//wallet and tip bot
var RPCip = config.RPCip;
var RPCport= config.RPCport
var RPCpass = config.RPCpass;
var RPCuser = config.RPCuser;
var lastestVersion = "v1.2";
//github chan 411029890608005121
var helpfile = "";
//https://discordapp.com/oauth2/authorize?client_id=&scope=bot&permissions=515136
const JSON = require('circular-json');
var coind = require('coind-client');
const msgEmbedToRich = require("discordjs-embed-converter");
var _ = require('lodash');
var anti_spam = require("discord-anti-spam"); //anitspam
var Twitter = require('twitter');
const getBearerToken = require('get-twitter-bearer-token');
var fs = require('fs');
var request = require('request');
const Discord = require('discord.js');//https://discordjs.readthedocs.io/en/latest/docs_client.html
const client2 = new Discord.Client(); //our bot
var externalip = require("externalip");
var client = new coind.Client({
host: RPCip,
port: RPCport,
user: RPCuser,
pass: RPCpass
});
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;
client2.on('ready', () => {
console.log('robotbot - Connected to Discord Server....');
});
//test RPC altcoin
client.cmd('getbalance', function(error, output) {
if (!error){
console.log("RPC is setup correctly, your good to go...");
return
}else{
console.log("Please correct RPC connection details in config.js");
console.log(error);
return;
}
});
client2.on('message', function(message) {
try{
if (message.content.split(" ")[0] === '!tip') {
//!tip <userid> amount
if(message.content.split(" ")[1] == "help"){
message.reply("📚 Help: \n 💁 Sends some coin to a user based on there user ID, tip them... cmon spread that 💖..\n ```!tip @user <amount>\nie: !tip 211492100485808130 100\n how to get USR ID: Shift + Click Name```");
return;
}
if(message.content.split(" ")[1] == undefined || message.content.split(" ")[2] == undefined){
message.reply("🛑Error: \n ```Check your your syntax, something is wrong...\n ```!tip <user ID> <amount>\nie: !tip @console 100\n how to get USR ID: Shift + Click Name```");
return;
//message.reply("Info to come...");
}
var payAmount = parseInt(message.content.split(" ")[2]);
if(!Number.isInteger(payAmount)){
payAmount = parseInt(message.content.split(" ")[3]);
if(!Number.isInteger(payAmount)){
message.reply("🛑Error: \n ```Check your your syntax, \n ```!tip <user ID> <amount>\nie: !tip @console 100\n how to get USER ID: Shift + Click Name```");
return;
}
}
if(!Number.isInteger(payAmount)){
message.reply("🛑Error: \n ```Check your your syntax, \n ```!tip <user ID> <amount>\nie: !tip @console 100\n how to get USER ID: Shift + Click Name```");
return;
}
var payto = message.content.split(" ")[1];
var amount = payAmount;
if(amount == ""){
amount = message.content.split(" ")[3];
}
console.log("Amount String: " );
amount = parseFloat(amount)
payto = payto.replace("<","");
payto = payto.replace(">","");
payto = payto.replace("@","");
console.log("[PAYTO]]: " + payto);
console.log("[AMOUNT]]: " + amount);
if(payto != undefined){
if(amount != undefined){
var id = message.author.id;
console.log(id);
var toId = payto;
//var name = toname;
//var toId = client2.users.get("name", to).id;
//console.log(toId);
//console.log(message.author.username);
//console.log(message.author.avatarURL);
//console.log(message.author.getNickname(message.channel.server));
client.cmd('getbalance', id, function(error, balance) {
if (!error){
if(amount == 0){
message.reply("[🛑Error] You cant send 0, dont be silly ...]");
return;
}
if(balance >= amount){
//get address from ID
//send to adderss / move
client.cmd('getaddressesbyaccount', toId, function(error, name) {
console.log("HERE: ")
console.log(name)
if(name ==[]){
message.reply("[Error]" + "You adempted to send to a user with no wallet, please get that user to type !wallet help" );
return;
}
if(!error){
//message.reply("[sent to address]" + name[0]);
client.cmd('move', id, toId, amount, function(error, tx) {
console.log(tx);
if(!error){
const embed = new Discord.RichEmbed()
.setTitle(message.author.username + " is SENDING a TIP")
.setAuthor(message.author.username, message.author.avatarURL)
/*
* Alternatively, use "#00AE86", [0, 174, 134] or an integer number.
*/
.setColor(0x00AE86)
.setDescription(message.author + " has sent you a tip, of " + amount + " <@"+toId+"> " +". He must think something you have done was really cool, dont spent it all in one place !!")
.setFooter("Congratulations wow !!", "http://www.untappedpotentialltd.co.uk/wp-content/uploads/2015/11/Tip.jpg")
.setImage("https://www.123rf.com/stock-photo/congratulations.html")
.setThumbnail("https://www.movinglabor.com/images/blog/tip-jar.png")
/*
* Takes a Date object, defaults to current date.
*/
.setTimestamp()
//.setURL("https://www.123rf.com/stock-photo/congratulations.html")
//.addField("Let your tip build up ",
/*
* Inline fields may not display as inline if the thumbnail and/or image is too big.
*/
//.addField("Inline Field", "They can also be inline.", true)
/*
* Blank field, useful to create some space.
*/
//.addBlankField(true) // field 2
//.addField("Inline Field 3", "You can have a maximum of 25 fields.", true);
message.reply({embed});
}else{
console.log(error);
}
});
}else{
message.reply("[Error]" + "You adempted to send to a user with no wallet, please get that user to type !wallet help" );
}
});
//message.reply("[💰Sending] You have enough coin... ]");
//message.reply("<@"+toId+"> " + message.author.username + " just sent you a 🎇TIP🎇 !!");
}else{
message.reply("[🛑Error] You dont have enough coin ...]");
}
return;
}else{
message.reply("🛑Error: \n ```Check your balance, you broke....");
return;
}
});
}
}
}
if (message.content.split(" ")[0] === '!wallet') {
if(message.content.split(" ")[1] == undefined){
message.reply("🛑Error: \n ```Check your balance or check your syntax, something is wrong...```");
return;
//message.reply("Info to come...");
}
if(message.content.split(" ")[1] == "help"){
var helptxt = "[HELP]\n " +
"📚 Syntax: !wallet <COMMAND> \n " +
"📚 IE: !wallet deposit \n" +
"📚 Commands: \n" +
"```deposit (or address), balance, send, withdraw```";
message.reply(helptxt);
return;
}
if(message.content.split(" ")[1] == "deposit" || message.content.split(" ")[1] == "address"){
var id = message.author.id;
var username = message.author.username;
client.cmd('getaddressesbyaccount', id, function(error, address) {
if (!error){
console.log(address);
if(address[0] == null){
message.reply("You are new here, please remember this is not 100% tested only store small amounts here you can risk...\n Generating new Deposit Adress...");
client.cmd('getnewaddress', id, function(error, address) {
if (!error){
message.reply("💰👛 Address has been created, try !wallet address, or !wallet deposit");
return
}else{
console.log(error);
return;
}
});
}else{
console.log(error);
}
message.reply("💰👛 Deposit Address: \n```" + address + "```");
return
}else{
console.log(error);
return;
}
})
}
if(message.content.split(" ")[1] == "balance"){
var id = message.author.id;
client.cmd('getbalance', id, function(error, balance) {
console.log(balance);
if (!error){
message.reply("💰👛 Balance: " + "\n```" + balance + "```");
return;
}else{
console.log(error);
return;
}
});
}
if(message.content.split(" ")[1] == "send" || message.content.split(" ")[1] == "withdraw"){
var amount = parseFloat(message.content.split(" ")[3])
var to = message.content.split(" ")[2]
var from = message.author.id;
//console.log(message.content.split(" "))
if(amount == undefined || to == undefined){
message.reply("🛑Bad syntax try: \n ```!wallet send ATP9fJjefZjt5zadw6Zsu4znDsqH7nRX3K 10```");
return;
}
console.log(amount);
console.log(to);
client.cmd('sendfrom', from, to, amount, function(error, tx) {
if (!error){
if(tx[0] == undefined){
message.reply("🛑Error: \n ```Check your balance or check your syntax, something is wrong with amount...```");
}
console.log(tx);
message.reply("TX: ```" + tx + "```");
message.reply("https://chainz.cryptoid.info/rns/search.dws?q=" + tx);
}else{
message.reply("🛑Error: \n ```Check your balance or check your syntax, something is wrong...```");
console.log(error);
}
});
}
}
}catch(e){
console.log("ERROR! " + e);
}
});
client2.login(realBotDiscordToken, function(error, token){
if(!error){
console.log(token);
}else{
console.log(error);
}
});