index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { initializeApp } from "firebase/app";
  2. import { getAnalytics } from "firebase/analytics";
  3. const functions = require('firebase-functions');
  4. // Your web app's Firebase configuration
  5. // For Firebase JS SDK v7.20.0 and later, measurementId is optional
  6. const firebaseConfig = {
  7. apiKey: "AIzaSyCqJj50pTiXBAtRgTVlNY5AQCBySgGSHqY",
  8. authDomain: "telegrambot-5f3ce.firebaseapp.com",
  9. projectId: "telegrambot-5f3ce",
  10. storageBucket: "telegrambot-5f3ce.appspot.com",
  11. messagingSenderId: "39238727150",
  12. appId: "1:39238727150:web:dbe83ac0c806527c7b0aff",
  13. measurementId: "G-9H7RKXYBD1"
  14. };
  15. // Initialize Firebase
  16. const appFire = initializeApp(firebaseConfig);
  17. const analytics = getAnalytics(app);
  18. const { Telegraf } = require('telegraf');
  19. const express = require('express')
  20. const token = '5717084656:AAET0Vzk61yjkhEO18yltR1GhvkDYtheZdg'
  21. const bot = new Telegraf(token, {polling: true})
  22. const app = express()
  23. const port = 3030
  24. const RegExpLink = /(([a-z]+:\/\/)?(([a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|local|internal))(:[0-9]{1,5})?(\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(\?[a-z0-9+_\-\.%=&]*)?)?(#[a-zA-Z0-9!$&'()*+.=-_~:@/?]*)?)(\s+|$)/gi;
  25. const idForBan = [];
  26. bot.on('message', async (ctx) => {
  27. console.log(ctx.message.from)
  28. if(ctx.message.text) {
  29. const str = ctx.message.text.toLowerCase();
  30. console.log(str)
  31. if(str.includes('iptv')){
  32. ctx.reply(`Message from ${ctx.update.message.from.first_name} edited by BOT
  33. ${str.replaceAll('iptv', '****')}`)
  34. ctx.deleteMessage(ctx.message.message_id)
  35. return
  36. }
  37. if(str.includes('шаринг')){
  38. ctx.reply(`Message from ${ctx.update.message.from.first_name} edited by BOT
  39. ${str.replaceAll('шаринг', '****')}`)
  40. ctx.deleteMessage(ctx.message.message_id)
  41. return
  42. }
  43. if(str.includes('playlist')){
  44. ctx.reply(`Message from ${ctx.update.message.from.first_name} edited by BOT
  45. ${str.replaceAll('playlist', '****')}`)
  46. ctx.deleteMessage(ctx.message.message_id)
  47. }
  48. if(RegExpLink.test(str) && (ctx.message.from.id !== 432003706)){
  49. console.log(ctx.message.from)
  50. ctx.reply(`Message from ${ctx.update.message.from.first_name} edited by BOT
  51. ${ctx.message.text.replace(RegExpLink, 'http****.***')}`)
  52. if(idForBan.includes(ctx.message.from.id)){
  53. bot.telegram.banChatMember(ctx.message.chat.id, ctx.message.from.id)
  54. }
  55. idForBan.push(ctx.message.from.id)
  56. ctx.deleteMessage(ctx.message.message_id)
  57. return
  58. }
  59. }
  60. if(ctx.message.document){
  61. const isPlaylist = ctx.message.document.file_name.includes('.m3u')
  62. if (isPlaylist){
  63. ctx.reply(`Hello ${ctx.update.message.from.first_name} playlists banned in this group `)
  64. ctx.deleteMessage(ctx.message.message_id)
  65. }
  66. }
  67. })
  68. console.log(idForBan)
  69. bot.launch()
  70. app.get('/', (req, res) => {
  71. res.send('Hello World!')
  72. })
  73. app.listen(port, () => {
  74. console.log(`Server listening on port ${port}`)
  75. })
  76. exports.bot = functions.https.onRequest(app);