min-amount btc-monitor

Signed-off-by: ale <ale@manalejandro.com>
This commit is contained in:
ale 2025-06-08 02:39:20 +02:00
parent 63a562eba7
commit 4b79569b2d
Signed by: ale
GPG Key ID: 244A9C4DAB1C0C81

View File

@ -19,6 +19,7 @@ config();
let btcMonitorChannel = null; let btcMonitorChannel = null;
let btcSocket = null; let btcSocket = null;
let isMonitoring = false; let isMonitoring = false;
let minBtcAmount = 0; // Minimum BTC amount to show transactions
const client = new Client({ const client = new Client({
intents: [ intents: [
@ -129,6 +130,13 @@ client.on(Events.ClientReady, async readyClient => {
type: 7, // CHANNEL type type: 7, // CHANNEL type
description: 'Channel to send Bitcoin updates (required for start)', description: 'Channel to send Bitcoin updates (required for start)',
required: false required: false
},
{
name: 'min-amount',
type: 10, // NUMBER type
description: 'Minimum BTC amount to show transactions (default: 0)',
required: false,
min_value: 0
} }
] ]
} }
@ -214,6 +222,11 @@ async function initBitcoinMonitoring() {
// Process transaction data // Process transaction data
const txData = await processBitcoinTransaction(tx, blockexplorer); const txData = await processBitcoinTransaction(tx, blockexplorer);
// Check if transaction meets minimum amount threshold
if (parseFloat(txData.amount) < minBtcAmount) {
return; // Skip this transaction if it's below the minimum amount
}
// Create Discord embed // Create Discord embed
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setTitle('🟠 New Bitcoin Transaction') .setTitle('🟠 New Bitcoin Transaction')
@ -225,7 +238,7 @@ async function initBitcoinMonitoring() {
{ name: '⚡ Fee Rate', value: `${txData.feeRate} sat/byte`, inline: true } { name: '⚡ Fee Rate', value: `${txData.feeRate} sat/byte`, inline: true }
) )
.setTimestamp() .setTimestamp()
.setFooter({ text: 'Live Bitcoin Network' }); .setFooter({ text: `Live Bitcoin Network | Min: ${minBtcAmount} BTC` });
// Add input addresses (max 5) // Add input addresses (max 5)
if (txData.inputAddresses.length > 0) { if (txData.inputAddresses.length > 0) {
@ -301,6 +314,7 @@ function stopBitcoinMonitoring() {
isMonitoring = false; isMonitoring = false;
btcSocket = null; btcSocket = null;
btcMonitorChannel = null; btcMonitorChannel = null;
minBtcAmount = 0; // Reset minimum amount
console.log('Bitcoin monitoring stopped'); console.log('Bitcoin monitoring stopped');
return true; return true;
} }
@ -501,6 +515,7 @@ client.on(Events.InteractionCreate, async interaction => {
case 'btc-monitor': case 'btc-monitor':
const action = interaction.options.getString('action'); const action = interaction.options.getString('action');
const channel = interaction.options.getChannel('channel'); const channel = interaction.options.getChannel('channel');
const minAmount = interaction.options.getNumber('min-amount');
try { try {
switch (action) { switch (action) {
@ -532,16 +547,17 @@ client.on(Events.InteractionCreate, async interaction => {
await interaction.deferReply({ ephemeral: true }); await interaction.deferReply({ ephemeral: true });
btcMonitorChannel = channel; btcMonitorChannel = channel;
minBtcAmount = minAmount || 0; // Set minimum amount or default to 0
const success = await initBitcoinMonitoring(); const success = await initBitcoinMonitoring();
if (success) { if (success) {
isMonitoring = true; isMonitoring = true;
await interaction.editReply('✅ Bitcoin transaction monitoring started! Real-time transactions will be posted to the specified channel.'); await interaction.editReply(`✅ Bitcoin transaction monitoring started! Real-time transactions with minimum ${minBtcAmount} BTC will be posted to the specified channel.`);
// Send initial message to the monitoring channel // Send initial message to the monitoring channel
const startEmbed = new EmbedBuilder() const startEmbed = new EmbedBuilder()
.setTitle('🟠 Bitcoin Transaction Monitor Started') .setTitle('🟠 Bitcoin Transaction Monitor Started')
.setDescription('Real-time Bitcoin transactions will be displayed here.') .setDescription(`Real-time Bitcoin transactions with minimum ${minBtcAmount} BTC will be displayed here.`)
.setColor(0xF7931A) .setColor(0xF7931A)
.setTimestamp(); .setTimestamp();
@ -579,7 +595,8 @@ client.on(Events.InteractionCreate, async interaction => {
.setTitle('🟠 Bitcoin Monitor Status') .setTitle('🟠 Bitcoin Monitor Status')
.addFields( .addFields(
{ name: 'Status', value: isMonitoring ? '🟢 Running' : '🔴 Stopped', inline: true }, { name: 'Status', value: isMonitoring ? '🟢 Running' : '🔴 Stopped', inline: true },
{ name: 'Channel', value: btcMonitorChannel ? btcMonitorChannel.toString() : 'None', inline: true } { name: 'Channel', value: btcMonitorChannel ? btcMonitorChannel.toString() : 'None', inline: true },
{ name: 'Min Amount', value: `${minBtcAmount} BTC`, inline: true }
) )
.setColor(isMonitoring ? 0x00FF00 : 0xFF0000) .setColor(isMonitoring ? 0x00FF00 : 0xFF0000)
.setTimestamp(); .setTimestamp();