forked from MyZubster-Ecosystem/myzubster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaymentNotifier.js
More file actions
180 lines (153 loc) · 4.27 KB
/
Copy pathpaymentNotifier.js
File metadata and controls
180 lines (153 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**
* Payment Notifier - Tracciamento automatico dei pagamenti bounty
*
* Questo modulo notifica via Telegram/Slack quando:
* - Un pagamento viene inviato
* - Un pagamento viene ricevuto
* - Un wallet viene registrato
*/
const axios = require('axios');
class PaymentNotifier {
constructor(config = {}) {
this.telegramToken = process.env.TELEGRAM_BOT_TOKEN || config.telegramToken;
this.telegramChatId = process.env.TELEGRAM_CHAT_ID || config.telegramChatId;
this.slackWebhook = process.env.SLACK_WEBHOOK_URL || config.slackWebhook;
this.payments = [];
this.wallets = new Map();
}
/**
* Registra un wallet per un contributor
*/
registerWallet(contributor, address, issueId, bounty) {
const wallet = {
contributor,
address,
issueId,
bounty,
registeredAt: new Date().toISOString(),
status: 'pending'
};
this.wallets.set(contributor, wallet);
this.notify(
`🌱 **Nuovo Wallet Registrato**
Contributor: ${contributor}
Issue: #${issueId}
Bounty: ${bounty} XMR
Address: \`${address}\`
Stato: ⏳ In attesa di pagamento`
);
return wallet;
}
/**
* Registra un pagamento inviato
*/
recordPayment(issueId, bounty, contributor, txid, address) {
const payment = {
issueId,
bounty,
contributor,
txid,
address,
sentAt: new Date().toISOString(),
status: 'sent'
};
this.payments.push(payment);
this.notify(
`✅ **Pagamento Inviato!**
Issue: #${issueId}
Bounty: ${bounty} XMR
Contributor: ${contributor}
TXID: \`${txid}\`
Address: \`${address}\`
Stato: ✅ Pagato`
);
return payment;
}
/**
* Registra un pagamento ricevuto (conferma)
*/
confirmPayment(txid) {
const payment = this.payments.find(p => p.txid === txid);
if (payment) {
payment.status = 'confirmed';
payment.confirmedAt = new Date().toISOString();
this.notify(
`✅ **Pagamento Confermato!**
TXID: \`${txid}\`
Issue: #${payment.issueId}
Bounty: ${payment.bounty} XMR
Contributor: ${payment.contributor}
Confermato sulla blockchain Monero ✅`
);
}
}
/**
* Invia notifica su Telegram/Slack
*/
async notify(message) {
// Invia su Telegram
if (this.telegramToken && this.telegramChatId) {
try {
await axios.post(
`https://api.telegram.org/bot${this.telegramToken}/sendMessage`,
{
chat_id: this.telegramChatId,
text: message,
parse_mode: 'Markdown'
}
);
} catch (error) {
console.error('Errore notifica Telegram:', error.message);
}
}
// Invia su Slack
if (this.slackWebhook) {
try {
await axios.post(this.slackWebhook, {
text: message,
mrkdwn: true
});
} catch (error) {
console.error('Errore notifica Slack:', error.message);
}
}
}
/**
* Ottieni lo stato di tutti i pagamenti
*/
getPaymentStatus() {
return {
total: this.payments.length,
sent: this.payments.filter(p => p.status === 'sent').length,
confirmed: this.payments.filter(p => p.status === 'confirmed').length,
pending: this.wallets.size - this.payments.length,
payments: this.payments,
wallets: Array.from(this.wallets.values())
};
}
/**
* Genera un report dei pagamenti
*/
generateReport() {
const status = this.getPaymentStatus();
let report = '📊 **Report Pagamenti MyZubster**\n\n';
report += `📦 Totale Pagamenti: ${status.total}\n`;
report += `✅ Confermati: ${status.confirmed}\n`;
report += `⏳ In attesa: ${status.sent - status.confirmed}\n`;
report += `🌱 Wallet Registrati: ${status.wallets.length}\n\n`;
if (status.payments.length > 0) {
report += '**Pagamenti Recenti:**\n';
status.payments.slice(-5).forEach(p => {
report += `- #${p.issueId}: ${p.bounty} XMR → ${p.contributor} (${p.status})\n`;
});
}
if (status.wallets.length > 0) {
report += '\n**Wallet Registrati:**\n';
status.wallets.forEach(w => {
report += `- ${w.contributor}: ${w.bounty} XMR (Issue #${w.issueId})\n`;
});
}
return report;
}
}
module.exports = PaymentNotifier;