Skip to content

Commit

Permalink
Merge pull request #1 from alliraine/achapman/major_update_1
Browse files Browse the repository at this point in the history
Achapman/major update 1
  • Loading branch information
alliraine authored Sep 18, 2023
2 parents fedfb2f + 81c33c1 commit 6d7382f
Show file tree
Hide file tree
Showing 10 changed files with 1,106 additions and 43 deletions.
3 changes: 2 additions & 1 deletion actions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .beep import BeepCommand
from .qotd import QotdCommand
from .aster import AsterCommand

__all__ = ["BeepCommand", "QotdCommand"]
__all__ = ["BeepCommand", "QotdCommand", "AsterCommand"]
26 changes: 26 additions & 0 deletions actions/aster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from signalbot import Command, Context
import openai
import os

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

async def handle(self, c: Context):
command = c.message.text
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
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
41 changes: 19 additions & 22 deletions actions/qotd.py
Original file line number Diff line number Diff line change
@@ -1,32 +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":
print("command qotd triggered")
await c.react('🤖')
qotd = get_qotd()
await c.send(f"❓QOTD: {qotd}")
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
500 changes: 500 additions & 0 deletions actions/random_questions.csv

Large diffs are not rendered by default.

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
Loading

0 comments on commit 6d7382f

Please sign in to comment.