Skip to content

Commit

Permalink
Add openai. Bump version. Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alliraine committed Sep 17, 2023
1 parent fedfb2f commit f748644
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 22 deletions.
4 changes: 3 additions & 1 deletion actions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from .beep import BeepCommand
from .qotd import QotdCommand
from .trivia import TriviaCommand
from .aster import AsterCommand

__all__ = ["BeepCommand", "QotdCommand"]
__all__ = ["BeepCommand", "QotdCommand", "TriviaCommand"]
25 changes: 25 additions & 0 deletions actions/aster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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
6 changes: 4 additions & 2 deletions actions/beep.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ def describe(self) -> str:

async def handle(self, c: Context):
command = c.message.text

print(command)
if "beep" in command.lower():
await c.start_typing()
await c.react('🤖')
response = "boop"
for x in range(command.lower().count("beep") - 1):
response += " boop"
await c.send(response)
await c.reply(response)
await c.stop_typing()
return
4 changes: 3 additions & 1 deletion actions/qotd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ 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.send(f"❓QOTD: {qotd}")
await c.reply(f"❓QOTD: {qotd}")
await c.stop_typing()
return
41 changes: 41 additions & 0 deletions actions/trivia.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from signalbot import Command, Context
from trivia import trivia

curr = None

class Trivia:
def __init__(self, category, type, difficulty, question, correct_answer):
self.category = category
self.type = type
self.difficulty = difficulty
self.question = question
self. correct_answer = correct_answer


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

async def handle(self, c: Context):
command = c.message.text
global curr

if command == "trivia":
await c.start_typing()
print("command trivia triggered")
await c.react('🤖')
question = await trivia.question(amount=1, category=0, difficulty='easy', quizType='multiple')
q = question[0]
curr = Trivia(q.get("category"), q.get("type"), q.get("difficulty"), q.get("question"), q.get("correct_answer"))
res = f"🧠Today's trivia is in the {curr.category} category! \n❓Question: {curr.question}"
await c.reply(f"{res}")
await c.stop_typing()
return

if command == "trivia answer":
await c.start_typing()
print("command trivia triggered")
await c.react('🤖')
await c.reply(f"The answer is: {curr.correct_answer}")
await c.stop_typing()
return
20 changes: 9 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,38 @@
import schedule
from signalbot import SignalBot
import logging
from actions import BeepCommand, QotdCommand
import chromedriver_autoinstaller
from actions import BeepCommand, QotdCommand, TriviaCommand, AsterCommand
from tasks.send_qotd import send_qotd

logging.getLogger().setLevel(logging.INFO)
logging.getLogger("apscheduler").setLevel(logging.WARNING)


def main():
signal_service = os.environ["SIGNAL_SERVICE"]
phone_number = os.environ["PHONE_NUMBER"]
group_id = os.environ["GROUP_ID"]
internal_id = os.environ["GROUP_INTERNAL_ID"]

chromedriver_autoinstaller.install()

config = {
"signal_service": signal_service,
"phone_number": phone_number,
"storage": None,
"phone_number": phone_number
}
bot = SignalBot(config)

bot.listen(group_id, internal_id)

bot.register(BeepCommand())
bot.register(QotdCommand())
bot.register(TriviaCommand())
bot.register(AsterCommand())
bot.start()

bot.send(internal_id, "I am aliveeeee", listen=True)
bot.send(group_id, "I am aliveeeee")

schedule.every(5).minutes.do(send_qotd, bot=bot)

while True:
schedule.run_pending()
time.sleep(1)


if __name__ == "__main__":
main()
main()
14 changes: 8 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
signalbot~=0.6.0

requests~=2.30.0
selenium~=4.9.1
beautifulsoup4~=4.12.2
schedule~=1.2.0
signalbot
chromedriver_autoinstaller
requests
selenium
beautifulsoup4
schedule
trivia.py
openai
4 changes: 3 additions & 1 deletion tasks/send_qotd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os

from actions.qotd import get_qotd


def send_qotd(bot):
print("triggered send_qotd")
bot.send(f"❓QOTD: {get_qotd()}")
bot.send(os.environ["GROUP_ID"], f"❓QOTD: {get_qotd()}")

0 comments on commit f748644

Please sign in to comment.