Compare commits

..

10 commits
0.3.0 ... main

2 changed files with 65 additions and 76 deletions

139
bot.py
View file

@ -1,6 +1,7 @@
import simplematrixbotlib as botLibrary
import json
import fetch
import time
version = "0.3.0"
@ -34,31 +35,27 @@ async def help_message(room, message):
and match.command("help")):
return
if debugMode == False:
message = (f"""
Help
============================
A work-in-progress Python rewrite of the original quotes bot, aiming for a mostly complete remake.
{PREFIX} help - show this message
{PREFIX} get - fetch a image from the defined instance
{PREFIX} source - send a link to the source code
{PREFIX} version - show the bot version
{PREFIX} die - kills the bot (only admins can do this!)
""")
message = (f"""Help
============================
A work-in-progress Python rewrite of the original quotes bot, aiming for a mostly complete remake.
{PREFIX} help - show this message
{PREFIX} get - fetch a image from the defined instance
{PREFIX} source - send a link to the source code
{PREFIX} version - show the bot version
{PREFIX} die - kills the bot (only admins can do this!)""")
else:
message = (f"""
Help
============================
A work-in-progress Python rewrite of the original quotes bot, aiming for a mostly complete remake.
{PREFIX} help - show this message
{PREFIX} get - fetch a image from the defined instance
{PREFIX} source - send a link to the source code
{PREFIX} version - show the bot version
{PREFIX} die - kills the bot (only admins can do this!)
message = (f"""Help
============================
A work-in-progress Python rewrite of the original quotes bot, aiming for a mostly complete remake.
{PREFIX} help - show this message
{PREFIX} get - fetch a image from the defined instance
{PREFIX} source - send a link to the source code
{PREFIX} version - show the bot version
{PREFIX} die - kills the bot (only admins can do this!)
---
---
NOTE: Debug mode is on. Output will be more verbose.
""")
NOTE: Debug mode is on. Output will be more verbose.""")
await bot.api.send_text_message(room.room_id, message)
@ -74,41 +71,51 @@ async def make_choice(room, message):
temp = False
else:
id = match.args()
id = str(id[1])
try:
id = int(id[1])
except ValueError:
youTriedMessage = ("Blunt tried :skull:")
await bot.api.send_text_message(room.room_id, youTriedMessage)
quoteImage = fetch.fetchQuote(id)
quoteData = fetch.fetchQuoteData(id)
def formatData(data):
dataToFormat = data
created = str(data['created'])
description = str(data['desc'])
imageid = str(data['iid'])
ocr = str(data['ocr'])
score = str(data['score'])
return created, description, imageid, ocr, score
if data is not None:
timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(data['created']))
dataToFormat = data
created = timestamp
description = str(data['desc'])
imageid = str(data['iid'])
ocr = str(data['ocr'])
score = str(data['score'])
return created, description, imageid, ocr, score
else:
dataToFormat = data
created = "Error"
description = "Error"
imageid = "Error"
ocr = "Error"
score = "Error"
return created, description, imageid, ocr, score
if debugMode == False:
created, description, imageid, ocr, score = formatData(quoteData)
message1 = (f"""
Created: {created}
Description: {description}
Image ID: {imageid}
OCR (Tesseract): {ocr}
Rating: {score}
""")
message1 = (f"""Created: {created}
Description: {description}
Image ID: {imageid}
OCR (Tesseract): {ocr}
Rating: {score}""")
else:
created, description, imageid, ocr, score = formatData(quoteData)
message1 = (f"""
Created: {created}
Description: {description}
Image ID: {imageid}
OCR (Tesseract): {ocr}
Rating: {score}
""")
message2 = (f"""
Command recived (DEBUG).
(We're supposed to fetch quote number {id} now.)
""")
message1 = (f"""Created: {created}
Description: {description}
Image ID: {imageid}
OCR (Tesseract):
> {ocr}
Rating: {score}""")
message2 = (f"""Command recived (DEBUG).
(We're supposed to fetch quote number {id} now.)""")
if debugMode == True:
await bot.api.send_text_message(room.room_id, message2)
@ -125,10 +132,8 @@ async def help_message(room, message):
and match.command("source")):
return
message = (f"""
quotes-bot-python by Nyx Tutt (@n:everypizza.im)
https://git.everypizza.im/n/quotes-bot-python/
""")
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)
@ -139,34 +144,18 @@ async def help_message(room, message):
and match.command("version")):
return
message = (f"""
quotes-bot-python version {version}
""")
message = (f"""quotes-bot-python version {version}""")
await bot.api.send_text_message(room.room_id, message)
@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.is_from_userid(admin)
and match.command("die")):
return
message = ("Ok")
await bot.api.send_text_message(room.room_id, message)
exit(0)
# We should find a better way to do this.
@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 not match.is_from_userid(admin)
and match.command("die")):
return
message = ("You don't have permissions for that.")
await bot.api.send_text_message(room.room_id, message)
if match.is_not_from_this_bot() and match.prefix() and match.command("die"):
if match.is_from_userid(admin):
await bot.api.send_text_message(room.room_id, "Ok")
exit(0)
else:
await bot.api.send_text_message(room.room_id, "You don't have permissions for that.")
bot.run()

View file

@ -30,7 +30,7 @@ def fetchQuoteData(quoteId):
print(quoteData.json())
else:
print(f"An error occured while saving the file: {quoteData.status_code}")
return "This file probably doesn't exist."
return None
def fetchTopQuotes(instance):
raise NotImplementedError