1
0
Fork 0
quotes-bot-python/bot.py

66 lines
2 KiB
Python
Raw Normal View History

2025-01-31 18:12:38 -06:00
import simplematrixbotlib as botLibrary
2025-01-31 18:20:14 -06:00
import json
2025-01-31 19:06:34 -06:00
import fetch
2025-01-31 18:12:38 -06:00
2025-01-31 18:20:14 -06:00
with open('config.json', 'r') as f:
config = json.load(f)
2025-01-31 18:38:04 -06:00
credentials = botLibrary.Creds(config['matrix']['server'], config['matrix']['userid'], config['matrix']['password'])
2025-01-31 18:20:14 -06:00
print(credentials)
2025-01-31 18:12:38 -06:00
bot = botLibrary.Bot(credentials)
PREFIX = "!q"
@bot.listener.on_message_event
async def help_message(room, message):
2025-01-31 18:29:15 -06:00
match = botLibrary.MessageMatch(room, message, bot, PREFIX)
2025-01-31 18:12:38 -06:00
if not (match.is_not_from_this_bot() and match.prefix()
and match.command("help")):
return
message = (f"""
Help
============================
A work-in-progress Python rewrite of the original quotes bot, aiming for a mostly complete remake.
2025-01-31 18:30:32 -06:00
{PREFIX} help - show this message
2025-01-31 19:17:34 -06:00
{PREFIX} get - fetch a image from the defined instance
2025-01-31 19:35:15 -06:00
{PREFIX} source - send a link to the source code
2025-01-31 18:12:38 -06:00
""")
await bot.api.send_text_message(room.room_id, message)
2025-01-31 18:18:21 -06:00
@bot.listener.on_message_event
async def make_choice(room, message):
2025-01-31 18:29:15 -06:00
match = botLibrary.MessageMatch(room, message, bot, PREFIX)
2025-01-31 18:18:21 -06:00
if not (match.is_not_from_this_bot() and match.prefix()
and match.command("get")):
return
temp = True
if not match.args():
temp = False
else:
id = match.args()
2025-01-31 18:36:46 -06:00
id = str(id[1])
2025-01-31 19:06:34 -06:00
quoteLink = fetch.fetchQuote(id)
2025-01-31 18:18:21 -06:00
message = (f"""
2025-01-31 18:36:46 -06:00
Command recived (DEBUG).
2025-01-31 19:06:34 -06:00
(We're supposed to fetch quote number {id} now, from {quoteLink}.)
2025-01-31 18:18:21 -06:00
""")
await bot.api.send_text_message(room.room_id, message)
2025-01-31 18:29:15 -06:00
2025-01-31 19:35:15 -06:00
@bot.listener.on_message_event
async def help_message(room, message):
match = botLibrary.MessageMatch(room, message, bot, PREFIX)
if not (match.is_not_from_this_bot() and match.prefix()
and match.command("help")):
return
message = (f"""
quotes-bot-python by Nyx Tutt (@n:everypizza.im)
https://git.everypizza.im/n/quotes-bot-python/
""")
await bot.api.send_text_message(room.room_id, message)
2025-01-31 18:29:15 -06:00
bot.run()