Kaynağa Gözat

Adding languages and some interfacing

okynos 8 yıl önce
ebeveyn
işleme
2ada58d93a
2 değiştirilmiş dosya ile 42 ekleme ve 11 silme
  1. 30 11
      downloadBot.js
  2. 12 0
      string/lang.json

+ 30 - 11
downloadBot.js

@@ -1,19 +1,38 @@
-const Telegram = require('telegraf/telegram')
-const Telegraf = require('telegraf')
-const fs = require('fs')
+const Telegram = require('telegraf/telegram');
+const Telegraf = require('telegraf');
+const fs = require('fs');
 const https = require('https');
-const telegram = new Telegram(process.env.BOT_TOKEN)
-const bot = new Telegraf(process.env.BOT_TOKEN)
-
+const telegram = new Telegram(process.env.BOT_TOKEN);
+const bot = new Telegraf(process.env.BOT_TOKEN);
+const admin = 170276072;
+const langData=fs.readFileSync('./string/lang.json', 'utf8');
+const language = JSON.parse(langData);
+var lang = language.en;
 
 bot.start( (ctx) => {
   console.log('started:', ctx.from.id)
-  return ctx.reply('Welcome!')
+  return ctx.reply(lang.welcome)
+})
+
+bot.command('spanish', (ctx) => {
+  lang = language.es;
+  ctx.reply(lang.langChanged)
 })
-bot.command('help', (ctx) => ctx.reply('Try send a sticker!'))
-bot.hears('hi', (ctx) => ctx.reply('Hey there!'))
-bot.hears(/buy/i, (ctx) => ctx.reply('Buy-buy!'))
-bot.on('sticker', (ctx) => ctx.reply('👍'))
+
+bot.command('english', (ctx) => {
+  lang = language.en;
+  ctx.reply(lang.langChanged)
+})
+
+bot.command('help', (ctx) => ctx.reply(lang.help))
+
+
+//bot.hears('hi', (ctx) => ctx.reply('Hey there!'))
+
+//bot.hears(/buy/i, (ctx) => ctx.reply('Buy-buy!'))
+
+//bot.on('sticker', (ctx) => ctx.reply('👍'))
+
 bot.on('audio', (ctx) => {
 	console.log('message received: ', ctx.from.id)
 	telegram.getFile( ctx.message.audio.file_id, (ctx) => { 

+ 12 - 0
string/lang.json

@@ -0,0 +1,12 @@
+{
+  "en":{
+    "welcome": "Welcome!, set bot language with /english or /spanish",
+    "langChanged": "Language changed to english.",
+    "help": "I store all audio media that you send in a folder of pylot@gmail.com plex, if you want to get access to this server send email to him.\n The commands that I accept:\n /english - To set language to English\n /spanish - To set language to Spanish\n /help - for show this message."
+  },
+  "es":{
+    "welcome": "Bienvenido!, establece el lenguage de este bot con /english o /spanish",
+    "langChanged": "Lenguaje establecido al español.",
+    "help": "Almaceno todos los audios que me mandes en la carpeta de plex de pylott@gmail.com, si quieres acceder a este servidor mándale un email.\n Los comandos que acepto son:\n /english - Para establecer el idioma en inglés\n /spanish - Para establecer el idioma en español\n /help - Para mostrar este mensaje."
+  }
+}