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