nerve/main.py

33 lines
792 B
Python
Raw Normal View History

2022-02-23 02:45:33 -05:00
import json
import nio
import simplematrixbotlib as botlib
2022-03-03 14:18:07 -05:00
import commands
2022-02-23 02:45:33 -05:00
data = json.loads(open('data.json').read())
creds = botlib.Creds(
data["homeserver"],
data['username'],
data['password']
)
2022-02-23 02:45:33 -05:00
bot = botlib.Bot(creds)
2022-03-07 04:24:40 -05:00
2022-02-23 02:45:33 -05:00
@bot.listener.on_message_event
async def faq(room, message):
result = commands.handle_command(message.sender, message.body)
if result['response'] != None and result['response'] != "":
2022-03-07 04:24:40 -05:00
await bot.api.send_markdown_message(
room.room_id,
result['response']
)
2022-02-23 02:45:33 -05:00
2022-03-07 04:24:40 -05:00
2022-02-23 02:45:33 -05:00
@bot.listener.on_custom_event(nio.InviteMemberEvent)
2022-02-23 03:47:03 -05:00
async def example(room, event):
2022-02-23 02:45:33 -05:00
if event.membership == "join":
await bot.api.send_markdown_message(
room.room_id,
commands.get_faq_string()
2022-02-23 02:45:33 -05:00
)
bot.run()