You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.1 KiB

5 years ago
  1. const TelegramBot = require('node-telegram-bot-api');
  2. var mumble = require('mumble');
  3. var config = require('./config');
  4. var chatId = "";
  5. const bot = new TelegramBot(config.telegramToken, {polling: true});
  6. bot.onText(/\/start/, (msg, match) => {
  7. console.log("chatId");
  8. console.log(chatId);
  9. if(chatId) {
  10. // bot.sendMessage(chatId, "[warning] Some other is trying to connect to the bot from another group/chat");
  11. // var msg = "For security reasons, only 1 instance of bot is allowed, if you want to connect to this bot, restart the bot from the server.";
  12. // bot.sendMessage(msg.chat.id, msg);
  13. } else {
  14. chatId = msg.chat.id;
  15. console.log("chatId", chatId);
  16. var msg = `
  17. Wellcome to mumble-telegram-bot. Available commands:
  18. /start
  19. /bambi
  20. /pot
  21. `;
  22. bot.sendMessage(chatId, msg);
  23. }
  24. });
  25. bot.onText(/\/bambi/, (msg, match) => {
  26. if(chatId) {
  27. bot.sendMessage(chatId, "This is not bambi 🦌");
  28. }
  29. });
  30. bot.onText(/\/pot/, (msg, match) => {
  31. if(chatId) {
  32. bot.sendMessage(chatId, "💰");
  33. }
  34. });
  35. var options = {};
  36. console.log( 'Connecting' );
  37. mumble.connect(config.mumbleURL, options, function ( error, connection ) {
  38. if( error ) { throw new Error( error ); }
  39. console.log( 'Connected' );
  40. connection.authenticate( 'TelegramBot' );
  41. connection.on( 'initialized', function() {
  42. console.log( 'Connection initialized' );
  43. });
  44. connection.on( 'user-connect', function( user ) {
  45. var msg = '[mumble] ✋️😊 User ' + user.name + ' connected at ' + user.channel.name + ' channel.\nThis is not Bambi 🦌';
  46. console.log(msg);
  47. if(chatId) {
  48. bot.sendMessage(chatId, msg);
  49. }
  50. });
  51. connection.on( 'user-move', function( user ) {
  52. var msg = '[mumble] 👋 User ' + user.name + ' moved to ' + user.channel.name + ' channel.';
  53. console.log(msg);
  54. if(chatId) {
  55. bot.sendMessage(chatId, msg);
  56. }
  57. });
  58. connection.on( 'user-disconnect', function( user ) {
  59. var msg = '[mumble] 😢 User ' + user.name + ' has disconnected.';
  60. console.log(msg);
  61. if(chatId) {
  62. bot.sendMessage(chatId, msg);
  63. }
  64. });
  65. });