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(
|
2022-05-20 06:35:33 -04:00
|
|
|
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):
|
2022-05-20 06:35:33 -04:00
|
|
|
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,
|
2022-05-20 06:35:33 -04:00
|
|
|
commands.get_faq_string()
|
2022-02-23 02:45:33 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
bot.run()
|