nerve/main.py

36 lines
921 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
2022-08-09 15:39:51 -04:00
async def message(room, message):
2022-09-28 11:02:35 -04:00
try:
result = commands.handle_command(message.sender, message.body)
if result['response'] != None and result['response'] != "":
await bot.api.send_markdown_message(
room.room_id,
result['response']
)
except:
with open("error.log",'a') as f:
f.write(f"Error:{message}")
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()