From ac448f8e330cf42e2ba1e3263f3fd7b59e5779f4 Mon Sep 17 00:00:00 2001 From: sheychen Date: Mon, 22 Apr 2019 20:48:32 +0200 Subject: [PATCH] Add multilang: WIP --- .env.sample | 7 +- database.json | 500 ++++++++++++++++++++++++++++++++++++--------- database_fr_2.json | 60 ++++++ index.js | 34 ++- 4 files changed, 488 insertions(+), 113 deletions(-) create mode 100644 database_fr_2.json diff --git a/.env.sample b/.env.sample index 8c5b404..eda1323 100644 --- a/.env.sample +++ b/.env.sample @@ -1,2 +1,5 @@ -ACCESS_TOKEN= -API_URL= \ No newline at end of file +API_URL=test-url +ACCESS_TOKEN=test +API_URL_FR=test-url1 +ACCESS_TOKEN_FR=test1 +ACCESS_TOKEN_EN=test2 \ No newline at end of file diff --git a/database.json b/database.json index aa393c4..498cfa8 100644 --- a/database.json +++ b/database.json @@ -1,102 +1,402 @@ [ - "You’re that “Nothing” when people ask me what I’m thinking about.", - "You look great today.", - "You’re a smart cookie.", - "I bet you make babies smile.", - "You have impeccable manners.", - "I like your style.", - "You have the best laugh.", - "I appreciate you.", - "You are the most perfect you there is.", - "Our system of inside jokes is so advanced that only you and I get it. And I like that.", - "You’re strong.", - "Your perspective is refreshing.", - "You’re an awesome friend.", - "You light up the room.", - "You deserve a hug right now.", - "You should be proud of yourself.", - "You’re more helpful than you realize.", - "You have a great sense of humor.", - "You’ve got all the right moves!", - "Is that your picture next to “charming” in the dictionary?", - "Your kindness is a balm to all who encounter it.", - "You’re all that and a super-size bag of chips.", - "On a scale from 1 to 10, you’re an 11.", - "You are brave.", - "You’re even more beautiful on the inside than you are on the outside.", - "You have the courage of your convictions.", - "Aside from food. You’re my favorite.", - "If cartoon bluebirds were real, a bunch of them would be sitting on your shoulders singing right now.", - "You are making a difference.", - "You’re like sunshine on a rainy day.", - "You bring out the best in other people.", - "Your ability to recall random factoids at just the right time is impressive.", - "You’re a great listener.", - "How is it that you always look great, even in sweatpants?", - "Everything would be better if more people were like you!", - "I bet you sweat glitter.", - "You were cool way before hipsters were cool.", - "That color is perfect on you.", - "Hanging out with you is always a blast.", - "You always know — and say — exactly what I need to hear when I need to hear it.", - "You smell really good.", - "You may dance like no one’s watching, but everyone’s watching because you’re an amazing dancer!", - "Being around you makes everything better!", - "When you say, “I meant to do that,” I totally believe you.", - "When you’re not afraid to be yourself is when you’re most incredible.", - "Colors seem brighter when you’re around.", - "You’re more fun than a ball pit filled with candy. (And seriously, what could be more fun than that?)", - "That thing you don’t like about yourself is what makes you so interesting.", - "You’re wonderful.", - "Everyday is just BLAH when I don’t see you For reals! (awesome – you are halfway through the list. You’re awesome!)", - "Jokes are funnier when you tell them.", - "You’re better than a triple-scoop ice cream cone. With sprinkles.", - "Your bellybutton is kind of adorable.", - "Your hair looks stunning.", - "You’re one of a kind!", - "You’re inspiring.", - "If you were a box of crayons, you’d be the giant name-brand one with the built-in sharpener.", - "You should be thanked more often. So thank you!!", - "Our community is better because you’re in it.", - "Someone is getting through something hard right now because you’ve got their back.", - "You have the best ideas.", - "You always know how to find that silver lining.", - "Everyone gets knocked down sometimes, but you always get back up and keep going.", - "You’re a candle in the darkness.", - "You’re a great example to others.", - "Being around you is like being on a happy little vacation.", - "You always know just what to say.", - "You’re always learning new things and trying to better yourself, which is awesome.", - "If someone based an Internet meme on you, it would have impeccable grammar.", - "You could survive a Zombie apocalypse.", - "You’re more fun than bubble wrap.", - "When you make a mistake, you fix it.", - "Who raised you? They deserve a medal for a job well done.", - "You’re great at figuring stuff out.", - "Your voice is magnificent.", - "The people you love are lucky to have you in their lives.", - "You’re like a breath of fresh air.", - "You’re gorgeous — and that’s the least interesting thing about you, too.", - "You’re so thoughtful.", - "Your creative potential seems limitless.", - "You’re the coolest person I know. And I consider myself bet friends with like all celebrities, so. . . .", - "You’re irresistible when you blush.", - "Actions speak louder than words, and yours tell an incredible story.", - "Somehow you make time stop and fly at the same time.", - "When you make up your mind about something, nothing stands in your way.", - "You seem to really know who you are.", - "Any team would be lucky to have you on it.", - "In high school I bet you were voted “most likely to keep being awesome.”", - "I bet you do the crossword puzzle in ink.", - "Babies and small animals probably love you.", - "If you were a scented candle they’d call it Perfectly Imperfect (and it would smell like summer).", - "There’s ordinary, and then there’s you.", - "You’re someone’s reason to smile.", - "You’re even better than a unicorn, because you’re real.", - "How do you keep being so funny and making everyone laugh?", - "You have a good head on your shoulders.", - "Has anyone ever told you that you have great posture?", - "The way you treasure your loved ones is incredible.", - "You’re really something special.", - "You’re a gift to those around you." + { + "EN": "You’re that “Nothing” when people ask me what I’m thinking about.", + "FR": "Quand on me demande à quoi je pense, je n’ose pas dire que je pense toujours à toi" + }, + { + "EN": "You look great today.", + "FR": "Tu as l’air en pleine forme aujourd’hui." + }, + { + "EN": "You’re a smart cookie.", + "FR": "Tu es un vrai chou à la crème" + }, + { + "EN": "I bet you make babies smile.", + "FR": "Je parie que les bébés sourient en te voyant." + }, + { + "EN": "You have impeccable manners.", + "FR": "Tu as un goût exquis." + }, + { + "EN": "I like your style.", + "FR": "J’adore ton style." + }, + { + "EN": "You have the best laugh.", + "FR": "Tu as un rire charmant" + }, + { + "EN": "I appreciate you.", + "FR": "J’aime beaucoup ce que tu fais et ce que tu es." + }, + { + "EN": "You are the most perfect you there is.", + "FR": "Tu es la personne la plus parfaite que je connaisse" + }, + { + "EN": "Our system of inside jokes is so advanced that only you and I get it. And I like that.", + "FR": "Notre complicité est géniale, j’adore les clins d’œil que nous nous faisons." + }, + { + "EN": "You’re strong.", + "FR": "Tu as de la personnalité, on peut te faire confiance." + }, + { + "EN": "Your perspective is refreshing.", + "FR": "Quand on te croise, la journée est moins dure." + }, + { + "EN": "You’re an awesome friend.", + "FR": "Ton amitié est précieuse." + }, + { + "EN": "You light up the room.", + "FR": "Quand tu apparais, tu illumines tout." + }, + { + "EN": "You deserve a hug right now.", + "FR": "Tu mérites qu’on t’embrasse dès maintenant." + }, + { + "EN": "You should be proud of yourself.", + "FR": "Tu peux être content⋅e de toi." + }, + { + "EN": "You’re more helpful than you realize.", + "FR": "Ton aide est précieuse plus encore que tu ne l’imagines." + }, + { + "EN": "You have a great sense of humor.", + "FR": "Tu as un sacré sens de l’humour." + }, + { + "EN": "You’ve got all the right moves!", + "FR": "Tu réussis tout ce que tu entreprends !" + }, + { + "EN": "Is that your picture next to “charming” in the dictionary?", + "FR": "Dans le dictionnaire, c’est ton portrait qui illustre le mot 'charme'" + }, + { + "EN": "Your kindness is a balm to all who encounter it.", + "FR": "Ta gentillesse est un parfum qui embaume tous ceux qui t’entourent." + }, + { + "EN": "You’re all that and a super-size bag of chips.", + "FR": "Tu es tout pour nous et bien plus encore." + }, + { + "EN": "On a scale from 1 to 10, you’re an 11.", + "FR": "Sur une échelle de 1 à 10, tu es à 11." + }, + { + "EN": "You are brave.", + "FR": "J’admire ton courage." + }, + { + "EN": "You’re even more beautiful on the inside than you are on the outside.", + "FR": "Tu es encore plus magnifique à l’intérieur qu’à l’extérieur." + }, + { + "EN": "You have the courage of your convictions.", + "FR": "Tu as le courage de défendre tes convictions." + }, + { + "EN": "Aside from food. You’re my favorite.", + "FR": "Après le tiramisu, c’est toi que je préfère." + }, + { + "EN": "If cartoon bluebirds were real, a bunch of them would be sitting on your shoulders singing right now.", + "FR": "Si les licornes existaient, elles te feraient une haie d’honneur chaque matin." + }, + { + "EN": "You are making a difference.", + "FR": "Tu fais vraiment la différence quand tu arrives." + }, + { + "EN": "You’re like sunshine on a rainy day.", + "FR": "Tu es comme un rayon de soleil après la pluie." + }, + { + "EN": "You bring out the best in other people.", + "FR": "Avec toi, chacun donne le meilleur de soi-même." + }, + { + "EN": "Your ability to recall random factoids at just the right time is impressive.", + "FR": "Ta mémoire est telle que tu n’oublies rien des moments heureux." + }, + { + "EN": "You’re a great listener.", + "FR": "Tu sais écouter les autres avec une réelle attention." + }, + { + "EN": "How is it that you always look great, even in sweatpants?", + "FR": "Comment se fait-il que tu aies toujours l’air impeccable, même avec un vieux survèt’ ?" + }, + { + "EN": "Everything would be better if more people were like you!", + "FR": "Le monde tournerait bien mieux si les autres étaient comme toi !" + }, + { + "EN": "I bet you sweat glitter.", + "FR": "Je parie que tes gouttes de sueur sont des perles." + }, + { + "EN": "You were cool way before hipsters were cool.", + "FR": "Tu étais déjà cool avant que la coolitude soit à la mode." + }, + { + "EN": "That color is perfect on you.", + "FR": "Les couleurs que tu choisis te vont très bien." + }, + { + "EN": "Hanging out with you is always a blast.", + "FR": "Se balader à tes côtés est une vraie partie de plaisir." + }, + { + "EN": "You always know — and say — exactly what I need to hear when I need to hear it.", + "FR": "Tu sais toujours dire exactement ce que j’ai besoin d’entendre." + }, + { + "EN": "You smell really good.", + "FR": "Ton parfum est un enchantement." + }, + { + "EN": "You may dance like no one’s watching, but everyone’s watching because you’re an amazing dancer!", + "FR": "Tu danses comme si personne ne te regardait, mais tu danses si bien que tout le monde te regarde !" + }, + { + "EN": "Being around you makes everything better!", + "FR": + }, + { + "EN": "When you say, “I meant to do that,” I totally believe you.", + "FR": + }, + { + "EN": "When you’re not afraid to be yourself is when you’re most incredible.", + "FR": + }, + { + "EN": "Colors seem brighter when you’re around.", + "FR": + }, + { + "EN": "You’re more fun than a ball pit filled with candy. (And seriously, what could be more fun than that?)", + "FR": + }, + { + "EN": "That thing you don’t like about yourself is what makes you so interesting.", + "FR": + }, + { + "EN": "You’re wonderful.", + "FR": + }, + { + "EN": "Everyday is just BLAH when I don’t see you For reals! (awesome – you are halfway through the list. You’re awesome!)", + "FR": + }, + { + "EN": "Jokes are funnier when you tell them.", + "FR": + }, + { + "EN": "You’re better than a triple-scoop ice cream cone. With sprinkles.", + "FR": + }, + { + "EN": "Your bellybutton is kind of adorable.", + "FR": + }, + { + "EN": "Your hair looks stunning.", + "FR": + }, + { + "EN": "You’re one of a kind!", + "FR": + }, + { + "EN": "You’re inspiring.", + "FR": + }, + { + "EN": "If you were a box of crayons, you’d be the giant name-brand one with the built-in sharpener.", + "FR": + }, + { + "EN": "You should be thanked more often. So thank you!!", + "FR": + }, + { + "EN": "Our community is better because you’re in it.", + "FR": + }, + { + "EN": "Someone is getting through something hard right now because you’ve got their back.", + "FR": + }, + { + "EN": "You have the best ideas.", + "FR": + }, + { + "EN": "You always know how to find that silver lining.", + "FR": + }, + { + "EN": "Everyone gets knocked down sometimes, but you always get back up and keep going.", + "FR": + }, + { + "EN": "You’re a candle in the darkness.", + "FR": + }, + { + "EN": "You’re a great example to others.", + "FR": + }, + { + "EN": "Being around you is like being on a happy little vacation.", + "FR": + }, + { + "EN": "You always know just what to say.", + "FR": + }, + { + "EN": "You’re always learning new things and trying to better yourself, which is awesome.", + "FR": + }, + { + "EN": "If someone based an Internet meme on you, it would have impeccable grammar.", + "FR": + }, + { + "EN": "You could survive a Zombie apocalypse.", + "FR": + }, + { + "EN": "You’re more fun than bubble wrap.", + "FR": + }, + { + "EN": "When you make a mistake, you fix it.", + "FR": + }, + { + "EN": "Who raised you? They deserve a medal for a job well done.", + "FR": + }, + { + "EN": "You’re great at figuring stuff out.", + "FR": + }, + { + "EN": "Your voice is magnificent.", + "FR": + }, + { + "EN": "The people you love are lucky to have you in their lives.", + "FR": + }, + { + "EN": "You’re like a breath of fresh air.", + "FR": + }, + { + "EN": "You’re gorgeous — and that’s the least interesting thing about you, too.", + "FR": + }, + { + "EN": "You’re so thoughtful.", + "FR": + }, + { + "EN": "Your creative potential seems limitless.", + "FR": + }, + { + "EN": "You’re the coolest person I know. And I consider myself bet friends with like all celebrities, so. . . .", + "FR": + }, + { + "EN": "You’re irresistible when you blush.", + "FR": + }, + { + "EN": "Actions speak louder than words, and yours tell an incredible story.", + "FR": + }, + { + "EN": "Somehow you make time stop and fly at the same time.", + "FR": + }, + { + "EN": "When you make up your mind about something, nothing stands in your way.", + "FR": + }, + { + "EN": "You seem to really know who you are.", + "FR": + }, + { + "EN": "Any team would be lucky to have you on it.", + "FR": + }, + { + "EN": "In high school I bet you were voted “most likely to keep being awesome.”", + "FR": + }, + { + "EN": "I bet you do the crossword puzzle in ink.", + "FR": + }, + { + "EN": "Babies and small animals probably love you.", + "FR": + }, + { + "EN": "If you were a scented candle they’d call it Perfectly Imperfect (and it would smell like summer).", + "FR": + }, + { + "EN": "There’s ordinary, and then there’s you.", + "FR": + }, + { + "EN": "You’re someone’s reason to smile.", + "FR": + }, + { + "EN": "You’re even better than a unicorn, because you’re real.", + "FR": + }, + { + "EN": "How do you keep being so funny and making everyone laugh?", + "FR": + }, + { + "EN": "You have a good head on your shoulders.", + "FR": + }, + { + "EN": "Has anyone ever told you that you have great posture?", + "FR": + }, + { + "EN": "The way you treasure your loved ones is incredible.", + "FR": + }, + { + "EN": "You’re really something special.", + "FR": + }, + { + "EN": "You’re a gift to those around you.", + "FR": + } ] \ No newline at end of file diff --git a/database_fr_2.json b/database_fr_2.json new file mode 100644 index 0000000..edef70e --- /dev/null +++ b/database_fr_2.json @@ -0,0 +1,60 @@ +[ +"Tout va mieux quand tu es tout près de moi !", +"Quand tu dis 'Voilà ce que je vais faire', j’ai envie de le faire avec toi.", +"Tu es incroyable quand tu n’as pas peur d’être toi-même.", +"Ta seule présence ravive les couleurs du quotidien.", +"Tu es plus chouette qu’un énorme paquet de chamallows.", +"C’est ce que tu n’aimes pas chez toi qui te rend une personne intéressante.", +"Tu es une merveille.", +"Chaque jour est tristounet quand je ne te vois pas en vrai !", +"Les blagues sont bien plus drôles quand c’est toi qui les racontes.", +"Tu es un tel délice que les glaces à la framboise me paraissent fades.", +"Même ton nombril est tout à fait mignon.", +"Ta chevelure est magnifique.", +"Tu te distingues vraiment du lot !", +"Tu es pour tout le monde une source d’inspiration.", +"Si tu étais un crayon de couleur, tu pourrais dessiner l’arc-en-ciel d’un seul trait.", +"Tout le monde peut te remercier. Merci pour tout ce que tu es !", +"Notre communauté est bien meilleure grâce à toi.", +"En ce moment, une personne surmonte ses difficultés grâce à ton aide et ton soutien.", +"Tes idées sont les meilleures.", +"Tu t’arranges toujours pour trouver le meilleur en chacun.", +"Tout le monde peut avoir un petit coup de blues, mais avec toi on surmonte cette épreuve.", +"Tu es comme une lumière dans l’obscurité de nos vies.", +"Tu es un exemple pour tout le monde.", +"Quand on est près de toi, c’est comme si on était en vacances.", +"Tu sais toujours quoi répondre face aux problèmes.", +"Tu as tellement soif d’apprendre et tu progresses tellement que tu es formidable.", +"Si on devait faire un mème pour Internet avec toi, ce serait avec tes paroles de sagesse.", +"Tu peux survivre à toutes les apocalypses.", +"Tu es beaucoup plus drôle que les humoristes professionnels.", +"Tu sais reconnaître tes erreurs et apprendre à mieux faire.", +"Tes parents méritent d’être récompensés de t’avoir mis⋅e au monde.", +"Tu sais fort bien démêler les affaires compliquées.", +"Ta voix est mélodieuse.", +"Les personnes que tu aimes ont bien de la chance !", +"Ton souffle est une brise de printemps.", +"Tu es splendide, mais c’est la moindre de tes qualités.", +"Tu es une personne réfléchie et fiable.", +"Ton potentiel créatif paraît sans limites.", +"Tu es la personne la plus géniale que je connaisse. Et je connais pourtant beaucoup de personnes très sympas…", +"Tu es irrésistible quand tu rougis.", +"Les actes valent mieux que les mots, et tes actes le prouvent chaque jour.", +"Avec toi le temps passe tellement vite qu’on ne s’ennuie jamais.", +"Quand tu as pris une décision, rien ne peut plus t’arrêter.", +"Tu as l’air de savoir vraiment ce que tu veux.", +"Toutes les associations et clubs voudraient bien que tu les rejoignes.", +"Tu étais sûrement la personne la plus populaire pendant tes études, tu l’es toujours aujourd’hui.”", +"Je parie que tu termines les mots croisés en 5 minutes.", +"Je parie que les chiens et les chats viennent spontanément près de toi avec amour.", +"Si tu étais un parfum on t’appellerait 'Fleurs d’été'.", +"Il y a les gens ordinaires, et puis il y a toi.", +"Tu donnes envie de sourire quand on te voit.", +"Tu vaux bien mieux qu’une licorne parce que tu existes vraiment.", +"Comment tu fais pour être si drôle et faire rire autour de toi ?", +"Tu as la tête sur les épaules en toutes circonstances.", +"On t’a déjà dit à quel point ton allure est impressionnante ?", +"Tu es incroyable avec les personnes que tu aimes.", +"Tu es vraiment une personne très spéciale.", +"Ta présence est un cadeau pour celles et ceux qui t’entourent." +] diff --git a/index.js b/index.js index ccfe6db..dc3a7fb 100644 --- a/index.js +++ b/index.js @@ -2,16 +2,28 @@ require('dotenv').config() const database = require('./database.json') const Mastodon = require('mastodon-api') -const M = new Mastodon({ - access_token: process.env.ACCESS_TOKEN, - timeout_ms: 60 * 1000, - api_url: `${process.env.API_URL}/api/v1/`, -}) +const TOKEN = 'ACCESS_TOKEN' +const URL = 'API_URL' -M.get('accounts/verify_credentials').then( - me => M.get(`accounts/${me.data.id}/followers`, { limit: 9999 }).then(fol => { - for (const follow of fol.data) { - M.post('statuses', { status: `@${follow.acct} ${database[Math.floor(Math.random() * database.length)]}`, visibility: 'unlisted' }) - } +Object.entries(process.env) + .filter(e => e[0].startsWith(TOKEN)) + .forEach(e => { + const lang = e[0].substring(TOKEN.length + 1) + + const M = new Mastodon({ + access_token: process.env[`${TOKEN}_${lang}`] || process.env[TOKEN], + api_url: `${process.env[`API_URL_${lang}`] || process.env[URL]}/api/v1/`, + timeout_ms: 60 * 1000 }) -) \ No newline at end of file + + M.get('accounts/verify_credentials').then( + me => M.get(`accounts/${me.data.id}/followers`, { limit: 9999 }).then(fol => { + for (const follow of fol.data) { + const messages = database[Math.floor(Math.random() * database.length)] + const text = lang.length > 0 ? messages[lang] : '\n' + Object.entries(messages).map(m => `[${m[0]}] ${m[1]}`).join('\n\n') + + M.post('statuses', { status: `@${follow.acct} ${text}`, visibility: 'unlisted' }) + } + }) + ) + })