Skip to content

Commit

Permalink
Ngve typescript (#259)
Browse files Browse the repository at this point in the history
* feat(core): add typescript to api endpoints and utils

* fix(chore): updated deps and moved scripts

* feat(typescript): add types and eslint
  • Loading branch information
leocabeza authored Jun 21, 2020
1 parent 367cabe commit 931a65b
Show file tree
Hide file tree
Showing 36 changed files with 3,343 additions and 1,681 deletions.
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.now
.github
.env
.eslintrc.js
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["./tsconfig.json"]
},
plugins: ["@typescript-eslint"],
extends: ["airbnb-typescript/base", "prettier/@typescript-eslint"],
env: {
node: true
},
rules: {
"no-console": "off"
}
};
42 changes: 0 additions & 42 deletions api/_utils/config.js

This file was deleted.

41 changes: 41 additions & 0 deletions api/_utils/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const config = {
whiteListedDomains: [
"https://github.com",
"https://medium.com",
"https://twitter.com"
],
githubFeeds: [
{
name: "angular",
repo: "angular/angular",
hasChangelog: true,
feed: "https://github.com/angular/angular/releases.atom"
},
{
name: "ionic",
repo: "driftyco/ionic",
hasChangelog: true,
feed: "https://github.com/driftyco/ionic/releases.atom"
},
{
name: "nativescript",
repo: "NativeScript/NativeScript",
hasChangelog: true,
feed: "https://github.com/NativeScript/NativeScript/releases.atom"
},
{
name: "wengy-ven",
repo: "ngVenezuela/wengy-ven",
hasChangelog: true,
feed: "https://github.com/ngVenezuela/wengy-ven/releases.atom"
}
],
blogFeeds: [
{
name: "Blog oficial de ngvenezuela",
feed: "https://dev.to/feed/ngvenezuela"
}
]
};

export default config;
54 changes: 0 additions & 54 deletions api/_utils/messages.js

This file was deleted.

54 changes: 54 additions & 0 deletions api/_utils/messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const messages: { [index: string]: any } = {
welcome: "Hola #{name}, ¡Bienvenid@ a ngVenezuela!. Te invitamos a ".concat(
"seguirnos en twitter como [@ngVenezuela](https://twitter.com/ngVenezuela) ",
"y a mirar nuestra comunidad en Github: https://github.com/ngvenezuela.\n\n",
"Además nos gustaría que respondieras esta pequeña encuesta: http://bit.ly/ngve-encuesta"
),
goodBye:
"¡Nos vemos pronto #{name}! Esperamos NO verte por el grupo de React Venezuela",
goodMornings: {
mondays: [
"Buenos días comunidad, ¡Que tengan un excelente inicio de semana! \u{1F60E}"
],
fridays: [
"Buenos días. Recuerden que los viernes no se hacen deploy \u{1F601}",
"Buenos días. ¡Hoy es viernes y el hardware lo sabe!",
"Buenos días comunidad. Feliz viernes",
"Buenos días. Hoy cualquier bug es un feature después de las 4pm"
],
generic: [
"Buenos días...¿tomaron café? \u{2615}",
"Buenos días. Recuerden que detrás de una persona exitosa ".concat(
"está una gran cantidad de café \u{2615}"
),
"Buenos días. Keep calm and drink \u{2615}",
"Buenos días \u{1F601}\u{2615}",
"Buenos días",
"Buenos días a todos",
"Buenos días comunidad",
"Buenos días #ngPanas",
"Buenos días comunidad, Y como dice @cesarfrick: ¡A trabajar, ".concat(
"vagos! Que los yates de sus jefes no se pagan solos"
)
]
},
newBlogPost: "*#{author}* ha agregado una nueva entrada al blog titulada: ".concat(
"*#{title}* y está disponible en: #{link}"
),
newTweet: "#ngVenezuelaTweet \u{1F426}\n".concat(
"#{tweetText}\n",
"----\n",
"Puedes ver el Tweet aquí: #{tweetUrl}"
),
githubRelease: "*#{name}* acaba de alcanzar la versión *#{version}*\n\n".concat(
"[Puedes ver los cambios aquí](#{url})"
),
githubOpenVeLink:
"El enlace de github para comunidades de Telegram es: https://github.com/OpenVE/comunidades-en-telegram",
gistCreated:
"gist creado por #{fullName} #{user} para https://t.me/ngvenezuela con https://github.com/ngVenezuela/wengy-ven",
gistRecommendation:
"Utiliza el comando /gist _codigo_ para generar un gist en github"
};

export default messages;
63 changes: 0 additions & 63 deletions api/_utils/telegram/admin.js

This file was deleted.

65 changes: 65 additions & 0 deletions api/_utils/telegram/admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import config from "../config";
import { forwardMessage, sendMessage } from "./bot-methods";
import { Chat, Message } from "./interfaces";

const { MAIN_GROUP_ID, ADMIN_GROUP_ID } = process.env;

export const getChatType = async (message: Message) => {
const {
chat: { id: chatId }
} = message;

if (chatId.toString() === MAIN_GROUP_ID) {
return "main";
}

if (chatId.toString() === ADMIN_GROUP_ID) {
return "admin";
}

return "private";
};

/**
* Send main or admin's group id.
* This will be used in your .env
*/
export const sendGroupId = async ({ id: chatId, type }: Chat) => {
if (["group", "supergroup"].includes(type)) {
await sendMessage({
chatId,
text: `Tú variable \`mainGroupId/adminGroupId\` es: ${chatId}`
});
}
};

export const verifyUrls = async (message: Message) => {
const type = await getChatType(message);

if (message.text && type === "main") {
const urlEntities = message.entities
? message.entities.filter(entity => entity.type === "url")
: [];
if (urlEntities.length > 0) {
const urls = urlEntities.map(entity =>
message
.text!.slice(entity.offset, entity.length + entity.offset)
.replace("https://www.", "https://")
);

const arePostedUrlsPermitted = urls.every(url =>
config.whiteListedDomains.some(whiteListedDomain =>
new RegExp(`^${whiteListedDomain}`).test(url)
)
);

if (arePostedUrlsPermitted && ADMIN_GROUP_ID) {
await forwardMessage({
chatId: Number(ADMIN_GROUP_ID),
fromChatId: message.chat.id,
messageId: message.message_id
});
}
}
}
};
Loading

0 comments on commit 931a65b

Please sign in to comment.