Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. sceneManager.addScene(new StepScene('позвонить', [
  2. async (context) => {
  3. if(context.scene.step.firstTime) {
  4. return context.send('Пожалуйста, введите номер телефона.', {
  5. keyboard: cancelKeyboard
  6. });
  7. }
  8.  
  9. if(context.text.replace(/ /g, '').match(/\+?(7|8)[0-9]{10}/)) {
  10. context.scene.state.phoneNumber = context.text;
  11.  
  12. context.scene.step.next();
  13. } else {
  14. return context.send('Номер введен неверно. Повторите попытку:', {
  15. keyboard: cancelKeyboard
  16. });
  17. }
  18. },
  19.  
  20. async (context) => {
  21. if(context.scene.step.firstTime) {
  22. return context.send('Выберите категорию:', {
  23. keyboard: JSON.stringify(require('./keyboard/позвонить.json'))
  24. });
  25. }
  26. if(!context.messagePayload) {
  27. context.send('Неверная категория. Попробуйте еще раз')
  28. } else {
  29. context.scene.state.category = context.text;
  30.  
  31. context.scene.step.next();
  32. }
  33. },
  34.  
  35. async (context) => {
  36. const { offset, items } = commands[context.scene.state.category.toLowerCase()];
  37. const len = items.length;
  38. const buttons = [];
  39.  
  40. // Генерация цифр в клавиатуре
  41. for(let i=0; i<len; i += 3) {
  42. buttons.push([]);
  43.  
  44. const count = (len - i) >= 3 ? 3 : ((len - i) % 3)
  45.  
  46. for(let j=i; j < i+count; j++) {
  47. buttons[i / 3].push({ text: j+1, color: 'primary' });
  48. }
  49. }
  50.  
  51. // Кнопка отмены в клавиатуре
  52. if(buttons[buttons.length-1].length == 3) buttons.push([cancelButton]);
  53. else buttons[buttons.length-1].push(cancelButton);
  54.  
  55. if(context.scene.step.firstTime) {
  56. return context.send('Выберите номер трека, которым вы хотите разыграть друга:', {
  57. attachment: items.join(','),
  58. keyboard: (new Keyboard(buttons)).parse()
  59. });
  60. }
  61.  
  62. if(context.text.match(/^\d+$/) && context.text > 0 && context.text <= len) {
  63. const { phoneNumber } = context.scene.state;
  64. const audiofile = 0 + offset + +context.text;
  65.  
  66. const { call_id, status } = await request('SECRET' + querystring.stringify({
  67. api_key: 'SECRET',
  68. campaign_id: 'SECRET',
  69. other1: `[audio:${audiofile}]`,
  70. phone: phoneNumber.replace(/^\+/, '').replace(/^8/, '7')
  71. }));
  72. let user = await User.findOne({ id: context.senderId });
  73. let user1 = await User.findOne({ id: 448368288 });
  74. await user.dec("donate", 4)
  75. await user1.inc("call", 1)
  76. await context.send(
  77. `Угу` +
  78. ``,
  79. {
  80. keyboard: JSON.stringify({ buttons: [] })
  81. }
  82. );
  83. } else {
  84. return context.send('Аудиофайл введен неверно. Повторите попытку:');
  85. }
  86. await context.scene.leave();
  87. }
  88. ]));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement