def process_what_ami_doing(statement: SugaroidStatement): response = None for i in statement.doc: if i.lower_ in WHAT_I_AM_GOING_TO_DO.keys(): _answers_subset = WHAT_I_AM_GOING_TO_DO[i.lower_] if isinstance(_answers_subset, str): response = str(_answers_subset) elif isinstance(_answers_subset, list) or isinstance( _answers_subset, tuple ): response = random_response(_answers_subset) else: # FIXME: Needs more testing response = _answers_subset break if response: st = SugaroidStatement( response, confidence=0.5, chatbot=True, emotion=Emotion.cry_overflow ) st.confidence = 0.5 return st else: return SugaroidStatement( "Ok", confidence=0, chatbot=True, emotion=Emotion.cry_overflow )
def process(self, statement, additional_response_selection_parameters=None): confidence = 1 # FIXME Creates unusual response nl = spac_token(statement, chatbot=self.chatbot) for i in nl: if (i.lower_ == "my") or (i.lemma_ == "be") or (i.lower_ == "name"): continue logging.info("{} {}".format(i, i.pos_)) if (i.pos_ == "NOUN") or (i.pos_ == "PROPN"): response = random_response(GREET).format(str(i.text).capitalize()) selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = confidence emotion = Emotion.positive selected_statement.emotion = emotion self.chatbot.globals["USERNAME"] = i.text return selected_statement else: response = ":)" confidence = 0 selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = confidence emotion = Emotion.neutral selected_statement.emotion = emotion return selected_statement
def process_what_ami_doing(statement: SugaroidStatement): response = None for i in statement.doc: if i.lower_ in WHAT_I_AM_GOING_TO_DO.keys(): response = WHAT_I_AM_GOING_TO_DO[i.lower_] break if response: st = SugaroidStatement(response, confidence=0.5, chatbot=True, emotion=Emotion.cry_overflow) st.confidence = 0.5 return st else: return SugaroidStatement("Ok", confidence=0, chatbot=True, emotion=Emotion.cry_overflow)
def process(self, statement, additional_response_selection_parameters=None): response = None if not self.chatbot.globals['learn']: response = 'Enter something you want to teach me. What is the statement that you want me to learn.' self.chatbot.globals['learn'] = 2 elif self.chatbot.globals['learn'] == 2: response = 'What should I respond to the above statement?' self.chatbot.globals['learn_last_conversation'].append( str(statement)) self.chatbot.globals['learn'] -= 1 elif self.chatbot.globals['learn'] == 1: response = 'Thanks for teaching me something new. I will always try to remember that' self.chatbot.globals['learn_last_conversation'].append( str(statement)) self.chatbot.globals['learn'] -= 1 list_trainer = ListTrainer(self.chatbot) list_trainer.train(self.chatbot.globals['learn_last_conversation']) selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = 9 selected_statement.adapter = 'LearnAdapter' emotion = Emotion.lol selected_statement.emotion = emotion return selected_statement
def process( self, statement: SugaroidStatement, additional_response_selection_parameters=None, ): if self.chatbot.globals["trivia"]["enabled"]: # this is the turn for the user to answer st = self.chatbot.globals["trivia"]["class"] if st.check_answer(): response = "Correct! You got it right!" else: response = f"Oops. You got it wrong. The correct answer was {st.correct_answer}" self.chatbot.globals["trivia"]["enabled"] = False del self.chatbot.globals["trivia"]["class"] self.chatbot.globals["trivia"]["class"] = None else: st = SugaroidTrivia() self.chatbot.globals["trivia"]["enabled"] = True self.chatbot.globals["trivia"]["class"] = st response = st.ask() selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = 1.0 emotion = Emotion.neutral selected_statement.emotion = emotion return selected_statement
def process(self, statement, additional_response_selection_parameters=None): confidence = 1 # FIXME Creates unusual response response = ABOUT_CORONAVIRUS if any_in(["I", "i"], self.normalized): response = "I will do a short approximation if you do have coronavirus\n{covidq}".format( covidq=COVID_QUESTIONS[0][1]) self.chatbot.globals["reversei"]["uid"] = "CORONAVIRUS" self.chatbot.globals["reversei"]["enabled"] = True logging.info( f"CovidAdapter sets ['reversei']['enabled'] as {self.chatbot.globals['reversei']['enabled']}" ) self.chatbot.globals["reversei"]["data"] = [1, 0] elif "you" in self.normalized: response = ( "Someone told that I had been contracted with corona from somewhere, but thats extremely wrong." " I will not get infected by any physical virus, (except Trojan or NO_HEROKU_CREDIT virus)" ) selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = confidence emotion = Emotion.neutral selected_statement.emotion = emotion return selected_statement
def process(self, statement, additional_response_selection_parameters=None): cos = max([ self.chatbot.lp.similarity(str(statement), "Tell me something"), self.chatbot.lp.similarity(str(statement), "Ask me something"), self.chatbot.lp.similarity(str(statement), "Ask me a question"), self.chatbot.lp.similarity(str(statement), "What can you do?"), ]) if self.chatbot.lp.similarity(str(statement), "What can you do?") > 0.9: response = ( "I can say a joke, answer some questions, play a game of Akinator too." ) else: response_raw = random_response(RNDQUESTIONS) response = response_raw[0] self.chatbot.globals["reversei"]["enabled"] = True self.chatbot.globals["reversei"]["uid"] = response_raw[1] self.chatbot.globals["reversei"]["type"] = response_raw[2] selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = cos emotion = Emotion.neutral selected_statement.emotion = emotion return selected_statement
def process(self, statement, additional_response_selection_parameters=None): emotion = Emotion.seriously confidence = 0.81 response = random_response(ONE_WORD) short = str(statement).lower() if ("name" in short) and ("my" in short): if self.chatbot.globals["USERNAME"]: response = "You are {}".format( self.chatbot.globals["USERNAME"]) else: response = random_response(WHO_AM_I) elif ("name" in short) and ("your" in short): v = VERSION response = "\n{} \n{}. \nBuild: {}".format( SUGAROID[0], random_response(WHO_ARE_YOU), v.get_commit()) else: confidence = 0.2 selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = confidence selected_statement.emotion = emotion selected_statement.adapter = None return selected_statement
def process(self, statement, additional_response_selection_parameters=None): response = None confidence = 2.0 # FIXME: Override all other answers emotion = Emotion.genie if 'stop' in self.normalized: self.chatbot.globals['hangman']['enabled'] = False response = 'I am sorry. You quit the game abrubtly. {}'.format( random_response(HOPE_GAME_WAS_GOOD)) else: if not self.chatbot.globals['hangman']['enabled']: self.chatbot.globals['hangman']['class'] = Hangman( self.chatbot) response = "[ {dashes} ] Life: {heart}" \ .format(dashes=' '.join(self.chatbot.globals['hangman']['class'].gen_dash()), heart=HANGMAN_EMOJI[self.chatbot.globals['hangman']['class'].get_remaining_life() - 1] * self.chatbot.globals['hangman']['class'].get_remaining_life()) else: response = self.chatbot.globals['hangman']['class'].process( str(statement)) selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = confidence selected_statement.emotion = emotion return selected_statement
def process(self, statement, additional_response_selection_parameters=None): response = None confidence = 2.0 # FIXME: Override all other answers emotion = Emotion.genie if "stop" in self.normalized: self.chatbot.globals["akinator"]["enabled"] = False response = "I am sorry. You quit the game abrubtly. {}".format( random_response(HOPE_GAME_WAS_GOOD)) elif not self.chatbot.globals["akinator"]["enabled"]: self.chatbot.globals["akinator"]["class"] = SugaroidAkinator( self.chatbot) response = self.chatbot.globals["akinator"]["class"].start_game() else: if not self.chatbot.globals["akinator"]["class"].game_over(): response = self.chatbot.globals["akinator"][ "class"].progression(statement) if not response: response = self.chatbot.globals["akinator"]["class"].win() else: if self.chatbot.globals["akinator"]["class"].start_check(): response = self.chatbot.globals["akinator"][ "class"].check_ans(statement) selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = confidence selected_statement.emotion = emotion return selected_statement
def process(self, statement, additional_response_selection_parameters=None): confidence = 0.95 # FIXME Creates unusual response if "do you know" in str(statement).lower(): if self.normalized[0] == "do": self.normalized.pop(0) if self.normalized[0] == "you": self.normalized.pop(0) if self.normalized[0] == "know": self.normalized.pop(0) if "i" in self.normalized: response = random_response(WHO_AM_I) elif "you" in self.normalized: if "to" in self.normalized: confidence = 0.5 response = "You!" else: v = VERSION response = "\n{} \n{}. \nBuild: {}".format( SUGAROID[0], random_response(WHO_ARE_YOU), v) else: response = "check the wiki" confidence = 0 selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = confidence emotion = Emotion.neutral selected_statement.emotion = emotion return selected_statement
def process(self, statement, additional_response_selection_parameters=None): emotion = Emotion.rich confidence = 0.9 response = None converted = [] for i in self.tokenized: if i.tag_ in ['LS', 'CD']: self.currencies_src_ord = i.text if self.currencies_src_ord: try: self.currencies_src_ord = float(self.currencies_src_ord) sg_currency = SugaroidCurrency() for destination in self.currencies_dest: converted.append('{} {}'.format( sg_currency.convert(self.currencies_src.upper( ), destination.upper(), self.currencies_src_ord), destination.upper()) ) response = ' '.join(converted) except ValueError: response = 'Seems like I cannot process {}. Maybe try a numerical value for me to understand better' \ .format(self.currencies_src_ord) else: response = 'Seems like you forgot the important part of your currency conversion statement. The number!' selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = confidence selected_statement.emotion = emotion return selected_statement
def process(self, statement, additional_response_selection_parameters=None): response = 'I can\t run the same game again. Soz!' confidence = .5 sent = [] for i in games: sent.append('play the game {}'.format(i)) sent.append('can you play the game {}'.format(i)) cos = [] for j in sent: cos.append(self.chatbot.lp.similarity(j, str(statement))) maxcos = max(cos) response = 'Ok, I guess your game was great!' try: exec('from freegames import {}'.format(self.game)) except Exception as e: response = 'Oops, it cant run on your system' import os try: if os.environ['SUGAROID'] == 'CLI': input('Enter any key to continue to Sugaroid') elif os.environ['SUGAROID'] == 'GUI': time.sleep(5) except KeyError: pass selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = maxcos selected_statement.emotion = Emotion.neutral return selected_statement
def process(self, statement, additional_response_selection_parameters=None): confidence = 0.9 # FIXME Creates unusual response nn = False it = False token = spac_token(statement, chatbot=self.chatbot) for i in token: if (i.tag_ == 'NNP') or (i.tag_ == 'NN'): nn = True if i.lower_ == 'it': it = True if nn and not it: response = random_response(HOW_DO_HE_FEEL) emotion = Emotion.seriously elif it: response = "Ask it!" emotion = Emotion.o elif 'I' in self.normalized: emotion = Emotion.depressed response = random_response(HOW_DO_I_FEEL) else: emotion = Emotion.blush response = random_response(HOW_DO_YOU_FEEL) selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = confidence selected_statement.emotion = emotion return selected_statement
def process(self, statement, additional_response_selection_parameters=None): selected_statement = SugaroidStatement('Ok!', chatbot=True) selected_statement.confidence = 0 selected_statement.emotion = Emotion.neutral return selected_statement
def process(self, statement, additional_response_selection_parameters=None): confidence = 1 # FIXME Creates unusual response if 'do you know' in str(statement).lower(): if self.normalized[0] == 'do': self.normalized.pop(0) if self.normalized[0] == 'you': self.normalized.pop(0) if self.normalized[0] == 'know': self.normalized.pop(0) if 'i' in self.normalized: response = random_response(WHO_AM_I) elif 'you' in self.normalized: if 'to' in self.normalized: confidence = 0.5 response = 'You!' else: v = VERSION response = "\n{} \n{}. \nBuild: {}".format( SUGAROID[0], random_response(WHO_ARE_YOU), v.get_commit()) else: response = 'check the wiki' confidence = 0 selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = confidence emotion = Emotion.neutral selected_statement.emotion = emotion return selected_statement
def process( self, statement: SugaroidStatement, additional_response_selection_parameters=None, ): # https://github.com/pratishrai/doraemon/blob/302a78f8ace4b4675f3cd293dce101ea448b3e13/cogs/fun.py#L1 try: response2 = requests.get( "https://v2.jokeapi.dev/joke/Any?blacklistFlags=nsfw,religious,political,racist,sexist,explicit" ).json() try: joke = response2["joke"] except KeyError: setup = response2["setup"] delivery = response2["delivery"] if self.chatbot.globals["rich"]: joke = f"{setup}\n\n<i>{delivery}</i>" else: joke = f"{setup}\n\n{delivery}" except Exception as e: joke = f"I think I am a joke sometimes.. {e}" selected_statement = SugaroidStatement(joke, chatbot=True) selected_statement.set_confidence(1) selected_statement.set_emotion(Emotion.lol) return selected_statement
def process(self, statement, additional_response_selection_parameters=None): confidence = 0 dis_word = False if any_in(['distinguish', 'disfigure', 'distinct', 'distinction', 'distant', 'distance', 'distribution', 'distilled'], self.normalized): confidence = 0 else: logging.info( "DisAdapter: Starting Advanced scan. dis_word == {}".format(self.dis)[0]) dis_word = self.dis[3:] logging.info("DisAdapter: Distilled word == {}".format(dis_word)) sia = SentimentIntensityAnalyzer().polarity_scores(dis_word) if dis_word[0] in ['a', 'e', 'i', 'o', 'u', 'g', 'm', 'p']: confidence += 0.4 if 'infect' in dis_word: confidence -= 0.3 if 'spirit' in dis_word: confidence += 0.2 if any_in(['play', 'pensary', 'pense', 'patch', 'port', 'persal', 'perse', 'persion', 'praise'], dis_word): confidence -= 0.2 confidence += sia['neg'] inflection = getInflection( self.chatbot.lp.tokenize(self.dis)[0].lemma_, 'VBD') if inflection is None: past_participle_form_of_verb = self.dis else: past_participle_form_of_verb = inflection[0] if 'you' in self.normalized: response = random_response(DIS_RESPONSES_YOU).format( past_participle_form_of_verb) emotion = Emotion.angry_non_expressive elif 'I' in self.normalized: response = "{} {}".format(random_response( DIS_RESPONSES_I), random_response(CONSOLATION)) emotion = Emotion.angel else: nn = None pn = None tokenized = spac_token(statement, chatbot=self.chatbot) for i in tokenized: if (i.pos_ == "NOUN") or (i.pos_ == 'PROPN'): nn = i.text elif i.pos_ == 'PRON': pn = i.text if not (nn or pn): response = 'Lol. What?' emotion = Emotion.seriously else: response = random_response(DIS_RESPONSES_HIM).format(nn or pn) emotion = Emotion.cry_overflow selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = confidence selected_statement.emotion = emotion selected_statement.adapter = None return selected_statement
def process(self, statement, additional_response_selection_parameters=None): response = "What?" selected_statement = SugaroidStatement(response, chatbot=True) if self.chatbot.globals["history"]["total"][-1] != 0: selected_statement = self.chatbot.globals["history"]["total"][-1] selected_statement.confidence = 1 selected_statement.emotion = Emotion.angel return selected_statement
def process(self, statement, additional_response_selection_parameters=None): self.chatbot.reset_variables() selected_statement = SugaroidStatement( "Reset of chatbot variables. SUCCESS", chatbot=True) selected_statement.confidence = 0.95 emotion = Emotion.neutral selected_statement.emotion = emotion return selected_statement
def process(self, statement, additional_response_selection_parameters=None): response = random_response(LET_THIS_HAPPEN) selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = 1 selected_statement.emotion = Emotion.blush return selected_statement
def process(self, statement, additional_response_selection_parameters=None): confidence = 0.7 ls = ['😀', '😁', '😂', '😏', '😝'] selected_statement = SugaroidStatement( "ok ok {}".format(random_response(ls)), chatbot=True) selected_statement.confidence = confidence emotion = Emotion.wink selected_statement.emotion = emotion return selected_statement
def process(self, statement, additional_response_selection_parameters=None): url = ("https://api.wolframalpha.com/v2/query?" "input={query}" "&format=plaintext&output=JSON&appid={appid}") url = url.format( query="+".join(self.normalized), appid=os.getenv("WOLFRAM_ALPHA_API", "DEMO"), ) response = requests.get(url, headers={ "Accept": "application/json" }).json() if not response["queryresult"]["success"]: confidence = 0.3 try: text = response["queryresult"]["tips"]["text"] except KeyError: text = "Wolfram Alpha didnt send back a response" confidence = 0 selected_statement = SugaroidStatement(text, chatbot=True) selected_statement.confidence = confidence selected_statement.emotion = Emotion.positive return selected_statement information = [] for i in response["queryresult"]["pods"]: for j in i["subpods"]: try: if j["img"]["alt"] == "Plot": information.append(j["img"]["src"]) except KeyError: pass if j["plaintext"]: information.append(j["plaintext"]) interpretation = "\n".join(information) selected_statement = SugaroidStatement(interpretation, chatbot=True) selected_statement.confidence = 1 emotion = Emotion.lol selected_statement.emotion = emotion return selected_statement
def process(self, statement, additional_response_selection_parameters=None): emotion = Emotion.neutral confidence = 1 selected_statement = SugaroidStatement(random_response(BYE_RESPONSE), chatbot=True) selected_statement.confidence = confidence selected_statement.emotion = emotion selected_statement.adapter = None return selected_statement
def process(self, statement, additional_response_selection_parameters=None): st = SugaroidTrivia() response = st.ask() selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = self.cos self.chatbot.globals["trivia_answer"] = st.answer() emotion = Emotion.neutral selected_statement.emotion = emotion return selected_statement
def process(self, statement, additional_response_selection_parameters=None): if ( self.normalized[0] == "get" and self.normalized[1] == "lyrics" and self.normalized[2] == "for" ): self.normalized[0:3] = [] elif self.normalized[0] == "lyrics" and self.normalized[1] == "for": self.normalized[0:2] = [] elif self.normalized[0] == "lyrics": self.normalized[0:1] = [] stripped_message = " ".join(self.normalized).strip() try: song, artist = stripped_message.split("$ by") except Exception as e: selected_statement = SugaroidStatement( "Usage: _Hello $by Adele_ or " "_get lyrics for The Nights $by Avicii_", chatbot=True, ) selected_statement.confidence = 1 emotion = Emotion.lol selected_statement.emotion = emotion return selected_statement try: lyrics = get_lyrics(song, artist) if not lyrics or not lyrics.strip(): raise LyricsNotFound except LyricsNotFound: lyrics = "I couldn't find the lyrics for '{}' by '{}'.".format(song, artist) selected_statement = SugaroidStatement(lyrics, chatbot=True) selected_statement.confidence = 1 emotion = Emotion.lol selected_statement.emotion = emotion return selected_statement
def process( self, statement: SugaroidStatement, additional_response_selection_parameters=None, ) -> SugaroidStatement: emotion = Emotion.seriously confidence = 0.40 response = random_response(ONE_WORD) selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = confidence selected_statement.emotion = emotion selected_statement.adapter = None return selected_statement
def process(self, statement, additional_response_selection_parameters=None): emotion = Emotion.positive hour, minutes = current_time() alert = False if hour <= 0: alert = True time = '' elif hour <= 11: time = 'morning' elif hour <= 15: time = 'afternoon' elif hour <= 19: time = 'evening' elif hour <= 20: time = 'night' else: alert = True time = '' if not alert: if (time in self.intersect) or ('time' in self.intersect): response = 'Good {}'.format(time) else: response = 'Good {}. {}'.format( time, random_response(TIME_RESPONSE).format( list(self.intersect)[0])) else: if self.chatbot.lp.similarity('good night', str(statement)) > 0.9: response = 'Sweet Dreams' emotion = Emotion.sleep else: response = "You are staying up late, you should sleep right now." emotion = Emotion.seriously if "what" in str(statement).lower(): # the user might be asking the time # so we have to inform it instead of wishing # the person good morning response = "The current time is {:02d}:{:02d}".format( hour, minutes) emotion = Emotion.adorable selected_statement = SugaroidStatement("{}".format(response), chatbot=True) selected_statement.confidence = 1 selected_statement.emotion = emotion return selected_statement
def process(self, statement, additional_response_selection_parameters=None): emotion = Emotion.neutral response = 'ok' confidence = 0 rectified = [] tokenized = nltk.pos_tag(self.normalized) for i in range(len(tokenized)): if tokenized[i][1] == 'WP': rectified.extend(self.normalized[i:]) break else: continue else: if ('my' in self.normalized) and ('name' in self.normalized): if self.chatbot.get_username(): response = 'Your name is {}'.format( self.chatbot.globals['username']) emotion = Emotion.neutral confidence = 1 else: response = 'No, I don\'t know your name' emotion = Emotion.cry_overflow confidence = 0.8 elif 'my' in self.normalized: response = 'Lol, maybe not' emotion = Emotion.lol confidence = 0.8 else: response = 'Yes, Yes I do!' emotion = Emotion.wink confidence = 0.8 if rectified: if 'Srevin' in rectified: response = "Srevin Saju is the creator of Sugaroid bot" confidence = 1 else: wk = WikiAdapter(self.chatbot) wk.text = self.normalized response = WikiAdapter.process( wk, Statement(' '.join(rectified))) return response selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = confidence selected_statement.emotion = emotion return selected_statement
def process(self, statement, additional_response_selection_parameters=None): pop = subprocess.Popen( shlex.split('{pip} install -U https://github.com/srevinsaju/sugaroid/archive/master.zip' .format(pip=shutil.which('pip'))), stdout=subprocess.PIPE, stderr=subprocess.PIPE ) pop.communicate() response = f"Reload : Traceback {pop.stdout.read().decode()} {pop.stdin.read().decode()} . Restarting bot" selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = 10 self.chatbot.update = True emotion = Emotion.rich selected_statement.emotion = emotion return selected_statement