mirror of
https://github.com/LBRYFoundation/lbry-wunderbot.git
synced 2025-08-23 17:47:27 +00:00
Added claimbot that uses chainquery instead of lbrycrd. Usage otherwise identical to old bot.
This commit is contained in:
parent
c46e1266aa
commit
d65d78b8a2
1 changed files with 78 additions and 34 deletions
|
@ -1,10 +1,12 @@
|
||||||
// Claimbot is a work in progress, it will use chainquery when done.
|
// Claimbot is a work in progress, it will use chainquery when done.
|
||||||
/* import { Command } from "discord.js-commando";
|
|
||||||
import { RichEmbed } from "discord.js";
|
import { RichEmbed } from "discord.js";
|
||||||
import welcomeEvent from "../../helpers/welcomeEvent";
|
import config from "config";
|
||||||
|
|
||||||
let bootupTime = null;
|
const Commando = require("discord.js-commando");
|
||||||
module.exports = class ClaimCommand extends Command {
|
|
||||||
|
let time = null;
|
||||||
|
const channels = config.get("Wunderbot.claimbot");
|
||||||
|
module.exports = class ClaimCommand extends Commando.Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
super(client, {
|
super(client, {
|
||||||
name: "claimbot",
|
name: "claimbot",
|
||||||
|
@ -24,12 +26,10 @@ module.exports = class ClaimCommand extends Command {
|
||||||
guildOnly: true,
|
guildOnly: true,
|
||||||
guarded: true
|
guarded: true
|
||||||
});
|
});
|
||||||
client.on("ready", () => {
|
client.on("ready", async () => {
|
||||||
bootupTime = new Date()
|
setInterval(() => {
|
||||||
.toISOString()
|
this.checkNewClaims();
|
||||||
.slice(0, 19)
|
}, 300000); // Check for new claims every 5 minutes
|
||||||
.replace("T", " ");
|
|
||||||
this.checkGuilds();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,45 +38,89 @@ module.exports = class ClaimCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(msg, { action }) {
|
async run(msg, { action }) {
|
||||||
if (action.toLowerCase() === "enable") {
|
|
||||||
}
|
|
||||||
if (action.toLowerCase() === "disable") {
|
|
||||||
}
|
|
||||||
if (action.toLowerCase() === "test") {
|
if (action.toLowerCase() === "test") {
|
||||||
console.log(
|
console.log(await this.getClaimsSince(bootupTime));
|
||||||
await this.getNewClaimsSince(
|
}
|
||||||
new Date()
|
}
|
||||||
.toISOString()
|
async checkNewClaims() {
|
||||||
.slice(0, 19)
|
if (time === null) {
|
||||||
.replace("T", " ")
|
time = new Date()
|
||||||
)
|
.toISOString()
|
||||||
);
|
.slice(0, 19)
|
||||||
|
.replace("T", " ");
|
||||||
|
} else {
|
||||||
|
const claims = await this.getClaimsSince(time);
|
||||||
|
// Output claims to channels
|
||||||
|
claims.data.forEach(c => {
|
||||||
|
const v = JSON.parse(c.value);
|
||||||
|
this.postToDiscord(c, v);
|
||||||
|
});
|
||||||
|
time = new Date()
|
||||||
|
.toISOString()
|
||||||
|
.slice(0, 19)
|
||||||
|
.replace("T", " ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkGuilds(){
|
postToDiscord(claim, value) {
|
||||||
|
const text = [];
|
||||||
|
if (value.author) {
|
||||||
|
text.push(`author: ${value.author}`);
|
||||||
|
}
|
||||||
|
if (value.description) {
|
||||||
|
text.push(value.description);
|
||||||
|
}
|
||||||
|
// if (value['content_type'])
|
||||||
|
// {
|
||||||
|
// text.push("*Content Type:* " + value['content_type']);
|
||||||
|
// }
|
||||||
|
if (value.nsfw) {
|
||||||
|
text.push("*Warning: Adult Content*");
|
||||||
|
}
|
||||||
|
|
||||||
|
// "fee":{"currency":"LBC","amount":186,"version":"_0_0_1","address":"bTGoFCakvQXvBrJg1b7FJzombFUu6iRJsk"}
|
||||||
|
if (value.fee) {
|
||||||
|
const fees = [];
|
||||||
|
text.push(`Price: ${value.fee.amount} *${value.fee.currency}*`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const claimEmbed = new RichEmbed();
|
||||||
|
claimEmbed
|
||||||
|
.setAuthor(value.author || "Anonymous", "http://barkpost-assets.s3.amazonaws.com/wp-content/uploads/2013/11/3dDoge.gif", `http://open.lbry.io/${claim.name}#${claim.claimId}`)
|
||||||
|
.setTitle(`lbry://${channelName ? `${channelName}/` : ""}${claim.name}`)
|
||||||
|
.setColor(1399626)
|
||||||
|
.setDescription(this.escapeSlackHtml(text.join("\n")))
|
||||||
|
.setFooter(`Block ${claimBlockHeight} • Claim ID ${claim.claimId}`)
|
||||||
|
.setImage(!value.nsfw ? value.thumbnail || "" : "")
|
||||||
|
.setURL(`http://open.lbry.io/${claim.name}#${claim.claimId}`);
|
||||||
|
channels.forEach(channel => {
|
||||||
|
this.bot.channels
|
||||||
|
.get(channel)
|
||||||
|
.send("", { embed: claimEmbed })
|
||||||
|
.catch(console.error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
async getNewClaimsSince(date, guild_id) {
|
async getClaimsSince(time) {
|
||||||
const query = `${`` +
|
const query = `${`${`` + `SELECT ` + `name, `}${`fee, ``value_as_json as value, `}bid_state, ` +
|
||||||
`SELECT ` +
|
|
||||||
`name, ` +
|
|
||||||
`value_as_json as value, ` +
|
|
||||||
`bid_state, ` +
|
|
||||||
`effective_amount, ` +
|
`effective_amount, ` +
|
||||||
`claim_id as claimId ` +
|
`claim_id as claimId ` +
|
||||||
// `,transaction_by_hash_id, ` + // txhash and vout needed to leverage old format for comparison.
|
// `,transaction_by_hash_id, ` + // txhash and vout needed to leverage old format for comparison.
|
||||||
// `vout ` +
|
// `vout ` +
|
||||||
`FROM claim ` +
|
`FROM claim ` +
|
||||||
`WHERE modified >='`}${date}'`;
|
`WHERE created >='`}${time}'`;
|
||||||
const newClaims = await this.client.request({
|
const claimList = await this.client.request({
|
||||||
url: `https://chainquery.lbry.io/api/sql?query=${query}`,
|
url: `https://chainquery.lbry.io/api/sql?query=${query}`,
|
||||||
cacheKey: `https://chainquery.lbry.io/api/sql?query=${query}`,
|
cacheKey: `https://chainquery.lbry.io/api/sql?query=${query}`,
|
||||||
cacheTTL: 1,
|
cacheTTL: 0,
|
||||||
cacheLimit: 1,
|
cacheLimit: 1,
|
||||||
resolveWithFullResponse: false
|
resolveWithFullResponse: false
|
||||||
});
|
});
|
||||||
console.log(newClaims);
|
return JSON.parse(claimList);
|
||||||
|
}
|
||||||
|
escapeSlackHtml(txt) {
|
||||||
|
return txt
|
||||||
|
.replace("&", "&")
|
||||||
|
.replace("<", "<")
|
||||||
|
.replace(">", ">");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
*/
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue