diff --git a/jarvis/main.py b/jarvis/main.py index 95455ca..0c8cac6 100644 --- a/jarvis/main.py +++ b/jarvis/main.py @@ -3,6 +3,7 @@ from flask import Flask, request, jsonify, Response from jarvis.ia import process from jarvis.skills import intent_manager +from jarvis.skills.entertainement.jokes import JokesSkill from jarvis.skills.research.wikipedia import WikipediaSkill from utils import config_utils, flask_utils, intents_utils, utils @@ -36,10 +37,12 @@ def process_request(): if __name__ == '__main__': # Tests WikipediaSkill().register() + JokesSkill().register() intent_manager.process_handlers() intent_manager.recognise("cherche sur wikipedia Elon Musk") + intent_manager.recognise("raconte moi une blague") # start the flask server app.config['JSON_AS_ASCII'] = False diff --git a/jarvis/skills/entertainement/jokes/__init__.py b/jarvis/skills/entertainement/jokes/__init__.py index e69de29..ac1d669 100644 --- a/jarvis/skills/entertainement/jokes/__init__.py +++ b/jarvis/skills/entertainement/jokes/__init__.py @@ -0,0 +1,41 @@ +import requests +from adapt.intent import IntentBuilder + +from jarvis.skills import Skill, SkillRegistering +from jarvis.skills.decorators import intent_handler +from jarvis.utils import languages_utils, config_utils + + +def speak_joke(): + # french jokes + if languages_utils.get_language().startswith("fr-"): + # please register on www.blagues-api.fr and set a token in your secret + response = requests.get('https://www.blagues-api.fr/api/random', headers={ + 'Authorization': 'Bearer ' + config_utils.get_in_secret('JOKES_FRENCH_API_TOKEN')}) + + data = response.json() + joke = data['joke'] + answer = data['answer'] + + return joke + " /pause:2s/ " + answer + + # english jokes + elif languages_utils.get_language().startswith("en-"): + response = requests.get('https://v2.jokeapi.dev/joke/Any?type=twopart') + data = response.json() + + joke = data['setup'] + answer = data['delivery'] + + return joke + " /pause:2s/ " + answer + else: + return "I don't know any jokes in your language..." + + +class JokesSkill(Skill, metaclass=SkillRegistering): + def __init__(self): + super().__init__("JokesSkill") + + @intent_handler(IntentBuilder("JokingIntent").require("Joke")) + def handle_joke(self, data): + print(speak_joke()) diff --git a/jarvis/skills/entertainement/jokes/info.json b/jarvis/skills/entertainement/jokes/info.json deleted file mode 100644 index a55b85f..0000000 --- a/jarvis/skills/entertainement/jokes/info.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "Jokes", - "languages": [ - "FR-FR", - "EN-EN" - ], - "intents": [ - "tell_me_a_joke" - ] -} \ No newline at end of file diff --git a/jarvis/skills/entertainement/jokes/intent.py b/jarvis/skills/entertainement/jokes/intent.py deleted file mode 100644 index 9c33945..0000000 --- a/jarvis/skills/entertainement/jokes/intent.py +++ /dev/null @@ -1,37 +0,0 @@ -import requests as requests - -from jarvis.utils import languages_utils, config_utils - - -def tell_me_a_joke(): - tag = 'tell_me_a_joke' - # response = intents_utils.get_response(tag) - - # french jokes - if languages_utils.get_language().startswith("fr-"): - - # please register on www.blagues-api.fr and set a token in your secret - response = requests.get( - 'https://www.blagues-api.fr/api/random', - headers={ - 'Authorization': 'Bearer ' + config_utils.get_in_secret('JOKES_FRENCH_API_TOKEN') - } - ) - - data = response.json() - joke = data['joke'] - answer = data['answer'] - - return joke + " /pause:2s/ " + answer - - # english jokes - elif languages_utils.get_language().startswith("en-"): - response = requests.get('https://v2.jokeapi.dev/joke/Any?type=twopart') - data = response.json() - - joke = data['setup'] - answer = data['delivery'] - - return joke + " /pause:2s/ " + answer - else: - return "I don't know any jokes in your language..." diff --git a/jarvis/skills/entertainement/jokes/lang/en-en.json b/jarvis/skills/entertainement/jokes/lang/en-en.json deleted file mode 100644 index 16520c2..0000000 --- a/jarvis/skills/entertainement/jokes/lang/en-en.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "tell_me_a_joke": { - "patterns": [ - "Tell me a joke", - "Make me laugh", - "Brighten my day" - ], - "responses": [ - ] - } -} \ No newline at end of file diff --git a/jarvis/skills/entertainement/jokes/lang/fr-fr.json b/jarvis/skills/entertainement/jokes/lang/fr-fr.json deleted file mode 100644 index a4aec2e..0000000 --- a/jarvis/skills/entertainement/jokes/lang/fr-fr.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "tell_me_a_joke": { - "patterns": [ - "raconte moi-voir une blague", - "dis moi une blague", - "raconte une blague", - "fait moi rire", - "donne une bonne blague", - "raconte moi une blagounette" - ], - "responses": [ - ] - } -} \ No newline at end of file diff --git a/jarvis/skills/entertainement/jokes/vocab/en-en/Chuck.voc b/jarvis/skills/entertainement/jokes/vocab/en-en/Chuck.voc new file mode 100644 index 0000000..28b30ed --- /dev/null +++ b/jarvis/skills/entertainement/jokes/vocab/en-en/Chuck.voc @@ -0,0 +1,2 @@ +chuck +chuck norris diff --git a/jarvis/skills/entertainement/jokes/vocab/en-en/Joke.voc b/jarvis/skills/entertainement/jokes/vocab/en-en/Joke.voc new file mode 100644 index 0000000..05e2f3f --- /dev/null +++ b/jarvis/skills/entertainement/jokes/vocab/en-en/Joke.voc @@ -0,0 +1,5 @@ +joke +jokes +make me laugh +brighten my day +tell me joke diff --git a/jarvis/skills/entertainement/jokes/vocab/en-en/Neutral.voc b/jarvis/skills/entertainement/jokes/vocab/en-en/Neutral.voc new file mode 100644 index 0000000..0f8b900 --- /dev/null +++ b/jarvis/skills/entertainement/jokes/vocab/en-en/Neutral.voc @@ -0,0 +1,3 @@ +neutral +non-offensive +geeky diff --git a/jarvis/skills/entertainement/jokes/vocab/fr-fr/Chuck.voc b/jarvis/skills/entertainement/jokes/vocab/fr-fr/Chuck.voc new file mode 100644 index 0000000..28b30ed --- /dev/null +++ b/jarvis/skills/entertainement/jokes/vocab/fr-fr/Chuck.voc @@ -0,0 +1,2 @@ +chuck +chuck norris diff --git a/jarvis/skills/entertainement/jokes/vocab/fr-fr/Joke.voc b/jarvis/skills/entertainement/jokes/vocab/fr-fr/Joke.voc new file mode 100644 index 0000000..724bcdd --- /dev/null +++ b/jarvis/skills/entertainement/jokes/vocab/fr-fr/Joke.voc @@ -0,0 +1,5 @@ +blague +blagues +fais moi rire +illumine ma journée +raconte moi une blague diff --git a/jarvis/skills/entertainement/jokes/vocab/fr-fr/Neutral.voc b/jarvis/skills/entertainement/jokes/vocab/fr-fr/Neutral.voc new file mode 100644 index 0000000..b229f44 --- /dev/null +++ b/jarvis/skills/entertainement/jokes/vocab/fr-fr/Neutral.voc @@ -0,0 +1,3 @@ +neutre +non offensant +geek