Skip to content

Commit 533af3c

Browse files
Merge pull request #12 from LukeSkywalker92/botonly
Botonly
2 parents 30670dd + 141c287 commit 533af3c

5 files changed

Lines changed: 314 additions & 251 deletions

File tree

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- [General](#manual-installation)
1818
- [Configuration](#configuration)
1919
- [Updating](#updating)
20+
- [Bot only mode (no GUI)](#bot-only-mode-no-gui)
2021
- [Building a TeleFrame](#building-a-teleframe)
2122

2223
## Installation
@@ -87,6 +88,15 @@ git pull && npm install
8788
If you changed nothing more than the config, this should work without any problems.
8889
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.
8990

91+
## Bot only mode (no GUI)
92+
93+
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
94+
95+
```bash
96+
npm run botonly
97+
```
98+
in the TeleFrame folder.
99+
90100
## Building a TeleFrame
91101

92102
A detailed instruction on how to build your own TeleFrame will follow soon.

botonly.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
Script for only running the telegram bot to save the images and videos to
3+
the images folder specified in the config
4+
*/
5+
6+
const {
7+
logger,
8+
rendererLogger
9+
} = require('./js/logger')
10+
const config = require('./config/config')
11+
const telebot = require('./js/bot')
12+
const fs = require('fs');
13+
14+
15+
logger.info('Running bot only version of TeleFrame ...');
16+
17+
18+
var ImageWatchdog = class {
19+
constructor(imageFolder, imageCount, logger) {
20+
this.imageFolder = imageFolder;
21+
this.imageCount = imageCount;
22+
this.logger = logger;
23+
this.images = []
24+
25+
//get paths of already downloaded images
26+
if (fs.existsSync(this.imageFolder + '/' + "images.json")) {
27+
fs.readFile(this.imageFolder + '/' + "images.json", (err, data) => {
28+
if (err) throw err;
29+
var jsonData = JSON.parse(data);
30+
for (var image in jsonData) {
31+
this.images.push(jsonData[image]);
32+
}
33+
});
34+
} else {
35+
this.saveImageArray()
36+
}
37+
}
38+
39+
newImage(src, sender, caption) {
40+
//handle new incoming image
41+
this.images.unshift({
42+
'src': src,
43+
'sender': sender,
44+
'caption': caption
45+
});
46+
if (this.images.length >= this.imageCount) {
47+
this.images.pop();
48+
}
49+
var type;
50+
if (src.split('.').pop() == 'mp4') {
51+
type = 'video';
52+
} else {
53+
type = 'image';
54+
}
55+
this.saveImageArray();
56+
}
57+
58+
saveImageArray() {
59+
var self = this;
60+
// stringify JSON Object
61+
var jsonContent = JSON.stringify(this.images);
62+
fs.writeFile(this.imageFolder + '/' + "images.json", jsonContent, 'utf8', function(err) {
63+
if (err) {
64+
self.logger.error("An error occured while writing JSON Object to File.");
65+
return console.log(err);
66+
}
67+
});
68+
}
69+
70+
}
71+
72+
// create imageWatchdog and bot
73+
const imageWatchdog = new ImageWatchdog(config.imageFolder, config.imageCount, logger);
74+
var bot = new telebot(config.botToken, config.imageFolder, imageWatchdog, config.showVideos, logger);
75+
76+
bot.startBot()

js/imageWatchdog.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
const testFolder = './tests/';
21
const fs = require('fs');
32

4-
5-
63
var ImageWatchdog = class {
74
constructor(imageFolder, imageCount, images, emitter, logger) {
85
this.imageFolder = imageFolder;

0 commit comments

Comments
 (0)