Commit 41cd6875 by Иван Кубота

added migrations

parent d0b83ebd
{
"dev": {
"driver": "mysql",
"database": "tg_bot",
"user": "root",
"password": {"ENV": "DEVELOP_MYSQL_PASSWORD"}
}
}
\ No newline at end of file
...@@ -2,7 +2,7 @@ module.exports = { ...@@ -2,7 +2,7 @@ module.exports = {
"ban": "Пользователь {{$first_name}} {{$last_name}} был забанен лопатой.", "ban": "Пользователь {{$first_name}} {{$last_name}} был забанен лопатой.",
"warn": "Пользователь {{$first_name}} {{$last_name}} получает {{$count}} предупреждение из {{$maxWarns}}, осталось {{$diff}} {{plural:$diff,предупреждение,предупреждения,предупреждений}}", "warn": "Пользователь {{$first_name}} {{$last_name}} получает {{$count}} предупреждение из {{$maxWarns}}, осталось {{$diff}} {{plural:$diff,предупреждение,предупреждения,предупреждений}}",
"unban": "Пользователя {{$full_name}} пришлось разбанить.", "unban": "Пользователя {{$full_name}} пришлось разбанить.",
"unbanGreeting": "Ты разбанены в {{$title}}", "unbanGreeting": "Ты разбанен в {{$title}}",
"pidor": "{{$first_name}}, ты — {{$condition?пацак:чатланин}}, а эта планета {{$condition?чатланская:пацакская}}.\n\nСчитай до {{$count}}.", "pidor": "{{$first_name}}, ты — {{$condition?пацак:чатланин}}, а эта планета {{$condition?чатланская:пацакская}}.\n\nСчитай до {{$count}}.",
"pidorDoNotCount1": "Считай, кому говорят", "pidorDoNotCount1": "Считай, кому говорят",
...@@ -23,5 +23,7 @@ module.exports = { ...@@ -23,5 +23,7 @@ module.exports = {
"newLocale": "Теперь напиши боту лично. У тебя есть на это 15 минут, поторопись.", "newLocale": "Теперь напиши боту лично. У тебя есть на это 15 минут, поторопись.",
"linkToUI": "Секретная ссылка! {{$link}}", "linkToUI": "Секретная ссылка! {{$link}}",
"_noSuchTemplate": "No such template: {{$string}}",
"_plural": "plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)" "_plural": "plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)"
}; };
\ No newline at end of file
'use strict';
var dbm;
var type;
var seed;
/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
};
exports.up = function(db, callback) {
return null;
};
exports.down = function(db, callback) {
return null;
};
exports._meta = {
"version": 1
};
'use strict';
const async = require('async');
var dbm;
var type;
var seed;
/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
};
exports.up = function(db, callback){
const locale = require( '../locale/locale.ru' );
const queries = [
db.createTable.bind( db, 'chat', {
columns: {
id: {
type: 'bigint',
primaryKey: true
}
},
ifNotExists: true
} ),
db.createTable.bind( db, 'chat', {
columns: {
id: {
type: 'bigint',
primaryKey: true
}
},
ifNotExists: true
} ),
db.createTable.bind( db, 'user', {
columns: {
userID: {
type: 'bigint'
},
chatID: {
type: 'bigint'
},
data: {
type: 'string'
}
},
ifNotExists: true
} ),
db.addIndex.bind( db, 'user', 'user_chat', [ 'chatID', 'userID' ], true ),
db.createTable.bind( db, 'locale', {
columns: {
k: { type: 'string' },
v: { type: 'string' }
},
ifNotExists: true
} )
];
for(const k in locale){
queries.push(db.insert.bind(db,'locale', ['k', 'v'], [k, locale[k]]));
}
return async.series(queries, callback)
};
exports.down = function(db, callback) {
db.dropTable('chat', function(err) {
if (err) { callback(err); return; }
db.dropTable('user', function(err) {
if (err) { callback(err); return; }
db.removeIndex('user', 'user_chat', function(err) {
if (err) { callback(err); return; }
db.dropTable('locale', function(err) {
if (err) { callback(err); return; }
callback();
})
})
})
});
};
exports._meta = {
"version": 1
};
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"localize.js": "^2.0.1", "async": "^3.1.0",
"json5": "^2.1.0",
"localize.js": "^2.0.2",
"ms": "^2.1.2", "ms": "^2.1.2",
"node-telegram-bot-api": "^0.30.0" "node-telegram-bot-api": "^0.30.0"
}, },
......
...@@ -2,20 +2,43 @@ const {Reply, Answer} = require('./Model/Event'), ...@@ -2,20 +2,43 @@ const {Reply, Answer} = require('./Model/Event'),
{Choose} = require('./Model/Choose'), {Choose} = require('./Model/Choose'),
L = require('localize.js')('ru', require('./locale/locale.ru')); L = require('localize.js')('ru', require('./locale/locale.ru'));
const JSON5 = require('json5');
const maxWarns = 3; const maxWarns = 3;
module.exports = [
Answer('/test {{$string}}', function(msg, match) { const testFn = function(msg, match) {
var tmp = L.L.variableResolveFailed; console.log(match);
L.L.variableResolveFailed = function(varName) {
return '${'+varName+'}'; var tmp = L.L.variableResolveFailed;
}; L.L.variableResolveFailed = function(varName) {
console.log(varName);
return '${'+varName+'}';
};
if(match.string in L.voc){
const data = { ...msg.chat, ...msg.user, ...(match.data || {}) };
msg.reply( msg.reply(
'Template: '+L.voc[match.string]+'\n'+ 'Template: ' + L.voc[ match.string ] + '\n' +
'Result: '+L(match.string, {...msg.chat, ...msg.user}) 'Result: ' + L( match.string, data )
); );
L.L.variableResolveFailed = tmp; }else{
msg.reply(L('_noSuchTemplate', match));
}
L.L.variableResolveFailed = tmp;
};
module.exports = [
Answer('/test {{$string}} \{{{$options}}\}', (msg, match)=>{
const json = '{' + match.options + '}';
try{
match.data = JSON5.parse( json );
}catch(e){
match.data = {};
msg.reply('JSON parse error: \n'+e.toString().replace(/JSON5:\s*/g,''));
}
return testFn(msg,match);
}), }),
Answer('/test {{$string}}', testFn),
Answer('/help', function(message) { Answer('/help', function(message) {
message.send( message.send(
'List of commands:\n'+ 'List of commands:\n'+
...@@ -64,7 +87,7 @@ module.exports = [ ...@@ -64,7 +87,7 @@ module.exports = [
message.reply('Ti pidor') message.reply('Ti pidor')
}), }),
Answer('/say {{$kokoko}}') Answer('/echo {{$kokoko}}')
.then((message, match)=>{ .then((message, match)=>{
message.send(match.kokoko) message.send(match.kokoko)
}), }),
......
This diff is collapsed. Click to expand it.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment