Explorar o código

Improving interface and saving

José Luis Fernández %!s(int64=8) %!d(string=hai) anos
pai
achega
df604f2d5e
Modificáronse 2 ficheiros con 16 adicións e 9 borrados
  1. 11 6
      downloadBot.js
  2. 5 3
      string/lang.json

+ 11 - 6
downloadBot.js

@@ -9,29 +9,30 @@ 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(lang.welcome)
 })
 
+
 bot.command('spanish', (ctx) => {
   lang = language.es;
   ctx.reply(lang.langChanged)
 })
 
+
 bot.command('english', (ctx) => {
   lang = language.en;
   ctx.reply(lang.langChanged)
 })
 
-bot.command('help', (ctx) => ctx.reply(lang.help))
 
+bot.command('donate', (ctx) => ctx.reply(lang.donate))
 
-//bot.hears('hi', (ctx) => ctx.reply('Hey there!'))
 
-//bot.hears(/buy/i, (ctx) => ctx.reply('Buy-buy!'))
+bot.command('help', (ctx) => ctx.reply(lang.help))
 
-//bot.on('sticker', (ctx) => ctx.reply('👍'))
 
 bot.on('audio', (ctx) => {
 	console.log('message received: ', ctx.from.id)
@@ -46,8 +47,12 @@ bot.on('audio', (ctx) => {
 		filename = filename.replace(new RegExp("\\" + specialChars[i], 'gi'), '')
 	}
 	filename = filename + ".mp3"
-	const downloadDir = "/var/music/bot/"
-	var file = fs.createWriteStream(downloadDir+filename);
+	const downloadDir = "/var/music/bot/" + audio.performer + "/";
+
+	if (!fs.existsSync(downloadDir)){
+		 fs.mkdirSync(downloadDir);
+	}
+	const file = fs.createWriteStream(downloadDir+filename);
         
 	const promise = telegram.getFile(audio.file_id)	
 	promise.then(function(result){

+ 5 - 3
string/lang.json

@@ -2,11 +2,13 @@
   "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."
+    "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 /donate - To see donate link.\n /help - for show this message.",
+    "donate": "If you want to donate to the author, this is the link: https://paypal.me/okynos"
   },
   "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."
+    "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 /donate - Para ver el link de donación.\n /help - Para mostrar este mensaje.",
+    "donate": "Si deseas donar al autor, este es el enlace: https://paypal.me/okynos"
   }
-}
+}