forked from 1inch/shieldy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8137adf
commit ea066d9
Showing
7 changed files
with
54 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,37 @@ | ||
// Dependencies | ||
import Telegraf, { ContextMessageUpdate } from 'telegraf' | ||
import { checkIfErrorDismissable } from './error' | ||
import { bot } from './bot' | ||
|
||
export async function report( | ||
bot: Telegraf<ContextMessageUpdate>, | ||
error: Error, | ||
ctx?: ContextMessageUpdate, | ||
reason?: string | ||
) { | ||
if (checkIfErrorDismissable(error)) { | ||
let errorsToReport = [] | ||
|
||
async function bulkReport() { | ||
const tempErrorsToReport = errorsToReport | ||
errorsToReport = [] | ||
const adminChatId = process.env.ADMIN | ||
if (!adminChatId) { | ||
return | ||
} | ||
const adminChatId = process.env.ADMIN | ||
if (!adminChatId) return | ||
try { | ||
await bot.telegram.sendMessage( | ||
adminChatId, | ||
`${reason ? `${reason}\n` : ''}<code>${error.message}</code>\n\n<code>${ | ||
error.stack | ||
}</code>${ | ||
ctx | ||
? `${JSON.stringify( | ||
ctx.message || | ||
ctx.channelPost || | ||
ctx.inlineQuery || | ||
ctx.callbackQuery, | ||
undefined, | ||
2 | ||
)}` | ||
: '' | ||
}`, | ||
{ | ||
parse_mode: 'HTML', | ||
} as any | ||
if (tempErrorsToReport.length > 15) { | ||
const reportText = tempErrorsToReport.reduce( | ||
(prev, cur) => `${prev}${cur}\n`, | ||
'' | ||
) | ||
} catch (err) { | ||
console.error(err) | ||
const chunks = reportText.match(/[\s\S]{1,4000}/g) | ||
for (const chunk of chunks) { | ||
try { | ||
await bot.telegram.sendMessage(adminChatId, chunk) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} | ||
} | ||
} | ||
|
||
setInterval(bulkReport, 60 * 1000) | ||
|
||
export async function report(error: Error, reason?: string) { | ||
if (checkIfErrorDismissable(error)) { | ||
return | ||
} | ||
errorsToReport.push(`${reason ? `${reason}\n` : ''}${error.message}`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters