-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
40 lines (33 loc) · 1.15 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from pyrogram import Client, filters
from gdrive import create_note
import logging
import json
from dotenv import load_dotenv
import os
load_dotenv()
logging.basicConfig(format="%(asctime)s %(levelname)s:%(name)s - %(message)s")
logger = logging.getLogger("obsidian-bot")
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
handler.setLevel(logging.INFO)
app = Client(
"obsidian-bot",
api_id=os.getenv("TG_API_ID"),
api_hash=os.getenv("TG_API_HASH"),
bot_token=os.getenv("TG_BOT_TOKEN"),
)
@app.on_message(filters.user(os.getenv("TG_MY_ID")) & filters.text)
async def handle_message(client, message):
logger.info(f"Saving new note")
note = create_note(message.text)
logger.info(
f"Successfully create a new note. Title: {note['title']}. Id: {note['id']}"
)
await message.reply(f"Nota salvata. Titolo: {note['title']}. Id: {note['id']}")
# @app.on_message(filters.user(bot_secret["my_id"]) & filters.photo)
# async def handle_photo(client, photo):
# file = await app.download_media(photo, in_memory=True)
# file_name = file.name
# file_bytes = bytes(file.getbuffer())
logger.info("Bot starting")
app.run()