<commit_before>import cmd
import random
import sys
import logging
import requests
import threading
import readline
import traceback

from will import settings
from will.utils import Bunch, UNSURE_REPLIES
from will.abstractions import Message, Person, Channel
from .base import StdInOutIOBackend


class ShellBackend(StdInOutIOBackend):
    friendly_name = "Interactive Shell"
    internal_name = "will.backends.io_adapters.shell"
    partner = Person(
        id="you",
        handle="you",
        source=Bunch(),
        name="Friend",
    )

    def send_direct_message(self, message_body, **kwargs):
        print("Will: %s" % message_body)

    def send_room_message(self, room_id, message_body, html=False, color="green", notify=False, **kwargs):
        print("Will: %s" % message_body)

    def set_room_topic(self, room_id, topic):
        print("Will: Setting the Topic to %s" & topic)

    def normalize_incoming_event(self, event):
        if event["type"] == "message.incoming.stdin":
            m = Message(
                content=event.data.content.strip(),
                type=event.type,
                is_direct=True,
                is_private_chat=True,
                is_group_chat=False,
                backend=self.name,
                sender=self.partner,
                will_is_mentioned=False,
                will_said_it=False,
                backend_supports_acl=False,
                source=event
            )
            return m
        else:
            # An event type the shell has no idea how to handle.
            return None

    def handle_outgoing_event(self, event):
        # Print any replies.
        # print "handle_outgoing_event"
        # print event
        if event.type in ["say", "reply"]:
            self.send_direct_message(event.content)

        elif event.type == "message.no_response":
            if event.data and hasattr(event.data, "content") and len(event.data.content) > 0:
                self.send_direct_message(random.choice(UNSURE_REPLIES))

        # Regardless of whether or not we had something to say,
        # give the user a new prompt.
        sys.stdout.write("You:  ")
        sys.stdout.flush()

    def bootstrap(self):
        # Bootstrap must provide a way to to have:
        # a) self.normalize_incoming_event fired, or incoming events put into self.incoming_queue
        # b) any necessary threads running for a)
        # c) self.me (Person) defined, with Will's info
        # d) self.people (dict of People) defined, with everyone in an organization/backend
        # e) self.channels (dict of Channels) defined, with all available channels/rooms.
        #    Note that Channel asks for members, a list of People.
        # f) A way for self.handle, self.me, self.people, and self.channels to be kept accurate,
        #    with a maximum lag of 60 seconds.
        self.people = {}
        self.channels = {}
        self.me = Person(
            id="will",
            handle="will",<commit_msg>Fixes up unsure response in shell backend<commit_after>import cmd
import random
import sys
import logging
import requests
import threading
import readline
import traceback

from will import settings
from will.utils import Bunch, UNSURE_REPLIES
from will.abstractions import Message, Person, Channel
from .base import StdInOutIOBackend


class ShellBackend(StdInOutIOBackend):
    friendly_name = "Interactive Shell"
    internal_name = "will.backends.io_adapters.shell"
    partner = Person(
        id="you",
        handle="you",
        source=Bunch(),
        name="Friend",
    )

    def send_direct_message(self, message_body, **kwargs):
        print("Will: %s" % message_body)

    def send_room_message(self, room_id, message_body, html=False, color="green", notify=False, **kwargs):
        print("Will: %s" % message_body)

    def set_room_topic(self, room_id, topic):
        print("Will: Setting the Topic to %s" & topic)

    def normalize_incoming_event(self, event):
        if event["type"] == "message.incoming.stdin":
            m = Message(
                content=event.data.content.strip(),
                type=event.type,
                is_direct=True,
                is_private_chat=True,
                is_group_chat=False,
                backend=self.name,
                sender=self.partner,
                will_is_mentioned=False,
                will_said_it=False,
                backend_supports_acl=False,
                source=event
            )
            return m
        else:
            # An event type the shell has no idea how to handle.
            return None

    def handle_outgoing_event(self, event):
        # Print any replies.
        # print "handle_outgoing_event"
        # print event
        if event.type in ["say", "reply"]:
            self.send_direct_message(event.content)

        elif event.type == "message.no_response":
            # TODO: Seriously fix this. It's gross and confusing.
            # print event.data["source"].data.content
            if event.data and "source" in event.data and len(event.data["source"].data.content) > 0:
                self.send_direct_message(random.choice(UNSURE_REPLIES))

        # Regardless of whether or not we had something to say,
        # give the user a new prompt.
        sys.stdout.write("You:  ")
        sys.stdout.flush()

    def bootstrap(self):
        # Bootstrap must provide a way to to have:
        # a) self.normalize_incoming_event fired, or incoming events put into self.incoming_queue
        # b) any necessary threads running for a)
        # c) self.me (Person) defined, with Will's info
        # d) self.people (dict of People) defined, with everyone in an organization/backend
        # e) self.channels (dict of Channels) defined, with all available channels/rooms.
        #    Note that Channel asks for members, a list of People.
        # f) A way for self.handle, self.me, self.people, and self.channels to be kept accurate,
        #    with a maximum lag of 60 seconds.
        self.people = {}
        self.channels = {}
        self.me = Person(
            id="will",
            handle="will",
{'fraction_non_alphanumeric': 0.09076148725442441, 'fraction_numerical': 0.000974184120798831, 'mean_word_length': 2.235294117647059, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5610208', 'n_tokens_mistral': 1754, 'n_tokens_neox': 1692, 'n_words': 512}