mirror of
https://github.com/LBRYFoundation/curate.git
synced 2025-08-23 17:37:25 +00:00
Add trusted commands
closes #52 Co-authored-by: Coolguy3289 <Coolguy3289@users.noreply.github.com>
This commit is contained in:
parent
a1725ec01b
commit
2dfeac3d22
8 changed files with 178 additions and 2 deletions
|
@ -13,6 +13,8 @@ module.exports = {
|
||||||
embedColor: 0x15521c,
|
embedColor: 0x15521c,
|
||||||
// [string|Array<string>] The role ID(s) for curator roles
|
// [string|Array<string>] The role ID(s) for curator roles
|
||||||
curatorRoleID: "",
|
curatorRoleID: "",
|
||||||
|
// [string|Array<string>] The role ID(s) for trusted roles
|
||||||
|
trustedRoleID: "",
|
||||||
// [string|Array<string>] The role ID(s) for admin roles
|
// [string|Array<string>] The role ID(s) for admin roles
|
||||||
adminRoleID: "",
|
adminRoleID: "",
|
||||||
// [string] guild_id
|
// [string] guild_id
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const Command = require('../../structures/Command');
|
const Command = require('../../structures/Command');
|
||||||
const Util = require('../../util');
|
const Util = require('../../util');
|
||||||
|
|
||||||
module.exports = class Abaondon extends Command {
|
module.exports = class Abandon extends Command {
|
||||||
get name() { return 'abandon'; }
|
get name() { return 'abandon'; }
|
||||||
|
|
||||||
get _options() { return {
|
get _options() { return {
|
||||||
|
|
40
src/commands/trusted/tabandon.js
Normal file
40
src/commands/trusted/tabandon.js
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
const Command = require('../../structures/Command');
|
||||||
|
const Util = require('../../util');
|
||||||
|
|
||||||
|
module.exports = class TAbandon extends Command {
|
||||||
|
get name() { return 'tabandon'; }
|
||||||
|
|
||||||
|
get _options() { return {
|
||||||
|
aliases: ['taban', 'tdrop'],
|
||||||
|
permissions: ['trustedOrAdmin'],
|
||||||
|
minimumArgs: 1
|
||||||
|
}; }
|
||||||
|
|
||||||
|
async exec(message, { args }) {
|
||||||
|
const givenClaim = Util.resolveToClaimID(args[0]);
|
||||||
|
if (!givenClaim)
|
||||||
|
// @TODO use claim_search for invalid claim ids
|
||||||
|
return message.channel.createMessage('That Claim ID isn\'t valid.');
|
||||||
|
|
||||||
|
if (!await this.client.messageAwaiter.confirm(message, {
|
||||||
|
header:
|
||||||
|
'Are you sure you want to abandon a claim from a **trusted** account?'
|
||||||
|
})) return;
|
||||||
|
|
||||||
|
const account = await Util.LBRY.findSDKAccount(this.client, account => account.is_default);
|
||||||
|
|
||||||
|
// Drop support
|
||||||
|
const response = await this.client.lbry.abandonSupport({
|
||||||
|
accountID: account.id, claimID: givenClaim });
|
||||||
|
const transaction = await response.json();
|
||||||
|
if (await this.handleResponse(message, response, transaction)) return;
|
||||||
|
const txid = transaction.result.txid;
|
||||||
|
return message.channel.createMessage(`Abandon successful! https://explorer.lbry.com/tx/${txid}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
get metadata() { return {
|
||||||
|
category: 'Trusted',
|
||||||
|
description: 'Abandons a support on a given claim from the trusted account.',
|
||||||
|
usage: '<claim>'
|
||||||
|
}; }
|
||||||
|
};
|
30
src/commands/trusted/tbalance.js
Normal file
30
src/commands/trusted/tbalance.js
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
const Command = require('../../structures/Command');
|
||||||
|
const Util = require('../../util');
|
||||||
|
const config = require('config');
|
||||||
|
|
||||||
|
module.exports = class TBalance extends Command {
|
||||||
|
get name() { return 'tbalance'; }
|
||||||
|
|
||||||
|
get _options() { return {
|
||||||
|
aliases: ['tbal', 'trustedbal', 'trustedbalance'],
|
||||||
|
permissions: ['trustedOrAdmin']
|
||||||
|
}; }
|
||||||
|
|
||||||
|
async exec(message) {
|
||||||
|
const account = await Util.LBRY.findSDKAccount(this.client, account => account.is_default);
|
||||||
|
const response = await this.client.lbry.accountBalance(account.id);
|
||||||
|
const wallet = await response.json();
|
||||||
|
if (await this.handleResponse(message, response, wallet)) return;
|
||||||
|
return message.channel.createMessage({ embed: {
|
||||||
|
color: config.embedColor,
|
||||||
|
description: `**${wallet.result.available}** LBC is available in the trusted account.\n\n` +
|
||||||
|
`Reserved in Supports: ${wallet.result.reserved_subtotals.supports} LBC\n` +
|
||||||
|
`Total: ${wallet.result.total} LBC`
|
||||||
|
} });
|
||||||
|
}
|
||||||
|
|
||||||
|
get metadata() { return {
|
||||||
|
category: 'Trusted',
|
||||||
|
description: 'Shows the trusted wallet balance.'
|
||||||
|
}; }
|
||||||
|
};
|
51
src/commands/trusted/tsupport.js
Normal file
51
src/commands/trusted/tsupport.js
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
const Command = require('../../structures/Command');
|
||||||
|
const Util = require('../../util');
|
||||||
|
|
||||||
|
module.exports = class TSupport extends Command {
|
||||||
|
get name() { return 'tsupport'; }
|
||||||
|
|
||||||
|
get _options() { return {
|
||||||
|
aliases: ['tsup'],
|
||||||
|
permissions: ['trustedOrAdmin'],
|
||||||
|
minimumArgs: 2
|
||||||
|
}; }
|
||||||
|
|
||||||
|
async exec(message, { args }) {
|
||||||
|
const givenAmount = Util.LBRY.ensureDecimal(args[1]);
|
||||||
|
if (!givenAmount)
|
||||||
|
return message.channel.createMessage('The second argument must be a numeric amount of LBC to send!');
|
||||||
|
|
||||||
|
const givenClaim = Util.resolveToClaimID(args[0]);
|
||||||
|
if (!givenClaim)
|
||||||
|
// @TODO use claim_search for invalid claim ids
|
||||||
|
return message.channel.createMessage('That Claim ID isn\'t valid.');
|
||||||
|
|
||||||
|
// Get and check balance
|
||||||
|
const account = await Util.LBRY.findSDKAccount(this.client, account => account.is_default);
|
||||||
|
const walletResponse = await this.client.lbry.accountBalance(account.id);
|
||||||
|
const wallet = await walletResponse.json();
|
||||||
|
if (await this.handleResponse(message, walletResponse, wallet)) return;
|
||||||
|
const balance = wallet.result.available;
|
||||||
|
if (parseFloat(givenAmount) > parseFloat(balance))
|
||||||
|
return message.channel.createMessage('You don\'t have enough LBC to do this!');
|
||||||
|
|
||||||
|
if (!await this.client.messageAwaiter.confirm(message, {
|
||||||
|
header:
|
||||||
|
'Are you sure you want to support a claim from a **trusted** account?'
|
||||||
|
})) return;
|
||||||
|
|
||||||
|
// Create support
|
||||||
|
const response = await this.client.lbry.createSupport({
|
||||||
|
accountID: account.id, claimID: givenClaim, amount: givenAmount });
|
||||||
|
const transaction = await response.json();
|
||||||
|
if (await this.handleResponse(message, response, transaction)) return;
|
||||||
|
const txid = transaction.result.txid;
|
||||||
|
return message.channel.createMessage(`Support successful! https://explorer.lbry.com/tx/${txid}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
get metadata() { return {
|
||||||
|
category: 'Trusted',
|
||||||
|
description: 'Support a given claim from the trusted account.',
|
||||||
|
usage: '<claim> <amount>'
|
||||||
|
}; }
|
||||||
|
};
|
42
src/commands/trusted/tsupports.js
Normal file
42
src/commands/trusted/tsupports.js
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
const Command = require('../../structures/Command');
|
||||||
|
const GenericPager = require('../../structures/GenericPager');
|
||||||
|
const Util = require('../../util');
|
||||||
|
|
||||||
|
module.exports = class TSupports extends Command {
|
||||||
|
get name() { return 'tsupports'; }
|
||||||
|
get _options() { return {
|
||||||
|
aliases: ['tsups'],
|
||||||
|
permissions: ['trustedOrAdmin'],
|
||||||
|
minimumArgs: 0
|
||||||
|
}; }
|
||||||
|
async exec(message, { args }) {
|
||||||
|
let givenClaim;
|
||||||
|
if (args[0]) {
|
||||||
|
givenClaim = Util.resolveToClaimID(args[0]);
|
||||||
|
if (!givenClaim)
|
||||||
|
// @TODO use claim_search for invalid claim ids
|
||||||
|
return message.channel.createMessage('That Claim ID isn\'t valid.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const account = await Util.LBRY.findSDKAccount(this.client, account => account.is_default);
|
||||||
|
const supportsCount = await Util.LBRY.getSupportsCount(this.client, account.id);
|
||||||
|
if (supportsCount <= 0)
|
||||||
|
return message.channel.createMessage('No supports found.');
|
||||||
|
|
||||||
|
const supportsResponse = await this.client.lbry.listSupports({
|
||||||
|
accountID: account.id, page_size: supportsCount, claimID: givenClaim });
|
||||||
|
const supports = (await supportsResponse.json()).result.items;
|
||||||
|
const paginator = new GenericPager(this.client, message, {
|
||||||
|
items: supports,
|
||||||
|
header: `All supports for the trusted account${
|
||||||
|
givenClaim ? ` on claim \`${givenClaim}\`` : ''}`, itemTitle: 'Supports',
|
||||||
|
display: item => `*lbry://**${item.name}***#\`${item.claim_id}\` (${item.amount} LBC)`
|
||||||
|
});
|
||||||
|
return paginator.start(message.channel.id, message.author.id);
|
||||||
|
}
|
||||||
|
get metadata() { return {
|
||||||
|
category: 'Trusted',
|
||||||
|
description: 'Shows the list of supports from the trusted account.',
|
||||||
|
usage: '[claimID]'
|
||||||
|
}; }
|
||||||
|
};
|
|
@ -21,7 +21,7 @@ class GenericPager extends Paginator {
|
||||||
constructor(client, message, {
|
constructor(client, message, {
|
||||||
items = [], itemsPerPage = 15,
|
items = [], itemsPerPage = 15,
|
||||||
display = item => item.toString(),
|
display = item => item.toString(),
|
||||||
embedExtra = {}, itemTitle = 'words.item.many',
|
embedExtra = {}, itemTitle = 'Items',
|
||||||
header = null, footer = null
|
header = null, footer = null
|
||||||
} = {}) {
|
} = {}) {
|
||||||
super(client, message, { items, itemsPerPage });
|
super(client, message, { items, itemsPerPage });
|
||||||
|
|
11
src/util.js
11
src/util.js
|
@ -94,6 +94,17 @@ Util.CommandPermissions = {
|
||||||
if (Util.CommandPermissions.elevated(client, message)) return true;
|
if (Util.CommandPermissions.elevated(client, message)) return true;
|
||||||
return roles.map(r => member.roles.includes(r)).includes(true);
|
return roles.map(r => member.roles.includes(r)).includes(true);
|
||||||
},
|
},
|
||||||
|
trustedOrAdmin: (client, message) => {
|
||||||
|
const member = message.guildID ? message.member :
|
||||||
|
client.guilds.get(config.guildID).members.get(message.author.id);
|
||||||
|
const roles = [
|
||||||
|
...(Array.isArray(config.adminRoleID) ? config.adminRoleID : [config.adminRoleID]),
|
||||||
|
...(Array.isArray(config.trustedRoleID) ? config.trustedRoleID : [config.trustedRoleID]),
|
||||||
|
];
|
||||||
|
if (!member) return false;
|
||||||
|
if (Util.CommandPermissions.elevated(client, message)) return true;
|
||||||
|
return roles.map(r => member.roles.includes(r)).includes(true);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue