Compare commits

..
1 Commits
Author SHA1 Message Date
retoor e5f12d0ae5 first commit 2024-12-16 23:15:42 +01:00
3 changed files with 23 additions and 34 deletions
-4
View File
@@ -1,4 +0,0 @@
# Boeh
## Description
Matrix bot written in Python that says boeh everytime that Joe talks. He knows why.
+12 -16
View File
@@ -1,18 +1,8 @@
import asyncio
import os
from nio import AsyncClient, RoomMessageText
import random
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):
self.url = url
self.username = username
@@ -22,23 +12,26 @@ class BooeehBot:
async def login(self):
try:
response = await self.client.login(self.password)
print(f"Logged in. Serving {self.username}.")
print(f"User logged in: {self.username}")
return response
except Exception as e:
print(f"Login error: {e}")
return None
async def handle_message(self, room, event):
specific_user_id = "@joewilliams007:matrix.org"
specific_user_id = '@joewilliams007:matrix.org'
if isinstance(event, RoomMessageText):
if event.sender == specific_user_id:
response_text = self.generate_boeh()
response_text = "booeeeh"
try:
await self.client.room_send(
room.room_id,
message_type="m.room.message",
content={"msgtype": "m.text", "body": response_text},
content={
"msgtype": "m.text",
"body": response_text
}
)
print(f"Response to {event.sender}: " + response_text)
except Exception as e:
@@ -55,3 +48,6 @@ class BooeehBot:
async def stop(self):
await self.client.close()
+2 -5
View File
@@ -1,7 +1,6 @@
import asyncio
from boeh import BooeehBot, env
from boeh import env
from boeh import BooeehBot
async def main_async():
url = "https://matrix.org"
@@ -14,10 +13,8 @@ async def main_async():
except KeyboardInterrupt:
await bot.stop()
def main():
asyncio.run(main_async())
if __name__ == "__main__":
main()