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 btcSocket = null;
let isMonitoring = false;
let minBtcAmount = 0; // Minimum BTC amount to show transactions
const client = new Client({
intents: [
@ -129,6 +130,13 @@ client.on(Events.ClientReady, async readyClient => {
type: 7, // CHANNEL type
description: 'Channel to send Bitcoin updates (required for start)',
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
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
const embed = new EmbedBuilder()
.setTitle('🟠 New Bitcoin Transaction')
@ -225,7 +238,7 @@ async function initBitcoinMonitoring() {
{ name: '⚡ Fee Rate', value: `${txData.feeRate} sat/byte`, inline: true }
)
.setTimestamp()
.setFooter({ text: 'Live Bitcoin Network' });
.setFooter({ text: `Live Bitcoin Network | Min: ${minBtcAmount} BTC` });
// Add input addresses (max 5)
if (txData.inputAddresses.length > 0) {
@ -301,6 +314,7 @@ function stopBitcoinMonitoring() {
isMonitoring = false;
btcSocket = null;
btcMonitorChannel = null;
minBtcAmount = 0; // Reset minimum amount
console.log('Bitcoin monitoring stopped');
return true;
}
@ -501,6 +515,7 @@ client.on(Events.InteractionCreate, async interaction => {
case 'btc-monitor':
const action = interaction.options.getString('action');
const channel = interaction.options.getChannel('channel');
const minAmount = interaction.options.getNumber('min-amount');
try {
switch (action) {
@ -532,16 +547,17 @@ client.on(Events.InteractionCreate, async interaction => {
await interaction.deferReply({ ephemeral: true });
btcMonitorChannel = channel;
minBtcAmount = minAmount || 0; // Set minimum amount or default to 0
const success = await initBitcoinMonitoring();
if (success) {
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
const startEmbed = new EmbedBuilder()
.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)
.setTimestamp();
@ -579,7 +595,8 @@ client.on(Events.InteractionCreate, async interaction => {
.setTitle('🟠 Bitcoin Monitor Status')
.addFields(
{ 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)
.setTimestamp();