trashbin-scheduler-bot-tg 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +18 -0
- package/LICENSE +373 -0
- package/README.md +157 -0
- package/db/2025-11.json +134 -0
- package/db/2025-12.json +29 -0
- package/db/2026-01.json +29 -0
- package/db/2026-02.json +26 -0
- package/db/2026-03.json +28 -0
- package/db/2026-04.json +26 -0
- package/db/2026-05.json +27 -0
- package/db/2026-06.json +27 -0
- package/ecosystem.config.js +26 -0
- package/lib/constants.js +12 -0
- package/lib/utils.js +130 -0
- package/package.json +51 -0
- package/trashbin-day-handler.js +264 -0
package/db/2025-12.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[
|
|
2
|
+
{ "date": "2025-12-01", "type": "ORGANICO" },
|
|
3
|
+
{ "date": "2025-12-02", "type": "PLASTICA E METALLI" },
|
|
4
|
+
{ "date": "2025-12-03", "type": "ORGANICO" },
|
|
5
|
+
{ "date": "2025-12-04", "type": "VETRO" },
|
|
6
|
+
{ "date": "2025-12-05", "type": "CARTA E CARTONE" },
|
|
7
|
+
{ "date": "2025-12-06", "type": "ORGANICO" },
|
|
8
|
+
{ "date": "2025-12-08", "type": "ORGANICO" },
|
|
9
|
+
{ "date": "2025-12-09", "type": "PLASTICA E METALLI" },
|
|
10
|
+
{ "date": "2025-12-10", "type": "ORGANICO" },
|
|
11
|
+
{ "date": "2025-12-11", "type": "SECCO RESIDUO" },
|
|
12
|
+
{ "date": "2025-12-12", "type": "CARTA E CARTONE" },
|
|
13
|
+
{ "date": "2025-12-13", "type": "ORGANICO" },
|
|
14
|
+
{ "date": "2025-12-14", "type": "ORGANICO" },
|
|
15
|
+
{ "date": "2025-12-15", "type": "ORGANICO" },
|
|
16
|
+
{ "date": "2025-12-16", "type": "PLASTICA E METALLI" },
|
|
17
|
+
{ "date": "2025-12-17", "type": "ORGANICO" },
|
|
18
|
+
{ "date": "2025-12-18", "type": "VETRO" },
|
|
19
|
+
{ "date": "2025-12-19", "type": "CARTA E CARTONE" },
|
|
20
|
+
{ "date": "2025-12-20", "type": "ORGANICO" },
|
|
21
|
+
{ "date": "2025-12-22", "type": "ORGANICO" },
|
|
22
|
+
{ "date": "2025-12-23", "type": "PLASTICA E METALLI" },
|
|
23
|
+
{ "date": "2025-12-24", "type": "SECCO RESIDUO" },
|
|
24
|
+
{ "date": "2025-12-26", "type": "CARTA E CARTONE" },
|
|
25
|
+
{ "date": "2025-12-27", "type": "ORGANICO" },
|
|
26
|
+
{ "date": "2025-12-29", "type": "ORGANICO" },
|
|
27
|
+
{ "date": "2025-12-30", "type": "SECCO RESIDUO" },
|
|
28
|
+
{ "date": "2025-12-31", "type": "VETRO" }
|
|
29
|
+
]
|
package/db/2026-01.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[
|
|
2
|
+
{ "date": "2026-01-01", "type": "ORGANICO" },
|
|
3
|
+
{ "date": "2026-01-02", "type": "CARTA E CARTONE" },
|
|
4
|
+
{ "date": "2026-01-03", "type": "ORGANICO" },
|
|
5
|
+
{ "date": "2026-01-05", "type": "ORGANICO" },
|
|
6
|
+
{ "date": "2026-01-06", "type": "PLASTICA E METALLI" },
|
|
7
|
+
{ "date": "2026-01-07", "type": "ORGANICO" },
|
|
8
|
+
{ "date": "2026-01-08", "type": "VETRO" },
|
|
9
|
+
{ "date": "2026-01-09", "type": "CARTA E CARTONE" },
|
|
10
|
+
{ "date": "2026-01-10", "type": "ORGANICO" },
|
|
11
|
+
{ "date": "2026-01-12", "type": "ORGANICO" },
|
|
12
|
+
{ "date": "2026-01-13", "type": "PLASTICA E METALLI" },
|
|
13
|
+
{ "date": "2026-01-14", "type": "ORGANICO" },
|
|
14
|
+
{ "date": "2026-01-15", "type": "SECCO RESIDUO" },
|
|
15
|
+
{ "date": "2026-01-16", "type": "CARTA E CARTONE" },
|
|
16
|
+
{ "date": "2026-01-17", "type": "ORGANICO" },
|
|
17
|
+
{ "date": "2026-01-19", "type": "ORGANICO" },
|
|
18
|
+
{ "date": "2026-01-20", "type": "PLASTICA E METALLI" },
|
|
19
|
+
{ "date": "2026-01-21", "type": "ORGANICO" },
|
|
20
|
+
{ "date": "2026-01-22", "type": "VETRO" },
|
|
21
|
+
{ "date": "2026-01-23", "type": "CARTA E CARTONE" },
|
|
22
|
+
{ "date": "2026-01-24", "type": "ORGANICO" },
|
|
23
|
+
{ "date": "2026-01-26", "type": "ORGANICO" },
|
|
24
|
+
{ "date": "2026-01-27", "type": "PLASTICA E METALLI" },
|
|
25
|
+
{ "date": "2026-01-28", "type": "ORGANICO" },
|
|
26
|
+
{ "date": "2026-01-29", "type": "SECCO RESIDUO" },
|
|
27
|
+
{ "date": "2026-01-30", "type": "CARTA E CARTONE" },
|
|
28
|
+
{ "date": "2026-01-31", "type": "ORGANICO" }
|
|
29
|
+
]
|
package/db/2026-02.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[
|
|
2
|
+
{ "date": "2026-02-01", "type": "ORGANICO" },
|
|
3
|
+
{ "date": "2026-02-03", "type": "PLASTICA E METALLI" },
|
|
4
|
+
{ "date": "2026-02-04", "type": "ORGANICO" },
|
|
5
|
+
{ "date": "2026-02-05", "type": "VETRO" },
|
|
6
|
+
{ "date": "2026-02-06", "type": "CARTA E CARTONE" },
|
|
7
|
+
{ "date": "2026-02-07", "type": "ORGANICO" },
|
|
8
|
+
{ "date": "2026-02-09", "type": "ORGANICO" },
|
|
9
|
+
{ "date": "2026-02-10", "type": "PLASTICA E METALLI" },
|
|
10
|
+
{ "date": "2026-02-11", "type": "ORGANICO" },
|
|
11
|
+
{ "date": "2026-02-12", "type": "SECCO RESIDUO" },
|
|
12
|
+
{ "date": "2026-02-13", "type": "CARTA E CARTONE" },
|
|
13
|
+
{ "date": "2026-02-14", "type": "ORGANICO" },
|
|
14
|
+
{ "date": "2026-02-16", "type": "ORGANICO" },
|
|
15
|
+
{ "date": "2026-02-17", "type": "PLASTICA E METALLI" },
|
|
16
|
+
{ "date": "2026-02-18", "type": "ORGANICO" },
|
|
17
|
+
{ "date": "2026-02-19", "type": "VETRO" },
|
|
18
|
+
{ "date": "2026-02-20", "type": "CARTA E CARTONE" },
|
|
19
|
+
{ "date": "2026-02-21", "type": "ORGANICO" },
|
|
20
|
+
{ "date": "2026-02-23", "type": "ORGANICO" },
|
|
21
|
+
{ "date": "2026-02-24", "type": "PLASTICA E METALLI" },
|
|
22
|
+
{ "date": "2026-02-25", "type": "ORGANICO" },
|
|
23
|
+
{ "date": "2026-02-26", "type": "SECCO RESIDUO" },
|
|
24
|
+
{ "date": "2026-02-27", "type": "CARTA E CARTONE" },
|
|
25
|
+
{ "date": "2026-02-28", "type": "ORGANICO" }
|
|
26
|
+
]
|
package/db/2026-03.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[
|
|
2
|
+
{ "date": "2026-03-01", "type": "ORGANICO" },
|
|
3
|
+
{ "date": "2026-03-02", "type": "ORGANICO" },
|
|
4
|
+
{ "date": "2026-03-03", "type": "PLASTICA E METALLI" },
|
|
5
|
+
{ "date": "2026-03-04", "type": "ORGANICO" },
|
|
6
|
+
{ "date": "2026-03-05", "type": "VETRO" },
|
|
7
|
+
{ "date": "2026-03-06", "type": "CARTA E CARTONE" },
|
|
8
|
+
{ "date": "2026-03-07", "type": "ORGANICO" },
|
|
9
|
+
{ "date": "2026-03-09", "type": "ORGANICO" },
|
|
10
|
+
{ "date": "2026-03-10", "type": "PLASTICA E METALLI" },
|
|
11
|
+
{ "date": "2026-03-11", "type": "ORGANICO" },
|
|
12
|
+
{ "date": "2026-03-12", "type": "SECCO RESIDUO" },
|
|
13
|
+
{ "date": "2026-03-13", "type": "CARTA E CARTONE" },
|
|
14
|
+
{ "date": "2026-03-14", "type": "ORGANICO" },
|
|
15
|
+
{ "date": "2026-03-16", "type": "ORGANICO" },
|
|
16
|
+
{ "date": "2026-03-17", "type": "PLASTICA E METALLI" },
|
|
17
|
+
{ "date": "2026-03-18", "type": "ORGANICO" },
|
|
18
|
+
{ "date": "2026-03-19", "type": "VETRO" },
|
|
19
|
+
{ "date": "2026-03-20", "type": "CARTA E CARTONE" },
|
|
20
|
+
{ "date": "2026-03-21", "type": "ORGANICO" },
|
|
21
|
+
{ "date": "2026-03-23", "type": "ORGANICO" },
|
|
22
|
+
{ "date": "2026-03-24", "type": "PLASTICA E METALLI" },
|
|
23
|
+
{ "date": "2026-03-26", "type": "SECCO RESIDUO" },
|
|
24
|
+
{ "date": "2026-03-27", "type": "CARTA E CARTONE" },
|
|
25
|
+
{ "date": "2026-03-28", "type": "ORGANICO" },
|
|
26
|
+
{ "date": "2026-03-30", "type": "ORGANICO" },
|
|
27
|
+
{ "date": "2026-03-31", "type": "PLASTICA E METALLI" }
|
|
28
|
+
]
|
package/db/2026-04.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[
|
|
2
|
+
{ "date": "2026-04-01", "type": "ORGANICO" },
|
|
3
|
+
{ "date": "2026-04-02", "type": "VETRO" },
|
|
4
|
+
{ "date": "2026-04-03", "type": "CARTA E CARTONE" },
|
|
5
|
+
{ "date": "2026-04-04", "type": "ORGANICO" },
|
|
6
|
+
{ "date": "2026-04-07", "type": "PLASTICA E METALLI" },
|
|
7
|
+
{ "date": "2026-04-08", "type": "ORGANICO" },
|
|
8
|
+
{ "date": "2026-04-09", "type": "SECCO RESIDUO" },
|
|
9
|
+
{ "date": "2026-04-10", "type": "CARTA E CARTONE" },
|
|
10
|
+
{ "date": "2026-04-11", "type": "ORGANICO" },
|
|
11
|
+
{ "date": "2026-04-13", "type": "ORGANICO" },
|
|
12
|
+
{ "date": "2026-04-14", "type": "PLASTICA E METALLI" },
|
|
13
|
+
{ "date": "2026-04-15", "type": "ORGANICO" },
|
|
14
|
+
{ "date": "2026-04-16", "type": "VETRO" },
|
|
15
|
+
{ "date": "2026-04-17", "type": "CARTA E CARTONE" },
|
|
16
|
+
{ "date": "2026-04-18", "type": "ORGANICO" },
|
|
17
|
+
{ "date": "2026-04-20", "type": "ORGANICO" },
|
|
18
|
+
{ "date": "2026-04-21", "type": "PLASTICA E METALLI" },
|
|
19
|
+
{ "date": "2026-04-22", "type": "ORGANICO" },
|
|
20
|
+
{ "date": "2026-04-23", "type": "SECCO RESIDUO" },
|
|
21
|
+
{ "date": "2026-04-24", "type": "CARTA E CARTONE" },
|
|
22
|
+
{ "date": "2026-04-27", "type": "ORGANICO" },
|
|
23
|
+
{ "date": "2026-04-28", "type": "PLASTICA E METALLI" },
|
|
24
|
+
{ "date": "2026-04-29", "type": "ORGANICO" },
|
|
25
|
+
{ "date": "2026-04-30", "type": "VETRO" }
|
|
26
|
+
]
|
package/db/2026-05.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[
|
|
2
|
+
{ "date": "2026-05-02", "type": "ORGANICO" },
|
|
3
|
+
{ "date": "2026-05-04", "type": "ORGANICO" },
|
|
4
|
+
{ "date": "2026-05-05", "type": "PLASTICA E METALLI" },
|
|
5
|
+
{ "date": "2026-05-06", "type": "ORGANICO" },
|
|
6
|
+
{ "date": "2026-05-07", "type": "SECCO RESIDUO" },
|
|
7
|
+
{ "date": "2026-05-08", "type": "CARTA E CARTONE" },
|
|
8
|
+
{ "date": "2026-05-09", "type": "ORGANICO" },
|
|
9
|
+
{ "date": "2026-05-11", "type": "ORGANICO" },
|
|
10
|
+
{ "date": "2026-05-12", "type": "PLASTICA E METALLI" },
|
|
11
|
+
{ "date": "2026-05-13", "type": "ORGANICO" },
|
|
12
|
+
{ "date": "2026-05-14", "type": "VETRO" },
|
|
13
|
+
{ "date": "2026-05-15", "type": "CARTA E CARTONE" },
|
|
14
|
+
{ "date": "2026-05-16", "type": "ORGANICO" },
|
|
15
|
+
{ "date": "2026-05-18", "type": "ORGANICO" },
|
|
16
|
+
{ "date": "2026-05-19", "type": "PLASTICA E METALLI" },
|
|
17
|
+
{ "date": "2026-05-20", "type": "ORGANICO" },
|
|
18
|
+
{ "date": "2026-05-21", "type": "SECCO RESIDUO" },
|
|
19
|
+
{ "date": "2026-05-22", "type": "CARTA E CARTONE" },
|
|
20
|
+
{ "date": "2026-05-23", "type": "ORGANICO" },
|
|
21
|
+
{ "date": "2026-05-25", "type": "ORGANICO" },
|
|
22
|
+
{ "date": "2026-05-26", "type": "PLASTICA E METALLI" },
|
|
23
|
+
{ "date": "2026-05-27", "type": "ORGANICO" },
|
|
24
|
+
{ "date": "2026-05-28", "type": "VETRO" },
|
|
25
|
+
{ "date": "2026-05-29", "type": "CARTA E CARTONE" },
|
|
26
|
+
{ "date": "2026-05-30", "type": "ORGANICO" }
|
|
27
|
+
]
|
package/db/2026-06.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[
|
|
2
|
+
{ "date": "2026-06-01", "type": "ORGANICO" },
|
|
3
|
+
{ "date": "2026-06-03", "type": "ORGANICO" },
|
|
4
|
+
{ "date": "2026-06-04", "type": "SECCO RESIDUO" },
|
|
5
|
+
{ "date": "2026-06-05", "type": "CARTA E CARTONE" },
|
|
6
|
+
{ "date": "2026-06-06", "type": "ORGANICO" },
|
|
7
|
+
{ "date": "2026-06-08", "type": "ORGANICO" },
|
|
8
|
+
{ "date": "2026-06-09", "type": "PLASTICA E METALLI" },
|
|
9
|
+
{ "date": "2026-06-10", "type": "ORGANICO" },
|
|
10
|
+
{ "date": "2026-06-11", "type": "VETRO" },
|
|
11
|
+
{ "date": "2026-06-12", "type": "CARTA E CARTONE" },
|
|
12
|
+
{ "date": "2026-06-13", "type": "ORGANICO" },
|
|
13
|
+
{ "date": "2026-06-15", "type": "ORGANICO" },
|
|
14
|
+
{ "date": "2026-06-16", "type": "PLASTICA E METALLI" },
|
|
15
|
+
{ "date": "2026-06-17", "type": "ORGANICO" },
|
|
16
|
+
{ "date": "2026-06-18", "type": "SECCO RESIDUO" },
|
|
17
|
+
{ "date": "2026-06-19", "type": "CARTA E CARTONE" },
|
|
18
|
+
{ "date": "2026-06-20", "type": "ORGANICO" },
|
|
19
|
+
{ "date": "2026-06-22", "type": "ORGANICO" },
|
|
20
|
+
{ "date": "2026-06-23", "type": "PLASTICA E METALLI" },
|
|
21
|
+
{ "date": "2026-06-24", "type": "ORGANICO" },
|
|
22
|
+
{ "date": "2026-06-25", "type": "VETRO" },
|
|
23
|
+
{ "date": "2026-06-26", "type": "CARTA E CARTONE" },
|
|
24
|
+
{ "date": "2026-06-27", "type": "ORGANICO" },
|
|
25
|
+
{ "date": "2026-06-29", "type": "ORGANICO" },
|
|
26
|
+
{ "date": "2026-06-30", "type": "PLASTICA E METALLI" }
|
|
27
|
+
]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PM2 process file.
|
|
3
|
+
*
|
|
4
|
+
* Secrets and configuration are NOT stored here. They are read from a local
|
|
5
|
+
* `.env` file (gitignored) by `dotenv` at startup — see `.env.example`.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* pm2 start ecosystem.config.js
|
|
9
|
+
* pm2 restart trashbin-bot
|
|
10
|
+
* pm2 logs trashbin-bot
|
|
11
|
+
*/
|
|
12
|
+
module.exports = {
|
|
13
|
+
apps: [
|
|
14
|
+
{
|
|
15
|
+
name: 'trashbin-bot',
|
|
16
|
+
script: './trashbin-day-handler.js',
|
|
17
|
+
instances: 1,
|
|
18
|
+
autorestart: true,
|
|
19
|
+
watch: false,
|
|
20
|
+
max_memory_restart: '120M',
|
|
21
|
+
env: {
|
|
22
|
+
NODE_ENV: 'production'
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
};
|
package/lib/constants.js
ADDED
package/lib/utils.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const parseTargetChats = (envStr) => {
|
|
5
|
+
const env = envStr || process.env.TARGET_CHAT_ID || '';
|
|
6
|
+
if (!env) return [];
|
|
7
|
+
return env.split(',').map(s => s.trim()).filter(Boolean);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const pad2 = (n) => n.toString().padStart(2, '0');
|
|
11
|
+
|
|
12
|
+
const composeMessageForDate = (schedule, dateObj) => {
|
|
13
|
+
const yyyy = dateObj.getFullYear();
|
|
14
|
+
const mm = pad2(dateObj.getMonth() + 1);
|
|
15
|
+
const dd = pad2(dateObj.getDate());
|
|
16
|
+
const dateStr = `${yyyy}-${mm}-${dd}`;
|
|
17
|
+
const item = schedule.find((d) => d.date === dateStr);
|
|
18
|
+
const type = item ? item.type : 'UNKNOWN';
|
|
19
|
+
return { dateStr, type };
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Load the monthly schedule file (db/YYYY-MM.json) that contains the given date.
|
|
23
|
+
// Returns an empty array if the file is missing or unreadable.
|
|
24
|
+
const loadScheduleForDate = (dateObj, baseDir) => {
|
|
25
|
+
const projectRoot = baseDir || path.join(__dirname, '..');
|
|
26
|
+
const yyyy = dateObj.getFullYear();
|
|
27
|
+
const mm = pad2(dateObj.getMonth() + 1);
|
|
28
|
+
const file = path.join(projectRoot, 'db', `${yyyy}-${mm}.json`);
|
|
29
|
+
try {
|
|
30
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
console.error(`Could not load schedule ${yyyy}-${mm}.json:`, e.message);
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Look up the collection entry for a single date, loading the correct monthly
|
|
38
|
+
// file automatically. Handles month boundaries (e.g. today vs. tomorrow).
|
|
39
|
+
const getEntryForDate = (dateObj, baseDir) => {
|
|
40
|
+
const schedule = loadScheduleForDate(dateObj, baseDir);
|
|
41
|
+
return composeMessageForDate(schedule, dateObj);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const ensureLogsDir = (baseDir) => {
|
|
45
|
+
// resolve project root: either baseDir provided by callers (typically __dirname from project root)
|
|
46
|
+
// or the parent of this lib directory
|
|
47
|
+
const projectRoot = baseDir || path.join(__dirname, '..');
|
|
48
|
+
const logsDir = path.join(projectRoot, 'logs');
|
|
49
|
+
if (!fs.existsSync(logsDir)) fs.mkdirSync(logsDir, { recursive: true });
|
|
50
|
+
return path.join(logsDir, 'requests.log');
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const logRequest = (msg, requestsLogPath, baseDir) => {
|
|
54
|
+
try {
|
|
55
|
+
const chatId = msg.chat && (msg.chat.id || msg.chat.username || 'unknown');
|
|
56
|
+
const user = (msg.from && (msg.from.username || `${msg.from.first_name || ''} ${msg.from.last_name || ''}`.trim())) || 'unknown';
|
|
57
|
+
const ts = new Date().toISOString();
|
|
58
|
+
const line = `${ts} | chatId=${chatId} | user=${user}`;
|
|
59
|
+
// always log to stdout so pm2 captures it
|
|
60
|
+
console.log(line);
|
|
61
|
+
// optionally persist to file when WRITE_REQUESTS_LOG=true
|
|
62
|
+
if (process.env.WRITE_REQUESTS_LOG === 'true') {
|
|
63
|
+
try {
|
|
64
|
+
const filePath = requestsLogPath || ensureLogsDir(baseDir);
|
|
65
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
66
|
+
fs.appendFileSync(filePath, line + '\n');
|
|
67
|
+
} catch (e) {
|
|
68
|
+
console.error('Failed to append request to file:', e.message);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} catch (e) {
|
|
72
|
+
console.error('Failed to log request:', e.message);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// Subscribers are persisted as a plain JSON array of chat-id strings in
|
|
77
|
+
// subscribers.json at the project root. This file is runtime state (gitignored)
|
|
78
|
+
// and is kept separate from configuration/secrets in .env.
|
|
79
|
+
const subscribersFile = (baseDir) => {
|
|
80
|
+
const projectRoot = baseDir || path.join(__dirname, '..');
|
|
81
|
+
return path.join(projectRoot, 'subscribers.json');
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const getSubscribers = (baseDir) => {
|
|
85
|
+
const file = subscribersFile(baseDir);
|
|
86
|
+
try {
|
|
87
|
+
if (!fs.existsSync(file)) return [];
|
|
88
|
+
const data = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
89
|
+
if (!Array.isArray(data)) return [];
|
|
90
|
+
return data.map(String).map(s => s.trim()).filter(Boolean);
|
|
91
|
+
} catch (e) {
|
|
92
|
+
console.error('Failed to read subscribers.json:', e.message);
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const writeSubscribers = (list, baseDir) => {
|
|
98
|
+
const file = subscribersFile(baseDir);
|
|
99
|
+
try {
|
|
100
|
+
fs.writeFileSync(file, JSON.stringify(list, null, 2) + '\n', 'utf8');
|
|
101
|
+
return true;
|
|
102
|
+
} catch (e) {
|
|
103
|
+
console.error('Failed to write subscribers.json:', e.message);
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const subscribeChat = (chatId, baseDir) => {
|
|
109
|
+
const set = new Set(getSubscribers(baseDir));
|
|
110
|
+
set.add(String(chatId));
|
|
111
|
+
return writeSubscribers(Array.from(set), baseDir);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const unsubscribeChat = (chatId, baseDir) => {
|
|
115
|
+
const list = getSubscribers(baseDir).filter(id => id !== String(chatId));
|
|
116
|
+
return writeSubscribers(list, baseDir);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
module.exports = {
|
|
120
|
+
parseTargetChats,
|
|
121
|
+
composeMessageForDate,
|
|
122
|
+
loadScheduleForDate,
|
|
123
|
+
getEntryForDate,
|
|
124
|
+
ensureLogsDir,
|
|
125
|
+
logRequest,
|
|
126
|
+
getSubscribers,
|
|
127
|
+
subscribeChat,
|
|
128
|
+
unsubscribeChat
|
|
129
|
+
};
|
|
130
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "trashbin-scheduler-bot-tg",
|
|
3
|
+
"version": "1.1.2",
|
|
4
|
+
"description": "Telegram bot that sends daily waste-collection reminders from a municipal pickup calendar.",
|
|
5
|
+
"main": "trashbin-day-handler.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"trashbin-scheduler-bot": "trashbin-day-handler.js"
|
|
8
|
+
},
|
|
9
|
+
"license": "MPL-2.0",
|
|
10
|
+
"author": "khalld",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/khalld/trashbin-scheduler-bot-tg.git"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/khalld/trashbin-scheduler-bot-tg/issues"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/khalld/trashbin-scheduler-bot-tg#readme",
|
|
19
|
+
"keywords": [
|
|
20
|
+
"telegram",
|
|
21
|
+
"telegram-bot",
|
|
22
|
+
"waste-collection",
|
|
23
|
+
"recycling",
|
|
24
|
+
"scheduler",
|
|
25
|
+
"raspberry-pi"
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=20"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"trashbin-day-handler.js",
|
|
32
|
+
"lib/",
|
|
33
|
+
"db/",
|
|
34
|
+
"ecosystem.config.js",
|
|
35
|
+
".env.example"
|
|
36
|
+
],
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"start": "node trashbin-day-handler.js",
|
|
42
|
+
"build": "ncc build trashbin-day-handler.js -o dist --minify"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"dotenv": "^16.4.5",
|
|
46
|
+
"node-telegram-bot-api": "^0.66.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@vercel/ncc": "^0.38.1"
|
|
50
|
+
}
|
|
51
|
+
}
|