init
This commit is contained in:
		
							
								
								
									
										128
									
								
								config.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										128
									
								
								config.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,128 @@
 | 
				
			|||||||
 | 
					const fs = require('fs');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const Markup = require('telegraf/markup');
 | 
				
			||||||
 | 
					const Extra = require('telegraf/extra');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const example_lang = require('./lang.js');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//=== TOOL FUNCTIONS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Here you usualy write util functions that are used multiple times in the code (or a second file is recommended)*/ 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//=== MAIN MODULE CONFIG
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module.exports = function(){
 | 
				
			||||||
 | 
						return {
 | 
				
			||||||
 | 
						name : "recipe", //Unique Module name
 | 
				
			||||||
 | 
						key : "rcp", //Unique Key for this module, if multiple instances add a number/text to it
 | 
				
			||||||
 | 
						version : 0.1, //Version Number, Currently unused
 | 
				
			||||||
 | 
						requirements : {
 | 
				
			||||||
 | 
							gps: false, //Currently un-used (all module have access to GPS)
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						text : [
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								trigger : ["/recipes"], //Array of Triggers
 | 
				
			||||||
 | 
								public : true, //Should it be shown to user (user can still run the command without knowing it exists)
 | 
				
			||||||
 | 
								desc : {0:"Pings the user",
 | 
				
			||||||
 | 
										1:"Envois un ping à l'utilisateur",
 | 
				
			||||||
 | 
										2:"Yu-za- de pingu wo tsukawashite",
 | 
				
			||||||
 | 
										3:"*insert arabic*",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								requirements : (bot,event,message)=>{ 
 | 
				
			||||||
 | 
									return new Promise((resolve, reject)=>{
 | 
				
			||||||
 | 
										if (false)
 | 
				
			||||||
 | 
											return reject(400);
 | 
				
			||||||
 | 
										return resolve(200);
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								action : (bot,event,message)=>{
 | 
				
			||||||
 | 
									return event.reply("pong");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						],
 | 
				
			||||||
 | 
						reply : [
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								requirements : (bot,event,message)=>{
 | 
				
			||||||
 | 
									return new Promise((resolve,reject)=>{
 | 
				
			||||||
 | 
										if(!message.text || message.reply_to_message.text != "Beep")
 | 
				
			||||||
 | 
											return reject(400);
 | 
				
			||||||
 | 
										return resolve(200);
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								action : (bot,event,message)=>{
 | 
				
			||||||
 | 
									return event.reply(bot.gls(example_lang,"boop",event.master.lang));
 | 
				
			||||||
 | 
									//The GLS functions returns automaticly the right message given the "key" and lang...
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						],
 | 
				
			||||||
 | 
						regex : [
 | 
				
			||||||
 | 
						],
 | 
				
			||||||
 | 
						media : [
 | 
				
			||||||
 | 
						],
 | 
				
			||||||
 | 
						callback : [
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								trigger : 'key_template',
 | 
				
			||||||
 | 
								requirements : (bot,event,message)=>{ 
 | 
				
			||||||
 | 
									return new Promise((resolve, reject)=>{
 | 
				
			||||||
 | 
										return resolve(200);
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								action : (bot,event,data)=>{
 | 
				
			||||||
 | 
									return event.reply("Beep");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						],
 | 
				
			||||||
 | 
						inline : [
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								public : true,
 | 
				
			||||||
 | 
								desc : {
 | 
				
			||||||
 | 
									0:"English",
 | 
				
			||||||
 | 
									1:"French",
 | 
				
			||||||
 | 
									2:"Japanese",
 | 
				
			||||||
 | 
									3:"Arabic",
 | 
				
			||||||
 | 
									4:"German",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								reply : (bot,event,data)=>{
 | 
				
			||||||
 | 
									return {
 | 
				
			||||||
 | 
										type: 'article',
 | 
				
			||||||
 | 
										id: 'aid',
 | 
				
			||||||
 | 
								        title: 'BEEP Template',
 | 
				
			||||||
 | 
								        description: "Template Module",
 | 
				
			||||||
 | 
								        message_text: "BEEP BOP",
 | 
				
			||||||
 | 
								        parse_mode:"Markdown",
 | 
				
			||||||
 | 
								        reply_markup:Markup.inlineKeyboard([]),
 | 
				
			||||||
 | 
								    };
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						],
 | 
				
			||||||
 | 
						new_member : (bot,event)=>{
 | 
				
			||||||
 | 
							//return event.replyWithMarkdown("Welcome !");
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						weburl : [
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								url : '_',
 | 
				
			||||||
 | 
								post_action : (bot,req,rep)=>{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								get_action : (bot,req,rep)=>{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						],
 | 
				
			||||||
 | 
						cron : [
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								cstr : '0 0 * * * *',
 | 
				
			||||||
 | 
								params : [ null, true],
 | 
				
			||||||
 | 
								timezone : 'Europe/Zurich',
 | 
				
			||||||
 | 
								action : function(bot){
 | 
				
			||||||
 | 
									this.bot = bot;
 | 
				
			||||||
 | 
									return function(){
 | 
				
			||||||
 | 
										return this.bot.telegram.sendMessage("0","Beep",{"parse_mode":"Markdown"});
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										39
									
								
								db_low.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								db_low.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
				
			|||||||
 | 
					const low = require('lowdb');
 | 
				
			||||||
 | 
					const FileSync = require('lowdb/adapters/FileSync');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var db = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function db_init(db){
 | 
				
			||||||
 | 
						db.defaults({ chats:[]}).write();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var dbc = function(name){
 | 
				
			||||||
 | 
						const db_file = "./db/"+name+".json";
 | 
				
			||||||
 | 
						var db = low(new FileSync(db_file));
 | 
				
			||||||
 | 
						db_init(db);
 | 
				
			||||||
 | 
						return db;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const schema = {
 | 
				
			||||||
 | 
						recipe:{
 | 
				
			||||||
 | 
							id: "reciple_id",
 | 
				
			||||||
 | 
							name:"recipe_name",
 | 
				
			||||||
 | 
							ingredients:"recipe_ingredients",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						ingredient:{
 | 
				
			||||||
 | 
							id: "ingredient_id",
 | 
				
			||||||
 | 
							name: ""
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module.exports = function(name){
 | 
				
			||||||
 | 
						this.name = name;
 | 
				
			||||||
 | 
						this.db = dbc(name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						this.dump_db = function(obj){
 | 
				
			||||||
 | 
							return new Promise((resolve, reject)=>{
 | 
				
			||||||
 | 
								resolve(this.db.get("chats").value());
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										17
									
								
								lang.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								lang.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					module.exports = {
 | 
				
			||||||
 | 
						"beep":{
 | 
				
			||||||
 | 
							0: `English Beep`,
 | 
				
			||||||
 | 
							1: `French Beep`,
 | 
				
			||||||
 | 
							2: `Japanese Beep`,
 | 
				
			||||||
 | 
							3: `Arabic Beep`,
 | 
				
			||||||
 | 
							4: `German Beep`,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						"boop":{
 | 
				
			||||||
 | 
							0: `English Boop`,
 | 
				
			||||||
 | 
							1: `French Boop`,
 | 
				
			||||||
 | 
							2: `Japanese Boop`,
 | 
				
			||||||
 | 
							3: `Arabic Boop`,
 | 
				
			||||||
 | 
							4: `German Boop`,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						//...
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										5
									
								
								recipes.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								recipes.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
						"ingredients":[
 | 
				
			||||||
 | 
							{"flour":5}
 | 
				
			||||||
 | 
						]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user