Added link saving
This commit is contained in:
parent
d24503d0f5
commit
21e5f08043
23
bot.py
23
bot.py
@ -1,4 +1,5 @@
|
||||
import simplematrixbotlib as botlib
|
||||
import validators
|
||||
|
||||
from bofa import BofaData
|
||||
from org import OrgData
|
||||
@ -152,4 +153,26 @@ async def list_bank_information(room, message):
|
||||
await bot.api.send_text_message(room_id, return_data)
|
||||
|
||||
|
||||
@bot.listener.on_message_event
|
||||
async def save_link(room, message):
|
||||
"""
|
||||
Function that lists banks information
|
||||
Usage:
|
||||
user: !banks
|
||||
bot: [prints current status of banks]
|
||||
"""
|
||||
match = botlib.MessageMatch(room, message, bot)
|
||||
message_content = message.body
|
||||
if match.is_not_from_this_bot() and validators.url(message_content):
|
||||
user = message.sender
|
||||
|
||||
if user == MATRIX_USERNAME:
|
||||
room_id = room.room_id
|
||||
|
||||
print(f"Room: {room_id}, User: {user}, Message: {message_content}")
|
||||
|
||||
OrgData().add_new_link(f"- {message_content}\n")
|
||||
await bot.api.send_text_message(room_id, "Link added!")
|
||||
|
||||
|
||||
bot.run()
|
||||
|
13
org.py
13
org.py
@ -5,7 +5,7 @@ from datetime import datetime
|
||||
from orgparse import loads
|
||||
|
||||
from nextcloud import NextCloudConnection
|
||||
from settings import ORG_CAPTURE_FILENAME, ORG_PLAN_FILENAME
|
||||
from settings import ORG_CAPTURE_FILENAME, ORG_LINKS_FILENAME, ORG_PLAN_FILENAME
|
||||
|
||||
locale.setlocale(locale.LC_ALL, "es_ES.utf8")
|
||||
|
||||
@ -49,3 +49,14 @@ class OrgData(NextCloudConnection):
|
||||
plan = loads(plan)
|
||||
|
||||
return plan[-1].get_body().replace("[X]", "✅").replace("[ ]", "❌")
|
||||
|
||||
def add_new_link(self, link: str) -> None:
|
||||
|
||||
self.client.download_file(ORG_LINKS_FILENAME, "./links.org")
|
||||
|
||||
with open("./links.org", "a") as capture_file:
|
||||
capture_file.write(link)
|
||||
|
||||
self.client.upload_file("./links.org", ORG_LINKS_FILENAME, overwrite=True)
|
||||
|
||||
os.remove("./links.org")
|
||||
|
@ -12,6 +12,7 @@ cfgv==3.3.1
|
||||
charset-normalizer==2.1.0
|
||||
click==8.1.3
|
||||
cryptography==37.0.4
|
||||
decorator==5.1.1
|
||||
distlib==0.3.5
|
||||
filelock==3.7.1
|
||||
flake8==5.0.3
|
||||
@ -63,6 +64,7 @@ toml==0.10.2
|
||||
tomli==2.0.1
|
||||
unpaddedbase64==2.1.0
|
||||
urllib3==1.26.11
|
||||
validators==0.20.0
|
||||
virtualenv==20.16.2
|
||||
webdav4==0.9.7
|
||||
yarl==1.8.0
|
||||
|
@ -24,6 +24,7 @@ NEXTCLOUD_PASSWORD = os.environ.get("NEXTCLOUD_PASSWORD")
|
||||
|
||||
ORG_CAPTURE_FILENAME = os.environ.get("ORG_CAPTURE_FILENAME")
|
||||
ORG_PLAN_FILENAME = os.environ.get("ORG_PLAN_FILENAME")
|
||||
ORG_LINKS_FILENAME = os.environ.get("ORG_LINKS_FILENAME")
|
||||
|
||||
PROMETEO_API_KEY = os.environ.get("PROMETEO_API_KEY")
|
||||
PROMETEO_URL = os.environ.get("PROMETEO_URL")
|
||||
|
Loading…
x
Reference in New Issue
Block a user