@@ -3,49 +3,46 @@ import { TransporterFactory } from "./transporter.factory";
33import { name , version } from "../package.json" ;
44
55export default ( app : Probot ) => {
6- console . info ( `running ${ name } : ${ version } ` ) ;
6+ console . info ( `Running ${ name } : ${ version } ` ) ;
7+
78 app . on ( "issues.labeled" , async ( context ) => {
8- const issue = context . payload . issue ;
9- const label = context . payload . label ?. name ;
9+ try {
10+ const issue = context . payload . issue ;
11+ const label = context . payload . label ?. name ;
1012
11- if ( label === "zap reward" ) {
12- const comments = await context . octokit . issues . listComments ( {
13- owner : context . payload . repository . owner . login ,
14- repo : context . payload . repository . name ,
15- issue_number : issue . number ,
16- } ) ;
13+ if ( label === "zap reward" ) {
14+ const comments = await context . octokit . issues . listComments ( {
15+ owner : context . payload . repository . owner . login ,
16+ repo : context . payload . repository . name ,
17+ issue_number : issue . number ,
18+ } ) ;
1719
18- const zapRequest = comments . data . map ( ( comment ) => parseZapReward ( comment . body ?? "" ) ) . find ( ( request ) => request !== null ) ;
20+ const zapRequest = comments . data
21+ . map ( ( comment ) => parseZapReward ( comment . body ?? "" ) )
22+ . find ( ( request ) => request !== null ) ;
1923
20- if ( zapRequest ) {
21- const message =
22- `🌟 **Zap Reward Request** 🌟\n\n` +
23- `**Amount:** ${ zapRequest . amount } ${ zapRequest . currency } \n` +
24- `**Expires On:** ${ zapRequest . expireAt } \n\n` +
25- `This reward has been requested for the following issue:\n` +
26- `🔗 [View Issue Here](${ issue . html_url } )\n\n` +
27- `Thank you for your participation! 🎉` ;
28- await sendToAll ( message ) ;
24+ if ( zapRequest ) {
25+ const message = generateMessage ( zapRequest . amount , issue . title , issue . html_url ) ;
26+ await sendToAll ( message ) ;
27+ }
2928 }
29+ } catch ( error ) {
30+ console . error ( "Error processing labeled issue:" , error ) ;
3031 }
3132 } ) ;
3233
3334 app . on ( "issue_comment.created" , async ( context ) => {
34- const comment = context . payload . comment . body ;
35- const issueUrl = context . payload . issue . html_url ;
36-
37- const parsedData = parseZapReward ( comment ) ;
35+ try {
36+ const comment = context . payload . comment . body ;
37+ const issue = context . payload . issue ;
38+ const zapRequest = parseZapReward ( comment ) ;
3839
39- if ( parsedData ) {
40- const message =
41- `🌟 **Zap Reward Request** 🌟\n\n` +
42- `**Amount:** ${ parsedData . amount } ${ parsedData . currency } \n` +
43- `**Expires On:** ${ parsedData . expireAt } \n\n` +
44- `This reward has been requested for the following issue:\n` +
45- `🔗 [View Issue Here](${ issueUrl } )\n\n` +
46- `Thank you for your participation! 🎉` ;
47-
48- await sendToAll ( message ) ;
40+ if ( zapRequest ) {
41+ const message = generateMessage ( zapRequest . amount , issue . title , issue . html_url ) ;
42+ await sendToAll ( message ) ;
43+ }
44+ } catch ( error ) {
45+ console . error ( "Error processing issue comment:" , error ) ;
4946 }
5047 } ) ;
5148} ;
@@ -54,26 +51,49 @@ export default (app: Probot) => {
5451 * Sends a message to both Telegram and Nostr.
5552 */
5653async function sendToAll ( message : string ) {
57- // const telegram = TransporterFactory.create("telegram");
58- // await telegram.send(message);
54+ try {
55+ const telegram = TransporterFactory . create ( "telegram" ) ;
56+ await telegram . send ( message ) ;
57+ } catch ( error ) {
58+ console . error ( "Error sending message to Telegram:" , error ) ;
59+ }
5960
60- const nostr = TransporterFactory . create ( "nostr" ) ;
61- await nostr . send ( message ) ;
61+ try {
62+ const nostr = TransporterFactory . create ( "nostr" ) ;
63+ await nostr . send ( message ) ;
64+ } catch ( error ) {
65+ console . error ( "Error sending message to Nostr:" , error ) ;
66+ }
6267}
6368
6469/**
6570 * Parses a Zap Reward template from the comment.
6671 */
6772function parseZapReward ( comment : string ) {
68- const zapRegex = / z a p r e w a r d : \s * a m o u n t : \s * ( \d + ) \s * c u r r e n c y : \s * ( S a t s | B T C ) \s * e x p i r e a t : \s * ( [ \d - ] + ) / i;
69- const match = comment . match ( zapRegex ) ;
73+ try {
74+ const zapRegex = / z a p r e w a r d : \s * a m o u n t : \s * ( \d + ) / i;
75+ const match = comment . match ( zapRegex ) ;
7076
71- if ( match ) {
72- return {
73- amount : parseInt ( match [ 1 ] , 10 ) ,
74- currency : match [ 2 ] ,
75- expireAt : match [ 3 ] ,
76- } ;
77+ if ( match ) {
78+ return {
79+ amount : parseInt ( match [ 1 ] , 10 ) ,
80+ } ;
81+ }
82+ return null ;
83+ } catch ( error ) {
84+ console . error ( "Error parsing Zap Reward:" , error ) ;
85+ return null ;
7786 }
78- return null ;
87+ }
88+
89+ function generateMessage ( amount : number , title : string , link : string ) : string {
90+ return (
91+ `🌟 New Zap Reward Request 🌟\n\n` +
92+ `**Issue:** 📌 ${ title } \n\n` +
93+ `**Amount:** ${ amount } Sats ⚡ \n\n` +
94+ `This reward has been requested for the following issue:\n` +
95+ `🔗 View Issue Here:\n${ link } \n\n` +
96+ `Thank you for your participation! 🎉\n\n` +
97+ `#devstr #dev #bounty #zap #job #jobstr`
98+ ) ;
7999}
0 commit comments