mirror of
https://github.com/alopexc0de/Simple-Bookmarking-Service.git
synced 2024-12-22 14:22:39 +00:00
setup bot connection to telegram
This commit is contained in:
parent
a356c50ce0
commit
6979c88d14
@ -10,6 +10,8 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import uuid
|
import uuid
|
||||||
|
import os
|
||||||
|
from telethon.sync import TelegramClient
|
||||||
from .db import Database
|
from .db import Database
|
||||||
|
|
||||||
class TelethonDatabase(Database):
|
class TelethonDatabase(Database):
|
||||||
@ -27,6 +29,17 @@ class TelethonDatabase(Database):
|
|||||||
"""
|
"""
|
||||||
super(TelethonDatabase, self).__init__(database)
|
super(TelethonDatabase, self).__init__(database)
|
||||||
|
|
||||||
|
# Load in the API tokens required for a bot
|
||||||
|
api_id = os.environ.get('telethon_api_id', False)
|
||||||
|
api_hash = os.environ.get('telethon_api_hash', False)
|
||||||
|
api_token = os.environ.get('telethon_token', False)
|
||||||
|
|
||||||
|
# Create an instance of the Telethon bot
|
||||||
|
if api_id and api_hash and api_token:
|
||||||
|
self.bot = TelegramClient('bot', api_id, api_hash).start(bot_token=api_token)
|
||||||
|
else:
|
||||||
|
self.bot = False
|
||||||
|
|
||||||
# Automatically create the table if it doesn't
|
# Automatically create the table if it doesn't
|
||||||
# already exist in the selected database
|
# already exist in the selected database
|
||||||
self._create_table()
|
self._create_table()
|
||||||
|
Loading…
Reference in New Issue
Block a user