Source code for sugaroid.brain.update

import importlib
import logging
import shutil
import subprocess
import shlex

from chatterbot.logic import LogicAdapter
from chatterbot.trainers import ListTrainer
from nltk import word_tokenize

from sugaroid.core.statement import SugaroidStatement
from sugaroid.brain.ooo import Emotion
from sugaroid.brain.preprocessors import normalize


[docs]class UpdateAdapter(LogicAdapter): """ [DO NOT CONNECT] a specific adapter for updating the sugaroid bot """ def __init__(self, chatbot, **kwargs): super().__init__(chatbot, **kwargs)
[docs] def can_process(self, statement): normalized = word_tokenize(str(statement).lower()) if "update" in normalized and "admin" not in normalized: return True else: return False
[docs] 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