Skip to content

Commit e1330a8

Browse files
committed
add Phoenixcoin
1 parent cf3efd0 commit e1330a8

File tree

4 files changed

+236
-1
lines changed

4 files changed

+236
-1
lines changed

bot/bot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ bot.on('ready', function() {
7777
'tiphelp in Discord for a commands list.'
7878
);
7979
bot.user.setActivity(config.prefix + 'Intialized!');
80-
var text = ['tiprvn', 'tipdoge', 'tiplbc', 'tiphelp'];
80+
var text = ['tiprvn', 'tipdoge', 'tiplbc', 'tipufo', 'tipproton', 'tippxc', 'tiphelp'];
8181
var counter = 0;
8282
setInterval(change, 10000);
8383

bot/modules/helpTipper.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bot/modules/phoenixTipper.js

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
'use strict';
2+
3+
const bitcoin = require('bitcoin');
4+
5+
let Regex = require('regex'),
6+
config = require('config'),
7+
spamchannels = config.get('moderation').botspamchannels;
8+
let config = config.get('pxcd');
9+
const pxc = new bitcoin.Client(config);
10+
11+
exports.commands = ['tippxc'];
12+
exports.tippxc = {
13+
usage: '<subcommand>',
14+
description:
15+
'**!tippxc** : Displays This Message\n **!tippxc balance** : get your balance\n **!tippxc deposit** : get address for your deposits\n **!tippxc withdraw <ADDRESS> <AMOUNT>** : withdraw coins to specified address\n **!tippxc <@user> <amount>** :mention a user with @ and then the amount to tip them\n **!tippxc private <user> <amount>** : put private before Mentioning a user to tip them privately.',
16+
process: async function(bot, msg, suffix) {
17+
let tipper = msg.author.id.replace('!', ''),
18+
words = msg.content
19+
.trim()
20+
.split(' ')
21+
.filter(function(n) {
22+
return n !== '';
23+
}),
24+
subcommand = words.length >= 2 ? words[1] : 'help',
25+
helpmsg =
26+
'**!tippxc** : Displays This Message\n **!tippxc balance** : get your balance\n **!tippxc deposit** : get address for your deposits\n **!tippxc withdraw <ADDRESS> <AMOUNT>** : withdraw coins to specified address\n **!tippxc <@user> <amount>** :mention a user with @ and then the amount to tip them\n **!tippxc private <user> <amount>** : put private before Mentioning a user to tip them privately.\n **<> : Replace with appropriate value.**',
27+
channelwarning = 'Please use <#bot-spam> or DMs to talk to bots.';
28+
switch (subcommand) {
29+
case 'help':
30+
privateorSpamChannel(msg, channelwarning, doHelp, [helpmsg]);
31+
break;
32+
case 'balance':
33+
doBalance(msg, tipper);
34+
break;
35+
case 'deposit':
36+
privateorSpamChannel(msg, channelwarning, doDeposit, [tipper]);
37+
break;
38+
case 'withdraw':
39+
privateorSpamChannel(msg, channelwarning, doWithdraw, [tipper, words, helpmsg]);
40+
break;
41+
default:
42+
doTip(bot, msg, tipper, words, helpmsg);
43+
}
44+
}
45+
};
46+
47+
function privateorSpamChannel(message, wrongchannelmsg, fn, args) {
48+
if (!inPrivateorSpamChannel(message)) {
49+
message.reply(wrongchannelmsg);
50+
return;
51+
}
52+
fn.apply(null, [message, ...args]);
53+
}
54+
55+
function doHelp(message, helpmsg) {
56+
message.author.send(helpmsg);
57+
}
58+
59+
function doBalance(message, tipper) {
60+
pxc.getBalance(tipper, 1, function(err, balance) {
61+
if (err) {
62+
message.reply('Error getting Phoenixcoin (PXC) balance.').then(message => message.delete(10000));
63+
} else {
64+
message.reply('You have **' + balance + '** Phoenixcoin (PXC)');
65+
}
66+
});
67+
}
68+
69+
function doDeposit(message, tipper) {
70+
getAddress(tipper, function(err, address) {
71+
if (err) {
72+
message.reply('Error getting your Phoenixcoin (PXC) deposit address.').then(message => message.delete(10000));
73+
} else {
74+
message.reply('Your Phoenixcoin (PXC) address is ' + address);
75+
}
76+
});
77+
}
78+
79+
function doWithdraw(message, tipper, words, helpmsg) {
80+
if (words.length < 4) {
81+
doHelp(message, helpmsg);
82+
return;
83+
}
84+
85+
var address = words[2],
86+
amount = getValidatedAmount(words[3]);
87+
88+
if (amount === null) {
89+
message.reply("I don't know how to withdraw that much Phoenixcoin (PXC)...").then(message => message.delete(10000));
90+
return;
91+
}
92+
93+
pxc.sendFrom(tipper, address, Number(amount), function(err, txId) {
94+
if (err) {
95+
message.reply(err.message).then(message => message.delete(10000));
96+
} else {
97+
message.reply('You withdrew ' + amount + ' Phoenixcoin (PXC) coins to ' + address + '\n' + txLink(txId) + '\n');
98+
}
99+
});
100+
}
101+
102+
function doTip(bot, message, tipper, words, helpmsg) {
103+
if (words.length < 3 || !words) {
104+
doHelp(message, helpmsg);
105+
return;
106+
}
107+
var prv = false;
108+
var amountOffset = 2;
109+
if (words.length >= 4 && words[1] === 'private') {
110+
prv = true;
111+
amountOffset = 3;
112+
}
113+
114+
let amount = getValidatedAmount(words[amountOffset]);
115+
116+
if (amount === null) {
117+
message.reply("I don't know how to tip that much Phoenixcoin (PXC)...").then(message => message.delete(10000));
118+
return;
119+
}
120+
if (!message.mentions.users.first()){
121+
message
122+
.reply('Sorry, I could not find a user in your tip...')
123+
.then(message => message.delete(10000));
124+
return;
125+
}
126+
if (message.mentions.users.first().id) {
127+
sendPXC(bot, message, tipper, message.mentions.users.first().id.replace('!', ''), amount, prv);
128+
} else {
129+
message.reply('Sorry, I could not find a user in your tip...').then(message => message.delete(10000));
130+
}
131+
}
132+
133+
function sendPXC(bot, message, tipper, recipient, amount, privacyFlag) {
134+
getAddress(recipient.toString(), function(err, address) {
135+
if (err) {
136+
message.reply(err.message).then(message => message.delete(10000));
137+
} else {
138+
pxc.sendFrom(tipper, address, Number(amount), 1, null, null, function(err, txId) {
139+
if (err) {
140+
message.reply(err.message).then(message => message.delete(10000));
141+
} else {
142+
if (privacyFlag) {
143+
let userProfile = message.guild.members.find('id', recipient);
144+
var iimessage =
145+
' You got privately tipped ' +
146+
amount +
147+
' Phoenixcoin (PXC)\n' +
148+
txLink(txId) +
149+
'\n' +
150+
'DM me `!tippxc` for pxcTipper instructions.';
151+
userProfile.user.send(iimessage);
152+
var imessage =
153+
' You privately tipped ' +
154+
userProfile.user.username +
155+
' ' +
156+
amount +
157+
' Phoenixcoin (PXC)\n' +
158+
txLink(txId) +
159+
'\n' +
160+
'DM me `!tippxc` for pxcTipper instructions.';
161+
message.author.send(imessage);
162+
163+
if (
164+
message.content.startsWith('!tippxc private ')
165+
) {
166+
message.delete(1000); //Supposed to delete message
167+
}
168+
} else {
169+
var iiimessage =
170+
' tipped <@' +
171+
recipient +
172+
'> ' +
173+
amount +
174+
' Phoenixcoin (PXC)\n' +
175+
txLink(txId) +
176+
'\n' +
177+
'DM me `!tippxc` for pxcTipper instructions.';
178+
message.reply(iiimessage);
179+
}
180+
}
181+
});
182+
}
183+
});
184+
}
185+
186+
function getAddress(userId, cb) {
187+
pxc.getAddressesByAccount(userId, function(err, addresses) {
188+
if (err) {
189+
cb(err);
190+
} else if (addresses.length > 0) {
191+
cb(null, addresses[0]);
192+
} else {
193+
pxc.getNewAddress(userId, function(err, address) {
194+
if (err) {
195+
cb(err);
196+
} else {
197+
cb(null, address);
198+
}
199+
});
200+
}
201+
});
202+
}
203+
204+
function inPrivateorSpamChannel(msg) {
205+
if (msg.channel.type == 'dm' || isSpam(msg)) {
206+
return true;
207+
} else {
208+
return false;
209+
}
210+
}
211+
212+
function isSpam(msg) {
213+
return spamchannels.includes(msg.channel.id);
214+
};
215+
216+
217+
function getValidatedAmount(amount) {
218+
amount = amount.trim();
219+
if (amount.toLowerCase().endsWith('pxc')) {
220+
amount = amount.substring(0, amount.length - 3);
221+
}
222+
return amount.match(/^[0-9]+(\.[0-9]+)?$/) ? amount : null;
223+
}
224+
225+
function txLink(txId) {
226+
return '' + txId;
227+
}

config/default.json.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
"user": "username",
3131
"pass": "Do-Not-Use-This-Password-Youll-Be-Hacked-For-all-Teh-Moneys!"
3232
},
33+
"phoenixd": {
34+
"port": 3339,
35+
"user": "username",
36+
"pass": "Do-Not-Use-This-Password-Youll-Be-Hacked-For-all-Teh-Moneys!"
37+
},
3338
"moderation":{
3439
"pm2Name": "TipBot",
3540
// Roles that have access to all commands.

0 commit comments

Comments
 (0)