Skip to content

Commit

Permalink
Merge pull request #12 from LukeSkywalker92/botonly
Browse files Browse the repository at this point in the history
Botonly
  • Loading branch information
LukeSkywalker92 authored Feb 21, 2019
2 parents 30670dd + 141c287 commit 533af3c
Show file tree
Hide file tree
Showing 5 changed files with 314 additions and 251 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [General](#manual-installation)
- [Configuration](#configuration)
- [Updating](#updating)
- [Bot only mode (no GUI)](#bot-only-mode-no-gui)
- [Building a TeleFrame](#building-a-teleframe)

## Installation
Expand Down Expand Up @@ -87,6 +88,15 @@ git pull && npm install
If you changed nothing more than the config, this should work without any problems.
Type `git status` to see your changes, if there are any, you can reset them with `git reset --hard`. After that, git pull should be possible.

## Bot only mode (no GUI)

To run only the bot (without GUI), that saves the recieved images and videos into the folder specified in the config you need to run

```bash
npm run botonly
```
in the TeleFrame folder.

## Building a TeleFrame

A detailed instruction on how to build your own TeleFrame will follow soon.
76 changes: 76 additions & 0 deletions botonly.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Script for only running the telegram bot to save the images and videos to
the images folder specified in the config
*/

const {
logger,
rendererLogger
} = require('./js/logger')
const config = require('./config/config')
const telebot = require('./js/bot')
const fs = require('fs');


logger.info('Running bot only version of TeleFrame ...');


var ImageWatchdog = class {
constructor(imageFolder, imageCount, logger) {
this.imageFolder = imageFolder;
this.imageCount = imageCount;
this.logger = logger;
this.images = []

//get paths of already downloaded images
if (fs.existsSync(this.imageFolder + '/' + "images.json")) {
fs.readFile(this.imageFolder + '/' + "images.json", (err, data) => {
if (err) throw err;
var jsonData = JSON.parse(data);
for (var image in jsonData) {
this.images.push(jsonData[image]);
}
});
} else {
this.saveImageArray()
}
}

newImage(src, sender, caption) {
//handle new incoming image
this.images.unshift({
'src': src,
'sender': sender,
'caption': caption
});
if (this.images.length >= this.imageCount) {
this.images.pop();
}
var type;
if (src.split('.').pop() == 'mp4') {
type = 'video';
} else {
type = 'image';
}
this.saveImageArray();
}

saveImageArray() {
var self = this;
// stringify JSON Object
var jsonContent = JSON.stringify(this.images);
fs.writeFile(this.imageFolder + '/' + "images.json", jsonContent, 'utf8', function(err) {
if (err) {
self.logger.error("An error occured while writing JSON Object to File.");
return console.log(err);
}
});
}

}

// create imageWatchdog and bot
const imageWatchdog = new ImageWatchdog(config.imageFolder, config.imageCount, logger);
var bot = new telebot(config.botToken, config.imageFolder, imageWatchdog, config.showVideos, logger);

bot.startBot()
3 changes: 0 additions & 3 deletions js/imageWatchdog.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
const testFolder = './tests/';
const fs = require('fs');



var ImageWatchdog = class {
constructor(imageFolder, imageCount, images, emitter, logger) {
this.imageFolder = imageFolder;
Expand Down
Loading

0 comments on commit 533af3c

Please sign in to comment.