Added data in create_skill and skill init (for client ip, port and more)

This commit is contained in:
Mathieu B 2021-08-01 11:48:57 +02:00
parent 59029f8398
commit 7dc92de383
4 changed files with 21 additions and 14 deletions

View File

@ -4,17 +4,23 @@ import types
from jarvis import get_path_file from jarvis import get_path_file
from jarvis.skills import intent_manager from jarvis.skills import intent_manager
from jarvis.utils import languages_utils from jarvis.utils import languages_utils, client_utils
class Skill: class Skill:
def __init__(self, name): def __init__(self, name, data):
self.name = name self.name = name
self.client_ip = data['client_ip']
self.client_port = data['client_port']
path = self.__module__.split(".") path = self.__module__.split(".")
self.category = path[2] self.category = path[2]
self.skill_folder = path[3] self.skill_folder = path[3]
def speak(self, sentence):
client_utils.speak(sentence, self.client_ip, self.client_port)
def register(self): def register(self):
self.register_entities() self.register_entities()
self.register_regex() self.register_regex()

View File

@ -33,13 +33,13 @@ def speak_joke():
class JokesSkill(Skill, metaclass=SkillRegistering): class JokesSkill(Skill, metaclass=SkillRegistering):
def __init__(self): def __init__(self, data=dict):
super().__init__("JokesSkill") super().__init__("JokesSkill", data)
@intent_handler(IntentBuilder("JokingIntent").require("Joke")) @intent_handler(IntentBuilder("JokingIntent").require("Joke"))
def handle_joke(self, data): def handle_joke(self, data):
print(speak_joke()) print(speak_joke())
def create_skill(): def create_skill(data):
return JokesSkill() return JokesSkill(data)

View File

@ -4,8 +4,8 @@ from jarvis.skills.entertainement.spotify import spotify
class SpotifySkill(Skill, metaclass=SkillRegistering): class SpotifySkill(Skill, metaclass=SkillRegistering):
def __init__(self): def __init__(self, data=dict):
super().__init__("SpotifySkill") super().__init__("SpotifySkill", data)
@intent_file_handler("play_a_song.intent", "PlaySongWithSpotifyIntent") @intent_file_handler("play_a_song.intent", "PlaySongWithSpotifyIntent")
def handle_play_a_song(self, data): def handle_play_a_song(self, data):
@ -31,6 +31,7 @@ class SpotifySkill(Skill, metaclass=SkillRegistering):
spotify.get_spotify().pause_playback() spotify.get_spotify().pause_playback()
print("[INFO INTENT] - Paused music for Spotify") print("[INFO INTENT] - Paused music for Spotify")
else: else:
self.speak("Rien n'est en cours de lecture sur Spotify...")
# TODO: speak : nothing is playing on spotify # TODO: speak : nothing is playing on spotify
pass pass
@ -55,5 +56,5 @@ class SpotifySkill(Skill, metaclass=SkillRegistering):
print("Nothing is playing") print("Nothing is playing")
def create_skill(): def create_skill(data):
return SpotifySkill() return SpotifySkill(data)

View File

@ -4,8 +4,8 @@ from jarvis.skills.research.wikipedia import wikipedia
class WikipediaSkill(Skill, metaclass=SkillRegistering): class WikipediaSkill(Skill, metaclass=SkillRegistering):
def __init__(self): def __init__(self, data=dict):
super().__init__("WikipediaSkill") super().__init__("WikipediaSkill", data)
@intent_file_handler("search.wikipedia.intent", "WikipediaQueryIntent") @intent_file_handler("search.wikipedia.intent", "WikipediaQueryIntent")
def handle_wikipedia_query_intent(self, data): def handle_wikipedia_query_intent(self, data):
@ -17,5 +17,5 @@ class WikipediaSkill(Skill, metaclass=SkillRegistering):
pass pass
def create_skill(): def create_skill(data):
return WikipediaSkill() return WikipediaSkill(data)