Skip to content

Commit 931a65b

Browse files
authored
Ngve typescript (#259)
* feat(core): add typescript to api endpoints and utils * fix(chore): updated deps and moved scripts * feat(typescript): add types and eslint
1 parent 367cabe commit 931a65b

36 files changed

+3343
-1681
lines changed

.eslintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.now
3+
.github
4+
.env
5+
.eslintrc.js

.eslintrc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
root: true,
3+
parser: "@typescript-eslint/parser",
4+
parserOptions: {
5+
project: ["./tsconfig.json"]
6+
},
7+
plugins: ["@typescript-eslint"],
8+
extends: ["airbnb-typescript/base", "prettier/@typescript-eslint"],
9+
env: {
10+
node: true
11+
},
12+
rules: {
13+
"no-console": "off"
14+
}
15+
};

api/_utils/config.js

Lines changed: 0 additions & 42 deletions
This file was deleted.

api/_utils/config.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const config = {
2+
whiteListedDomains: [
3+
"https://github.com",
4+
"https://medium.com",
5+
"https://twitter.com"
6+
],
7+
githubFeeds: [
8+
{
9+
name: "angular",
10+
repo: "angular/angular",
11+
hasChangelog: true,
12+
feed: "https://github.com/angular/angular/releases.atom"
13+
},
14+
{
15+
name: "ionic",
16+
repo: "driftyco/ionic",
17+
hasChangelog: true,
18+
feed: "https://github.com/driftyco/ionic/releases.atom"
19+
},
20+
{
21+
name: "nativescript",
22+
repo: "NativeScript/NativeScript",
23+
hasChangelog: true,
24+
feed: "https://github.com/NativeScript/NativeScript/releases.atom"
25+
},
26+
{
27+
name: "wengy-ven",
28+
repo: "ngVenezuela/wengy-ven",
29+
hasChangelog: true,
30+
feed: "https://github.com/ngVenezuela/wengy-ven/releases.atom"
31+
}
32+
],
33+
blogFeeds: [
34+
{
35+
name: "Blog oficial de ngvenezuela",
36+
feed: "https://dev.to/feed/ngvenezuela"
37+
}
38+
]
39+
};
40+
41+
export default config;

api/_utils/messages.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

api/_utils/messages.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const messages: { [index: string]: any } = {
2+
welcome: "Hola #{name}, ¡Bienvenid@ a ngVenezuela!. Te invitamos a ".concat(
3+
"seguirnos en twitter como [@ngVenezuela](https://twitter.com/ngVenezuela) ",
4+
"y a mirar nuestra comunidad en Github: https://github.com/ngvenezuela.\n\n",
5+
"Además nos gustaría que respondieras esta pequeña encuesta: http://bit.ly/ngve-encuesta"
6+
),
7+
goodBye:
8+
"¡Nos vemos pronto #{name}! Esperamos NO verte por el grupo de React Venezuela",
9+
goodMornings: {
10+
mondays: [
11+
"Buenos días comunidad, ¡Que tengan un excelente inicio de semana! \u{1F60E}"
12+
],
13+
fridays: [
14+
"Buenos días. Recuerden que los viernes no se hacen deploy \u{1F601}",
15+
"Buenos días. ¡Hoy es viernes y el hardware lo sabe!",
16+
"Buenos días comunidad. Feliz viernes",
17+
"Buenos días. Hoy cualquier bug es un feature después de las 4pm"
18+
],
19+
generic: [
20+
"Buenos días...¿tomaron café? \u{2615}",
21+
"Buenos días. Recuerden que detrás de una persona exitosa ".concat(
22+
"está una gran cantidad de café \u{2615}"
23+
),
24+
"Buenos días. Keep calm and drink \u{2615}",
25+
"Buenos días \u{1F601}\u{2615}",
26+
"Buenos días",
27+
"Buenos días a todos",
28+
"Buenos días comunidad",
29+
"Buenos días #ngPanas",
30+
"Buenos días comunidad, Y como dice @cesarfrick: ¡A trabajar, ".concat(
31+
"vagos! Que los yates de sus jefes no se pagan solos"
32+
)
33+
]
34+
},
35+
newBlogPost: "*#{author}* ha agregado una nueva entrada al blog titulada: ".concat(
36+
"*#{title}* y está disponible en: #{link}"
37+
),
38+
newTweet: "#ngVenezuelaTweet \u{1F426}\n".concat(
39+
"#{tweetText}\n",
40+
"----\n",
41+
"Puedes ver el Tweet aquí: #{tweetUrl}"
42+
),
43+
githubRelease: "*#{name}* acaba de alcanzar la versión *#{version}*\n\n".concat(
44+
"[Puedes ver los cambios aquí](#{url})"
45+
),
46+
githubOpenVeLink:
47+
"El enlace de github para comunidades de Telegram es: https://github.com/OpenVE/comunidades-en-telegram",
48+
gistCreated:
49+
"gist creado por #{fullName} #{user} para https://t.me/ngvenezuela con https://github.com/ngVenezuela/wengy-ven",
50+
gistRecommendation:
51+
"Utiliza el comando /gist _codigo_ para generar un gist en github"
52+
};
53+
54+
export default messages;

api/_utils/telegram/admin.js

Lines changed: 0 additions & 63 deletions
This file was deleted.

api/_utils/telegram/admin.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import config from "../config";
2+
import { forwardMessage, sendMessage } from "./bot-methods";
3+
import { Chat, Message } from "./interfaces";
4+
5+
const { MAIN_GROUP_ID, ADMIN_GROUP_ID } = process.env;
6+
7+
export const getChatType = async (message: Message) => {
8+
const {
9+
chat: { id: chatId }
10+
} = message;
11+
12+
if (chatId.toString() === MAIN_GROUP_ID) {
13+
return "main";
14+
}
15+
16+
if (chatId.toString() === ADMIN_GROUP_ID) {
17+
return "admin";
18+
}
19+
20+
return "private";
21+
};
22+
23+
/**
24+
* Send main or admin's group id.
25+
* This will be used in your .env
26+
*/
27+
export const sendGroupId = async ({ id: chatId, type }: Chat) => {
28+
if (["group", "supergroup"].includes(type)) {
29+
await sendMessage({
30+
chatId,
31+
text: `Tú variable \`mainGroupId/adminGroupId\` es: ${chatId}`
32+
});
33+
}
34+
};
35+
36+
export const verifyUrls = async (message: Message) => {
37+
const type = await getChatType(message);
38+
39+
if (message.text && type === "main") {
40+
const urlEntities = message.entities
41+
? message.entities.filter(entity => entity.type === "url")
42+
: [];
43+
if (urlEntities.length > 0) {
44+
const urls = urlEntities.map(entity =>
45+
message
46+
.text!.slice(entity.offset, entity.length + entity.offset)
47+
.replace("https://www.", "https://")
48+
);
49+
50+
const arePostedUrlsPermitted = urls.every(url =>
51+
config.whiteListedDomains.some(whiteListedDomain =>
52+
new RegExp(`^${whiteListedDomain}`).test(url)
53+
)
54+
);
55+
56+
if (arePostedUrlsPermitted && ADMIN_GROUP_ID) {
57+
await forwardMessage({
58+
chatId: Number(ADMIN_GROUP_ID),
59+
fromChatId: message.chat.id,
60+
messageId: message.message_id
61+
});
62+
}
63+
}
64+
}
65+
};

0 commit comments

Comments
 (0)