def process(self, interaction): '''Say how RORI is''' rmd = DirectReplyMDProcessor(interaction).process() cjoy = EmotionsManager().get_emotions( str(interaction.device_author["id"]))[1] humor = self.rori.get_localized_sentence('soso', self.sentences) if cjoy > 60: humor = self.rori.get_localized_sentence('happy', self.sentences) if cjoy < 40: humor = self.rori.get_localized_sentence('bad', self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, humor, rmd) # Update emotions csadness = EmotionsManager().get_emotions( str(interaction.device_author["id"]))[4] csadness = 20 if csadness > 20 else csadness cjoy = 65 if cjoy < 65 else cjoy EmotionsManager().go_to_emotion(d_id=str( interaction.device_author["id"]), delta=2, joy=cjoy, sadness=csadness) self.stop_processing = True
def process(self, interaction): '''Search somebody on wikipedia''' rmd = DirectReplyMDProcessor(interaction).process() m = re.findall(r"(who.is|qui.es(t)).(.*)", interaction.body, re.IGNORECASE) who = m[0][-1] try: if who[:4].lower() != "rori": string_to_say = wikipedia.summary(who, sentences=2) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) else: string_to_say = self.rori.get_localized_sentence( 'me', self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) except: string_to_say = self.rori.get_localized_sentence( 'dont_know', self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) self.stop_processing = True
def process(self, interaction): '''Pause music for compatible devices''' rmd = DirectReplyMDProcessor(interaction).process() emotions = EmotionsManager().get_emotions(str(interaction.device_author["id"])) cjoy = emotions[1] csadness = emotions[4] if (cjoy < 30 or csadness > 60) and random.randint(0,3) is 1: # RORI do not want to play music string_to_say = self.rori.get_localized_sentence('later', self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) self.stop_processing = True return # Start music and change emotions res = self.rori.send_for_best_client("music", interaction.device_author, "pause", rmd) csadness = 60 if csadness > 60 else csadness cjoy = 80 if csadness < 80 else cjoy EmotionsManager().go_to_emotion(d_id=str(interaction.device_author["id"]), delta=5, joy=cjoy, sadness=csadness) # Send if success or not if res: string_to_say = self.rori.get_localized_sentence('ok', self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) else: string_to_say = self.rori.get_localized_sentence('cant', self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) self.stop_processing = True
def process(self, interaction): '''Answer to thx''' rmd = DirectReplyMDProcessor(interaction).process() cjoy = EmotionsManager().get_emotions( str(interaction.device_author["id"]))[1] choice = random.randint(0, 4) if choice != 4: sentences = ['welcome', 'np', 'servitor'] to_say = self.rori.get_localized_sentence(sentences[choice - 1], self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, to_say, rmd) # Update emotions csadness = EmotionsManager().get_emotions( str(interaction.device_author["id"]))[4] csadness = 20 if csadness > 20 else csadness cjoy = 65 if cjoy < 65 else cjoy EmotionsManager().go_to_emotion(d_id=str( interaction.device_author["id"]), delta=2, joy=cjoy, sadness=csadness) self.stop_processing = True
def process(self, interaction): '''Add new feeds to follow''' rmd = DirectReplyMDProcessor(interaction).process() self.stop_processing = True url = re.search("(?P<url>https?://[^\s]+)", myString).group("url") config_dir = appdirs.user_data_dir('RORI', 'AmarOk') emotions = EmotionsManager().get_emotions( str(interaction.device_author["id"])) cjoy = emotions[1] csadness = emotions[4] with open(f'{config_dir}/feed/config.json', 'r+') as config: data = json.load(config) new_data = [] for rsc in data: if rsc['url'] == url: string_to_say = self.rori.get_localized_sentence( 'found', self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) csadness = 40 if csadness < 40 else csadness cjoy = 50 if csadness > 50 else cjoy EmotionsManager().go_to_emotion(d_id=str( interaction.device_author["id"]), delta=2, joy=cjoy, sadness=csadness) else: new_data.append(rsc) with open(f'{config_dir}/feed/config.json', 'w+') as config: config.write(json.dumps(new_data)) if new_data.empty(): success = Scheduler().rm('parse_feed', interaction.get_author(), []) if not success: string_to_say = self.rori.get_localized_sentence( 'failed', self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) csadness = 60 if csadness < 60 else csadness cjoy = 40 if csadness > 40 else cjoy EmotionsManager().go_to_emotion(d_id=str( interaction.device_author["id"]), delta=2, joy=cjoy, sadness=csadness) return
def process(self, interaction): '''Say when RORI is born''' rmd = DirectReplyMDProcessor(interaction).process() randomstr = random.choice(["2011", "immortal"]) string_to_say = self.rori.get_localized_sentence(randomstr, self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) # Update emotions csadness = EmotionsManager().get_emotions(str(interaction.device_author["id"]))[4] csadness = 20 if csadness > 20 else csadness cjoy = EmotionsManager().get_emotions(str(interaction.device_author["id"]))[1] cjoy = 60 if cjoy < 65 else cjoy EmotionsManager().go_to_emotion(d_id=str(interaction.device_author["id"]), delta=2, joy=cjoy, sadness=csadness) self.stop_processing = True
def process(self, interaction): '''Say bye to the devices if never seen''' rmd = DirectReplyMDProcessor(interaction).process() alreadySeen = False nbSeen = 0 for message in Database().select_message_from_today( str(interaction.device_author["id"])): p = re.compile( '^(salut|bonjour|bonsoir|hei|hi|hello|yo|o/)( rori| ?!?)$', re.IGNORECASE) m = re.findall(p, message[0]) if len(m) > 0: nbSeen += 1 if nbSeen > 1: alreadySeen = True break if alreadySeen: randomstr = random.choice(["aurevoir", "next", "goodnight", "bye"]) string_to_say = self.rori.get_localized_sentence( randomstr, self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) # Update emotions csadness = EmotionsManager().get_emotions( str(interaction.device_author["id"]))[4] csadness = 20 if csadness > 20 else csadness EmotionsManager().go_to_emotion(d_id=str( interaction.device_author["id"]), delta=2, joy=60, sadness=csadness) else: # Say nothing canger = EmotionsManager().get_emotions( str(interaction.device_author["id"]))[3] canger = 40 if canger > 40 else canger cjoy = EmotionsManager().get_emotions( str(interaction.device_author["id"]))[1] cjoy = 50 if cjoy > 50 else cjoy EmotionsManager().go_to_emotion(d_id=str( interaction.device_author["id"]), delta=1, anger=canger, joy=cjoy) self.stop_processing = True
def process(self, interaction): '''Exec pactl set-sink-volume 0 100% on the wanted device''' rmd = DirectReplyMDProcessor(interaction).process() self.stop_processing = True emotions = EmotionsManager().get_emotions( str(interaction.device_author["id"])) cjoy = emotions[1] csadness = emotions[4] if (cjoy < 30 or csadness > 60) and random.randint(0, 3) is 1: # RORI do not want to play music string_to_say = self.rori.get_localized_sentence( 'later', self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) return # Enable sound on linux res = self.rori.send_for_best_client("command", interaction.device_author, "pactl set-sink-volume 0 100%", rmd) csadness = 60 if csadness > 60 else csadness cjoy = 80 if csadness < 80 else cjoy EmotionsManager().go_to_emotion(d_id=str( interaction.device_author["id"]), delta=10, joy=cjoy, sadness=csadness) # Send if success or not if res: string_to_say = self.rori.get_localized_sentence( 'unmute', self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) else: string_to_say = self.rori.get_localized_sentence( 'cant', self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd)
def process(self, interaction): '''Say hi to the devices if never seen''' rmd = DirectReplyMDProcessor(interaction).process() # TODO multidevice hi. alreadySeen = False nbSeen = 0 for message in Database().select_message_from_today( str(interaction.device_author["id"])): p = re.compile( '^(salut|bonjour|bonsoir|hei|hi|hello|yo|o/)( rori| ?!?)$', re.IGNORECASE) m = re.findall(p, message[0]) if len(m) > 0: nbSeen += 1 if nbSeen > 1: alreadySeen = True break if alreadySeen: randomstr = random.choice(["already", "already2", ""]) string_to_say = self.rori.get_localized_sentence( randomstr, self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) # Update emotions csadness = EmotionsManager().get_emotions( str(interaction.device_author["id"]))[4] csadness = 20 if csadness > 20 else csadness EmotionsManager().go_to_emotion(d_id=str( interaction.device_author["id"]), delta=2, joy=60, sadness=csadness) else: randomstr = random.choice(["salut", "bonjour", "longtime", "o/"]) string_to_say = self.rori.get_localized_sentence( randomstr, self.sentences) res = self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) self.stop_processing = True
def process(self, interaction): '''Say since when the server is up''' with open('/proc/uptime', 'r') as f: uptime_seconds = float(f.readline().split()[0]) uptime_string = str(timedelta(seconds=uptime_seconds)) uptime_string = uptime_string[:uptime_string.rfind(':')].replace( ':', 'h') string_to_say = self.rori.get_localized_sentence( 'time', self.sentences) + uptime_string rmd = DirectReplyMDProcessor(interaction).process() self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) # Update emotions cjoy = EmotionsManager().get_emotions( str(interaction.device_author["id"]))[1] cjoy = 20 if cjoy > 20 else cjoy EmotionsManager().go_to_emotion(d_id=str( interaction.device_author["id"]), delta=1, joy=cjoy) self.stop_processing = True
def process(self, interaction): '''Check followed RSS feeds''' try: rmd = DirectReplyMDProcessor(interaction).process() self.stop_processing = True emotions = EmotionsManager().get_emotions(str(interaction.device_author["id"])) cjoy = emotions[1] csadness = emotions[4] if (cjoy < 30 or csadness > 60) and random.randint(0,3) == 1: # RORI do not want to play music string_to_say = self.rori.get_localized_sentence('later', self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) return config_dir = appdirs.user_data_dir('RORI', 'AmarOk') with open(f'{config_dir}/feed/config.json') as config: data = json.load(config) for rsc in data: parser = RSSParser(rsc['name'], rsc['url']) for news in parser.get_news(): # TODO localized name = rsc['name'] title = news['title'] description = news['description'] link = news['link'] to_say = f'New post for {name}: {title}\n' to_say += f'{description}: {link}' self.rori.send_for_best_client("text/plain", interaction.device_author, to_say, rmd) # Enable sound on linux csadness = 60 if csadness > 60 else csadness cjoy = 80 if csadness < 80 else cjoy EmotionsManager().go_to_emotion(d_id=str(interaction.device_author["id"]), delta=10, joy=cjoy, sadness=csadness) except: pass # TODO replace interaction.device_author ? same for emotionsManager
def process(self, interaction): '''Retrieve the current meteo''' rmd = DirectReplyMDProcessor(interaction).process() self.stop_processing = True emotions = EmotionsManager().get_emotions( str(interaction.device_author["id"])) cjoy = emotions[1] csadness = emotions[4] if (cjoy < 30 or csadness > 60) and random.randint(0, 3) is 1: # RORI do not want to play music string_to_say = self.rori.get_localized_sentence( 'later', self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) return m = re.findall(r"(tomorrow|day)", interaction.body) forecastMode = len(m) != 0 split_str = re.split(' (in) ', interaction.body) m = re.findall(r" (for|next) ", interaction.body) forMode = len(m) != 0 city = '' getNext = False for splitted in split_str: m = re.findall(r"(([A-z]|[0-9])+) +days", splitted) if m and not forMode: getNext = False continue if getNext: city = splitted.split()[0] if splitted == 'in': getNext = True if city == '': g = geocoder.ip('me') # TODO retrieve peer ip city = g.city self.rori.send_for_best_client("text/plain", interaction.device_author, city, rmd) json_meteo = self.getMeteo(city, forecastMode) meteo = json.loads(json_meteo) try: if forecastMode: nbDays = 1 block = 4 # The answer is a JSON with the weather each 3 hours, so 4 * 3 = 12 = midday dayParsed = False m = re.findall(r"tomorrow", interaction.body) if len(m) != 0: dayParsed = True if not dayParsed: m = re.findall(r"(([A-z]|[0-9])+) +days", interaction.body) nbDays = self.parseDay(m[0][0].lower()) if nbDays > 5: nbDays = 5 # Max for the AP if forMode: for d in range(0, nbDays): meteoBlock = meteo["list"][block + 8 * d] self.processDesc(meteoBlock, interaction, rmd, city, emotions, d + 1) time.sleep(1) else: meteoBlock = meteo["list"][block + 8 * (nbDays - 1)] self.processDesc(meteoBlock, interaction, rmd, city, emotions, nbDays) else: self.processDesc(meteo, interaction, rmd, city, emotions) except: if meteo["message"] == "Error: Not found city": string_to_say = self.rori.get_localized_sentence( 'bad_meteo', self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) # Change emotions csadness = 60 if csadness < 60 else csadness cjoy = 40 if csadness > 40 else cjoy EmotionsManager().go_to_emotion(d_id=str( interaction.device_author["id"]), delta=2, joy=cjoy, sadness=csadness)
def process(self, interaction): '''RORI wake up user''' rmd = DirectReplyMDProcessor(interaction).process() self.stop_processing = True m = re.findall(r"(in|at|dans|à|a).([0-9]+)(:|h|.*)([0-9]*)", interaction.body) hour = 0 minute = 0 if m[0][0] == "dans" or m[0][0] == "in": now = time.localtime() hour = now.tm_hour minute = now.tm_min if m[0][2] is not ':' and m[0][2] is not 'h': is_min = re.findall(r"(hour|heure|min|[0-9]+ ?h|[0-9]+ ?m)", interaction.body) if len(is_min) == 0: string_to_say = self.rori.get_localized_sentence( 'cant', self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) return if 'm' in is_min[0]: minute += int(m[0][1]) else: hour += int(m[0][1]) else: hour += int(m[0][1]) if m[0][3] is not '': minute += int(m[0][3]) else: hour = int(m[0][1]) if m[0][3] is not '': minute = int(m[0][3]) hour = (hour + int(minute / 60)) % 24 minute = minute % 60 minute_str = "%02d" % minute hour_str = "%02d" % hour string_to_say = hour_str + ":" + minute_str res = self.rori.send_for_best_client("alarm", interaction.device_author, string_to_say, rmd) if res is False: string_to_say = self.rori.get_localized_sentence( 'nodetect', self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) else: string_to_say = self.rori.get_localized_sentence( 'ok', self.sentences) + string_to_say self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) # Update emotions cjoy = EmotionsManager().get_emotions( str(interaction.device_author["id"]))[1] cjoy = 40 if cjoy < 40 else cjoy EmotionsManager().go_to_emotion(d_id=str( interaction.device_author["id"]), delta=1, joy=cjoy)
def process(self, interaction): '''Add new feeds to follow''' rmd = DirectReplyMDProcessor(interaction).process() self.stop_processing = True url = re.search("(?P<url>https?://[^\s]+)", interaction.body).group("url") config_dir = appdirs.user_data_dir('RORI', 'AmarOk') config_file = f'{config_dir}/feed/config.json' parsed = feedparser.parse(url) emotions = EmotionsManager().get_emotions( str(interaction.device_author["id"])) cjoy = emotions[1] csadness = emotions[4] if not os.path.exists(config_file): directory = os.path.dirname(config_file) if not os.path.exists(directory): os.makedirs(directory) with open(config_file, 'w+') as config: config.write( json.dumps([{ "name": parsed.feed.title, "url": url }])) success = Scheduler().add_or_update( 'parse_feed', interaction.device_author["ring_id"], interaction.get_author(), interaction.metadatas, minutes=5, repeat=True) if not success: string_to_say = self.rori.get_localized_sentence( 'failed', self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) csadness = 60 if csadness < 60 else csadness cjoy = 40 if csadness > 40 else cjoy EmotionsManager().go_to_emotion(d_id=str( interaction.device_author["id"]), delta=2, joy=cjoy, sadness=csadness) return else: with open(config_file, 'r') as config: data = json.load(config) for rsc in data: if url == rsc['url']: string_to_say = self.rori.get_localized_sentence( 'found', self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) csadness = 60 if csadness < 60 else csadness cjoy = 40 if csadness > 40 else cjoy EmotionsManager().go_to_emotion(d_id=str( interaction.device_author["id"]), delta=2, joy=cjoy, sadness=csadness) return data.append({"name": parsed.feed.title, "url": url}) with open(f'{config_dir}/feed/config.json', 'w+') as config: config.write(json.dumps(data)) string_to_say = self.rori.get_localized_sentence( 'added', self.sentences) self.rori.send_for_best_client("text/plain", interaction.device_author, string_to_say, rmd) csadness = 40 if csadness < 40 else csadness cjoy = 60 if csadness > 60 else cjoy EmotionsManager().go_to_emotion(d_id=str( interaction.device_author["id"]), delta=2, joy=cjoy, sadness=csadness)