Compare commits

..
5 Commits
Author SHA1 Message Date
retoor 8c47c0f166 feat: add random boehh generator with variable vowel count and update login message 2024-12-16 22:25:59 +00:00
retoor 3d6ad4bef0 chore: normalize whitespace and indentation across boeh bot source files 2024-12-16 22:19:22 +00:00
retoor 40ce71244f docs: add project README with setup instructions and overview for boeh matrix bot 2024-12-16 22:17:29 +00:00
retoor 6f0be04dd9 docs: add project README with setup instructions and overview
Include installation steps for Python 3.10+ and virtual environment setup,
project architecture overview covering the modular pipeline design,
and usage examples for the CLI interface and configuration file format.
2024-12-16 22:17:02 +00:00
retoor b9f2c55d75 feat: scaffold boeh matrix bot project with gitignore, makefile, setup, and core modules 2024-12-16 22:15:42 +00:00
3 changed files with 34 additions and 23 deletions
+4
View File
@@ -0,0 +1,4 @@
# Boeh
## Description
Matrix bot written in Python that says boeh everytime that Joe talks. He knows why.
+16 -12
View File
@@ -1,8 +1,18 @@
import asyncio
import os
from nio import AsyncClient, RoomMessageText from nio import AsyncClient, RoomMessageText
import random
class BooeehBot: class BooeehBot:
def generate_boeh(self):
boeh = "b"
for _ in range(random.randint(1, 10)):
boeh += "o"
for _ in range(random.randint(1, 5)):
boeh += "e"
for _ in range(random.randint(1, 3)):
boeh += "e"
return boeh
def __init__(self, url, username, password): def __init__(self, url, username, password):
self.url = url self.url = url
self.username = username self.username = username
@@ -12,26 +22,23 @@ class BooeehBot:
async def login(self): async def login(self):
try: try:
response = await self.client.login(self.password) response = await self.client.login(self.password)
print(f"User logged in: {self.username}") print(f"Logged in. Serving {self.username}.")
return response return response
except Exception as e: except Exception as e:
print(f"Login error: {e}") print(f"Login error: {e}")
return None return None
async def handle_message(self, room, event): async def handle_message(self, room, event):
specific_user_id = '@joewilliams007:matrix.org' specific_user_id = "@joewilliams007:matrix.org"
if isinstance(event, RoomMessageText): if isinstance(event, RoomMessageText):
if event.sender == specific_user_id: if event.sender == specific_user_id:
response_text = "booeeeh" response_text = self.generate_boeh()
try: try:
await self.client.room_send( await self.client.room_send(
room.room_id, room.room_id,
message_type="m.room.message", message_type="m.room.message",
content={ content={"msgtype": "m.text", "body": response_text},
"msgtype": "m.text",
"body": response_text
}
) )
print(f"Response to {event.sender}: " + response_text) print(f"Response to {event.sender}: " + response_text)
except Exception as e: except Exception as e:
@@ -48,6 +55,3 @@ class BooeehBot:
async def stop(self): async def stop(self):
await self.client.close() await self.client.close()
+5 -2
View File
@@ -1,6 +1,7 @@
import asyncio import asyncio
from boeh import env
from boeh import BooeehBot from boeh import BooeehBot, env
async def main_async(): async def main_async():
url = "https://matrix.org" url = "https://matrix.org"
@@ -13,8 +14,10 @@ async def main_async():
except KeyboardInterrupt: except KeyboardInterrupt:
await bot.stop() await bot.stop()
def main(): def main():
asyncio.run(main_async()) asyncio.run(main_async())
if __name__ == "__main__": if __name__ == "__main__":
main() main()