mirror of
https://github.com/LBRYFoundation/curate.git
synced 2025-08-23 17:37:25 +00:00
Resolve LBRY URLs into claim IDs
This commit is contained in:
parent
8ecec7e455
commit
e7ad2851cd
3 changed files with 18 additions and 4 deletions
|
@ -11,8 +11,8 @@ module.exports = class Abaondon extends Command {
|
||||||
}; }
|
}; }
|
||||||
|
|
||||||
async exec(message, { args }) {
|
async exec(message, { args }) {
|
||||||
const givenClaim = args[0];
|
const givenClaim = Util.resolveToClaimID(args[0]);
|
||||||
if (!/^[a-f0-9]{40}$/.test(givenClaim))
|
if (!givenClaim)
|
||||||
// @TODO use claim_search for invalid claim ids
|
// @TODO use claim_search for invalid claim ids
|
||||||
return message.channel.createMessage('That Claim ID isn\'t valid.');
|
return message.channel.createMessage('That Claim ID isn\'t valid.');
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,8 @@ module.exports = class Support extends Command {
|
||||||
if (!givenAmount)
|
if (!givenAmount)
|
||||||
return message.channel.createMessage('The second argument must be a numeric amount of LBC to send!');
|
return message.channel.createMessage('The second argument must be a numeric amount of LBC to send!');
|
||||||
|
|
||||||
const givenClaim = args[0];
|
const givenClaim = Util.resolveToClaimID(args[0]);
|
||||||
if (!/^[a-f0-9]{40}$/.test(givenClaim))
|
if (!givenClaim)
|
||||||
// @TODO use claim_search for invalid claim ids
|
// @TODO use claim_search for invalid claim ids
|
||||||
return message.channel.createMessage('That Claim ID isn\'t valid.');
|
return message.channel.createMessage('That Claim ID isn\'t valid.');
|
||||||
|
|
||||||
|
|
14
src/util.js
14
src/util.js
|
@ -150,6 +150,20 @@ Util.resolveToUserID = (arg) => {
|
||||||
else return null;
|
else return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve argument to a claim ID
|
||||||
|
* @memberof Util.
|
||||||
|
* @param {string} arg
|
||||||
|
* @returns {?string}
|
||||||
|
*/
|
||||||
|
Util.resolveToClaimID = (arg) => {
|
||||||
|
if (/^[a-f0-9]{40}$/.test(arg))
|
||||||
|
return arg;
|
||||||
|
else if (/^lbry:\/\/@?[\w-]+#([a-f0-9]{40})$/.test(arg))
|
||||||
|
return arg.replace(/^<@!?(\d{17,18})>$/, '$1');
|
||||||
|
else return null;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a promise that resolves after some time
|
* Make a promise that resolves after some time
|
||||||
* @memberof Util.
|
* @memberof Util.
|
||||||
|
|
Loading…
Add table
Reference in a new issue