Skip to content

Commit

Permalink
Add QOTD command. Add boop response per beep
Browse files Browse the repository at this point in the history
  • Loading branch information
alliraine committed May 11, 2023
1 parent 65aa5af commit ba4e82c
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.envrc
.idea
Empty file added Dockerfile
Empty file.
3 changes: 2 additions & 1 deletion actions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .beep import BeepCommand
from .qotd import QotdCommand

__all__ = ["BeepCommand"]
__all__ = ["BeepCommand", "QotdCommand"]
Binary file modified actions/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file modified actions/__pycache__/beep.cpython-310.pyc
Binary file not shown.
Binary file added actions/__pycache__/qotd.cpython-310.pyc
Binary file not shown.
6 changes: 4 additions & 2 deletions actions/beep.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ def describe(self) -> str:
async def handle(self, c: Context):
command = c.message.text

if command == "beep":
await c.send("boop")
if "beep" in command:
await c.react('🤖')
for x in range(command.count("beep")):
await c.send("boop")
return
27 changes: 27 additions & 0 deletions actions/qotd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from selenium.webdriver.chrome.options import Options
from signalbot import Command, Context
from bs4 import BeautifulSoup
import requests
from selenium import webdriver

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

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

if command == "qotd":
print("command qotd triggered")
await c.react('🤖')
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')
qotd = s.find('span', class_='support-sentence')
await c.send(f"❓QOTD: {qotd.text}")
driver.quit()
return
6 changes: 5 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
from signalbot import SignalBot
import logging
from actions import BeepCommand
from actions import BeepCommand, QotdCommand
import chromedriver_autoinstaller

logging.getLogger().setLevel(logging.INFO)
logging.getLogger("apscheduler").setLevel(logging.WARNING)
Expand All @@ -13,6 +14,8 @@ def main():
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,
Expand All @@ -23,6 +26,7 @@ def main():
bot.listen(group_id, internal_id)

bot.register(BeepCommand())
bot.register(QotdCommand())


bot.start()
Expand Down
24 changes: 24 additions & 0 deletions manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: asterdroid
labels:
app: asterdroid
spec:
replicas: 3
selector:
matchLabels:
app: asterdroid
template:
metadata:
labels:
app: asterdroid
spec:
containers:
- name: signal-cli
image: bbernhard/signal-cli-rest-api
ports:
- containerPort: 8080
env:
- name: MODE
value: "json-rpc"

0 comments on commit ba4e82c

Please sign in to comment.