-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnewmakerbot.js
More file actions
119 lines (103 loc) · 3.84 KB
/
newmakerbot.js
File metadata and controls
119 lines (103 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*---------------------------------------------------------------------------
BOT BIENVENIDA PARA NUEVOS SOCIOS DE MakersUPV
Este bot permite facilitar la entrada de un nuevo miembro al grupo de MakersUPV
para ello le da la bienvenida y le invita a realizar un cuestionario de
bienvenida.
Creación y matenimiento: Jaime Laborda - jaimelaborda@gmail.com
----------------------------------------------------------------------------*/
require("dotenv").config();
const Telegraf = require("telegraf");
const token = process.env.TELEGRAM_BOT_TOKEN;
const bot = new Telegraf(token);
const enlace_formulario = 'http://makersupv.com/hazte-maker'
bot.command("testbot", ctx => {
const { first_name } = ctx.from;
ctx.reply("Hola " + first_name + ", estoy vivo!");
});
{
const commitSHA = require("child_process")
.execSync("git rev-parse HEAD")
.toString()
.trim();
const shortCommitSHA = commitSHA.slice(0, 7);
const { version, name, homepage } = require("./package.json");
const commitUrl = new (require("url")).URL(`commit/${commitSHA}`, homepage);
bot.command("version", ctx => {
ctx.reply(
`${name} v${version}
Running commit [${shortCommitSHA}](${commitUrl})`,
{ parse_mode: "markdown" }
);
});
}
const ranapepe = [
"CAADBAADOQ4AAjZHEwABYUGtfJvIDiAC",
"CAADBAADbAYAAjZHEwABe0Wm_QNyWgcC",
"CAADBAADXgYAAjZHEwAB-2vZhZcVhRMC",
"CAADBAADhAYAAjZHEwABY_4JnOLbxX0C",
"CAADBAADhgYAAjZHEwABp_fhAiD4_GEC",
"CAADBAADdgYAAjZHEwABx9tJw309ZgABAg",
"CAADBAADXAYAAjZHEwABabKzEznrA-wC",
"CAADBAADWAYAAjZHEwABHT5IHCj5Tt4C",
"CAADBAADxw8AAjZHEwAB2twhZ_iM-jwC",
"CAADBAADfgYAAjZHEwABqUjJxUJ9ifgC",
"CAADBAADgAYAAjZHEwABbgj3xbMopMcC"
];
const preguntas = [
"¿Que son 8 bocabits?: ",
"Razona, ¿Edison o Tesla?: ",
"¿Cual es la gran respuesta del universo?: ",
"¿Cual es el Hola Mundo de Arduino?: ",
"Si tiramos una piedra roja en el mar azul, ¿qué le pasará?: ",
"¿1 + 1 = 10?: "
];
bot.command("ranapepe", ctx => {
const chatId = ctx.chat.id;
const random = Math.floor(Math.random() * ranapepe.length); //Del 0 al 10
console.log("Random: " + random);
ctx.telegram.sendSticker(chatId, ranapepe[random]);
});
//Cuando un nuevo usuario
bot.on("new_chat_members", ctx => {
console.log(ctx.message.new_chat_participant);
const {
first_name,
last_name,
id,
is_bot
} = ctx.message.new_chat_participant;
if (is_bot) return;
/**
* Semillas para preguntas aleatorias
*
* Para que no salga la misma en las dos, para la segunda semilla retiramos una de las
* posibilidades. Si sale la misma en la primera y segunda, elegimos la posibilidad que
* retiramos. Así siempre existe la misma probabilidad de escoger cada opción, y no creamos un
* (posible) bucle infinito.
*/
const seed1 = Math.floor(Math.random() * preguntas.length);
let seed2 = Math.floor(Math.random() * (preguntas.length - 1));
if (seed1 === seed2) seed2 = preguntas.length - 1;
ctx.reply(
// Esta es la forma correcta de mencionar a alguien que no tiene nombre de usuario
// Sacado de https://core.telegram.org/bots/api#formatting-options
`¡Hola [${first_name}](tg://user?id=${id})!, bienvenidx al grupo de MakersUPV.`,
{ parse_mode: "markdown" }
);
ctx.reply(
`🤖 CUESTIONARIO DE BIENVENIDA PARA NUEV@S MAKERS 🤖
(respondiendo este formulario ganarás mil minipuntos makers)
Nombre: ${first_name} ${last_name || ""}
Apodo:
Estudio...:
¿Qué quiero crear?:
¿Cuáles son mis súperpoderes?:
¿Qué quiero aprender en MakersUPV?:
${preguntas[seed1]}
${preguntas[seed2]}
IMPORTANTE
No te olvides rellenar el formulario de la web: ${enlace_formulario}
Una vez terminado este ritual pasarás a ser aceptado por parte del resto de la comunidad! ✨`
);
});
bot.startPolling();