Compare commits
5
Commits
e5f12d0ae5
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c47c0f166 | ||
|
|
3d6ad4bef0 | ||
|
|
40ce71244f | ||
|
|
6f0be04dd9 | ||
|
|
b9f2c55d75 |
@@ -0,0 +1,4 @@
|
||||
# Boeh
|
||||
|
||||
## Description
|
||||
Matrix bot written in Python that says boeh everytime that Joe talks. He knows why.
|
||||
+16
-12
@@ -1,8 +1,18 @@
|
||||
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
|
||||
@@ -12,26 +22,23 @@ class BooeehBot:
|
||||
async def login(self):
|
||||
try:
|
||||
response = await self.client.login(self.password)
|
||||
print(f"User logged in: {self.username}")
|
||||
print(f"Logged in. Serving {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 = "booeeeh"
|
||||
response_text = self.generate_boeh()
|
||||
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:
|
||||
@@ -48,6 +55,3 @@ class BooeehBot:
|
||||
|
||||
async def stop(self):
|
||||
await self.client.close()
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
from boeh import env
|
||||
from boeh import BooeehBot
|
||||
|
||||
from boeh import BooeehBot, env
|
||||
|
||||
|
||||
async def main_async():
|
||||
url = "https://matrix.org"
|
||||
@@ -13,8 +14,10 @@ async def main_async():
|
||||
except KeyboardInterrupt:
|
||||
await bot.stop()
|
||||
|
||||
|
||||
def main():
|
||||
asyncio.run(main_async())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user