2020-09-17 12:27:50 +03:00
|
|
|
"""
|
|
|
|
This file is only the "core" of the bot. It is responsible for loading the
|
|
|
|
plugins module and initializing it. You may obtain the plugins by running:
|
|
|
|
|
|
|
|
git clone https://github.com/Lonami/TelethonianBotExt plugins
|
|
|
|
|
|
|
|
In the same folder where this file lives. As a result, the directory should
|
|
|
|
look like the following:
|
|
|
|
|
|
|
|
assistant.py
|
|
|
|
plugins/
|
|
|
|
...
|
|
|
|
"""
|
2018-06-26 16:48:56 +03:00
|
|
|
import asyncio
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
2020-09-17 12:27:50 +03:00
|
|
|
from telethon import TelegramClient
|
2018-06-26 16:48:56 +03:00
|
|
|
|
2018-10-26 11:25:29 +03:00
|
|
|
try:
|
2020-09-17 12:27:50 +03:00
|
|
|
# Standalone script assistant.py with folder plugins/
|
|
|
|
import plugins
|
2018-10-26 11:25:29 +03:00
|
|
|
except ImportError:
|
2020-09-17 12:27:50 +03:00
|
|
|
try:
|
|
|
|
# Running as a module with `python -m assistant` and structure:
|
|
|
|
#
|
|
|
|
# assistant/
|
|
|
|
# __main__.py (this file)
|
|
|
|
# plugins/ (cloned)
|
|
|
|
from . import plugins
|
|
|
|
except ImportError:
|
|
|
|
print('could not load the plugins module, does the directory exist '
|
|
|
|
'in the correct location?', file=sys.stderr)
|
|
|
|
|
|
|
|
exit(1)
|
2018-06-26 16:48:56 +03:00
|
|
|
|
2019-05-11 21:41:10 +03:00
|
|
|
|
2018-09-04 12:52:18 +03:00
|
|
|
def get_env(name, message, cast=str):
|
|
|
|
if name in os.environ:
|
|
|
|
return os.environ[name]
|
|
|
|
while True:
|
|
|
|
value = input(message)
|
|
|
|
try:
|
|
|
|
return cast(value)
|
|
|
|
except ValueError as e:
|
|
|
|
print(e, file=sys.stderr)
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
|
|
|
|
API_ID = get_env('TG_API_ID', 'Enter your API ID: ', int)
|
|
|
|
API_HASH = get_env('TG_API_HASH', 'Enter your API hash: ')
|
|
|
|
TOKEN = get_env('TG_TOKEN', 'Enter the bot token: ')
|
|
|
|
NAME = TOKEN.split(':')[0]
|
2018-06-26 16:48:56 +03:00
|
|
|
|
|
|
|
|
2020-09-17 12:27:50 +03:00
|
|
|
async def main():
|
|
|
|
bot = TelegramClient(NAME, API_ID, API_HASH)
|
2018-06-26 16:48:56 +03:00
|
|
|
|
2020-09-17 12:27:50 +03:00
|
|
|
await bot.start(bot_token=TOKEN)
|
2018-11-15 19:53:14 +03:00
|
|
|
|
2019-05-11 21:44:35 +03:00
|
|
|
try:
|
2020-09-17 12:27:50 +03:00
|
|
|
await plugins.init(bot)
|
|
|
|
await bot.run_until_disconnected()
|
|
|
|
finally:
|
|
|
|
await bot.disconnect()
|
|
|
|
|
2018-06-26 16:48:56 +03:00
|
|
|
|
2020-09-17 12:27:50 +03:00
|
|
|
if __name__ == '__main__':
|
|
|
|
asyncio.run(main())
|