Beispiel #1
0
class TestBlocking:
    def setup(self):
        self.rs = RandomStuff()

    def test_invalid_joke_error(self):
        with pytest.raises(RuntimeError) as exc:
            self.rs.get_joke("deva")
        assert "deva" in str(exc)

    def test_invalid_image_error(self):
        with pytest.raises(RuntimeError) as exc:
            self.rs.get_image("awww")
        assert "awww" in str(exc)

    def test_joke_response(self):
        response = self.rs.get_joke("dev")

        assert isinstance(response, dict)
        assert set(response.keys()).issuperset(joke_response_keys)

    def test_ai_response(self):
        response = self.rs.get_ai_response("Hello!")

        assert isinstance(response, str)

    def test_image_reponse(self):
        response = self.rs.get_image("aww")

        assert isinstance(response, str)

    def teardown(self):
        self.rs.close()
Beispiel #2
0
class TestAsync:
    def setup(self):
        self.rs = RandomStuff(async_mode=True)
        self.loop = get_event_loop()
        self.run = self.loop.run_until_complete

    def test_joke_response(self):
        response = self.run(self.rs.get_joke("dev"))

        assert isinstance(response, dict)
        assert set(response.keys()).issuperset(joke_response_keys)

    def test_image_response(self):
        response = self.run(self.rs.get_image("aww"))

        assert isinstance(response, str)

    def test_ai_response(self):
        response = self.run(self.rs.get_ai_response("Hello!"))

        assert isinstance(response, str)
Beispiel #3
0
def post_message():
    message = request.form['message']
    rs = RandomStuff()
    response = rs.get_ai_response(message)
    return f"""<h1>You >> {message}<br> Spot >>> {response}<br></h1>"""
# import the module
from prsaw import RandomStuff

# initiate the object
rs = RandomStuff()

# get a response from an endpoint
response = rs.get_ai_response("How are you?")
print(response)

# close the object once done (recommended)
rs.close()
Beispiel #5
0
import discord, os
from life import revive_stamina
from prsaw import RandomStuff

rs = RandomStuff()
client = discord.Client(async_mode=True)
res = rs.get_ai_response("Hi there!")


@client.event
async def on_ready():
    print("Let's go, {0.user}!".format(client))


@client.event
async def on_message(message):
    if client.user == message.author:
        return

    res = rs.get_ai_response(message.content)
    await message.reply(res)


revive_stamina()
client.run(os.getenv('TOKEN'))