Skip to content

Commit

Permalink
Fixed to run on Pi Zero
Browse files Browse the repository at this point in the history
  • Loading branch information
alliraine committed Sep 18, 2023
1 parent f748644 commit 81c33c1
Show file tree
Hide file tree
Showing 7 changed files with 1,034 additions and 45 deletions.
3 changes: 1 addition & 2 deletions actions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .beep import BeepCommand
from .qotd import QotdCommand
from .trivia import TriviaCommand
from .aster import AsterCommand

__all__ = ["BeepCommand", "QotdCommand", "TriviaCommand"]
__all__ = ["BeepCommand", "QotdCommand", "AsterCommand"]
31 changes: 16 additions & 15 deletions actions/aster.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
from signalbot import Command, Context
import openai
import os
openai.organization = "org-39lwdYbHwZNWOWJ9k9IrCctR"
openai.api_key = os.getenv("OPENAI_API_KEY")

class AsterCommand(Command):
def describe(self) -> str:
return "OpenAI Trigger"

async def handle(self, c: Context):
command = c.message.text
if "aster" in command.lower():
await c.start_typing()
await c.react('🤖')
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a chat bot called Asterbot. You are here to assisted The Constellation which consists of Alli, Jen, Ellie, and Sae. They are a queer polycule"},
{"role": "user", "content": command}
]
)
await c.reply(response.choices[0].message)
await c.stop_typing()
return
print(c.message.mentions)
if len(c.message.mentions) > 0:
if "2219a1a4-828b-4af1-9804-ca839236d40f" in c.message.mentions[0]["uuid"]:
await c.start_typing()
await c.react('🤖')
openai.api_key = os.getenv("OPEN_AI")
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a chat bot called Asterbot. You are here to assisted The Constellation a queer lesbian polycule which consists of Alli, Jen, Ellie, and Sae."},
{"role": "user", "content": command}
]
)
await c.send(response.choices[0].message.content)
await c.stop_typing()
return
43 changes: 19 additions & 24 deletions actions/qotd.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
from selenium.webdriver.chrome.options import Options
from signalbot import Command, Context
from bs4 import BeautifulSoup
import requests
from selenium import webdriver
from signalbot import Command, Context, triggered


def get_qotd():
options = Options()
options.headless = True
driver = webdriver.Chrome(options=options)
driver.get('https://randomwordgenerator.com/question.php')
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')
s = soup.find('ol', id='result')
driver.quit()
return s.find('span', class_='support-sentence').text
file = open("data/random_questions.csv", "r")
questions = file.read()
question_list = questions.split('\n')

question = question_list[0]

with open('data/random_questions.csv', 'w') as fp:
fp.write('\n'.join(question_list[1:]))

return question


class QotdCommand(Command):
def describe(self) -> str:
return "🏓 Beep Command: Listen for a beep"

@triggered("qotd")
async def handle(self, c: Context):
command = c.message.text

if command == "qotd":
await c.start_typing()
print("command qotd triggered")
await c.react('🤖')
qotd = get_qotd()
await c.reply(f"❓QOTD: {qotd}")
await c.stop_typing()
return
await c.start_typing()
print("command qotd triggered")
await c.react('🤖')
qotd = get_qotd()
await c.reply(f"❓QOTD: {qotd}")
await c.stop_typing()
return
Loading

0 comments on commit 81c33c1

Please sign in to comment.