Advertisement
BimoSora

bot

Aug 9th, 2021
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 111.74 KB | None | 0 0
  1. require('dotenv').config()
  2. const { Telegraf } = require('telegraf')
  3. const bot = new Telegraf(process.env.TOKEN)
  4.  
  5. process.env.TZ = "Asia/Jakarta";
  6.  
  7. //database
  8. const db = require('./config/connection')
  9. const collection = require('./config/collection')
  10. const saver = require('./database/filesaver')
  11. const helpcommand = require('./help.js');
  12.  
  13. //DATABASE CONNECTION
  14. db.connect((err) => {
  15. if(err) { console.log('error connection db' + err); }
  16. else { console.log('db connected'); }
  17. })
  18.  
  19. //ID Channel/Group
  20. const channelId = `${process.env.CHANNELJOIN}`;
  21.  
  22. function today(ctx){
  23. var today = new Date();
  24. var dd = String(today.getDate()).padStart(2, '0');
  25. var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
  26. var yyyy = today.getFullYear();
  27. var hours = today.getHours();
  28. var minutes = today.getMinutes();
  29. var seconds = today.getSeconds();
  30. return today = mm + '/' + dd + '/' + yyyy + ' ' + hours + ':' + minutes + ':' + seconds;
  31. }
  32.  
  33. function today2(ctx){
  34. var today2 = new Date();
  35. var dd2 = String(today2.getDate()).padStart(2, '0');
  36. var mm2 = String(today2.getMonth() + 1).padStart(2, '0'); //January is 0!
  37. var yyyy2 = today2.getFullYear();
  38. var hours2 = today2.getHours();
  39. var minutes2 = today2.getMinutes();
  40. var seconds2 = today2.getSeconds();
  41. return today2 = mm2 + '/' + dd2 + '/' + yyyy2 + '-' + hours2 + ':' + minutes2 + ':' + seconds2;
  42. }
  43.  
  44. //Function
  45. function first_name(ctx){
  46. return `${ctx.from.first_name ? ctx.from.first_name : ""}`;
  47. }
  48. function last_name(ctx){
  49. return `${ctx.from.last_name ? ctx.from.last_name : ""}`;
  50. }
  51. function username(ctx){
  52. return ctx.from.username ? `@${ctx.from.username}` : "";
  53. }
  54. function fromid(ctx){
  55. return ctx.from.id ? `[${ctx.from.id}]` : `""`;
  56. }
  57. function captionbuild(ctx){
  58. return `${process.env.CAPTIONLINK}`;
  59. }
  60. function welcomejoin(ctx){
  61. return `${process.env.WELCOMEJOINBOT}\n\n${today(ctx)}`;
  62. }
  63. function messagewelcome(ctx){
  64. return `${process.env.MESSAGEWELCOMEBOT}\n\n${today(ctx)}`;
  65. }
  66. function messagebanned(ctx){
  67. return `āš  ANDA DILARANG KARENA MENYALAHGUNAKAN BOT, HUBUNGI ADMIN UNTUK BANDING.`;
  68. }
  69. function messagebotnoaddgroup(ctx){
  70. return `BOT belum masuk channel/grup pemiliknya.`;
  71. }
  72. function messagelink(ctx){
  73. return `Kirim BOT video, photo dan dokumen.`;
  74. }
  75. function documentation(ctx){
  76. return `BOT di buat menggunakan \n<b>Program:</b> Node JS \n<b>API:</b> <a href='https://telegraf.js.org/'>Telegraf</a>`;
  77. }
  78.  
  79. // inline keyboard
  80. const inKey = [
  81. [{text:'šŸ”Ž Pencarian',switch_inline_query:''},{text:'šŸ“Ž Tautan',callback_data:'POP'}],
  82. [{text:'šŸ“š Documentation',callback_data:'DOC'},{text:'šŸ†˜ Bantuan',callback_data:'HELP'}],
  83. [{text:'šŸ“Ž Gabung', url: `${process.env.LINKCHANNEL}`}]
  84. ];
  85.  
  86. const inKey2 = [
  87. [{text:'šŸ“Ž Gabung', url: `${process.env.LINKCHANNEL}`}]
  88. ];
  89.  
  90. //BOT START
  91. bot.start(async(ctx)=>{
  92.  
  93. msg = ctx.message.text
  94. let msgArray = msg.split(' ')
  95. //console.log(msgArray.length);
  96. let length = msgArray.length
  97. msgArray.shift()
  98. let query = msgArray.join(' ')
  99.  
  100. user ={
  101. first_name:ctx.from.first_name,
  102. userId:ctx.from.id
  103. }
  104.  
  105. if(ctx.chat.type == 'private') {
  106. if(ctx.from.id ==process.env.ADMIN || ctx.from.id == process.env.ADMIN1 || ctx.from.id == process.env.ADMIN2){
  107. //welcoming message on /start and ifthere is a query available we can send files
  108. if(length == 1){
  109. var profile = await bot.telegram.getUserProfilePhotos(ctx.chat.id)
  110. if(!profile || profile.total_count == 0)
  111. return ctx.reply(`<a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a> \n\n${messagewelcome(ctx)}`,{
  112. parse_mode:'HTML',
  113. disable_web_page_preview: true,
  114. reply_markup:{
  115. inline_keyboard:inKey
  116. }
  117. })
  118. ctx.replyWithPhoto(profile.photos[0][0].file_id,{caption: `<a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a> \n\n${messagewelcome(ctx)}`,
  119. parse_mode:'HTML',
  120. disable_web_page_preview: true,
  121. reply_markup:{
  122. inline_keyboard:inKey
  123. }
  124. })
  125. }else{
  126. if (query.indexOf('grp_') > -1){
  127. var query1 = query.replace('grp_','');
  128. file = await saver.getFile1(query1).then((res1)=>{
  129. //console.log(res1);
  130. let mediagroup = [];
  131. for (let index = 0; index < res1.length; index++) {
  132. const data = res1[index];
  133. mediagroup.push({type: data.type, media: data.file_id, caption: data.caption, parse_mode:'HTML'});
  134. }
  135. //console.log(mediagroup);
  136. return ctx.telegram.sendMediaGroup(ctx.chat.id, mediagroup);
  137. })
  138. }else{
  139. let query2 = query;
  140. file2 = await saver.getFile2(query2).then((res2)=>{
  141. //console.log(res2);
  142. if(res2.type=='video'){
  143. if(!res2.caption)
  144. return ctx.replyWithVideo(res2.file_id,{caption: `\n\n${captionbuild(ctx)}`,
  145. parse_mode:'HTML'
  146. })
  147. ctx.replyWithVideo(res2.file_id,{caption: `${res2.caption} \n\n${captionbuild(ctx)}`,
  148. parse_mode:'HTML'
  149. })
  150. }else if(res2.type=='photo'){
  151. if(!res2.caption)
  152. return ctx.replyWithPhoto(res2.file_id,{caption: `\n\n${captionbuild(ctx)}`,
  153. parse_mode:'HTML'
  154. })
  155. ctx.replyWithPhoto(res2.file_id,{caption: `${res2.caption} \n\n${captionbuild(ctx)}`,
  156. parse_mode:'HTML'
  157. })
  158. }else if(res2.type=='document'){
  159. if(!res2.caption)
  160. return ctx.replyWithDocument(res2.file_id,{caption: `\n\n${captionbuild(ctx)}`,
  161. parse_mode:'HTML'
  162. })
  163. ctx.replyWithDocument(res2.file_id,{caption: `${res2.caption} \n\n${captionbuild(ctx)}`,
  164. parse_mode:'HTML'
  165. })
  166. }
  167. })
  168. }
  169. }
  170. }else{
  171. try {
  172. var botStatus = await bot.telegram.getChatMember(channelId, ctx.botInfo.id)
  173. var member = await bot.telegram.getChatMember(channelId, ctx.from.id)
  174. //console.log(member);
  175. if(!member || member.status == 'left' || member.status == 'kicked'){
  176. var profile2 = await bot.telegram.getUserProfilePhotos(ctx.chat.id)
  177. if(!profile2 || profile2.total_count == 0)
  178. return ctx.reply(`<a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a> \n\n${welcomejoin(ctx)}`,{
  179. parse_mode:'HTML',
  180. disable_web_page_preview: true,
  181. reply_markup:{
  182. inline_keyboard:inKey2
  183. }
  184. })
  185. ctx.replyWithPhoto(profile2.photos[0][0].file_id,{caption: `<a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a> \n\n${welcomejoin(ctx)}`,
  186. parse_mode:'HTML',
  187. disable_web_page_preview: true,
  188. reply_markup:{
  189. inline_keyboard:inKey2
  190. }
  191. })
  192. }else{
  193. //welcoming message on /start and ifthere is a query available we can send files
  194. if(length == 1){
  195. var profile3 = await bot.telegram.getUserProfilePhotos(ctx.chat.id)
  196. if(!profile3 || profile3.total_count == 0)
  197. return ctx.reply(`<a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a> \n\n${messagewelcome(ctx)}`,{
  198. parse_mode:'HTML',
  199. disable_web_page_preview: true,
  200. reply_markup:{
  201. inline_keyboard:inKey
  202. }
  203. })
  204. ctx.replyWithPhoto(profile3.photos[0][0].file_id,{caption: `<a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a> \n\n${messagewelcome(ctx)}`,
  205. parse_mode:'HTML',
  206. disable_web_page_preview: true,
  207. reply_markup:{
  208. inline_keyboard:inKey
  209. }
  210. })
  211. }else{
  212. if (query.indexOf('grp_') > -1){
  213. var query1 = query.replace('grp_','');
  214. file = await saver.getFile1(query1).then((res1)=>{
  215. //console.log(res1);
  216. let mediagroup = [];
  217. for (let index = 0; index < res1.length; index++) {
  218. const data = res1[index];
  219. mediagroup.push({type: data.type, media: data.file_id, caption: data.caption, parse_mode:'HTML'});
  220. }
  221. //console.log(mediagroup);
  222. return ctx.telegram.sendMediaGroup(ctx.chat.id, mediagroup);
  223. })
  224. }else{
  225. let query2 = query;
  226. file2 = await saver.getFile2(query2).then((res2)=>{
  227. //console.log(res2);
  228. if(res2.type=='video'){
  229. if(!res2.caption)
  230. return ctx.replyWithVideo(res2.file_id,{caption: `\n\n${captionbuild(ctx)}`,
  231. parse_mode:'HTML'
  232. })
  233. ctx.replyWithVideo(res2.file_id,{caption: `${res2.caption} \n\n${captionbuild(ctx)}`,
  234. parse_mode:'HTML'
  235. })
  236. }else if(res2.type=='photo'){
  237. if(!res2.caption)
  238. return ctx.replyWithPhoto(res2.file_id,{caption: `\n\n${captionbuild(ctx)}`,
  239. parse_mode:'HTML'
  240. })
  241. ctx.replyWithPhoto(res2.file_id,{caption: `${res2.caption} \n\n${captionbuild(ctx)}`,
  242. parse_mode:'HTML'
  243. })
  244. }else if(res2.type=='document'){
  245. if(!res2.caption)
  246. return ctx.replyWithDocument(res2.file_id,{caption: `\n\n${captionbuild(ctx)}`,
  247. parse_mode:'HTML'
  248. })
  249. ctx.replyWithDocument(res2.file_id,{caption: `${res2.caption} \n\n${captionbuild(ctx)}`,
  250. parse_mode:'HTML'
  251. })
  252. }
  253. })
  254. }
  255. }
  256. }
  257. }
  258. catch(error){
  259. ctx.reply(`${messagebotnoaddgroup(ctx)}`)
  260. }
  261. }
  262. //saving user details to the database
  263. saver.saveUser(user)
  264. }
  265. })
  266.  
  267. //DEFINING POP CALLBACK
  268. bot.action('POP',(ctx)=>{
  269. ctx.deleteMessage()
  270. ctx.reply(`${messagelink(ctx)}`,{
  271. parse_mode: 'HTML',
  272. reply_markup:{
  273. inline_keyboard: [
  274. [{text:'Batal',callback_data:'STARTUP'}]
  275. ]
  276. }
  277. })
  278. })
  279.  
  280. //DEFINING DOC CALLBACK
  281. bot.action('DOC',(ctx)=>{
  282. ctx.deleteMessage()
  283. ctx.reply(`${documentation(ctx)}`,{
  284. parse_mode: 'HTML',
  285. reply_markup:{
  286. inline_keyboard: [
  287. [{text:'Kembali',callback_data:'STARTUP'}]
  288. ]
  289. }
  290. })
  291. })
  292.  
  293. bot.action('HELP',(ctx)=>{
  294. ctx.deleteMessage()
  295. ctx.reply(`${helpcommand.bothelp}`,{
  296. parse_mode: 'HTML',
  297. disable_web_page_preview: true,
  298. reply_markup:{
  299. inline_keyboard: [
  300. [{text:'šŸ’æ Install',callback_data:'INS'},{text:'šŸŖ’ Perintah',callback_data:'COMM'}],
  301. [{text:'Kembali',callback_data:'STARTUP'}]
  302. ]
  303. }
  304. })
  305. })
  306.  
  307. bot.action('INS',(ctx)=>{
  308. ctx.deleteMessage()
  309. ctx.reply(`${helpcommand.botinstall}`,{
  310. parse_mode: 'HTML',
  311. disable_web_page_preview: true,
  312. reply_markup:{
  313. inline_keyboard: [
  314. [{text:'Kembali',callback_data:'HELP'}]
  315. ]
  316. }
  317. })
  318. })
  319.  
  320. bot.action('COMM',(ctx)=>{
  321. ctx.deleteMessage()
  322. ctx.reply(`${helpcommand.botcommand}`,{
  323. parse_mode: 'HTML',
  324. disable_web_page_preview: true,
  325. reply_markup:{
  326. inline_keyboard: [
  327. [{text:'Kembali',callback_data:'HELP'}]
  328. ]
  329. }
  330. })
  331. })
  332.  
  333. bot.action('STARTUP',async(ctx)=>{
  334. ctx.deleteMessage()
  335. var profile = await bot.telegram.getUserProfilePhotos(ctx.chat.id)
  336. if(!profile || profile.total_count == 0)
  337. return ctx.reply(`<a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a> \n\n${messagewelcome(ctx)}`,{
  338. parse_mode:'HTML',
  339. disable_web_page_preview: true,
  340. reply_markup:{
  341. inline_keyboard:inKey
  342. }
  343. })
  344. ctx.replyWithPhoto(profile.photos[0][0].file_id,{caption: `<a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a> \n\n${messagewelcome(ctx)}`,
  345. parse_mode:'HTML',
  346. disable_web_page_preview: true,
  347. reply_markup:{
  348. inline_keyboard:inKey
  349. }
  350. })
  351. })
  352.  
  353. //TEST BOT
  354. bot.hears('ping',(ctx)=>{
  355. let chatId = ctx.message.from.id;
  356. let opts = {
  357. reply_to_message_id: ctx.message.message_id,
  358. reply_markup:{
  359. inline_keyboard: [[{text:'OK',callback_data:'PONG'}]]
  360. }
  361. }
  362. return bot.telegram.sendMessage(chatId, 'pong', opts);
  363. })
  364.  
  365. bot.action('PONG',(ctx)=>{
  366. ctx.deleteMessage()
  367. })
  368.  
  369. //GROUP COMMAND
  370. bot.command('reload',async(ctx)=>{
  371. group ={
  372. groupId:ctx.chat.id
  373. }
  374.  
  375. var botStatus = await bot.telegram.getChatMember(ctx.chat.id, ctx.botInfo.id)
  376. var memberstatus = await bot.telegram.getChatMember(ctx.chat.id, ctx.from.id)
  377. //console.log(memberstatus);
  378. if(ctx.chat.type == 'group' || ctx.chat.type == 'supergroup') {
  379. if(!memberstatus || memberstatus.status == 'creator' || memberstatus.status == 'administrator'){
  380. ctx.reply('BOT dimulai ulang')
  381. saver.saveGroup(group)
  382. }
  383. if(ctx.from.username == 'GroupAnonymousBot'){
  384. ctx.reply('BOT dimulai ulang')
  385. saver.saveGroup(group)
  386. }
  387. }
  388. })
  389.  
  390. bot.command('kick',async(ctx)=>{
  391. groupDetails = await saver.getGroup().then((res)=>{
  392. n = res.length
  393. groupId = []
  394. for (i = n-1; i >=0; i--) {
  395. groupId.push(res[i].groupId)
  396. }
  397. async function kick() {
  398. for (const group of groupId) {
  399. var botStatus = await bot.telegram.getChatMember(group, ctx.botInfo.id)
  400. var memberstatus = await bot.telegram.getChatMember(group, ctx.from.id)
  401. //console.log(memberstatus);
  402.  
  403. if(ctx.chat.type == 'group' || ctx.chat.type == 'supergroup') {
  404. if(memberstatus.status == 'administrator'){
  405. if(!memberstatus || memberstatus.can_restrict_members == true){
  406. if(ctx.message.reply_to_message == undefined){
  407. let args = ctx.message.text.split(" ").slice(1)
  408. await bot.telegram.kickChatMember(ctx.chat.id, args[0]).then(result=>{
  409. //console.log(result)
  410. })
  411. }
  412. await bot.telegram.kickChatMember(ctx.chat.id, ctx.message.reply_to_message.from.id).then(result=>{
  413. //console.log(result)
  414. })
  415. }
  416. }else if(memberstatus.status == 'creator'){
  417. if(ctx.message.reply_to_message == undefined){
  418. let args = ctx.message.text.split(" ").slice(1)
  419. await bot.telegram.kickChatMember(ctx.chat.id, args[0]).then(result=>{
  420. //console.log(result)
  421. })
  422. }
  423. await bot.telegram.kickChatMember(ctx.chat.id, ctx.message.reply_to_message.from.id).then(result=>{
  424. //console.log(result)
  425. })
  426. }else{
  427. if(ctx.from.username == 'GroupAnonymousBot'){
  428. if(ctx.message.reply_to_message == undefined){
  429. let args = ctx.message.text.split(" ").slice(1)
  430. await bot.telegram.kickChatMember(ctx.chat.id, args[0]).then(result=>{
  431. //console.log(result)
  432. })
  433. }
  434. await bot.telegram.kickChatMember(ctx.chat.id, ctx.message.reply_to_message.from.id).then(result=>{
  435. //console.log(result)
  436. })
  437. }
  438. }
  439. }
  440. }
  441. }
  442. kick()
  443. })
  444. })
  445.  
  446. bot.command('ban',async(ctx)=>{
  447. groupDetails = await saver.getGroup().then((res)=>{
  448. n = res.length
  449. groupId = []
  450. for (i = n-1; i >=0; i--) {
  451. groupId.push(res[i].groupId)
  452. }
  453. async function ban() {
  454. for (const group of groupId) {
  455. var botStatus = await bot.telegram.getChatMember(group, ctx.botInfo.id)
  456. var memberstatus = await bot.telegram.getChatMember(group, ctx.from.id)
  457. //console.log(memberstatus);
  458.  
  459. if(ctx.chat.type == 'group' || ctx.chat.type == 'supergroup') {
  460. if(memberstatus.status == 'administrator'){
  461. if(!memberstatus || memberstatus.can_restrict_members == true){
  462. if(ctx.message.reply_to_message == undefined){
  463.  
  464. const str = ctx.message.text;
  465. const words = str.split(/ +/g);
  466. const command = words.shift().slice(1);
  467. const userId = words.shift();
  468. const caption = words.join(" ");
  469.  
  470. await bot.telegram.callApi('banChatMember', {
  471. chat_id: ctx.message.chat.id,
  472. user_id: userId
  473. }).then(result=>{
  474. //console.log(result)
  475. ctx.reply(`[${userId}] ${caption}`,{
  476. reply_to_message_id: ctx.message.message_id
  477. })
  478. return bot.telegram.sendMessage(userId, `${caption} Anda telah melanggar peraturan di ${ctx.message.chat.title}`)
  479. })
  480. }
  481.  
  482. const str = ctx.message.text;
  483. const words = str.split(/ +/g);
  484. const command = words.shift().slice(1);
  485. const caption = words.join(" ");
  486.  
  487. await bot.telegram.callApi('banChatMember', {
  488. chat_id: ctx.message.chat.id,
  489. user_id: ctx.message.reply_to_message.from.id
  490. }).then(result=>{
  491. //console.log(result)
  492. let replyUsername = ctx.message.reply_to_message.from.username ? `@${ctx.message.reply_to_message.from.username}` : `${ctx.message.reply_to_message.from.first_name}`;
  493. let replyFromid = ctx.message.reply_to_message.from.id ? `[${ctx.message.reply_to_message.from.id}]` : "";
  494. ctx.reply(`${replyUsername} ${replyFromid} ${caption}`,{
  495. reply_to_message_id: ctx.message.message_id
  496. })
  497. return bot.telegram.sendMessage(ctx.message.reply_to_message.from.id, `${caption} Anda telah melanggar peraturan di ${ctx.message.chat.title}`)
  498. })
  499. }
  500. }else if(memberstatus.status == 'creator'){
  501. if(ctx.message.reply_to_message == undefined){
  502.  
  503. const str = ctx.message.text;
  504. const words = str.split(/ +/g);
  505. const command = words.shift().slice(1);
  506. const userId = words.shift();
  507. const caption = words.join(" ");
  508.  
  509. await bot.telegram.callApi('banChatMember', {
  510. chat_id: ctx.message.chat.id,
  511. user_id: userId
  512. }).then(result=>{
  513. //console.log(result)
  514. ctx.reply(`[${userId}] ${caption}`,{
  515. reply_to_message_id: ctx.message.message_id
  516. })
  517. return bot.telegram.sendMessage(userId, `${caption} Anda telah melanggar peraturan di ${ctx.message.chat.title}`)
  518. })
  519. }
  520.  
  521. const str = ctx.message.text;
  522. const words = str.split(/ +/g);
  523. const command = words.shift().slice(1);
  524. const caption = words.join(" ");
  525.  
  526. await bot.telegram.callApi('banChatMember', {
  527. chat_id: ctx.message.chat.id,
  528. user_id: ctx.message.reply_to_message.from.id
  529. }).then(result=>{
  530. //console.log(result)
  531. let replyUsername = ctx.message.reply_to_message.from.username ? `@${ctx.message.reply_to_message.from.username}` : `${ctx.message.reply_to_message.from.first_name}`;
  532. let replyFromid = ctx.message.reply_to_message.from.id ? `[${ctx.message.reply_to_message.from.id}]` : "";
  533. ctx.reply(`${replyUsername} ${replyFromid} ${caption}`,{
  534. reply_to_message_id: ctx.message.message_id
  535. })
  536. return bot.telegram.sendMessage(ctx.message.reply_to_message.from.id, `${caption} Anda telah melanggar peraturan di ${ctx.message.chat.title}`)
  537. })
  538. }else{
  539. if(ctx.from.username == 'GroupAnonymousBot'){
  540. if(ctx.message.reply_to_message == undefined){
  541.  
  542. const str = ctx.message.text;
  543. const words = str.split(/ +/g);
  544. const command = words.shift().slice(1);
  545. const userId = words.shift();
  546. const caption = words.join(" ");
  547.  
  548. await bot.telegram.callApi('banChatMember', {
  549. chat_id: ctx.message.chat.id,
  550. user_id: userId
  551. }).then(result=>{
  552. //console.log(result)
  553. ctx.reply(`[${userId}] ${caption}`,{
  554. reply_to_message_id: ctx.message.message_id
  555. })
  556. return bot.telegram.sendMessage(userId, `${caption} Anda telah melanggar peraturan di ${ctx.message.chat.title}`)
  557. })
  558. }
  559.  
  560. const str = ctx.message.text;
  561. const words = str.split(/ +/g);
  562. const command = words.shift().slice(1);
  563. const caption = words.join(" ");
  564.  
  565. await bot.telegram.callApi('banChatMember', {
  566. chat_id: ctx.message.chat.id,
  567. user_id: ctx.message.reply_to_message.from.id
  568. }).then(result=>{
  569. //console.log(result)
  570. let replyUsername = ctx.message.reply_to_message.from.username ? `@${ctx.message.reply_to_message.from.username}` : `${ctx.message.reply_to_message.from.first_name}`;
  571. let replyFromid = ctx.message.reply_to_message.from.id ? `[${ctx.message.reply_to_message.from.id}]` : "";
  572. ctx.reply(`${replyUsername} ${replyFromid} ${caption}`,{
  573. reply_to_message_id: ctx.message.message_id
  574. })
  575. return bot.telegram.sendMessage(ctx.message.reply_to_message.from.id, `${caption} Anda telah melanggar peraturan di ${ctx.message.chat.title}`)
  576. })
  577. }
  578. }
  579. }
  580. }
  581. }
  582. ban()
  583. })
  584. })
  585.  
  586. bot.command('unban',async(ctx)=>{
  587. groupDetails = await saver.getGroup().then((res)=>{
  588. n = res.length
  589. groupId = []
  590. for (i = n-1; i >=0; i--) {
  591. groupId.push(res[i].groupId)
  592. }
  593. async function unban() {
  594. for (const group of groupId) {
  595. var botStatus = await bot.telegram.getChatMember(group, ctx.botInfo.id)
  596. var memberstatus = await bot.telegram.getChatMember(group, ctx.from.id)
  597. //console.log(memberstatus);
  598.  
  599. if(ctx.chat.type == 'group' || ctx.chat.type == 'supergroup') {
  600. if(memberstatus.status == 'administrator'){
  601. if(!memberstatus || memberstatus.can_restrict_members == true){
  602. if(ctx.message.reply_to_message == undefined){
  603. let args = ctx.message.text.split(" ").slice(1)
  604. await bot.telegram.unbanChatMember(ctx.chat.id, args[0]).then(result=>{
  605. //console.log(result)
  606. ctx.reply(`[${args[0]}] tidak diblokir, boleh masuk kembali!`,{
  607. reply_to_message_id: ctx.message.message_id
  608. })
  609. return bot.telegram.sendMessage(args[0], `Anda tidak diblokir, boleh masuk kembali di ${ctx.message.chat.title}`)
  610. })
  611. }
  612. await bot.telegram.unbanChatMember(ctx.chat.id, ctx.message.reply_to_message.from.id).then(result=>{
  613. //console.log(result)
  614. let replyUsername = ctx.message.reply_to_message.from.username ? `@${ctx.message.reply_to_message.from.username}` : `${ctx.message.reply_to_message.from.first_name}`;
  615. let replyFromid = ctx.message.reply_to_message.from.id ? `[${ctx.message.reply_to_message.from.id}]` : "";
  616. ctx.reply(`${replyUsername} ${replyFromid} tidak diblokir, boleh masuk kembali!`,{
  617. reply_to_message_id: ctx.message.message_id
  618. })
  619. return bot.telegram.sendMessage(ctx.message.reply_to_message.from.id, `Anda tidak diblokir, boleh masuk kembali di ${ctx.message.chat.title}`)
  620. })
  621. }
  622. }else if(memberstatus.status == 'creator'){
  623. if(ctx.message.reply_to_message == undefined){
  624. let args = ctx.message.text.split(" ").slice(1)
  625. await bot.telegram.unbanChatMember(ctx.chat.id, args[0]).then(result=>{
  626. //console.log(result)
  627. ctx.reply(`[${args[0]}] tidak diblokir, boleh masuk kembali!`,{
  628. reply_to_message_id: ctx.message.message_id
  629. })
  630. return bot.telegram.sendMessage(args[0], `Anda tidak diblokir, boleh masuk kembali di ${ctx.message.chat.title}`)
  631. })
  632. }
  633. await bot.telegram.unbanChatMember(ctx.chat.id, ctx.message.reply_to_message.from.id).then(result=>{
  634. //console.log(result)
  635. let replyUsername = ctx.message.reply_to_message.from.username ? `@${ctx.message.reply_to_message.from.username}` : `${ctx.message.reply_to_message.from.first_name}`;
  636. let replyFromid = ctx.message.reply_to_message.from.id ? `[${ctx.message.reply_to_message.from.id}]` : "";
  637. ctx.reply(`${replyUsername} ${replyFromid} tidak diblokir, boleh masuk kembali!`,{
  638. reply_to_message_id: ctx.message.message_id
  639. })
  640. return bot.telegram.sendMessage(ctx.message.reply_to_message.from.id, `Anda tidak diblokir, boleh masuk kembali di ${ctx.message.chat.title}`)
  641. })
  642. }else{
  643. if(ctx.from.username == 'GroupAnonymousBot'){
  644. if(ctx.message.reply_to_message == undefined){
  645. let args = ctx.message.text.split(" ").slice(1)
  646. await bot.telegram.unbanChatMember(ctx.chat.id, args[0]).then(result=>{
  647. //console.log(result)
  648. ctx.reply(`[${args[0]}] tidak diblokir, boleh masuk kembali!`,{
  649. reply_to_message_id: ctx.message.message_id
  650. })
  651. return bot.telegram.sendMessage(args[0], `Anda tidak diblokir, boleh masuk kembali di ${ctx.message.chat.title}`)
  652. })
  653. }
  654. await bot.telegram.unbanChatMember(ctx.chat.id, ctx.message.reply_to_message.from.id).then(result=>{
  655. //console.log(result)
  656. let replyUsername = ctx.message.reply_to_message.from.username ? `@${ctx.message.reply_to_message.from.username}` : `${ctx.message.reply_to_message.from.first_name}`;
  657. let replyFromid = ctx.message.reply_to_message.from.id ? `[${ctx.message.reply_to_message.from.id}]` : "";
  658. ctx.reply(`${replyUsername} ${replyFromid} tidak diblokir, boleh masuk kembali!`,{
  659. reply_to_message_id: ctx.message.message_id
  660. })
  661. return bot.telegram.sendMessage(ctx.message.reply_to_message.from.id, `Anda tidak diblokir, boleh masuk kembali di ${ctx.message.chat.title}`)
  662. })
  663. }
  664. }
  665. }
  666. }
  667. }
  668. unban()
  669. })
  670. })
  671.  
  672. bot.command('pin',async(ctx)=>{
  673. groupDetails = await saver.getGroup().then((res)=>{
  674. n = res.length
  675. groupId = []
  676. for (i = n-1; i >=0; i--) {
  677. groupId.push(res[i].groupId)
  678. }
  679. async function pin() {
  680. for (const group of groupId) {
  681. var botStatus = await bot.telegram.getChatMember(group, ctx.botInfo.id)
  682. var memberstatus = await bot.telegram.getChatMember(group, ctx.from.id)
  683. //console.log(memberstatus);
  684.  
  685. if(ctx.chat.type == 'group' || ctx.chat.type == 'supergroup') {
  686. if(memberstatus.status == 'administrator'){
  687. if(!memberstatus || memberstatus.can_pin_messages == true){
  688. await bot.telegram.pinChatMessage(ctx.chat.id, ctx.message.reply_to_message.message_id,{
  689. disable_notification: false,
  690. }).then(result=>{
  691. //console.log(result)
  692. })
  693. }
  694. }else if(memberstatus.status == 'creator'){
  695. await bot.telegram.pinChatMessage(ctx.chat.id, ctx.message.reply_to_message.message_id,{
  696. disable_notification: false,
  697. }).then(result=>{
  698. //console.log(result)
  699. })
  700. }else{
  701. if(ctx.from.username == 'GroupAnonymousBot'){
  702. await bot.telegram.pinChatMessage(ctx.chat.id, ctx.message.reply_to_message.message_id,{
  703. disable_notification: false,
  704. }).then(result=>{
  705. //console.log(result)
  706. })
  707. }
  708. }
  709. }
  710. }
  711. }
  712. pin()
  713. })
  714. })
  715.  
  716. bot.command('unpin',async(ctx)=>{
  717. groupDetails = await saver.getGroup().then((res)=>{
  718. n = res.length
  719. groupId = []
  720. for (i = n-1; i >=0; i--) {
  721. groupId.push(res[i].groupId)
  722. }
  723. async function unpin() {
  724. for (const group of groupId) {
  725. var botStatus = await bot.telegram.getChatMember(group, ctx.botInfo.id)
  726. var memberstatus = await bot.telegram.getChatMember(group, ctx.from.id)
  727. //console.log(memberstatus);
  728.  
  729. if(ctx.chat.type == 'group' || ctx.chat.type == 'supergroup') {
  730. if(memberstatus.status == 'administrator'){
  731. if(!memberstatus || memberstatus.can_pin_messages == true){
  732. await bot.telegram.unpinChatMessage(ctx.chat.id, ctx.message.reply_to_message.message_id).then(result=>{
  733. //console.log(result)
  734. })
  735. }
  736. }else if(memberstatus.status == 'creator'){
  737. await bot.telegram.unpinChatMessage(ctx.chat.id, ctx.message.reply_to_message.message_id).then(result=>{
  738. //console.log(result)
  739. })
  740. }else{
  741. if(ctx.from.username == 'GroupAnonymousBot'){
  742. await bot.telegram.unpinChatMessage(ctx.chat.id, ctx.message.reply_to_message.message_id).then(result=>{
  743. //console.log(result)
  744. })
  745. }
  746. }
  747. }
  748. }
  749. }
  750. unpin()
  751. })
  752. })
  753.  
  754. bot.command('send',async(ctx)=>{
  755. groupDetails = await saver.getGroup().then((res)=>{
  756. n = res.length
  757. groupId = []
  758. for (i = n-1; i >=0; i--) {
  759. groupId.push(res[i].groupId)
  760. }
  761. async function send() {
  762. for (const group of groupId) {
  763. var botStatus = await bot.telegram.getChatMember(group, ctx.botInfo.id)
  764. var memberstatus = await bot.telegram.getChatMember(group, ctx.from.id)
  765. //console.log(memberstatus);
  766.  
  767. if(ctx.chat.type == 'group' || ctx.chat.type == 'supergroup') {
  768. if(!memberstatus || memberstatus.status == 'creator' || memberstatus.status == 'administrator'){
  769. const str = ctx.message.text;
  770. const words = str.split(/ +/g);
  771. const command = words.shift().slice(1);
  772. const caption = words.join(" ");
  773.  
  774. return bot.telegram.sendMessage(group, `${caption}`)
  775. }
  776. if(ctx.from.username == 'GroupAnonymousBot'){
  777. const str = ctx.message.text;
  778. const words = str.split(/ +/g);
  779. const command = words.shift().slice(1);
  780. const caption = words.join(" ");
  781.  
  782. return bot.telegram.sendMessage(group, `${caption}`)
  783. }
  784. }
  785. }
  786. }
  787. send()
  788. })
  789. })
  790. //END
  791.  
  792. //check account
  793. bot.command('getid',async(ctx)=>{
  794.  
  795. var profile4 = await bot.telegram.getUserProfilePhotos(ctx.chat.id)
  796.  
  797. if(ctx.chat.type == 'private') {
  798. if(!profile4 || profile4.total_count == 0){
  799. ctx.reply(`<b>Name:</b> <a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n<b>Username:</b> ${username(ctx)}\n<b>ID:</b> ${ctx.from.id}`,{
  800. parse_mode:'HTML'
  801. })
  802. }else{
  803. ctx.replyWithPhoto(profile4.photos[0][0].file_id,{caption: `<b>Name:</b> <a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n<b>Username:</b> ${username(ctx)}\n<b>ID:</b> ${ctx.from.id}`,
  804. parse_mode:'HTML'
  805. })
  806. }
  807. }
  808. })
  809.  
  810. //remove files with file_id
  811. bot.command('rem', (ctx) => {
  812. msg = ctx.message.text
  813. let msgArray = msg.split(' ')
  814. msgArray.shift()
  815. let text = msgArray.join(' ')
  816. //console.log(text);
  817.  
  818. if(ctx.chat.type == 'private') {
  819. if(ctx.from.id ==process.env.ADMIN || ctx.from.id == process.env.ADMIN1 || ctx.from.id == process.env.ADMIN2){
  820. saver.removeFile(text)
  821. ctx.reply('āœ… Dihapus')
  822. }
  823. }
  824. })
  825.  
  826. //remove whole collection(remove all files)
  827. bot.command('clear',(ctx)=>{
  828. if(ctx.chat.type == 'private') {
  829. if(ctx.from.id ==process.env.ADMIN || ctx.from.id == process.env.ADMIN1 || ctx.from.id == process.env.ADMIN2){
  830. saver.deleteCollection()
  831. ctx.reply('āœ… Dihapus')
  832. }
  833. }
  834. })
  835.  
  836. //removing all files sent by a user
  837. bot.command('remall', (ctx) => {
  838. msg = ctx.message.text
  839. let msgArray = msg.split(' ')
  840. msgArray.shift()
  841. let text = msgArray.join(' ')
  842. //console.log(text);
  843. let id = parseInt(text)
  844.  
  845. if(ctx.chat.type == 'private') {
  846. if(ctx.from.id ==process.env.ADMIN || ctx.from.id == process.env.ADMIN1 || ctx.from.id == process.env.ADMIN2){
  847. saver.removeUserFile(id)
  848. ctx.reply('āœ… Dihapus')
  849. }
  850. }
  851. })
  852.  
  853. bot.command('sendchat',async(ctx)=>{
  854. groupDetails = await saver.getGroup().then((res)=>{
  855. n = res.length
  856. groupId = []
  857. for (i = n-1; i >=0; i--) {
  858. groupId.push(res[i].groupId)
  859. }
  860. async function sendchat() {
  861. for (const group of groupId) {
  862. var memberstatus = await bot.telegram.getChatMember(group, ctx.from.id)
  863. //console.log(memberstatus);
  864.  
  865. if(!memberstatus || memberstatus.status == 'creator' || memberstatus.status == 'administrator'){
  866. const str = ctx.message.text;
  867. const words = str.split(/ +/g);
  868. const command = words.shift().slice(1);
  869. const userId = words.shift();
  870. const caption = words.join(" ");
  871. ctx.reply('Terkirim!',{
  872. reply_to_message_id: ctx.message.message_id
  873. })
  874. return bot.telegram.sendMessage(userId, `${caption}`)
  875. }
  876. }
  877. }
  878.  
  879. if(ctx.chat.type == 'private') {
  880. if(ctx.from.id ==process.env.ADMIN || ctx.from.id == process.env.ADMIN1 || ctx.from.id == process.env.ADMIN2){
  881. const str = ctx.message.text;
  882. const words = str.split(/ +/g);
  883. const command = words.shift().slice(1);
  884. const userId = words.shift();
  885. const caption = words.join(" ");
  886. ctx.reply('Terkirim!',{
  887. reply_to_message_id: ctx.message.message_id
  888. })
  889.  
  890. return bot.telegram.sendMessage(userId, `${caption}`)
  891. }
  892.  
  893. sendchat()
  894. }
  895. })
  896. })
  897.  
  898. //broadcasting message to bot users(from last joined to first)
  899. bot.command('broadcast',async(ctx)=>{
  900. msg = ctx.message.text
  901. let msgArray = msg.split(' ')
  902. msgArray.shift()
  903. let text = msgArray.join(' ')
  904.  
  905. if(ctx.chat.type == 'private') {
  906. userDetails = await saver.getUser().then((res)=>{
  907. n = res.length
  908. userId = []
  909. for (i = n-1; i >=0; i--) {
  910. userId.push(res[i].userId)
  911. }
  912.  
  913. //broadcasting
  914. totalBroadCast = 0
  915. totalFail = []
  916.  
  917. //creating function for broadcasting and to know bot user status
  918. async function broadcast(text) {
  919. for (const users of userId) {
  920. try {
  921. await bot.telegram.sendMessage(users, String(text),{
  922. parse_mode:'HTML',
  923. disable_web_page_preview: true
  924. }
  925. )
  926. } catch (err) {
  927. saver.updateUser(users)
  928. totalFail.push(users)
  929.  
  930. }
  931. }
  932. ctx.reply(`āœ… <b>Jumlah pengguna aktif:</b> ${userId.length - totalFail.length}\nāŒ <b>Total siaran yang gagal:</b> ${totalFail.length}`,{
  933. parse_mode:'HTML'
  934. })
  935.  
  936. }
  937. if(ctx.from.id ==process.env.ADMIN || ctx.from.id == process.env.ADMIN1 || ctx.from.id == process.env.ADMIN2){
  938. broadcast(text)
  939. ctx.reply('Penyiaran dimulai (Pesan disiarkan dari terakhir bergabung hingga pertama).')
  940.  
  941. }else{
  942. ctx.reply(`Perintah hanya bisa digunakan oleh Admin`)
  943. }
  944.  
  945. })
  946. }
  947. })
  948.  
  949. //ban user with user id
  950. bot.command('banchat', (ctx) => {
  951. msg = ctx.message.text
  952. let msgArray = msg.split(' ')
  953. msgArray.shift()
  954. let text = msgArray.join(' ')
  955. //console.log(text)
  956. userId = {
  957. id: text
  958. }
  959.  
  960. if(ctx.chat.type == 'private') {
  961. if(ctx.from.id ==process.env.ADMIN|| ctx.from.id == process.env.ADMIN1 || ctx.from.id == process.env.ADMIN2){
  962. saver.banUser(userId).then((res) => {
  963. ctx.reply('Dilarang')
  964. })
  965. }
  966. }
  967.  
  968. })
  969.  
  970. //unban user with user id
  971. bot.command('unbanchat', (ctx) => {
  972. msg = ctx.message.text
  973. let msgArray = msg.split(' ')
  974. msgArray.shift()
  975. let text = msgArray.join(' ')
  976. //console.log(text)
  977. userId = {
  978. id: text
  979. }
  980.  
  981. if(ctx.chat.type == 'private') {
  982. if(ctx.from.id ==process.env.ADMIN || ctx.from.id == process.env.ADMIN1 || ctx.from.id == process.env.ADMIN2){
  983. saver.unBan(userId).then((res) => {
  984. ctx.reply('āœ… Selesai')
  985. })
  986. }
  987. }
  988. })
  989.  
  990. //list update
  991. var updates = []
  992. bot.use(async (ctx, next) => {
  993. if(ctx.message.media_group_id){
  994. updates.push(ctx.update);
  995. }
  996. console.time(`Processing update ${ctx.update}`);
  997. await next()
  998. console.log(update)
  999. console.timeEnd(`Processing update ${ctx.update}`);
  1000. })
  1001.  
  1002. //saving documents to db and generating link
  1003. bot.on('document', async (ctx) => {
  1004. document = ctx.message.document
  1005. //console.log(ctx);
  1006.  
  1007. fileDetails1 = {
  1008. file_name: document.file_name,
  1009. userId:ctx.from.id,
  1010. file_id: document.file_id,
  1011. mediaId: ctx.message.media_group_id,
  1012. caption: ctx.message.caption,
  1013. file_size: document.file_size,
  1014. uniqueId: document.file_unique_id,
  1015. type: 'document'
  1016. }
  1017. //console.log(fileDetails1.caption);
  1018.  
  1019. if(fileDetails1.mediaId == undefined){
  1020. if(fileDetails1.file_name == undefined){
  1021. fileDetails2 = {
  1022. file_name: today2(ctx),
  1023. userId:ctx.from.id,
  1024. file_id: document.file_id,
  1025. caption: ctx.message.caption,
  1026. file_size: document.file_size,
  1027. uniqueId: document.file_unique_id,
  1028. type: 'document'
  1029. }
  1030. //console.log(fileDetails2.caption);
  1031. }else{
  1032. var exstension = document.file_name;
  1033. var regex = /\.[A-Za-z0-9]+$/gm
  1034. var doctext = exstension.replace(regex, '');
  1035. fileDetails = {
  1036. file_name: doctext,
  1037. userId:ctx.from.id,
  1038. file_id: document.file_id,
  1039. caption: ctx.message.caption,
  1040. file_size: document.file_size,
  1041. uniqueId: document.file_unique_id,
  1042. type: 'document'
  1043. }
  1044. //console.log(fileDetails.caption);
  1045. }
  1046. }else{
  1047. if(fileDetails1.file_name == undefined){
  1048. fileDetails4 = {
  1049. file_name: today2(ctx),
  1050. userId:ctx.from.id,
  1051. file_id: document.file_id,
  1052. mediaId: ctx.message.media_group_id,
  1053. caption: ctx.message.caption,
  1054. file_size: document.file_size,
  1055. uniqueId: document.file_unique_id,
  1056. type: 'document'
  1057. }
  1058. //console.log(fileDetails4.caption);
  1059. }else{
  1060. var exstension = document.file_name;
  1061. var regex = /\.[A-Za-z0-9]+$/gm
  1062. var doctext = exstension.replace(regex, '');
  1063. fileDetails3 = {
  1064. file_name: doctext,
  1065. userId:ctx.from.id,
  1066. file_id: document.file_id,
  1067. mediaId: ctx.message.media_group_id,
  1068. caption: ctx.message.caption,
  1069. file_size: document.file_size,
  1070. uniqueId: document.file_unique_id,
  1071. type: 'document'
  1072. }
  1073. //console.log(fileDetails3.caption);
  1074. }
  1075. }
  1076.  
  1077. if(ctx.from.id ==process.env.ADMIN || ctx.from.id == process.env.ADMIN1 || ctx.from.id == process.env.ADMIN2){
  1078. if(!fileDetails1.mediaId){
  1079. if(!fileDetails1.file_name){
  1080. saver.saveFile(fileDetails2)
  1081. if(ctx.chat.type == 'private') {
  1082. ctx.reply(`āœ”ļø Document disimpan \n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_unique_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${document.file_unique_id}`,{
  1083. parse_mode: 'HTML',
  1084. disable_web_page_preview: true,
  1085. reply_to_message_id: ctx.message.message_id
  1086. })
  1087. }
  1088. if(!ctx.message.caption)
  1089. return ctx.replyWithDocument(document.file_id, {
  1090. chat_id: process.env.LOG_CHANNEL,
  1091. caption: `āœ”ļø Document disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${document.file_unique_id}`,
  1092. parse_mode:'HTML'
  1093. })
  1094. ctx.replyWithDocument(document.file_id, {
  1095. chat_id: process.env.LOG_CHANNEL,
  1096. caption: `${ctx.message.caption}\n\nāœ”ļø Document disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${document.file_unique_id}`,
  1097. parse_mode:'HTML'
  1098. })
  1099. }else{
  1100. saver.saveFile(fileDetails)
  1101. if(ctx.chat.type == 'private') {
  1102. ctx.reply(`āœ”ļø Document disimpan \n<b>Nama file:</b> ${doctext}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_unique_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${document.file_unique_id}`,{
  1103. parse_mode: 'HTML',
  1104. disable_web_page_preview: true,
  1105. reply_to_message_id: ctx.message.message_id
  1106. })
  1107. }
  1108. if(!ctx.message.caption)
  1109. return ctx.replyWithDocument(document.file_id, {
  1110. chat_id: process.env.LOG_CHANNEL,
  1111. caption: `āœ”ļø Document disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${doctext}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${document.file_unique_id}`,
  1112. parse_mode:'HTML'
  1113. })
  1114. ctx.replyWithDocument(document.file_id, {
  1115. chat_id: process.env.LOG_CHANNEL,
  1116. caption: `${ctx.message.caption}\n\nāœ”ļø Document disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${doctext}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${document.file_unique_id}`,
  1117. parse_mode:'HTML'
  1118. })
  1119. }
  1120. }
  1121. if(!fileDetails1.file_name){
  1122. saver.saveFile(fileDetails4)
  1123. if(ctx.chat.type == 'private') {
  1124. if(ctx.message.media_group_id){
  1125. if(updates.length > 1){
  1126. ctx.reply(`āœ”ļø Grup disimpan \n<b>ID grup:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,{
  1127. parse_mode: 'HTML',
  1128. disable_web_page_preview: true,
  1129. reply_to_message_id: updates[0].message.message_id
  1130. })
  1131. updates = []
  1132. }
  1133. }
  1134. }
  1135. if(!ctx.message.caption)
  1136. return ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1137. type: 'document',
  1138. media: fileDetails1.file_id,
  1139. caption: `āœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${document.file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1140. parse_mode:'HTML'
  1141. }])
  1142. ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1143. type: 'document',
  1144. media: fileDetails1.file_id,
  1145. caption: `${ctx.message.caption}\n\nāœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${document.file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1146. parse_mode:'HTML'
  1147. }])
  1148. }else{
  1149. saver.saveFile(fileDetails3)
  1150. if(ctx.chat.type == 'private') {
  1151. if(ctx.message.media_group_id){
  1152. if(updates.length > 1){
  1153. ctx.reply(`āœ”ļø Grup disimpan \n<b>ID grup:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,{
  1154. parse_mode: 'HTML',
  1155. disable_web_page_preview: true,
  1156. reply_to_message_id: updates[0].message.message_id
  1157. })
  1158. updates = []
  1159. }
  1160. }
  1161. }
  1162. if(!ctx.message.caption)
  1163. return ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1164. type: 'document',
  1165. media: fileDetails1.file_id,
  1166. caption: `āœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${doctext}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${document.file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1167. parse_mode:'HTML'
  1168. }])
  1169. ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1170. type: 'document',
  1171. media: fileDetails1.file_id,
  1172. caption: `${ctx.message.caption}\n\nāœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${doctext}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${document.file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1173. parse_mode:'HTML'
  1174. }])
  1175. }
  1176. }else{
  1177. //try{
  1178. var botStatus3 = await bot.telegram.getChatMember(channelId, ctx.botInfo.id)
  1179. var member3 = await bot.telegram.getChatMember(channelId, ctx.from.id)
  1180. //console.log(member3);
  1181. if(!member3 || member3.status == 'left' || member3.status == 'kicked'){
  1182. var profile6 = await bot.telegram.getUserProfilePhotos(ctx.chat.id)
  1183. if(!profile6 || profile6.total_count == 0)
  1184. return ctx.reply(`<a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a> \n\n${welcomejoin(ctx)}`,{
  1185. parse_mode:'HTML',
  1186. disable_web_page_preview: true,
  1187. reply_markup:{
  1188. inline_keyboard:inKey2
  1189. }
  1190. })
  1191. ctx.replyWithPhoto(profile6.photos[0][0].file_id,{caption: `<a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a> \n\n${welcomejoin(ctx)}`,
  1192. parse_mode:'HTML',
  1193. disable_web_page_preview: true,
  1194. reply_markup:{
  1195. inline_keyboard:inKey2
  1196. }
  1197. })
  1198. }else{
  1199. await saver.checkBan(`${ctx.from.id}`).then((res) => {
  1200. //console.log(res);
  1201. if(res == true) {
  1202. if(ctx.chat.type == 'private') {
  1203. ctx.reply(`${messagebanned(ctx)}`)
  1204. }
  1205. }else{
  1206. if(!fileDetails1.mediaId){
  1207. if(!fileDetails1.file_name){
  1208. saver.saveFile(fileDetails2)
  1209. if(ctx.chat.type == 'private') {
  1210. ctx.reply(`āœ”ļø Document disimpan \n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_unique_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${document.file_unique_id}`,{
  1211. parse_mode: 'HTML',
  1212. disable_web_page_preview: true,
  1213. reply_to_message_id: ctx.message.message_id
  1214. })
  1215. }
  1216. if(!ctx.message.caption)
  1217. return ctx.replyWithDocument(document.file_id, {
  1218. chat_id: process.env.LOG_CHANNEL,
  1219. caption: `āœ”ļø Document disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${document.file_unique_id}`,
  1220. parse_mode:'HTML'
  1221. })
  1222. ctx.replyWithDocument(document.file_id, {
  1223. chat_id: process.env.LOG_CHANNEL,
  1224. caption: `${ctx.message.caption}\n\nāœ”ļø Document disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${document.file_unique_id}`,
  1225. parse_mode:'HTML'
  1226. })
  1227. }else{
  1228. saver.saveFile(fileDetails)
  1229. if(ctx.chat.type == 'private') {
  1230. ctx.reply(`āœ”ļø Document disimpan \n<b>Nama file:</b> ${doctext}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_unique_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${document.file_unique_id}`,{
  1231. parse_mode: 'HTML',
  1232. disable_web_page_preview: true,
  1233. reply_to_message_id: ctx.message.message_id
  1234. })
  1235. }
  1236. if(!ctx.message.caption)
  1237. return ctx.replyWithDocument(document.file_id, {
  1238. chat_id: process.env.LOG_CHANNEL,
  1239. caption: `āœ”ļø Document disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${doctext}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${document.file_unique_id}`,
  1240. parse_mode:'HTML'
  1241. })
  1242. ctx.replyWithDocument(document.file_id, {
  1243. chat_id: process.env.LOG_CHANNEL,
  1244. caption: `${ctx.message.caption}\n\nāœ”ļø Document disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${doctext}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${document.file_unique_id}`,
  1245. parse_mode:'HTML'
  1246. })
  1247. }
  1248. }
  1249. }
  1250. if(!fileDetails1.file_name){
  1251. saver.saveFile(fileDetails4)
  1252. if(ctx.chat.type == 'private') {
  1253. if(ctx.message.media_group_id){
  1254. if(updates.length > 1){
  1255. ctx.reply(`āœ”ļø Grup disimpan \n<b>ID grup:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,{
  1256. parse_mode: 'HTML',
  1257. disable_web_page_preview: true,
  1258. reply_to_message_id: updates[0].message.message_id
  1259. })
  1260. updates = []
  1261. }
  1262. }
  1263. }
  1264. if(!ctx.message.caption)
  1265. return ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1266. type: 'document',
  1267. media: fileDetails1.file_id,
  1268. caption: `āœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${document.file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1269. parse_mode:'HTML'
  1270. }])
  1271. ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1272. type: 'document',
  1273. media: fileDetails1.file_id,
  1274. caption: `${ctx.message.caption}\n\nāœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${document.file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1275. parse_mode:'HTML'
  1276. }])
  1277. }else{
  1278. saver.saveFile(fileDetails3)
  1279. if(ctx.chat.type == 'private') {
  1280. if(ctx.message.media_group_id){
  1281. if(updates.length > 1){
  1282. ctx.reply(`āœ”ļø Grup disimpan \n<b>ID grup:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/grp_${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,{
  1283. parse_mode: 'HTML',
  1284. disable_web_page_preview: true,
  1285. reply_to_message_id: updates[0].message.message_id
  1286. })
  1287. updates = []
  1288. }
  1289. }
  1290. }
  1291. if(!ctx.message.caption)
  1292. return ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1293. type: 'document',
  1294. media: fileDetails1.file_id,
  1295. caption: `āœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${doctext}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${document.file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1296. parse_mode:'HTML'
  1297. }])
  1298. ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1299. type: 'document',
  1300. media: fileDetails1.file_id,
  1301. caption: `${ctx.message.caption}\n\nāœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${doctext}\n<b>Size:</b> ${document.file_size} B\n<b>ID file:</b> ${document.file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${document.file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1302. parse_mode:'HTML'
  1303. }])
  1304. }
  1305. })
  1306. }
  1307. //}
  1308. //catch(error){
  1309. // ctx.reply(`${messagebotnoaddgroup(ctx)}`)
  1310. //}
  1311. }
  1312.  
  1313. })
  1314.  
  1315. //video files
  1316. bot.on('video', async(ctx) => {
  1317. video = ctx.message.video
  1318. //console.log(ctx);
  1319.  
  1320. fileDetails1 = {
  1321. file_name: video.file_name,
  1322. userId:ctx.from.id,
  1323. file_id: video.file_id,
  1324. mediaId: ctx.message.media_group_id,
  1325. caption: ctx.message.caption,
  1326. file_size: video.file_size,
  1327. uniqueId: video.file_unique_id,
  1328. type: 'video'
  1329. }
  1330. //console.log(fileDetails1.caption);
  1331.  
  1332. if(fileDetails1.mediaId == undefined){
  1333. if(fileDetails1.file_name == undefined){
  1334. fileDetails2 = {
  1335. file_name: today2(ctx),
  1336. userId:ctx.from.id,
  1337. file_id: video.file_id,
  1338. caption: ctx.message.caption,
  1339. file_size: video.file_size,
  1340. uniqueId: video.file_unique_id,
  1341. type: 'video'
  1342. }
  1343. //console.log(fileDetails2.caption);
  1344. }else{
  1345. var exstension = video.file_name;
  1346. var regex = /\.[A-Za-z0-9]+$/gm
  1347. var vidext = exstension.replace(regex, '');
  1348. fileDetails = {
  1349. file_name: vidext,
  1350. userId:ctx.from.id,
  1351. file_id: video.file_id,
  1352. caption: ctx.message.caption,
  1353. file_size: video.file_size,
  1354. uniqueId: video.file_unique_id,
  1355. type: 'video'
  1356. }
  1357. //console.log(fileDetails.caption);
  1358. }
  1359. }else{
  1360. if(fileDetails1.file_name == undefined){
  1361. fileDetails4 = {
  1362. file_name: today2(ctx),
  1363. userId:ctx.from.id,
  1364. file_id: video.file_id,
  1365. mediaId: ctx.message.media_group_id,
  1366. caption: ctx.message.caption,
  1367. file_size: video.file_size,
  1368. uniqueId: video.file_unique_id,
  1369. type: 'video'
  1370. }
  1371. //console.log(fileDetails4.caption);
  1372. }else{
  1373. var exstension = video.file_name;
  1374. var regex = /\.[A-Za-z0-9]+$/gm
  1375. var vidext = exstension.replace(regex, '');
  1376. fileDetails3 = {
  1377. file_name: vidext,
  1378. userId:ctx.from.id,
  1379. file_id: video.file_id,
  1380. mediaId: ctx.message.media_group_id,
  1381. caption: ctx.message.caption,
  1382. file_size: video.file_size,
  1383. uniqueId: video.file_unique_id,
  1384. type: 'video'
  1385. }
  1386. //console.log(fileDetails3.caption);
  1387. }
  1388. }
  1389.  
  1390. if(ctx.from.id ==process.env.ADMIN || ctx.from.id == process.env.ADMIN1 || ctx.from.id == process.env.ADMIN2){
  1391. if(!fileDetails1.mediaId){
  1392. if(!fileDetails1.file_name){
  1393. saver.saveFile(fileDetails2)
  1394. if(ctx.chat.type == 'private') {
  1395. ctx.reply(`āœ”ļø Video disimpan \n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_unique_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}`,{
  1396. parse_mode: 'HTML',
  1397. disable_web_page_preview: true,
  1398. reply_to_message_id: ctx.message.message_id
  1399. })
  1400. }
  1401. if(!ctx.message.caption)
  1402. return ctx.replyWithVideo(video.file_id, {
  1403. chat_id: process.env.LOG_CHANNEL,
  1404. caption: `āœ”ļø Video disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}`,
  1405. parse_mode:'HTML'
  1406. })
  1407. ctx.replyWithVideo(video.file_id, {
  1408. chat_id: process.env.LOG_CHANNEL,
  1409. caption: `${ctx.message.caption}\n\nāœ”ļø Video disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}`,
  1410. parse_mode:'HTML'
  1411. })
  1412. }else{
  1413. saver.saveFile(fileDetails)
  1414. if(ctx.chat.type == 'private') {
  1415. ctx.reply(`āœ”ļø Video disimpan \n<b>Nama file:</b> ${vidext}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_unique_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}`,{
  1416. parse_mode: 'HTML',
  1417. disable_web_page_preview: true,
  1418. reply_to_message_id: ctx.message.message_id
  1419. })
  1420. }
  1421. if(!ctx.message.caption)
  1422. return ctx.replyWithVideo(video.file_id, {
  1423. chat_id: process.env.LOG_CHANNEL,
  1424. caption: `āœ”ļø Video disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${vidext}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}`,
  1425. parse_mode:'HTML'
  1426. })
  1427. ctx.replyWithVideo(video.file_id, {
  1428. chat_id: process.env.LOG_CHANNEL,
  1429. caption: `${ctx.message.caption}\n\nāœ”ļø Video disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${vidext}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}`,
  1430. parse_mode:'HTML'
  1431. })
  1432. }
  1433. }
  1434. if(!fileDetails1.file_name){
  1435. saver.saveFile(fileDetails4)
  1436. if(ctx.chat.type == 'private') {
  1437. if(ctx.message.media_group_id){
  1438. if(updates.length > 1){
  1439. ctx.reply(`āœ”ļø Grup disimpan \n<b>ID grup:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,{
  1440. parse_mode: 'HTML',
  1441. disable_web_page_preview: true,
  1442. reply_to_message_id: updates[0].message.message_id
  1443. })
  1444. updates = []
  1445. }
  1446. }
  1447. }
  1448. if(!ctx.message.caption)
  1449. return ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1450. type: 'video',
  1451. media: fileDetails1.file_id,
  1452. caption: `āœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1453. parse_mode:'HTML'
  1454. }])
  1455. ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1456. type: 'video',
  1457. media: fileDetails1.file_id,
  1458. caption: `${ctx.message.caption}\n\nāœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1459. parse_mode:'HTML'
  1460. }])
  1461. }else{
  1462. saver.saveFile(fileDetails3)
  1463. if(ctx.chat.type == 'private') {
  1464. if(ctx.message.media_group_id){
  1465. if(updates.length > 1){
  1466. ctx.reply(`āœ”ļø Grup disimpan \n<b>ID grup:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,{
  1467. parse_mode: 'HTML',
  1468. disable_web_page_preview: true,
  1469. reply_to_message_id: updates[0].message.message_id
  1470. })
  1471. updates = []
  1472. }
  1473. }
  1474. }
  1475. if(!ctx.message.caption)
  1476. return ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1477. type: 'video',
  1478. media: fileDetails1.file_id,
  1479. caption: `āœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${vidext}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1480. parse_mode:'HTML'
  1481. }])
  1482. ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1483. type: 'video',
  1484. media: fileDetails1.file_id,
  1485. caption: `${ctx.message.caption}\n\nāœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${vidext}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1486. parse_mode:'HTML'
  1487. }])
  1488. }
  1489. }else{
  1490. //try{
  1491. var botStatus3 = await bot.telegram.getChatMember(channelId, ctx.botInfo.id)
  1492. var member3 = await bot.telegram.getChatMember(channelId, ctx.from.id)
  1493. //console.log(member3);
  1494. if(!member3 || member3.status == 'left' || member3.status == 'kicked'){
  1495. var profile6 = await bot.telegram.getUserProfilePhotos(ctx.chat.id)
  1496. if(!profile6 || profile6.total_count == 0)
  1497. return ctx.reply(`<a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a> \n\n${welcomejoin(ctx)}`,{
  1498. parse_mode:'HTML',
  1499. disable_web_page_preview: true,
  1500. reply_markup:{
  1501. inline_keyboard:inKey2
  1502. }
  1503. })
  1504. ctx.replyWithPhoto(profile6.photos[0][0].file_id,{caption: `<a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a> \n\n${welcomejoin(ctx)}`,
  1505. parse_mode:'HTML',
  1506. disable_web_page_preview: true,
  1507. reply_markup:{
  1508. inline_keyboard:inKey2
  1509. }
  1510. })
  1511. }else{
  1512. await saver.checkBan(`${ctx.from.id}`).then((res) => {
  1513. //console.log(res);
  1514. if(res == true) {
  1515. if(ctx.chat.type == 'private') {
  1516. ctx.reply(`${messagebanned(ctx)}`)
  1517. }
  1518. }else{
  1519. if(!fileDetails1.mediaId){
  1520. if(!fileDetails1.file_name){
  1521. saver.saveFile(fileDetails2)
  1522. if(ctx.chat.type == 'private') {
  1523. ctx.reply(`āœ”ļø Video disimpan \n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_unique_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}`,{
  1524. parse_mode: 'HTML',
  1525. disable_web_page_preview: true,
  1526. reply_to_message_id: ctx.message.message_id
  1527. })
  1528. }
  1529. if(!ctx.message.caption)
  1530. return ctx.replyWithVideo(video.file_id, {
  1531. chat_id: process.env.LOG_CHANNEL,
  1532. caption: `āœ”ļø Video disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}`,
  1533. parse_mode:'HTML'
  1534. })
  1535. ctx.replyWithVideo(video.file_id, {
  1536. chat_id: process.env.LOG_CHANNEL,
  1537. caption: `${ctx.message.caption}\n\n<b>āœ”ļø Video disimpan \nDari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}`,
  1538. parse_mode:'HTML'
  1539. })
  1540. }else{
  1541. saver.saveFile(fileDetails)
  1542. if(ctx.chat.type == 'private') {
  1543. ctx.reply(`āœ”ļø Video disimpan \n<b>Nama file:</b> ${vidext}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_unique_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}`,{
  1544. parse_mode: 'HTML',
  1545. disable_web_page_preview: true,
  1546. reply_to_message_id: ctx.message.message_id
  1547. })
  1548. }
  1549. if(!ctx.message.caption)
  1550. return ctx.replyWithVideo(video.file_id, {
  1551. chat_id: process.env.LOG_CHANNEL,
  1552. caption: `āœ”ļø Video disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${vidext}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}`,
  1553. parse_mode:'HTML'
  1554. })
  1555. ctx.replyWithVideo(video.file_id, {
  1556. chat_id: process.env.LOG_CHANNEL,
  1557. caption: `${ctx.message.caption}\n\nāœ”ļø Video disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${vidext}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}`,
  1558. parse_mode:'HTML'
  1559. })
  1560. }
  1561. }
  1562. }
  1563. if(!fileDetails1.file_name){
  1564. saver.saveFile(fileDetails4)
  1565. if(ctx.chat.type == 'private') {
  1566. if(ctx.message.media_group_id){
  1567. if(updates.length > 1){
  1568. ctx.reply(`āœ”ļø Grup disimpan \n<b>ID grup:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,{
  1569. parse_mode: 'HTML',
  1570. disable_web_page_preview: true,
  1571. reply_to_message_id: updates[0].message.message_id
  1572. })
  1573. updates = []
  1574. }
  1575. }
  1576. }
  1577. if(!ctx.message.caption)
  1578. return ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1579. type: 'video',
  1580. media: fileDetails1.file_id,
  1581. caption: `āœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1582. parse_mode:'HTML'
  1583. }])
  1584. ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1585. type: 'video',
  1586. media: fileDetails1.file_id,
  1587. caption: `${ctx.message.caption}\n\nāœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1588. parse_mode:'HTML'
  1589. }])
  1590. }else{
  1591. saver.saveFile(fileDetails3)
  1592. if(ctx.chat.type == 'private') {
  1593. if(ctx.message.media_group_id){
  1594. if(updates.length > 1){
  1595. ctx.reply(`āœ”ļø Grup disimpan \n<b>ID grup:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,{
  1596. parse_mode: 'HTML',
  1597. disable_web_page_preview: true,
  1598. reply_to_message_id: updates[0].message.message_id
  1599. })
  1600. updates = []
  1601. }
  1602. }
  1603. }
  1604. if(!ctx.message.caption)
  1605. return ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1606. type: 'video',
  1607. media: fileDetails1.file_id,
  1608. caption: `āœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${vidext}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1609. parse_mode:'HTML'
  1610. }])
  1611. ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1612. type: 'video',
  1613. media: fileDetails1.file_id,
  1614. caption: `${ctx.message.caption}\n\nāœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${vidext}\n<b>Size:</b> ${video.file_size} B\n<b>ID file:</b> ${video.file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${video.file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1615. parse_mode:'HTML'
  1616. }])
  1617. }
  1618. })
  1619. }
  1620. //}
  1621. //catch(error){
  1622. // ctx.reply(`${messagebotnoaddgroup(ctx)}`)
  1623. //}
  1624. }
  1625.  
  1626. })
  1627.  
  1628. //photo files
  1629. bot.on('photo', async(ctx) => {
  1630. photo = ctx.message.photo
  1631. //console.log(ctx);
  1632.  
  1633. fileDetails1 = {
  1634. file_name: photo[1].file_name,
  1635. userId:ctx.from.id,
  1636. file_id: photo[1].file_id,
  1637. mediaId: ctx.message.media_group_id,
  1638. caption: ctx.message.caption,
  1639. file_size: photo[1].file_size,
  1640. uniqueId: photo[1].file_unique_id,
  1641. type: 'photo'
  1642. }
  1643. //console.log(fileDetails1.caption);
  1644.  
  1645. if(fileDetails1.mediaId == undefined){
  1646. if(fileDetails1.file_name == undefined){
  1647. fileDetails2 = {
  1648. file_name: today2(ctx),
  1649. userId:ctx.from.id,
  1650. file_id: photo[1].file_id,
  1651. caption: ctx.message.caption,
  1652. file_size: photo[1].file_size,
  1653. uniqueId: photo[1].file_unique_id,
  1654. type: 'photo'
  1655. }
  1656. //console.log(fileDetails2.caption);
  1657. }else{
  1658. var exstension = photo[1].file_name;
  1659. var regex = /\.[A-Za-z0-9]+$/gm
  1660. var photext = exstension.replace(regex, '');
  1661. fileDetails = {
  1662. file_name: photext,
  1663. userId:ctx.from.id,
  1664. file_id: photo[1].file_id,
  1665. caption: ctx.message.caption,
  1666. file_size: photo[1].file_size,
  1667. uniqueId: photo[1].file_unique_id,
  1668. type: 'photo'
  1669. }
  1670. //console.log(fileDetails.caption);
  1671. }
  1672. }else{
  1673. if(fileDetails1.file_name == undefined){
  1674. fileDetails4 = {
  1675. file_name: today2(ctx),
  1676. userId:ctx.from.id,
  1677. file_id: photo[1].file_id,
  1678. mediaId: ctx.message.media_group_id,
  1679. caption: ctx.message.caption,
  1680. file_size: photo[1].file_size,
  1681. uniqueId: photo[1].file_unique_id,
  1682. type: 'photo'
  1683. }
  1684. //console.log(fileDetails4.caption);
  1685. }else{
  1686. var exstension = photo[1].file_name;
  1687. var regex = /\.[A-Za-z0-9]+$/gm
  1688. var photext = exstension.replace(regex, '');
  1689. fileDetails3 = {
  1690. file_name: photext,
  1691. userId:ctx.from.id,
  1692. file_id: photo[1].file_id,
  1693. mediaId: ctx.message.media_group_id,
  1694. caption: ctx.message.caption,
  1695. file_size: photo[1].file_size,
  1696. uniqueId: photo[1].file_unique_id,
  1697. type: 'photo'
  1698. }
  1699. //console.log(fileDetails3.caption);
  1700. }
  1701. }
  1702.  
  1703. if(ctx.from.id ==process.env.ADMIN || ctx.from.id == process.env.ADMIN1 || ctx.from.id == process.env.ADMIN2){
  1704. if(!fileDetails1.mediaId){
  1705. if(!fileDetails1.file_name){
  1706. saver.saveFile(fileDetails2)
  1707. if(ctx.chat.type == 'private') {
  1708. ctx.reply(`āœ”ļø Photo disimpan \n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_unique_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}`,{
  1709. parse_mode: 'HTML',
  1710. disable_web_page_preview: true,
  1711. reply_to_message_id: ctx.message.message_id
  1712. })
  1713. }
  1714. if(!ctx.message.caption)
  1715. return ctx.replyWithPhoto(photo[1].file_id, {
  1716. chat_id: process.env.LOG_CHANNEL,
  1717. caption: `āœ”ļø Photo disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}`,
  1718. parse_mode:'HTML'
  1719. })
  1720. ctx.replyWithPhoto(photo[1].file_id, {
  1721. chat_id: process.env.LOG_CHANNEL,
  1722. caption: `${ctx.message.caption}\n\nāœ”ļø Photo disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}`,
  1723. parse_mode:'HTML'
  1724. })
  1725. }else{
  1726. saver.saveFile(fileDetails)
  1727. if(ctx.chat.type == 'private') {
  1728. ctx.reply(`āœ”ļø Photo disimpan \n<b>Nama file:</b> ${photext}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_unique_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}`,{
  1729. parse_mode: 'HTML',
  1730. disable_web_page_preview: true,
  1731. reply_to_message_id: ctx.message.message_id
  1732. })
  1733. }
  1734. if(!ctx.message.caption)
  1735. return ctx.replyWithPhoto(photo[1].file_id, {
  1736. chat_id: process.env.LOG_CHANNEL,
  1737. caption: `āœ”ļø Photo disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${photext}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}`,
  1738. parse_mode:'HTML'
  1739. })
  1740. ctx.replyWithPhoto(photo[1].file_id, {
  1741. chat_id: process.env.LOG_CHANNEL,
  1742. caption: `${ctx.message.caption}\n\nāœ”ļø Photo disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${photext}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}`,
  1743. parse_mode:'HTML'
  1744. })
  1745. }
  1746. }
  1747. if(!fileDetails1.file_name){
  1748. saver.saveFile(fileDetails4)
  1749. if(ctx.chat.type == 'private') {
  1750. if(ctx.message.media_group_id){
  1751. if(updates.length > 1){
  1752. ctx.reply(`āœ”ļø Grup disimpan \n<b>ID grup:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,{
  1753. parse_mode: 'HTML',
  1754. disable_web_page_preview: true,
  1755. reply_to_message_id: updates[0].message.message_id
  1756. })
  1757. updates = []
  1758. }
  1759. }
  1760. }
  1761. if(!ctx.message.caption)
  1762. return ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1763. type: 'photo',
  1764. media: fileDetails1.file_id,
  1765. caption: `āœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1766. parse_mode:'HTML'
  1767. }])
  1768. ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1769. type: 'photo',
  1770. media: fileDetails1.file_id,
  1771. caption: `${ctx.message.caption}\n\nāœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1772. parse_mode:'HTML'
  1773. }])
  1774. }else{
  1775. saver.saveFile(fileDetails3)
  1776. if(ctx.chat.type == 'private') {
  1777. if(ctx.message.media_group_id){
  1778. if(updates.length > 1){
  1779. ctx.reply(`āœ”ļø Grup disimpan \n<b>ID grup:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,{
  1780. parse_mode: 'HTML',
  1781. disable_web_page_preview: true,
  1782. reply_to_message_id: updates[0].message.message_id
  1783. })
  1784. updates = []
  1785. }
  1786. }
  1787. }
  1788. if(!ctx.message.caption)
  1789. return ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1790. type: 'photo',
  1791. media: fileDetails1.file_id,
  1792. caption: `āœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${photext}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1793. parse_mode:'HTML'
  1794. }])
  1795. ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1796. type: 'photo',
  1797. media: fileDetails1.file_id,
  1798. caption: `${ctx.message.caption}\n\nāœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${photext}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1799. parse_mode:'HTML'
  1800. }])
  1801. }
  1802. }else{
  1803. //try{
  1804. var botStatus3 = await bot.telegram.getChatMember(channelId, ctx.botInfo.id)
  1805. var member3 = await bot.telegram.getChatMember(channelId, ctx.from.id)
  1806. //console.log(member3);
  1807. if(!member3 || member3.status == 'left' || member3.status == 'kicked'){
  1808. var profile6 = await bot.telegram.getUserProfilePhotos(ctx.chat.id)
  1809. if(!profile6 || profile6.total_count == 0)
  1810. return ctx.reply(`<a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a> \n\n${welcomejoin(ctx)}`,{
  1811. parse_mode:'HTML',
  1812. disable_web_page_preview: true,
  1813. reply_markup:{
  1814. inline_keyboard:inKey2
  1815. }
  1816. })
  1817. ctx.replyWithPhoto(profile6.photos[0][0].file_id,{caption: `<a href="tg://user?id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a> \n\n${welcomejoin(ctx)}`,
  1818. parse_mode:'HTML',
  1819. disable_web_page_preview: true,
  1820. reply_markup:{
  1821. inline_keyboard:inKey2
  1822. }
  1823. })
  1824. }else{
  1825. await saver.checkBan(`${ctx.from.id}`).then((res) => {
  1826. //console.log(res);
  1827. if(res == true) {
  1828. if(ctx.chat.type == 'private') {
  1829. ctx.reply(`${messagebanned(ctx)}`)
  1830. }
  1831. }else{
  1832. if(!fileDetails1.mediaId){
  1833. if(!fileDetails1.file_name){
  1834. saver.saveFile(fileDetails2)
  1835. if(ctx.chat.type == 'private') {
  1836. ctx.reply(`āœ”ļø Photo disimpan \n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_unique_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}`,{
  1837. parse_mode: 'HTML',
  1838. disable_web_page_preview: true,
  1839. reply_to_message_id: ctx.message.message_id
  1840. })
  1841. }
  1842. if(!ctx.message.caption)
  1843. return ctx.replyWithPhoto(photo[1].file_id, {
  1844. chat_id: process.env.LOG_CHANNEL,
  1845. caption: `āœ”ļø Photo disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}`,
  1846. parse_mode:'HTML'
  1847. })
  1848. ctx.replyWithPhoto(photo[1].file_id, {
  1849. chat_id: process.env.LOG_CHANNEL,
  1850. caption: `${ctx.message.caption}\n\nāœ”ļø Photo disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}`,
  1851. parse_mode:'HTML'
  1852. })
  1853. }else{
  1854. saver.saveFile(fileDetails)
  1855. if(ctx.chat.type == 'private') {
  1856. ctx.reply(`āœ”ļø Photo disimpan \n<b>Nama file:</b> ${photext}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_unique_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}`,{
  1857. parse_mode: 'HTML',
  1858. disable_web_page_preview: true,
  1859. reply_to_message_id: ctx.message.message_id
  1860. })
  1861. }
  1862. if(!ctx.message.caption)
  1863. return ctx.replyWithPhoto(photo[1].file_id, {
  1864. chat_id: process.env.LOG_CHANNEL,
  1865. caption: `āœ”ļø Photo disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${photext}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}`,
  1866. parse_mode:'HTML'
  1867. })
  1868. ctx.replyWithPhoto(photo[1].file_id, {
  1869. chat_id: process.env.LOG_CHANNEL,
  1870. caption: `${ctx.message.caption}\n\nāœ”ļø Photo disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${photext}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}`,
  1871. parse_mode:'HTML'
  1872. })
  1873. }
  1874. }
  1875. }
  1876. if(!fileDetails1.file_name){
  1877. saver.saveFile(fileDetails4)
  1878. if(ctx.chat.type == 'private') {
  1879. if(ctx.message.media_group_id){
  1880. if(updates.length > 1){
  1881. ctx.reply(`<b>ID grup:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,{
  1882. parse_mode: 'HTML',
  1883. disable_web_page_preview: true,
  1884. reply_to_message_id: updates[0].message.message_id
  1885. })
  1886. updates = []
  1887. }
  1888. }
  1889. }
  1890. if(!ctx.message.caption)
  1891. return ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1892. type: 'photo',
  1893. media: fileDetails1.file_id,
  1894. caption: `āœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1895. parse_mode:'HTML'
  1896. }])
  1897. ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1898. type: 'photo',
  1899. media: fileDetails1.file_id,
  1900. caption: `${ctx.message.caption}\n\nāœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${today2(ctx)}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1901. parse_mode:'HTML'
  1902. }])
  1903. }else{
  1904. saver.saveFile(fileDetails3)
  1905. if(ctx.chat.type == 'private') {
  1906. if(ctx.message.media_group_id){
  1907. if(updates.length > 1){
  1908. ctx.reply(`<b>āœ”ļø Grup disimpan \nID grup:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,{
  1909. parse_mode: 'HTML',
  1910. disable_web_page_preview: true,
  1911. reply_to_message_id: updates[0].message.message_id
  1912. })
  1913. updates = []
  1914. }
  1915. }
  1916. }
  1917. if(!ctx.message.caption)
  1918. return ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1919. type: 'photo',
  1920. media: fileDetails1.file_id,
  1921. caption: `āœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${photext}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1922. parse_mode:'HTML'
  1923. }])
  1924. ctx.telegram.sendMediaGroup(process.env.LOG_CHANNEL,[{
  1925. type: 'photo',
  1926. media: fileDetails1.file_id,
  1927. caption: `${ctx.message.caption}\n\nāœ”ļø Grup disimpan \n<b>Dari:</b> ${ctx.from.id}\n<b>Nama:</b> <a href="tg://openmessage?user_id=${ctx.from.id}">${first_name(ctx)} ${last_name(ctx)}</a>\n\n<b>Nama file:</b> ${photext}\n<b>Size:</b> ${photo[1].file_size} B\n<b>ID file:</b> ${photo[1].file_id}\n<b>ID Group:</b> ${ctx.message.media_group_id}\n\nhttps://t.me/${process.env.BOTUSERNAME}?start=${photo[1].file_unique_id}\nhttps://t.me/${process.env.BOTUSERNAME}?start=grp_${ctx.message.media_group_id}`,
  1928. parse_mode:'HTML'
  1929. }])
  1930. }
  1931. })
  1932. }
  1933. //}
  1934. //catch(error){
  1935. // ctx.reply(`${messagebotnoaddgroup(ctx)}`)
  1936. //}
  1937. }
  1938.  
  1939. })
  1940.  
  1941. bot.command('stats',async(ctx)=>{
  1942. stats = await saver.getUser().then((res)=>{
  1943. if(ctx.from.id ==process.env.ADMIN || ctx.from.id == process.env.ADMIN1 || ctx.from.id == process.env.ADMIN2){
  1944. ctx.reply(`šŸ“Š Total pengguna: <b>${res.length}</b>`,{parse_mode:'HTML'})
  1945. }
  1946.  
  1947. })
  1948. stats = await saver.getMedia().then((res)=>{
  1949. if(ctx.from.id ==process.env.ADMIN || ctx.from.id == process.env.ADMIN1 || ctx.from.id == process.env.ADMIN2){
  1950. ctx.reply(`šŸ“Š Total media: <b>${res.length}</b>`,{parse_mode:'HTML'})
  1951. }
  1952.  
  1953. })
  1954. stats = await saver.getBan().then((res)=>{
  1955. if(ctx.from.id ==process.env.ADMIN || ctx.from.id == process.env.ADMIN1 || ctx.from.id == process.env.ADMIN2){
  1956. ctx.reply(`šŸ“Š Total pengguna melanggar: <b>${res.length}</b>`,{parse_mode:'HTML'})
  1957. }
  1958.  
  1959. })
  1960. stats = await saver.getGroup().then((res)=>{
  1961. if(ctx.from.id ==process.env.ADMIN || ctx.from.id == process.env.ADMIN1 || ctx.from.id == process.env.ADMIN2){
  1962. ctx.reply(`šŸ“Š Total grup terdaftar: <b>${res.length}</b>`,{parse_mode:'HTML'})
  1963. }
  1964.  
  1965. })
  1966. })
  1967.  
  1968. //getting files as inline result
  1969. bot.on('inline_query',async(ctx)=>{
  1970. query = ctx.inlineQuery.query
  1971. if(query.length>0){
  1972. // pastikan input sesuai regex
  1973. const type_reg = /(document|video|photo)?\s(\w*)/;
  1974. var reg_veriv = type_reg.exec(query)
  1975.  
  1976. if(!reg_veriv) return;
  1977. if(!reg_veriv[1])return;
  1978.  
  1979. var file_type = reg_veriv[1];
  1980. var keyword = reg_veriv[2];
  1981.  
  1982. let searchResult = saver.getfileInline(keyword).then((res)=>{
  1983. let result = res.filter(e => e.type == file_type).map((ctx,index)=>{
  1984. var data = {
  1985. type:ctx.type,
  1986. id:ctx._id,
  1987. title:ctx.file_name,
  1988. caption:ctx.caption,
  1989. reply_markup:{
  1990. inline_keyboard:[
  1991. [{text:"Pencarian",switch_inline_query:''}]
  1992. ]
  1993. }
  1994. }
  1995. data[`${ctx.type}_file_id`] = ctx.file_id;
  1996. return data;
  1997. }
  1998. )
  1999. ctx.answerInlineQuery(result)
  2000. })
  2001. }else{
  2002. //console.log('query not found');
  2003. }
  2004. })
  2005.  
  2006. //heroku config
  2007. domain = `${process.env.DOMAIN}.herokuapp.com`
  2008. bot.launch({
  2009. webhook:{
  2010. domain:domain,
  2011. port:Number(process.env.PORT)
  2012.  
  2013. }
  2014. })
  2015.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement