mirror of
https://github.com/LBRYFoundation/lbry-wunderbot.git
synced 2025-08-23 17:47:27 +00:00
Merge branch 'master' into patch-6
This commit is contained in:
commit
ec4f157448
2 changed files with 164 additions and 163 deletions
|
@ -13,47 +13,46 @@ exports.addrole = {
|
||||||
usage: '<role>',
|
usage: '<role>',
|
||||||
description: 'Adds you to specified role',
|
description: 'Adds you to specified role',
|
||||||
process: function(bot, msg, suffix) {
|
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.
|
||||||
// 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('name', suffix);
|
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('name', rolelist.baserole);
|
let baserole = msg.guild.roles.find('name', rolelist.baserole);
|
||||||
// Checks if the user put a role in the message.
|
|
||||||
if (inPrivate(msg)) {
|
// Provide shortened syntax for the sake of code cleanliness
|
||||||
msg.channel.send('You can not set roles in DMs! Please go to the Discord server to do this.');
|
let send = (msgTxt) => { msg.channel.send(msgTxt); return; };
|
||||||
|
let rolecmd = botconfig.prefix + "roles";
|
||||||
|
|
||||||
|
// 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.');
|
||||||
|
// 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('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;
|
return;
|
||||||
} else {
|
// Confirm that the role exists on the server and if not then be sure to send a nag message
|
||||||
if (suffix) {
|
if(!baserole)
|
||||||
//suffix = suffix.toLowerCase();
|
return send("The base role of " + rolelist.baserole + " has been set in config but is missing from the server");
|
||||||
// Checks if the role mentioned in the message is in the allowed roles listed in the wunderbot config.
|
// Confirm if the user has the baserole already, including if it was added just now
|
||||||
if (rolelist.allowedroles.includes(suffix) || rolelist.baserole.includes(suffix)) {
|
if(msg.member.roles.find('name', baserole.name))
|
||||||
// Checks if the role even exists in the discord server
|
return;
|
||||||
if (newrole !== null) {
|
// Add the base role and avoid spamming the user by only mentioning them in the previous message
|
||||||
// Checks if the member has the role that they are trying to add
|
msg.member.addRole(baserole).then(send("We also added the base " + rolelist.baserole + " role for you!"));
|
||||||
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!');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
exports.delrole = {
|
exports.delrole = {
|
||||||
|
@ -61,33 +60,30 @@ exports.delrole = {
|
||||||
description: 'Deletes the specified role from your account',
|
description: 'Deletes the specified role from your account',
|
||||||
process: function(bot, msg, suffix) {
|
process: function(bot, msg, suffix) {
|
||||||
// Here in the bot, msg and suffix are available, this function can be async if needed.
|
// Here in the bot, msg and suffix are available, this function can be async if needed.
|
||||||
let oldrole = msg.guild.roles.find('name', suffix);
|
// Make sure to eliminate case sensitivity, do this here to only perform the sweep once.
|
||||||
// Checks if the user put a role in the message.
|
let oldrole = msg.guild.roles.find(role => role.name.toLowerCase() === suffix.toLowerCase());
|
||||||
if (inPrivate(msg)) {
|
// Provide shortened syntax for the sake of code cleanliness
|
||||||
msg.channel.send('You can not set roles in DMs! Please go to the Discord server to do this.');
|
let send = (msgTxt) => { msg.channel.send(msgTxt); return; };
|
||||||
return;
|
let rolecmd = botconfig.prefix + "roles";
|
||||||
} else {
|
|
||||||
if (suffix) {
|
// Checks if the user has messaged the bot via Direct Message
|
||||||
// Checks if the role mentioned in the message is in the allowed roles listed in the Wunderbot config.
|
if (inPrivate(msg))
|
||||||
if (rolelist.allowedroles.includes(suffix)) {
|
return send('You can not set roles in DMs! Please go to the Discord server to do this.');
|
||||||
// Checks if the role exists in the Discord server
|
// Checks if the user included a role in their message
|
||||||
if (oldrole !== null) {
|
if (!suffix)
|
||||||
// Checks if the member has the role that they are trying to add
|
return send("Please specify a role. Type " + rolecmd + " to see which you may remove yourself!");
|
||||||
if (msg.member.roles.find('name', suffix)) {
|
// Checks if there is a matching role found on the server
|
||||||
msg.member.removeRole(oldrole).then(msg.channel.send(msg.member + ' has been removed from the ' + suffix + ' role!'));
|
if(!newrole)
|
||||||
} else {
|
return send("The role specified `" + suffix + "` does not exist on this server!");
|
||||||
msg.channel.send("You don't seem to have that role! Try adding it first with the " + botconfig.prefix + 'addrole command!');
|
// Checks that the allowed roles against the matched role's name, since this eliminates case sensitivity issues
|
||||||
}
|
if(!rolelist.allowedroles.includes(oldrole.name))
|
||||||
} else {
|
return send("That role isn't one you can remove yourself! If you need it removed, please ask a moderator!");
|
||||||
msg.channel.send('The role ' + '`' + suffix + '`' + ' does not exist!');
|
// Use the matched name to check against the member's existing roles
|
||||||
}
|
if(!msg.member.roles.find('name', oldrole.name))
|
||||||
} else {
|
return send("It seems you don't actually have the " + oldrole.name + "role! Mission accomplished!");
|
||||||
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.');
|
|
||||||
}
|
// Assuming all these factors succeed, add the role
|
||||||
} else {
|
msg.member.removeRole(oldrole).then(send(msg.member + " has been removed from the " + oldrole.name + " role!"));
|
||||||
msg.channel.send('Please specify a role. Type ' + botconfig.prefix + 'roles to see which you may add!');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
exports.roles = {
|
exports.roles = {
|
||||||
|
|
|
@ -8,20 +8,19 @@ exports.stats = {
|
||||||
usage: '',
|
usage: '',
|
||||||
description: 'Displays list of current Market stats',
|
description: 'Displays list of current Market stats',
|
||||||
process: function(bot, msg) {
|
process: function(bot, msg) {
|
||||||
needle.get('https://api.coinmarketcap.com/v2/ticker/1298/?convert=BTC', function(error, response) {
|
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) {
|
if (error || response.statusCode !== 200) {
|
||||||
msg.channel.send('coinmarketcap API is not available');
|
msg.channel.send('coingecko API is not available');
|
||||||
} else {
|
} else {
|
||||||
let data = response.body.data;
|
let data = response.body.data;
|
||||||
let rank = data.rank;
|
let rank = data.market_cap_rank;
|
||||||
let price_usd = Number(data.quotes.USD.price);
|
let price_btc = Number(data.current_price);
|
||||||
let price_btc = Number(data.quotes.BTC.price);
|
let market_cap_btc = Number(data.quotes.market_cap);
|
||||||
let market_cap_usd = Number(data.quotes.USD.market_cap);
|
|
||||||
let circulating_supply = Number(data.circulating_supply);
|
let circulating_supply = Number(data.circulating_supply);
|
||||||
let total_supply = Number(data.total_supply);
|
let total_supply = Number(data.total_supply);
|
||||||
let percent_change_1h = Number(data.quotes.USD.percent_change_1h);
|
let percent_change_1h = Number(data.price_change_percentage_1h_in_currency);
|
||||||
let percent_change_24h = Number(data.quotes.USD.percent_change_24h);
|
let percent_change_24h = Number(data.price_change_percentage_24h_in_currency);
|
||||||
let volume24_usd = Number(data.quotes.USD.volume_24h);
|
let volume24_btc = Number(data.total_volume);
|
||||||
let dt = new Date();
|
let dt = new Date();
|
||||||
let timestamp = dt.toUTCString();
|
let timestamp = dt.toUTCString();
|
||||||
let hr_indicator = ':thumbsup:';
|
let hr_indicator = ':thumbsup:';
|
||||||
|
@ -33,37 +32,41 @@ exports.stats = {
|
||||||
day_indicator = ':thumbsdown:';
|
day_indicator = ':thumbsdown:';
|
||||||
}
|
}
|
||||||
|
|
||||||
needle.get('https://api.coinmarketcap.com/v2/ticker/1298/?convert=GBP', function(error, response) {
|
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) {
|
if (error || response.statusCode !== 200) {
|
||||||
msg.channel.send('coinmarketcap API is not available');
|
msg.channel.send('coingecko API is not available');
|
||||||
} else {
|
} else {
|
||||||
data = response.body.data;
|
data = response.body.data;
|
||||||
let price_gbp = Number(data.quotes.GBP.price);
|
let price_gbp = Number(data.current_price);
|
||||||
needle.get('https://api.coinmarketcap.com/v2/ticker/1298/?convert=EUR', function(error, response) {
|
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) {
|
if (error || response.statusCode !== 200) {
|
||||||
msg.channel.send('coinmarketcap API is not available');
|
msg.channel.send('coingecko API is not available');
|
||||||
} else {
|
} else {
|
||||||
data = response.body.data;
|
data = response.body.data;
|
||||||
let price_eur = Number(data.quotes.EUR.price);
|
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.data;
|
||||||
|
let price_usd = Number(data.current_price);
|
||||||
let description = `**Rank: [${rank}](${statsurl})**
|
let description = `**Rank: [${rank}](${statsurl})**
|
||||||
**Data**
|
**Data**
|
||||||
Market Cap: [$${numberWithCommas(market_cap_usd)}](${statsurl})
|
Market Cap: [$${numberWithCommas(market_cap_usd)}](${statsurl})
|
||||||
Total Supply: [${numberWithCommas(total_supply)} LBC](${statsurl})
|
Total Supply: [${numberWithCommas(total_supply)} LBC](${statsurl})
|
||||||
Circulating Supply: [${numberWithCommas(circulating_supply)} LBC](${statsurl})
|
Circulating Supply: [${numberWithCommas(circulating_supply)} LBC](${statsurl})
|
||||||
24 Hour Volume: [$${volume24_usd}](${statsurl})
|
24 Hour Volume: [$${volume24_usd}](${statsurl})
|
||||||
|
|
||||||
**Price**
|
**Price**
|
||||||
BTC: [₿${price_btc.toFixed(8)}](${statsurl})
|
BTC: [₿${price_btc.toFixed(8)}](${statsurl})
|
||||||
USD: [$${price_usd.toFixed(2)}](${statsurl})
|
USD: [$${price_usd.toFixed(2)}](${statsurl})
|
||||||
EUR: [€${price_eur.toFixed(2)}](${statsurl})
|
EUR: [€${price_eur.toFixed(2)}](${statsurl})
|
||||||
GBP: [£${price_gbp.toFixed(2)}](${statsurl})
|
GBP: [£${price_gbp.toFixed(2)}](${statsurl})
|
||||||
|
|
||||||
**% Change**
|
**% Change**
|
||||||
1 Hour: [${percent_change_1h}](${statsurl}) ${hr_indicator}
|
1 Hour: [${percent_change_1h}](${statsurl}) ${hr_indicator}
|
||||||
|
|
||||||
1 Day: [${percent_change_24h}](${statsurl}) ${day_indicator}
|
1 Day: [${percent_change_24h}](${statsurl}) ${day_indicator}`;
|
||||||
|
|
||||||
`;
|
|
||||||
const embed = {
|
const embed = {
|
||||||
description: description,
|
description: description,
|
||||||
color: 7976557,
|
color: 7976557,
|
||||||
|
@ -76,7 +79,7 @@ GBP: [£${price_gbp.toFixed(2)}](${statsurl})
|
||||||
icon_url: 'https://spee.ch/2/pinkylbryheart.png'
|
icon_url: 'https://spee.ch/2/pinkylbryheart.png'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
msg.channel.send({ embed });
|
msg.channel.send({embed});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -104,4 +107,6 @@ GBP: [£${price_gbp.toFixed(2)}](${statsurl})
|
||||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue