mirror of
https://github.com/thedevs-network/the-guard-bot
synced 2025-08-31 06:05:22 +00:00
initial
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
config.json
|
14
index.js
Normal file
14
index.js
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
// validate config
|
||||
require('child_process').execSync('node init.js', { stdio: 'inherit' });
|
||||
|
||||
const { loadJSON } = require('./utils/json');
|
||||
const Telegraf = require('telegraf');
|
||||
|
||||
const config = loadJSON('config.json');
|
||||
|
||||
const bot = new Telegraf(config.token);
|
||||
|
||||
|
||||
bot.startPolling();
|
36
init.js
Normal file
36
init.js
Normal file
@@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
const { createInterface } = require('readline');
|
||||
const { loadJSON, saveJSON } = require('./utils/json');
|
||||
|
||||
function loadConfig() {
|
||||
try {
|
||||
return loadJSON('config.json');
|
||||
} catch (err) {
|
||||
return {
|
||||
token: 'token'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function validateConfig(input, config) {
|
||||
config = Object.assign({}, config);
|
||||
for (const key in config) {
|
||||
while (config[key] === key || config[key] === '') {
|
||||
console.log('Enter ' + key + ': ');
|
||||
config[key] = (await input()).trim();
|
||||
}
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
const rl = createInterface({ input: process.stdin });
|
||||
|
||||
const line = () =>
|
||||
new Promise(resolve =>
|
||||
rl.once('line', resolve));
|
||||
|
||||
validateConfig(line, loadConfig()).then(config =>
|
||||
(saveJSON('config.json', config),
|
||||
rl.close(),
|
||||
console.log('Config OK')));
|
23
package.json
Normal file
23
package.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "thedevs_bot",
|
||||
"version": "0.1.0",
|
||||
"description": "Official Bot for TheDevs Network!",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/TheDevs-Network/bot.git"
|
||||
},
|
||||
"keywords": [
|
||||
"bot",
|
||||
"thedevs"
|
||||
],
|
||||
"author": "Thomas Rory Gummerson <thomas@gummerson.no> (https://trgwii.no)",
|
||||
"license": "Beerware",
|
||||
"bugs": {
|
||||
"url": "https://github.com/TheDevs-Network/bot/issues"
|
||||
},
|
||||
"homepage": "https://github.com/TheDevs-Network/bot#readme"
|
||||
}
|
10
utils/json.js
Normal file
10
utils/json.js
Normal file
@@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const { readFileSync, writeFileSync } = require('fs');
|
||||
|
||||
const loadJSON = file => JSON.parse(readFileSync(file, 'utf8'));
|
||||
|
||||
const saveJSON = (file, data) => writeFileSync(file,
|
||||
JSON.stringify(data, undefined, '\t'));
|
||||
|
||||
module.exports = { loadJSON, saveJSON };
|
Reference in New Issue
Block a user