mirror of
https://github.com/LBRYFoundation/lbry-wunderbot.git
synced 2025-08-23 17:47:27 +00:00
Merge branch 'master' into Coolguy3289-patch-3
This commit is contained in:
commit
fa0a916774
10 changed files with 344 additions and 412 deletions
|
@ -73,9 +73,9 @@ bot.on('error', function(error) {
|
|||
|
||||
function checkMessageForCommand(msg, isEdit) {
|
||||
//check if message is a command
|
||||
if (msg.author.id != bot.user.id && msg.content.startsWith(config.prefix)) {
|
||||
if (msg.author.id !== bot.user.id && msg.content.startsWith(config.prefix)) {
|
||||
//check if user is Online
|
||||
if (!msg.author.presence.status || msg.author.presence.status == 'offline' || msg.author.presence.status == 'invisible') {
|
||||
if (!msg.author.presence.status || msg.author.presence.status === 'offline' || msg.author.presence.status === 'invisible') {
|
||||
msg.author.send('Please set your Discord Presence to Online to talk to the bot!').catch(function(error) {
|
||||
msg.channel
|
||||
.send(
|
||||
|
@ -185,7 +185,7 @@ function checkMessageForCommand(msg, isEdit) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (msg.author != bot.user && msg.isMentioned(bot.user)) {
|
||||
if (msg.author !== bot.user && msg.isMentioned(bot.user)) {
|
||||
msg.channel.send('yes?'); //using a mention here can lead to looping
|
||||
} else {
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ let config = require('config');
|
|||
let channels = config.get('claimbot').channels;
|
||||
const Discord = require('discord.js');
|
||||
const request = require('request');
|
||||
let lastProcessedBlock = 0;
|
||||
|
||||
module.exports = {
|
||||
init: init
|
||||
|
|
|
@ -14,7 +14,7 @@ exports.price = {
|
|||
usage: '<currency> <amount>',
|
||||
description: 'displays price of lbc',
|
||||
process: function(bot, msg, suffix) {
|
||||
var options = {
|
||||
let options = {
|
||||
defaultCurrency: 'BTC',
|
||||
|
||||
// supported currencies and api steps to arrive at the final value
|
||||
|
@ -503,22 +503,22 @@ exports.price = {
|
|||
// refresh rate in milliseconds to retrieve a new price (default to 10 minutes)
|
||||
refreshTime: 100000
|
||||
};
|
||||
var words = suffix
|
||||
let words = suffix
|
||||
.trim()
|
||||
.split(' ')
|
||||
.filter(function(n) {
|
||||
return n !== '';
|
||||
});
|
||||
|
||||
var currency = words.length > 0 ? words[0].toUpperCase() : options.defaultCurrency;
|
||||
var amount = words.length > 1 ? parseFloat(words[1], 10) : 1;
|
||||
var showHelp = isNaN(amount) || Object.keys(options.currencies).indexOf(currency) === -1;
|
||||
let currency = words.length > 0 ? words[0].toUpperCase() : options.defaultCurrency;
|
||||
let amount = words.length > 1 ? parseFloat(words[1], 10) : 1;
|
||||
let showHelp = isNaN(amount) || Object.keys(options.currencies).indexOf(currency) === -1;
|
||||
// store the last retrieved rate
|
||||
var cachedRates = {};
|
||||
var command = '!price';
|
||||
let cachedRates = {};
|
||||
let command = '!price';
|
||||
|
||||
var currencies = Object.keys(options.currencies);
|
||||
for (var i = 0; i < currencies.length; i++) {
|
||||
let currencies = Object.keys(options.currencies);
|
||||
for (let i = 0; i < currencies.length; i++) {
|
||||
cachedRates[currencies[i]] = {
|
||||
rate: 0,
|
||||
time: null
|
||||
|
@ -539,7 +539,7 @@ exports.price = {
|
|||
msg.channel.send('Please use <#' + ChannelID + '> or DMs to talk to price bot.');
|
||||
return;
|
||||
}
|
||||
var message = `**${command}**: show the price of 1 LBC in ${options.defaultCurrency}
|
||||
let message = `**${command}**: show the price of 1 LBC in ${options.defaultCurrency}
|
||||
**${command} help**: this message
|
||||
**${command} CURRENCY**: show the price of 1 LBC in CURRENCY. Supported values for CURRENCY are Listed Below
|
||||
**${command} CURRENCY AMOUNT**: show the price of AMOUNT LBC in CURRENCY
|
||||
|
@ -548,28 +548,28 @@ exports.price = {
|
|||
}
|
||||
|
||||
function formatMessage(amount, rate, option) {
|
||||
var cur = option.sign;
|
||||
var value = numeral(rate.rate * amount).format(option.format);
|
||||
let cur = option.sign;
|
||||
let value = numeral(rate.rate * amount).format(option.format);
|
||||
return `*${numeral(amount).format('0,0[.][00000000]')} LBC = ${cur} ${value}*
|
||||
_last updated ${rate.time.utc().format(options.dtFormat)}_`;
|
||||
}
|
||||
|
||||
function doSteps(bot, currency, amount) {
|
||||
var option = options.currencies[currency];
|
||||
var shouldReload = true;
|
||||
let option = options.currencies[currency];
|
||||
let shouldReload = true;
|
||||
if (cachedRates[currency]) {
|
||||
var cache = cachedRates[currency];
|
||||
let cache = cachedRates[currency];
|
||||
shouldReload = cache.time === null || moment().diff(cache.time) >= options.refreshTime;
|
||||
if (!shouldReload) {
|
||||
var message = formatMessage(amount, cache, option);
|
||||
let message = formatMessage(amount, cache, option);
|
||||
msg.channel.send(message);
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldReload) {
|
||||
// copy the steps array
|
||||
var steps = [];
|
||||
for (var i = 0; i < option.steps.length; i++) {
|
||||
let steps = [];
|
||||
for (let i = 0; i < option.steps.length; i++) {
|
||||
steps.push(option.steps[i]);
|
||||
}
|
||||
|
||||
|
@ -579,19 +579,19 @@ _last updated ${rate.time.utc().format(options.dtFormat)}_`;
|
|||
|
||||
function processSteps(bot, currency, rate, amount, steps, option) {
|
||||
if (steps.length > 0) {
|
||||
var pairName = steps[0];
|
||||
let pairName = steps[0];
|
||||
if (!options.api[pairName]) {
|
||||
msg.channel.send(`There was a configuration error. ${pairName} pair was not found.`);
|
||||
return;
|
||||
}
|
||||
|
||||
var pair = options.api[pairName];
|
||||
let pair = options.api[pairName];
|
||||
request.get(pair.url, function(error, response, body) {
|
||||
if (error) {
|
||||
msg.channel.send(err.message ? err.message : 'The request could not be completed at this time. Please try again later.');
|
||||
return;
|
||||
}
|
||||
var pairRate = 0;
|
||||
let pairRate = 0;
|
||||
try {
|
||||
pairRate = jp.query(JSON.parse(body), pair.path);
|
||||
if (Array.isArray(pairRate) && pairRate.length > 0) {
|
||||
|
@ -610,7 +610,7 @@ _last updated ${rate.time.utc().format(options.dtFormat)}_`;
|
|||
}
|
||||
|
||||
// final step, cache and then response
|
||||
var result = {
|
||||
let result = {
|
||||
rate: rate,
|
||||
time: moment()
|
||||
};
|
||||
|
|
|
@ -13,12 +13,13 @@ exports.purge = {
|
|||
return;
|
||||
}
|
||||
if (hasPerms(msg)) {
|
||||
let newamount = 0;
|
||||
if (!suffix) {
|
||||
var newamount = '2';
|
||||
newamount = 2;
|
||||
} else {
|
||||
var amount = Number(suffix);
|
||||
var adding = 1;
|
||||
var newamount = amount + adding;
|
||||
let amount = Number(suffix);
|
||||
let adding = 1;
|
||||
newamount = amount + adding;
|
||||
}
|
||||
let messagecount = newamount.toString();
|
||||
msg.channel
|
||||
|
|
|
@ -5,167 +5,127 @@ let inPrivate = require('../helpers.js').inPrivate;
|
|||
let ChannelID = config.get('gitrelease').channel;
|
||||
|
||||
exports.commands = [
|
||||
'releasenotes' // command that is in this file, every command needs it own export as shown below
|
||||
'releasenotes' // command that is in this file, every command needs it own export as shown below
|
||||
];
|
||||
|
||||
exports.releasenotes = {
|
||||
usage: '',
|
||||
description: 'gets current release notes from GITHUB',
|
||||
process: function(bot, msg, suffix) {
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'User-Agent': 'Super Agent/0.0.1'
|
||||
};
|
||||
// Configure the request
|
||||
const options = {
|
||||
url: 'https://api.github.com/repos/lbryio/lbry-desktop/releases/latest',
|
||||
method: 'GET',
|
||||
headers: headers
|
||||
};
|
||||
|
||||
// Start the request
|
||||
let message;
|
||||
request(options, function(error, response, body) {
|
||||
let releasemessage = JSON.parse(body).body;
|
||||
let releasename = JSON.parse(body).name;
|
||||
let releasedate = JSON.parse(body).published_at;
|
||||
let releaseurl = JSON.parse(body).html_url;
|
||||
if (releasemessage.length < 2000) {
|
||||
message = {
|
||||
embed: {
|
||||
title: '*Download ' + releasename + ' here!*',
|
||||
description: releasemessage,
|
||||
url: releaseurl,
|
||||
color: 7976557,
|
||||
timestamp: releasedate,
|
||||
author: {
|
||||
name: 'LBRY Desktop release Notes for ' + releasename,
|
||||
icon_url: 'https://spee.ch/b/Github-PNG-Image.png'
|
||||
},
|
||||
footer: {
|
||||
icon_url: 'https://spee.ch/2/pinkylbryheart.png',
|
||||
text: 'LBRY Desktop Updated '
|
||||
}
|
||||
}
|
||||
};
|
||||
if (inPrivate(msg)) {
|
||||
msg.channel.send(message);
|
||||
return;
|
||||
usage: '<desktop/android>',
|
||||
description: 'gets current release notes from GitHub, for either Desktop or Android',
|
||||
process: function(bot, msg, suffix) {
|
||||
let releaseType = suffix.toLowerCase();
|
||||
let releaseTypePost = null;
|
||||
if (releaseType === 'android post' || 'desktop post') {
|
||||
releaseTypePost = releaseType.charAt(0).toUpperCase() + releaseType.slice(1,7);
|
||||
console.log('Post message detected ' + releaseTypePost);
|
||||
}
|
||||
if (hasPerms(msg) && suffix === 'post') {
|
||||
bot.channels.get(ChannelID).send(message);
|
||||
let releaseTypeName = releaseType.charAt(0).toUpperCase() + releaseType.slice(1);
|
||||
if (releaseType !== 'android' && releaseType !== 'desktop' && releaseType !== 'android post' && releaseType !== 'desktop post') {
|
||||
msg.reply('Please specify which release notes to display: "desktop" or "android".');
|
||||
return;
|
||||
}
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'User-Agent': 'Super Agent/0.0.1'
|
||||
};
|
||||
// Configure the request
|
||||
let options;
|
||||
if (releaseTypePost !== null) {
|
||||
options = {
|
||||
url: 'https://api.github.com/repos/lbryio/lbry-' + releaseTypePost + '/releases/latest',
|
||||
method: 'GET',
|
||||
headers: headers
|
||||
};
|
||||
} else {
|
||||
msg.channel.send(msg.author + ' Release notes sent via DM');
|
||||
msg.author.send(message);
|
||||
console.log('Release being sent: ' + releaseTypeName);
|
||||
options = {
|
||||
url: 'https://api.github.com/repos/lbryio/lbry-' + releaseTypeName + '/releases/latest',
|
||||
method: 'GET',
|
||||
headers: headers
|
||||
};
|
||||
}
|
||||
} else {
|
||||
message = releasemessage
|
||||
.trim()
|
||||
.split('###')
|
||||
.filter(function(n) {
|
||||
return n !== '';
|
||||
});
|
||||
let releasemessage1 = message[0];
|
||||
let releasemessage2 = message[1];
|
||||
let releasemessage3 = message[2];
|
||||
let releasemessage4 = message[3];
|
||||
let releasemessage5 = message[4];
|
||||
let message1 = {
|
||||
embed: {
|
||||
title: '*Download ' + releasename + ' here!*',
|
||||
description: releasemessage1,
|
||||
url: releaseurl,
|
||||
color: 7976557,
|
||||
timestamp: releasedate,
|
||||
author: {
|
||||
name: 'LBRY Desktop Release Notes for ' + releasename,
|
||||
icon_url: 'https://spee.ch/b/Github-PNG-Image.png'
|
||||
},
|
||||
footer: {
|
||||
icon_url: 'https://spee.ch/2/pinkylbryheart.png',
|
||||
text: 'LBRY Desktop Updated '
|
||||
// Start the request
|
||||
let message;
|
||||
request(options, function(error, response, body) {
|
||||
let json = JSON.parse(body);
|
||||
let releasemessage = json.body;
|
||||
console.log(releasemessage);
|
||||
let releasename = json.name || json.tag_name;
|
||||
let releasedate = json.published_at;
|
||||
let releaseurl = json.html_url;
|
||||
if (releasemessage.length < 2000) {
|
||||
message = {
|
||||
embed: {
|
||||
title: '*Download ' + releasename + ' here!*',
|
||||
description: releasemessage.replace('###', ''),
|
||||
url: releaseurl,
|
||||
color: 7976557,
|
||||
timestamp: releasedate,
|
||||
author: {
|
||||
name: 'LBRY ' + releaseType + ' release notes for ' + releasename,
|
||||
icon_url: 'https://spee.ch/b/Github-PNG-Image.png'
|
||||
},
|
||||
footer: {
|
||||
icon_url: 'https://spee.ch/2/pinkylbryheart.png',
|
||||
text: 'LBRY ' + releaseType + ' updated '
|
||||
}
|
||||
}
|
||||
};
|
||||
if (inPrivate(msg)) {
|
||||
msg.channel.send(message);
|
||||
return;
|
||||
}
|
||||
if (hasPerms(msg) && suffix === 'android post' || 'desktop post') {
|
||||
bot.channels.get(ChannelID).send(message);
|
||||
} else {
|
||||
msg.channel.send(msg.author + ' Release notes sent via DM');
|
||||
msg.author.send(message);
|
||||
}
|
||||
} else {
|
||||
message = releasemessage
|
||||
.trim()
|
||||
.split('###')
|
||||
.filter(function(n) {
|
||||
return n !== '';
|
||||
});
|
||||
let embedmessages = [];
|
||||
for (let i = 0; i < message.length; i++) {
|
||||
if (message[i]) {
|
||||
embedmessages.push({
|
||||
embed: {
|
||||
description: message[i],
|
||||
url: releaseurl,
|
||||
color: 7976557,
|
||||
timestamp: releasedate,
|
||||
author: {
|
||||
name: 'LBRY ' + releaseTypeName + ' release notes for ' + releasename,
|
||||
icon_url: 'https://spee.ch/b/Github-PNG-Image.png'
|
||||
},
|
||||
footer: {
|
||||
icon_url: 'https://spee.ch/2/pinkylbryheart.png',
|
||||
text: 'LBRY ' + releaseTypeName + ' updated '
|
||||
}
|
||||
}
|
||||
});
|
||||
if (i === 0) embedmessages[i].embed.title = '*Download ' + releasename + ' here!*';
|
||||
}
|
||||
}
|
||||
if (inPrivate(msg)) {
|
||||
for (let i = 0; i < embedmessages.length; i++) {
|
||||
msg.channel.send(embedmessages[i]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (hasPerms(msg) && suffix === 'android post' || 'desktop post') {
|
||||
for (let i = 0; i < embedmessages.length; i++) {
|
||||
bot.channels.get(ChannelID).send(embedmessages[i]);
|
||||
}
|
||||
} else {
|
||||
msg.channel.send(msg.author + ' Release notes sent via DM');
|
||||
for (let i = 0; i < embedmessages.length; i++) {
|
||||
msg.author.send(embedmessages[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
let message2 = {
|
||||
embed: {
|
||||
description: releasemessage2,
|
||||
color: 7976557,
|
||||
timestamp: releasedate,
|
||||
author: {
|
||||
icon_url: 'https://spee.ch/b/Github-PNG-Image.png'
|
||||
},
|
||||
footer: {
|
||||
icon_url: 'https://spee.ch/2/pinkylbryheart.png',
|
||||
text: 'LBRY Desktop Updated '
|
||||
}
|
||||
}
|
||||
};
|
||||
let message3 = {
|
||||
embed: {
|
||||
description: releasemessage3,
|
||||
color: 7976557,
|
||||
timestamp: releasedate,
|
||||
author: {
|
||||
icon_url: 'https://spee.ch/b/Github-PNG-Image.png'
|
||||
},
|
||||
footer: {
|
||||
icon_url: 'https://spee.ch/2/pinkylbryheart.png',
|
||||
text: 'LBRY Desktop Updated '
|
||||
}
|
||||
}
|
||||
};
|
||||
let message4 = {
|
||||
embed: {
|
||||
description: releasemessage4,
|
||||
color: 7976557,
|
||||
timestamp: releasedate,
|
||||
author: {
|
||||
icon_url: 'https://spee.ch/b/Github-PNG-Image.png'
|
||||
},
|
||||
footer: {
|
||||
icon_url: 'https://spee.ch/2/pinkylbryheart.png',
|
||||
text: 'LBRY Desktop Updated '
|
||||
}
|
||||
}
|
||||
};
|
||||
let message5 = {
|
||||
embed: {
|
||||
description: releasemessage5,
|
||||
color: 7976557,
|
||||
timestamp: releasedate,
|
||||
author: {
|
||||
icon_url: 'http://www.pngall.com/wp-content/uploads/2016/04/Github-PNG-Image.png'
|
||||
},
|
||||
footer: {
|
||||
icon_url: 'https://spee.ch/2/pinkylbryheart.png',
|
||||
text: 'LBRY Desktop Updated '
|
||||
}
|
||||
}
|
||||
};
|
||||
if (inPrivate(msg)) {
|
||||
msg.channel.send(message1);
|
||||
msg.channel.send(message2);
|
||||
msg.channel.send(message3);
|
||||
msg.channel.send(message4);
|
||||
msg.channel.send(message5);
|
||||
return;
|
||||
}
|
||||
if (hasPerms(msg) && suffix === 'post') {
|
||||
bot.channels.get(ChannelID).send(message1);
|
||||
bot.channels.get(ChannelID).send(message2);
|
||||
bot.channels.get(ChannelID).send(message3);
|
||||
bot.channels.get(ChannelID).send(message4);
|
||||
bot.channels.get(ChannelID).send(message5);
|
||||
} else {
|
||||
msg.channel.send(msg.author + ' Release notes sent via DM');
|
||||
msg.author.send(message1);
|
||||
msg.author.send(message2);
|
||||
msg.author.send(message3);
|
||||
msg.author.send(message4);
|
||||
msg.author.send(message5);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -13,93 +13,75 @@ exports.addrole = {
|
|||
usage: '<role>',
|
||||
description: 'Adds you to specified role',
|
||||
process: function(bot, msg, suffix) {
|
||||
//rolelist.allowedroles = rolelist.allowedroles.map(v => v.toLowerCase());
|
||||
// Here the bot,msg and suffix is avaible, this function can be async if needed.
|
||||
let newrole = msg.guild.roles.find('name', suffix);
|
||||
let baserole = msg.guild.roles.find('name', rolelist.baserole);
|
||||
// Checks if the user put a role in the message.
|
||||
if (inPrivate(msg)) {
|
||||
msg.channel.send('You can not set roles in DMs! Please go to the Discord server to do this.');
|
||||
return;
|
||||
} else {
|
||||
if (suffix) {
|
||||
//suffix = suffix.toLowerCase();
|
||||
// Checks if the role mentioned in the message is in the allowed roles listed in the wunderbot config.
|
||||
if (rolelist.allowedroles.includes(suffix) || rolelist.baserole.includes(suffix)) {
|
||||
// Checks if the role even exists in the discord server
|
||||
if (newrole !== null) {
|
||||
// Checks if the member has the role that they are trying to add
|
||||
if (!msg.member.roles.find('name', suffix)) {
|
||||
msg.member.addRole(newrole).then(msg.channel.send(msg.member + ' has been added to the ' + suffix + ' role!'));
|
||||
if (rolelist.baserole !== ' ') {
|
||||
if (baserole !== null) {
|
||||
// Checks if Member has the baserole, and also checks if they just added the baserole
|
||||
if (!msg.member.roles.find('name', rolelist.baserole) && suffix !== rolelist.baserole) {
|
||||
msg.member.addRole(baserole).then(msg.channel.send(msg.member + ' has been added to the ' + rolelist.baserole + ' role!'));
|
||||
}
|
||||
} else {
|
||||
msg.channel.send('The ' + rolelist.baserole + " Role doesn't exist. Please add that role first!");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
msg.channel.send('It seems that you already have that role! Try removing it first with the ' + botconfig.prefix + 'delrole command!');
|
||||
}
|
||||
} else {
|
||||
msg.channel.send('The role ' + '`' + suffix + '`' + ' does not exist!');
|
||||
}
|
||||
} else {
|
||||
msg.channel.send("That role isn't one you can add yourself to! Please run the " + botconfig.prefix + 'roles command to find out which ones are allowed.');
|
||||
}
|
||||
} else {
|
||||
msg.channel.send('Please specify a role. Type ' + botconfig.prefix + 'roles to see which you may add!');
|
||||
}
|
||||
}
|
||||
// Provide shortened syntax for the sake of code cleanliness
|
||||
let send = msgTxt => msg.channel.send(msgTxt);
|
||||
// Checks if the user has messaged the bot via Direct Message
|
||||
if (inPrivate(msg)) return send('You can not set roles in DMs! Please go to the Discord server to do this.');
|
||||
|
||||
// Here the bot, msg and suffix is avaible, this function can be async if needed.
|
||||
// Make sure to eliminate case sensitivity, do this here to only perform the sweep once.
|
||||
let newrole = msg.guild.roles.find(role => role.name.toLowerCase() === suffix.toLowerCase());
|
||||
// Baserole is assumed to already be case accurate as it's handled in the config itself.
|
||||
let baserole = msg.guild.roles.find(item => item.name === rolelist.baserole);
|
||||
|
||||
let rolecmd = botconfig.prefix + 'roles';
|
||||
|
||||
// Checks if the user included a role in their message
|
||||
if (!suffix) return send('Please specify a role. Type ' + rolecmd + ' to see which you may add yourself!');
|
||||
// Checks if there is a matching role found on the server
|
||||
if (!newrole) return send('The role specified `' + suffix + '` does not exist on this server!');
|
||||
// Checks that the allowed roles and base role against the matched role's name, since this eliminates case sensitivity issues
|
||||
if (!rolelist.allowedroles.includes(newrole.name) && !rolelist.baserole.includes(newrole.name)) return send("That role isn't one you can add yourself to! Type " + rolecmd + ' command to find out which ones are allowed.');
|
||||
// Use the matched name to check against the member's existing roles
|
||||
if (msg.member.roles.find(item => item.name === newrole.name)) return send('It seems you already have the ' + newrole.name + 'role');
|
||||
|
||||
// Assuming all these factors succeed, add the role
|
||||
msg.member.addRole(newrole).then(send(msg.member + ' has been added to the ' + newrole.name + ' role!'));
|
||||
|
||||
// Check if a baserole is actually set
|
||||
if (!rolelist.baserole) return;
|
||||
// Confirm that the role exists on the server and if not then be sure to send a nag message
|
||||
if (!baserole) return send('The base role of ' + rolelist.baserole + ' has been set in config but is missing from the server');
|
||||
// Confirm if the user has the baserole already, including if it was added just now
|
||||
if (msg.member.roles.find(item => item.name === baserole.name)) return;
|
||||
// Add the base role and avoid spamming the user by only mentioning them in the previous message
|
||||
msg.member.addRole(baserole).then(send('We also added the base ' + rolelist.baserole + ' role for you!'));
|
||||
}
|
||||
};
|
||||
exports.delrole = {
|
||||
usage: '<role>',
|
||||
description: 'Deletes the specified role from your account',
|
||||
process: function(bot, msg, suffix) {
|
||||
// Provide shortened syntax for the sake of code cleanliness
|
||||
let send = msgTxt => msg.channel.send(msgTxt);
|
||||
// Checks if the user has messaged the bot via Direct Message
|
||||
if (inPrivate(msg)) return send('You can not set roles in DMs! Please go to the Discord server to do this.');
|
||||
// Here in the bot, msg and suffix are available, this function can be async if needed.
|
||||
let oldrole = msg.guild.roles.find('name', suffix);
|
||||
// Checks if the user put a role in the message.
|
||||
if (inPrivate(msg)) {
|
||||
msg.channel.send('You can not set roles in DMs! Please go to the Discord server to do this.');
|
||||
return;
|
||||
} else {
|
||||
if (suffix) {
|
||||
// Checks if the role mentioned in the message is in the allowed roles listed in the Wunderbot config.
|
||||
if (rolelist.allowedroles.includes(suffix)) {
|
||||
// Checks if the role exists in the Discord server
|
||||
if (oldrole !== null) {
|
||||
// Checks if the member has the role that they are trying to add
|
||||
if (msg.member.roles.find('name', suffix)) {
|
||||
msg.member.removeRole(oldrole).then(msg.channel.send(msg.member + ' has been removed from the ' + suffix + ' role!'));
|
||||
} else {
|
||||
msg.channel.send("You don't seem to have that role! Try adding it first with the " + botconfig.prefix + 'addrole command!');
|
||||
}
|
||||
} else {
|
||||
msg.channel.send('The role ' + '`' + suffix + '`' + ' does not exist!');
|
||||
}
|
||||
} else {
|
||||
msg.channel.send("That role isn't one you can add yourself to! Please run the " + botconfig.prefix + 'roles command to find out which ones are allowed.');
|
||||
}
|
||||
} else {
|
||||
msg.channel.send('Please specify a role. Type ' + botconfig.prefix + 'roles to see which you may add!');
|
||||
}
|
||||
}
|
||||
// Make sure to eliminate case sensitivity, do this here to only perform the sweep once.
|
||||
let oldrole = msg.guild.roles.find(role => role.name.toLowerCase() === suffix.toLowerCase());
|
||||
let rolecmd = botconfig.prefix + 'roles';
|
||||
// Checks if the user included a role in their message
|
||||
if (!suffix) return send('Please specify a role. Type ' + rolecmd + ' to see which you may remove yourself!');
|
||||
// Checks if there is a matching role found on the server
|
||||
if (!oldrole) return send('The role specified `' + suffix + '` does not exist on this server!');
|
||||
// Checks that the allowed roles against the matched role's name, since this eliminates case sensitivity issues
|
||||
if (!rolelist.allowedroles.includes(oldrole.name)) return send("That role isn't one you can remove yourself! If you need it removed, please ask a moderator!");
|
||||
// Use the matched name to check against the member's existing roles
|
||||
if (!msg.member.roles.find(item => item.name === oldrole.name)) return send("It seems you don't actually have the " + oldrole.name + 'role! Mission accomplished!');
|
||||
|
||||
// Assuming all these factors succeed, add the role
|
||||
msg.member.removeRole(oldrole).then(send(msg.member + ' has been removed from the ' + oldrole.name + ' role!'));
|
||||
}
|
||||
};
|
||||
exports.roles = {
|
||||
usage: '',
|
||||
description: 'displays roles you can give yourself',
|
||||
process: function(bot, msg, suffix) {
|
||||
if (inPrivate(msg)) {
|
||||
msg.channel.send('You can not set roles in DMs! Please go to the Discord server to do this.');
|
||||
return;
|
||||
} else {
|
||||
let send = msgTxt => msg.channel.send(msgTxt);
|
||||
if (inPrivate(msg)) return send('You can not set roles in DMs! Please go to the Discord server to do this.');
|
||||
else {
|
||||
// Here in the bot, msg and suffix are available, this function can be async if needed.
|
||||
msg.channel.send({
|
||||
send({
|
||||
embed: {
|
||||
color: 3447003,
|
||||
title: 'Wunderbot',
|
||||
|
@ -132,7 +114,6 @@ exports.roles = {
|
|||
}
|
||||
}
|
||||
});
|
||||
//msg.channel.send(JSON.stringify(rolelist.allowedroles));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,107 +1,109 @@
|
|||
let needle = require('needle');
|
||||
let statsurl = 'https://coinmarketcap.com/currencies/library-credit/';
|
||||
let statsurl = 'https://www.coingecko.com/en/coins/lbry-credits';
|
||||
exports.commands = [
|
||||
'stats' // command that is in this file, every command needs it own export as shown below
|
||||
'stats' // command that is in this file, every command needs it own export as shown below
|
||||
];
|
||||
|
||||
exports.stats = {
|
||||
usage: '',
|
||||
description: 'Displays list of current Market stats',
|
||||
process: function(bot, msg) {
|
||||
needle.get('https://api.coinmarketcap.com/v2/ticker/1298/?convert=BTC', function(error, response) {
|
||||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send('coinmarketcap API is not available');
|
||||
} else {
|
||||
let data = response.body.data;
|
||||
let rank = data.rank;
|
||||
let price_usd = Number(data.quotes.USD.price);
|
||||
let price_btc = Number(data.quotes.BTC.price);
|
||||
let market_cap_usd = Number(data.quotes.USD.market_cap);
|
||||
let circulating_supply = Number(data.circulating_supply);
|
||||
let total_supply = Number(data.total_supply);
|
||||
let percent_change_1h = Number(data.quotes.USD.percent_change_1h);
|
||||
let percent_change_24h = Number(data.quotes.USD.percent_change_24h);
|
||||
let volume24_usd = Number(data.quotes.USD.volume_24h);
|
||||
let dt = new Date();
|
||||
let timestamp = dt.toUTCString();
|
||||
let hr_indicator = ':thumbsup:';
|
||||
let day_indicator = ':thumbsup:';
|
||||
if (percent_change_1h < 0) {
|
||||
hr_indicator = ':thumbsdown:';
|
||||
}
|
||||
if (percent_change_24h < 0) {
|
||||
day_indicator = ':thumbsdown:';
|
||||
}
|
||||
usage: '',
|
||||
description: 'Displays list of Current Market Statistics',
|
||||
process: function(bot, msg) {
|
||||
needle.get('https://api.coingecko.com/api/v3/coins/markets?vs_currency=btc&ids=lbry-credits&order=market_cap_desc&per_page=100&page=1&sparkline=false&price_change_percentage=24h%2C1h%2C7d', function(error, response) {
|
||||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send('coingecko API is not available');
|
||||
} else {
|
||||
// console.log(response);
|
||||
// console.log(response.body[0]);
|
||||
let data = response.body[0];
|
||||
let rank = data.market_cap_rank;
|
||||
let price_btc = Number(data.current_price);
|
||||
let circulating_supply = Number(data.circulating_supply);
|
||||
let total_supply = Number(data.total_supply);
|
||||
let percent_change_1h = Number(data.price_change_percentage_1h_in_currency);
|
||||
let percent_change_24h = Number(data.price_change_percentage_24h_in_currency);
|
||||
let dt = new Date();
|
||||
let timestamp = dt.toUTCString();
|
||||
let hr_indicator = (percent_change_1h < 0) ? ':thumbsdown:' : ':thumbsup:';
|
||||
let day_indicator = (percent_change_24h < 0) ? ':thumbsdown:' : ':thumbsup:';
|
||||
|
||||
needle.get('https://api.coinmarketcap.com/v2/ticker/1298/?convert=GBP', function(error, response) {
|
||||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send('coinmarketcap API is not available');
|
||||
} else {
|
||||
data = response.body.data;
|
||||
let price_gbp = Number(data.quotes.GBP.price);
|
||||
needle.get('https://api.coinmarketcap.com/v2/ticker/1298/?convert=EUR', function(error, response) {
|
||||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send('coinmarketcap API is not available');
|
||||
} else {
|
||||
data = response.body.data;
|
||||
let price_eur = Number(data.quotes.EUR.price);
|
||||
let description = `**Rank: [${rank}](${statsurl})**
|
||||
**Data**
|
||||
Market Cap: [$${numberWithCommas(market_cap_usd)}](${statsurl})
|
||||
Total Supply: [${numberWithCommas(total_supply)} LBC](${statsurl})
|
||||
Circulating Supply: [${numberWithCommas(circulating_supply)} LBC](${statsurl})
|
||||
24 Hour Volume: [$${volume24_usd}](${statsurl})
|
||||
needle.get('https://api.coingecko.com/api/v3/coins/markets?vs_currency=gbp&ids=lbry-credits&order=market_cap_desc&per_page=100&page=1&sparkline=false', function (error, response) {
|
||||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send('coingecko API is not available');
|
||||
} else {
|
||||
data = response.body[0];
|
||||
let price_gbp = Number(data.current_price);
|
||||
needle.get('https://api.coingecko.com/api/v3/coins/markets?vs_currency=eur&ids=lbry-credits&order=market_cap_desc&per_page=100&page=1&sparkline=false', function (error, response) {
|
||||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send('coingecko API is not available');
|
||||
} else {
|
||||
data = response.body[0];
|
||||
let price_eur = Number(data.current_price);
|
||||
needle.get('https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=lbry-credits&order=market_cap_desc&per_page=100&page=1&sparkline=false', function (error, response) {
|
||||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send('coingecko API is not available');
|
||||
} else {
|
||||
data = response.body[0];
|
||||
let price_usd = Number(data.current_price);
|
||||
let market_cap_usd = Number(data.market_cap);
|
||||
let volume24_usd = Number(data.total_volume);
|
||||
let description = `**Rank: [${rank}](${statsurl})**
|
||||
**Data**
|
||||
Market Cap: [$${numberWithCommas(market_cap_usd)}](${statsurl})
|
||||
Total Supply: [${numberWithCommas(total_supply)} LBC](${statsurl})
|
||||
Circulating Supply: [${numberWithCommas(circulating_supply.toFixed(0))} LBC](${statsurl})
|
||||
24 Hour Volume: [$${numberWithCommas(volume24_usd)}](${statsurl})
|
||||
|
||||
**Price**
|
||||
BTC: [₿${price_btc.toFixed(8)}](${statsurl})
|
||||
USD: [$${price_usd.toFixed(5)}](${statsurl})
|
||||
EUR: [€${price_eur.toFixed(5)}](${statsurl})
|
||||
GBP: [£${price_gbp.toFixed(5)}](${statsurl})
|
||||
|
||||
**% Change**
|
||||
1 Hour: [${percent_change_1h.toFixed(2)}%](${statsurl}) ${hr_indicator}
|
||||
|
||||
1 Day: [${percent_change_24h.toFixed(2)}%](${statsurl}) ${day_indicator}`;
|
||||
const embed = {
|
||||
description: description,
|
||||
color: 7976557,
|
||||
footer: {
|
||||
text: 'Last Updated: ' + timestamp
|
||||
},
|
||||
author: {
|
||||
name: 'Coin Gecko Stats (LBC)',
|
||||
url: statsurl,
|
||||
icon_url: 'https://spee.ch/2/pinkylbryheart.png'
|
||||
}
|
||||
};
|
||||
msg.channel.send({embed});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
**Price**
|
||||
BTC: [₿${price_btc.toFixed(8)}](${statsurl})
|
||||
USD: [$${price_usd.toFixed(2)}](${statsurl})
|
||||
EUR: [€${price_eur.toFixed(2)}](${statsurl})
|
||||
GBP: [£${price_gbp.toFixed(2)}](${statsurl})
|
||||
function parse_obj(obj) {
|
||||
let array = [];
|
||||
let prop;
|
||||
for (prop in obj) {
|
||||
if (obj.hasOwnProperty(prop)) {
|
||||
let key = parseInt(prop, 10);
|
||||
let value = obj[prop];
|
||||
if (typeof value == 'object') {
|
||||
value = parse_obj(value);
|
||||
}
|
||||
array[key] = value;
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
**% Change**
|
||||
1 Hour: [${percent_change_1h}](${statsurl}) ${hr_indicator}
|
||||
|
||||
1 Day: [${percent_change_24h}](${statsurl}) ${day_indicator}
|
||||
|
||||
`;
|
||||
const embed = {
|
||||
description: description,
|
||||
color: 7976557,
|
||||
footer: {
|
||||
text: 'Last Updated: ' + timestamp
|
||||
},
|
||||
author: {
|
||||
name: 'Coin Market Cap Stats (LBC)',
|
||||
url: statsurl,
|
||||
icon_url: 'https://spee.ch/2/pinkylbryheart.png'
|
||||
}
|
||||
};
|
||||
msg.channel.send({ embed });
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function parse_obj(obj) {
|
||||
let array = [];
|
||||
let prop;
|
||||
for (prop in obj) {
|
||||
if (obj.hasOwnProperty(prop)) {
|
||||
let key = parseInt(prop, 10);
|
||||
let value = obj[prop];
|
||||
if (typeof value == 'object') {
|
||||
value = parse_obj(value);
|
||||
}
|
||||
array[key] = value;
|
||||
}
|
||||
}
|
||||
return array;
|
||||
function numberWithCommas(x) {
|
||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function numberWithCommas(x) {
|
||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -30,6 +30,22 @@
|
|||
"icon_url": "https://spee.ch/2/pinkylbryheart.png"
|
||||
}
|
||||
}
|
||||
},
|
||||
"!whitepaper": {
|
||||
"usage": "",
|
||||
"description": "LBRY White Paper",
|
||||
"operation": "send",
|
||||
"bundle": {
|
||||
"url": "https://spec.lbry.com/",
|
||||
"title": "",
|
||||
"description": "The [LBRY White Paper](https://spec.lbry.com/) defines the LBRY protocol, its components, and how they fit together. \nThis document assumes that the reader is familiar with distributed hash tables (DHTs), the BitTorrent protocol, Bitcoin, and blockchain technology in general. It does not attempt to document these technologies or explain how they work.",
|
||||
"color": 16777215,
|
||||
"author": {
|
||||
"name": "LBRY White Paper",
|
||||
"url": "https://spec.lbry.com/",
|
||||
"icon_url": "https://spee.ch/0/info-white.png"
|
||||
}
|
||||
}
|
||||
},
|
||||
"!begging": {
|
||||
"usage": "",
|
||||
|
@ -39,11 +55,11 @@
|
|||
"url": "",
|
||||
"title": "",
|
||||
"description": "Please don't request free coins or invites, we have a strict policy against begging. Further offenses will result in removal from the chat.",
|
||||
"color": 7976557,
|
||||
"color": 16718635,
|
||||
"author": {
|
||||
"name": "BEGGING!",
|
||||
"url": "",
|
||||
"icon_url": "https://spee.ch/7/LBRY-Discord-Warning.png"
|
||||
"icon_url": "https://spee.ch/8/caution-red.png"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -263,11 +279,11 @@
|
|||
"url": "",
|
||||
"title": "",
|
||||
"description": "Please keep conversations on topic, or move random conversations to #random if you wish to continue",
|
||||
"color": 7976557,
|
||||
"color": 16764237,
|
||||
"author": {
|
||||
"name": "Random",
|
||||
"url": "",
|
||||
"icon_url": "https://spee.ch/7/LBRY-Discord-Warning.png"
|
||||
"icon_url": "https://spee.ch/3/question-orange.png"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -383,22 +399,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"!rewardsapprove": {
|
||||
"usage": "",
|
||||
"description": "How to become Rewards approved",
|
||||
"operation": "send",
|
||||
"bundle": {
|
||||
"url": "",
|
||||
"title": "",
|
||||
"description": "Please download the latest version from [HERE](https://lbry.com/get) Upon install, you'll be greeted with a welcome message. If you already had the app installed, please go to the wallet (bank icon in the top right) > Rewards - This should show your current status. New users will need to get their rewards approved in order to access Rewards. Type !cc or see the !rewardsapproval information below.",
|
||||
"color": 7976557,
|
||||
"author": {
|
||||
"name": "How to become Rewards approved",
|
||||
"url": "",
|
||||
"icon_url": "https://spee.ch/2/pinkylbryheart.png"
|
||||
}
|
||||
}
|
||||
},
|
||||
"!verify": {
|
||||
"usage": "",
|
||||
"description": "How to become Rewards approved",
|
||||
|
@ -431,22 +431,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"!verification": {
|
||||
"usage": "",
|
||||
"description": "Rewards Approval Help Message",
|
||||
"operation": "send",
|
||||
"bundle": {
|
||||
"url": "",
|
||||
"title": "",
|
||||
"description": "If you would like to be approved for rewards, please go to <#571001864271691805> and send a Direct Message to @RewardsBot#0287 \n You can do this by right clicking on the name, and selecting Message. . A LBRY mod will get back to you as soon as possible. We appreciate your patience. Only one account per household is allowed access to LBRY Rewards. Check out our [Rewards FAQ](https://lbry.io/faq/rewards) to know more about rewards.",
|
||||
"color": 7976557,
|
||||
"author": {
|
||||
"name": "Applying for Rewards Approval",
|
||||
"url": "",
|
||||
"icon_url": "https://spee.ch/2/pinkylbryheart.png"
|
||||
}
|
||||
}
|
||||
},
|
||||
"!logfile": {
|
||||
"usage": "",
|
||||
"description": "How to Find LBRY App Log File?",
|
||||
|
@ -913,7 +897,22 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
|
||||
"!why": {
|
||||
"usage": "",
|
||||
"description": "Why should I use LBRY?",
|
||||
"operation": "send",
|
||||
"bundle": {
|
||||
"url": "",
|
||||
"title": "",
|
||||
"description": "LBRY is a new protocol which allows anyone to build apps that interact with digital content on the LBRY network. Apps built on the protocol allow creators to upload their work to the LBRY network of hosts (like BitTorrent), and set a price per stream or download (like iTunes) or give it away for free (like YouTube without ads). It benefits the consumer, because there's no ads, and you can often buy things cheaper on LBRY, and it benefits the creator, because there's no risk of demonetization, essentially no fees, and it's a lot harder to censor. You can find out more on the [FAQ](https://lbry.com/faq), or ask anyone here for their experience!",
|
||||
"color": 7976557,
|
||||
"author": {
|
||||
"name": "Why should I use LBRY?",
|
||||
"url": "https://lbry.com/faq",
|
||||
"icon_url": "https://spee.ch/2/pinkylbryheart.png"
|
||||
}
|
||||
}
|
||||
},
|
||||
"!piratebay": {
|
||||
"usage": "",
|
||||
"description": "Why LBRY has piratebay.com",
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
},
|
||||
"rolelist": {
|
||||
"baserole": "LBRYian",
|
||||
"allowedroles": ["NSFW", "Traders", "Miners", "Off-Topic Chats", "International", "Dev"]
|
||||
"allowedroles": ["Off-Topic Chats", "Dev"]
|
||||
},
|
||||
"irc": {
|
||||
"enabled": false,
|
||||
|
|
24
package-lock.json
generated
24
package-lock.json
generated
|
@ -2599,9 +2599,9 @@
|
|||
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
|
||||
},
|
||||
"mixin-deep": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.1.tgz",
|
||||
"integrity": "sha512-8ZItLHeEgaqEvd5lYBXfm4EZSFCX29Jb9K+lAHhDKzReKBQKj3R+7NOF6tjqYi9t4oI8VUfaWITJQm86wnXGNQ==",
|
||||
"version": "1.3.2",
|
||||
"resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.2.tgz",
|
||||
"integrity": "sha512-WRoDn//mXBiJ1H40rqa3vH0toePwSsGb45iInWlTySa+Uu4k3tYUSxa2v1KqAiLtvlrSzaExqS1gtk96A9zvEA==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"for-in": "^1.0.2",
|
||||
|
@ -2633,23 +2633,13 @@
|
|||
"integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg=="
|
||||
},
|
||||
"mongodb": {
|
||||
"version": "3.2.7",
|
||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.2.7.tgz",
|
||||
"integrity": "sha512-2YdWrdf1PJgxcCrT1tWoL6nHuk6hCxhddAAaEh8QJL231ci4+P9FLyqopbTm2Z2sAU6mhCri+wd9r1hOcHdoMw==",
|
||||
"requires": {
|
||||
"mongodb-core": "3.2.7",
|
||||
"safe-buffer": "^5.1.2"
|
||||
}
|
||||
},
|
||||
"mongodb-core": {
|
||||
"version": "3.2.7",
|
||||
"resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.2.7.tgz",
|
||||
"integrity": "sha512-WypKdLxFNPOH/Jy6i9z47IjG2wIldA54iDZBmHMINcgKOUcWJh8og+Wix76oGd7EyYkHJKssQ2FAOw5Su/n4XQ==",
|
||||
"version": "3.3.2",
|
||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.3.2.tgz",
|
||||
"integrity": "sha512-fqJt3iywelk4yKu/lfwQg163Bjpo5zDKhXiohycvon4iQHbrfflSAz9AIlRE6496Pm/dQKQK5bMigdVo2s6gBg==",
|
||||
"requires": {
|
||||
"bson": "^1.1.1",
|
||||
"require_optional": "^1.0.1",
|
||||
"safe-buffer": "^5.1.2",
|
||||
"saslprep": "^1.0.0"
|
||||
"safe-buffer": "^5.1.2"
|
||||
}
|
||||
},
|
||||
"mongoose": {
|
||||
|
|
Loading…
Add table
Reference in a new issue