mirror of
https://github.com/thedevs-network/the-guard-bot
synced 2025-08-31 14:15:25 +00:00
More fixes
This commit is contained in:
9
index.js
9
index.js
@@ -26,10 +26,17 @@ const config = loadJSON('config.json');
|
|||||||
|
|
||||||
const bot = new Telegraf(config.token);
|
const bot = new Telegraf(config.token);
|
||||||
|
|
||||||
bot.command('admin', ({ message, reply }) => {
|
bot.command('admin', async ({ message, reply }) => {
|
||||||
|
if (message.from.id !== config.masterID) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const userToAdmin = message.reply_to_message
|
const userToAdmin = message.reply_to_message
|
||||||
? message.reply_to_message.from
|
? message.reply_to_message.from
|
||||||
: message.from;
|
: message.from;
|
||||||
|
|
||||||
|
if (await admins.isAdmin(userToAdmin)) {
|
||||||
|
return reply('Already admin');
|
||||||
|
}
|
||||||
return admins.admin(userToAdmin).then(() =>
|
return admins.admin(userToAdmin).then(() =>
|
||||||
reply('Admined ' + link(userToAdmin), replyOptions));
|
reply('Admined ' + link(userToAdmin), replyOptions));
|
||||||
});
|
});
|
||||||
|
16
init.js
16
init.js
@@ -4,6 +4,11 @@ const { existsSync, mkdirSync } = require('fs');
|
|||||||
const { createInterface } = require('readline');
|
const { createInterface } = require('readline');
|
||||||
const { loadJSON, saveJSON } = require('./utils/json');
|
const { loadJSON, saveJSON } = require('./utils/json');
|
||||||
|
|
||||||
|
const defaultConfig = {
|
||||||
|
masterID: 'masterID',
|
||||||
|
token: 'token'
|
||||||
|
};
|
||||||
|
|
||||||
function dirs() {
|
function dirs() {
|
||||||
if (!existsSync('data')) {
|
if (!existsSync('data')) {
|
||||||
mkdirSync('data');
|
mkdirSync('data');
|
||||||
@@ -14,19 +19,20 @@ function loadConfig() {
|
|||||||
try {
|
try {
|
||||||
return loadJSON('config.json');
|
return loadJSON('config.json');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return {
|
return defaultConfig;
|
||||||
token: 'token'
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function validateConfig(input, config) {
|
async function validateConfig(input, config) {
|
||||||
config = Object.assign({}, config);
|
config = Object.assign({}, defaultConfig, config);
|
||||||
for (const key in config) {
|
for (const key in config) {
|
||||||
while (config[key] === key || config[key] === '') {
|
while (config[key] === key || config[key] === '') {
|
||||||
console.log('Enter ' + key + ': ');
|
console.log('Enter ' + key + ': ');
|
||||||
/* eslint no-await-in-loop: "off" */
|
/* eslint no-await-in-loop: "off" */
|
||||||
config[key] = (await input()).trim();
|
const value = (await input()).trim();
|
||||||
|
config[key] = Number.isNaN(Number(value))
|
||||||
|
? value
|
||||||
|
: Number(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
|
Reference in New Issue
Block a user