2018-06-26 16:48:56 +03:00
|
|
|
|
import asyncio
|
2018-10-26 11:49:02 +03:00
|
|
|
|
import html
|
2018-06-26 16:48:56 +03:00
|
|
|
|
import logging
|
|
|
|
|
import os
|
2018-10-12 14:33:55 +03:00
|
|
|
|
import re
|
2018-06-26 16:48:56 +03:00
|
|
|
|
import sys
|
|
|
|
|
import time
|
|
|
|
|
import urllib.parse
|
|
|
|
|
|
2019-02-12 12:48:02 +03:00
|
|
|
|
from telethon import TelegramClient, events, types, custom, utils, errors
|
2018-06-26 16:48:56 +03:00
|
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.WARNING)
|
|
|
|
|
logging.getLogger('asyncio').setLevel(logging.ERROR)
|
|
|
|
|
|
2018-10-26 11:25:29 +03:00
|
|
|
|
try:
|
|
|
|
|
import aiohttp
|
|
|
|
|
except ImportError:
|
|
|
|
|
aiohttp = None
|
|
|
|
|
logging.warning('aiohttp module not available; #haste command disabled')
|
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]
|
|
|
|
|
bot = TelegramClient(NAME, API_ID, API_HASH)
|
2018-06-26 16:48:56 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ============================== Constants ==============================
|
2018-08-24 15:09:55 +03:00
|
|
|
|
WELCOME = {
|
2019-05-11 21:41:10 +03:00
|
|
|
|
-1001109500936:
|
2018-06-26 16:48:56 +03:00
|
|
|
|
'Hi and welcome to the group. Before asking any questions, **please** '
|
2019-05-22 12:29:46 +03:00
|
|
|
|
'read [the docs](https://docs.telethon.dev/). Make sure you are '
|
2018-06-26 16:48:56 +03:00
|
|
|
|
'using the latest version with `pip3 install -U telethon`, since most '
|
2018-08-24 15:09:55 +03:00
|
|
|
|
'problems have already been fixed in newer versions.',
|
|
|
|
|
|
2019-05-11 21:41:10 +03:00
|
|
|
|
-1001200633650:
|
2018-08-24 15:09:55 +03:00
|
|
|
|
'Welcome to the off-topic group. Feel free to talk, ask or test anything '
|
|
|
|
|
'here, politely. Check the description if you need to test more spammy '
|
|
|
|
|
'"features" of your or other people\'s bots (sed commands too).'
|
|
|
|
|
}
|
2018-06-26 16:48:56 +03:00
|
|
|
|
|
|
|
|
|
READ_FULL = (
|
2019-05-22 12:29:46 +03:00
|
|
|
|
'Please read [Accessing the Full API](https://docs.telethon.dev'
|
2019-05-09 15:09:22 +03:00
|
|
|
|
'/en/latest/concepts/full-api.html)'
|
2018-06-26 16:48:56 +03:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
SEARCH = (
|
|
|
|
|
'Remember [search is your friend]'
|
2019-05-22 12:29:46 +03:00
|
|
|
|
'(https://tl.telethon.dev/?q={}&redirect=no)'
|
2018-06-26 16:48:56 +03:00
|
|
|
|
)
|
|
|
|
|
|
2019-05-22 12:29:46 +03:00
|
|
|
|
DOCS = 'TL Reference for [{}](https://tl.telethon.dev/?q={})'
|
|
|
|
|
RTD = '[Read The Docs!](https://docs.telethon.dev)'
|
|
|
|
|
RTFD = '[Read The F* Docs!](https://docs.telethon.dev)'
|
2018-11-15 19:53:14 +03:00
|
|
|
|
UPDATES = (
|
2019-05-22 12:29:46 +03:00
|
|
|
|
'Check out [Working with Updates](https://docs.telethon.dev'
|
2019-05-09 15:09:22 +03:00
|
|
|
|
'/en/latest/basic/updates.html) in the documentation.'
|
2018-11-15 19:53:14 +03:00
|
|
|
|
)
|
2018-08-24 15:09:55 +03:00
|
|
|
|
|
2018-09-03 19:10:57 +03:00
|
|
|
|
SPAM = (
|
|
|
|
|
"Telethon is free software. That means using it is a right: you are "
|
|
|
|
|
"free to use it for absolutely any purpose whatsoever. However, help "
|
|
|
|
|
"and support with using it is a privilege. If you misbehave or want "
|
|
|
|
|
"to do bad things, nobody is obligated to help you and you're not "
|
|
|
|
|
"welcome here."
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
OFFTOPIC = {
|
2018-09-03 19:14:00 +03:00
|
|
|
|
-1001109500936:
|
2018-09-03 19:10:57 +03:00
|
|
|
|
'That is not related to Telethon. '
|
2018-09-03 19:14:00 +03:00
|
|
|
|
'You may continue the conversation in @TelethonOffTopic',
|
|
|
|
|
-1001200633650:
|
2018-09-03 19:10:57 +03:00
|
|
|
|
'That seems to be related to Telethon. Try asking in @TelethonChat'
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-19 15:33:30 +03:00
|
|
|
|
UNKNOWN_OFFTOPIC = (
|
|
|
|
|
"I don't know of any off-topic group for this chat! Maybe you want to "
|
|
|
|
|
"visit the on-topic @TelethonChat, or the off-topic @TelethonOffTopic?"
|
|
|
|
|
)
|
|
|
|
|
|
2018-08-24 15:09:55 +03:00
|
|
|
|
ASK = (
|
|
|
|
|
"Hey, that's not how you ask a question! If you want helpful advice "
|
|
|
|
|
"(or any response at all) [read this first](https://stackoverflow.com"
|
2018-09-03 19:10:57 +03:00
|
|
|
|
"/help/how-to-ask) and then ask again. If you have the time, [How To "
|
|
|
|
|
"Ask Questions The Smart Way](catb.org/~esr/faqs/smart-questions.html)"
|
|
|
|
|
" is another wonderful resource worth reading."
|
2018-08-24 15:09:55 +03:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
LOGGING = '''
|
|
|
|
|
**Please enable logging:**
|
|
|
|
|
```import logging
|
|
|
|
|
logging.basicConfig(level=logging.WARNING)```
|
|
|
|
|
|
|
|
|
|
If you need more information, use `logging.DEBUG` instead.
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
ALREADY_FIXED = (
|
|
|
|
|
"This issue has already been fixed, but it's not yet available in PyPi. "
|
2018-11-15 19:53:14 +03:00
|
|
|
|
"You can upgrade now with `pip3 install -U https://github.com/LonamiWebs"
|
|
|
|
|
"/Telethon/archive/master.zip`."
|
2018-08-24 15:09:55 +03:00
|
|
|
|
)
|
|
|
|
|
|
2018-10-12 14:33:55 +03:00
|
|
|
|
GOOD_RESOURCES = (
|
|
|
|
|
"Some good resources to learn Python:\n"
|
2018-08-24 15:09:55 +03:00
|
|
|
|
"• [Official Docs](https://docs.python.org/3/tutorial/index.html).\n"
|
2019-02-12 12:48:02 +03:00
|
|
|
|
"• [Dive Into Python 3](https://rawcdn.githack.com/diveintomark/"
|
|
|
|
|
"diveintopython3/master/table-of-contents.html).\n"
|
2018-08-24 15:09:55 +03:00
|
|
|
|
"• [Learn Python](https://www.learnpython.org/).\n"
|
2018-10-06 21:20:11 +03:00
|
|
|
|
"• [Project Python](http://projectpython.net/).\n"
|
2018-08-24 21:14:29 +03:00
|
|
|
|
"• [Computer Science Circles](https://cscircles.cemc.uwaterloo.ca/).\n"
|
|
|
|
|
"• [MIT OpenCourse](https://ocw.mit.edu/courses/electrical-engineering-"
|
|
|
|
|
"and-computer-science/6-0001-introduction-to-computer-science-and-progr"
|
|
|
|
|
"amming-in-python-fall-2016/).\n"
|
2018-08-24 15:09:55 +03:00
|
|
|
|
"• [Hitchhiker’s Guide to Python](https://docs.python-guide.org/).\n"
|
|
|
|
|
"• The @PythonRes Telegram Channel.\n"
|
|
|
|
|
"• Corey Schafer videos for [beginners](https://www.youtube.com/watch?v="
|
|
|
|
|
"YYXdXT2l-Gg&list=PL-osiE80TeTskrapNbzXhwoFUiLCjGgY7) and in [general]"
|
|
|
|
|
"(https://www.youtube.com/watch?v=YYXdXT2l-Gg&list=PL-osiE80TeTt2d9bfV"
|
|
|
|
|
"yTiXJA-UTHn6WwU)."
|
|
|
|
|
)
|
|
|
|
|
|
2018-10-12 14:33:55 +03:00
|
|
|
|
LEARN_PYTHON = (
|
|
|
|
|
"That issue is no longer related with Telethon. You should learn more "
|
|
|
|
|
"Python before trying again. " + GOOD_RESOURCES
|
|
|
|
|
)
|
|
|
|
|
|
2018-06-26 16:48:56 +03:00
|
|
|
|
# ============================== Constants ==============================
|
|
|
|
|
# ============================== Welcome ==============================
|
2018-08-24 15:09:55 +03:00
|
|
|
|
last_welcome = {}
|
2018-06-26 16:48:56 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.on(events.ChatAction)
|
|
|
|
|
async def handler(event):
|
|
|
|
|
if event.user_joined:
|
2018-08-24 15:09:55 +03:00
|
|
|
|
if event.chat_id in last_welcome:
|
2019-02-12 12:48:02 +03:00
|
|
|
|
try:
|
|
|
|
|
await last_welcome[event.chat_id].delete()
|
|
|
|
|
except errors.MessageDeleteForbiddenError:
|
|
|
|
|
# We believe this happens when trying to delete old messages
|
|
|
|
|
pass
|
2018-06-26 16:48:56 +03:00
|
|
|
|
|
2018-08-24 15:09:55 +03:00
|
|
|
|
last_welcome[event.chat_id] = await event.reply(WELCOME[event.chat_id])
|
2018-06-26 16:48:56 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ============================== Welcome ==============================
|
|
|
|
|
# ============================== Commands ==============================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.on(events.NewMessage(pattern='#ping', forwards=False))
|
|
|
|
|
async def handler(event):
|
|
|
|
|
s = time.time()
|
|
|
|
|
message = await event.reply('Pong!')
|
|
|
|
|
d = time.time() - s
|
|
|
|
|
await message.edit(f'Pong! __(reply took {d:.2f}s)__')
|
|
|
|
|
await asyncio.sleep(5)
|
|
|
|
|
await asyncio.wait([event.delete(), message.delete()])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.on(events.NewMessage(pattern='#full', forwards=False))
|
|
|
|
|
async def handler(event):
|
|
|
|
|
"""#full: Advises to read "Accessing the full API" in the docs."""
|
|
|
|
|
await asyncio.wait([
|
|
|
|
|
event.delete(),
|
|
|
|
|
event.respond(READ_FULL, reply_to=event.reply_to_msg_id)
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.on(events.NewMessage(pattern='#search (.+)', forwards=False))
|
|
|
|
|
async def handler(event):
|
|
|
|
|
"""#search query: Searches for "query" in the method reference."""
|
|
|
|
|
query = urllib.parse.quote(event.pattern_match.group(1))
|
|
|
|
|
await asyncio.wait([
|
|
|
|
|
event.delete(),
|
|
|
|
|
event.respond(SEARCH.format(query), reply_to=event.reply_to_msg_id)
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.on(events.NewMessage(pattern='(?i)#(?:docs|ref) (.+)', forwards=False))
|
|
|
|
|
async def handler(event):
|
|
|
|
|
"""#docs or #ref query: Like #search but shows the query."""
|
|
|
|
|
q1 = event.pattern_match.group(1)
|
|
|
|
|
q2 = urllib.parse.quote(q1)
|
|
|
|
|
await asyncio.wait([
|
|
|
|
|
event.delete(),
|
|
|
|
|
event.respond(DOCS.format(q1, q2), reply_to=event.reply_to_msg_id)
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.on(events.NewMessage(pattern='#rt(f)?d', forwards=False))
|
|
|
|
|
async def handler(event):
|
|
|
|
|
"""#rtd: Tells the user to please read the docs."""
|
|
|
|
|
rtd = RTFD if event.pattern_match.group(1) else RTD
|
|
|
|
|
await asyncio.wait([
|
|
|
|
|
event.delete(),
|
|
|
|
|
event.respond(rtd, reply_to=event.reply_to_msg_id)
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 19:53:14 +03:00
|
|
|
|
@bot.on(events.NewMessage(pattern='#(updates|events?)', forwards=False))
|
|
|
|
|
async def handler(event):
|
|
|
|
|
"""#updates: Advices the user to read "Working with Updates"."""
|
|
|
|
|
await asyncio.wait([
|
|
|
|
|
event.delete(),
|
|
|
|
|
event.respond(UPDATES, reply_to=event.reply_to_msg_id)
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
2018-08-24 15:09:55 +03:00
|
|
|
|
@bot.on(events.NewMessage(pattern='(?i)#(ask|question)', forwards=False))
|
|
|
|
|
async def handler(event):
|
|
|
|
|
"""#ask or #question: Advices the user to ask a better question."""
|
|
|
|
|
await asyncio.wait([
|
|
|
|
|
event.delete(),
|
|
|
|
|
event.respond(
|
|
|
|
|
ASK, reply_to=event.reply_to_msg_id, link_preview=False)
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
2018-09-03 19:10:57 +03:00
|
|
|
|
@bot.on(events.NewMessage(pattern='(?i)#spam(mer|ming)?', forwards=False))
|
|
|
|
|
async def handler(event):
|
|
|
|
|
"""#spam, #spammer, #spamming: Informs spammers that they are not welcome here."""
|
|
|
|
|
await asyncio.wait([
|
|
|
|
|
event.delete(),
|
|
|
|
|
event.respond(SPAM, reply_to=event.reply_to_msg_id)
|
|
|
|
|
])
|
|
|
|
|
|
2019-05-11 21:41:10 +03:00
|
|
|
|
|
2018-09-03 19:10:57 +03:00
|
|
|
|
@bot.on(events.NewMessage(pattern='(?i)#(ot|offtopic)', forwards=False))
|
|
|
|
|
async def handler(event):
|
|
|
|
|
"""#ot, #offtopic: Tells the user to move to @TelethonOffTopic."""
|
|
|
|
|
await asyncio.wait([
|
|
|
|
|
event.delete(),
|
2020-01-19 15:33:30 +03:00
|
|
|
|
event.respond(OFFTOPIC.get(event.chat_id, UNKNOWN_OFFTOPIC), reply_to=event.reply_to_msg_id)
|
2018-09-03 19:10:57 +03:00
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
2018-08-24 15:09:55 +03:00
|
|
|
|
@bot.on(events.NewMessage(pattern='(?i)#log(s|ging)?', forwards=False))
|
|
|
|
|
async def handler(event):
|
|
|
|
|
"""#log, #logs or #logging: Explains how to enable logging."""
|
|
|
|
|
await asyncio.wait([
|
|
|
|
|
event.delete(),
|
|
|
|
|
event.respond(LOGGING, reply_to=event.reply_to_msg_id)
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.on(events.NewMessage(pattern='(?i)#master', forwards=False))
|
|
|
|
|
async def handler(event):
|
|
|
|
|
"""#master: The bug has been fixed in the `master` branch."""
|
|
|
|
|
await asyncio.wait([
|
|
|
|
|
event.delete(),
|
|
|
|
|
event.respond(ALREADY_FIXED, reply_to=event.reply_to_msg_id)
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.on(events.NewMessage(pattern='(?i)#(learn|python)', forwards=False))
|
|
|
|
|
async def handler(event):
|
|
|
|
|
"""#learn or #python: Tells the user to learn some Python first."""
|
|
|
|
|
await asyncio.wait([
|
|
|
|
|
event.delete(),
|
|
|
|
|
event.respond(
|
|
|
|
|
LEARN_PYTHON, reply_to=event.reply_to_msg_id, link_preview=False)
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
2018-09-03 19:10:57 +03:00
|
|
|
|
@bot.on(events.NewMessage(pattern='(?i)#(list|help)', forwards=False))
|
2018-06-26 16:48:56 +03:00
|
|
|
|
async def handler(event):
|
|
|
|
|
await event.delete()
|
|
|
|
|
text = 'Available commands:\n'
|
|
|
|
|
for callback, handler in bot.list_event_handlers():
|
|
|
|
|
if isinstance(handler, events.NewMessage) and callback.__doc__:
|
2019-02-19 18:41:51 +03:00
|
|
|
|
text += f'\n{callback.__doc__.strip()}'
|
2018-09-03 19:10:57 +03:00
|
|
|
|
text += '\n\nYou can suggest new commands [here](https://docs.google.com/'\
|
|
|
|
|
'spreadsheets/d/12yWwixUu_vB426_toLBAiajXxYKvR2J1DD6yZtQz9l4/edit).'
|
2018-06-26 16:48:56 +03:00
|
|
|
|
|
2018-09-03 19:10:57 +03:00
|
|
|
|
message = await event.respond(text, link_preview=False)
|
2018-06-26 16:48:56 +03:00
|
|
|
|
await asyncio.sleep(1 * text.count(' ')) # Sleep ~1 second per word
|
|
|
|
|
await message.delete()
|
|
|
|
|
|
|
|
|
|
|
2018-10-26 11:25:29 +03:00
|
|
|
|
if aiohttp:
|
2020-01-22 14:29:04 +03:00
|
|
|
|
@bot.on(events.NewMessage(pattern='(?i)#([hp]aste|dog|inu)(bin)?', forwards=False))
|
2018-10-26 11:25:29 +03:00
|
|
|
|
async def handler(event):
|
|
|
|
|
"""
|
2020-01-22 14:29:04 +03:00
|
|
|
|
#haste: Replaces the message you reply to with a dogbin link.
|
2018-10-26 11:25:29 +03:00
|
|
|
|
"""
|
|
|
|
|
await event.delete()
|
|
|
|
|
if not event.reply_to_msg_id:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
msg = await event.get_reply_message()
|
2018-10-26 11:49:02 +03:00
|
|
|
|
if len(msg.raw_text or '') < 200:
|
|
|
|
|
return
|
|
|
|
|
|
2018-10-26 11:25:29 +03:00
|
|
|
|
sent = await event.respond(
|
2018-11-15 19:53:14 +03:00
|
|
|
|
'Uploading paste…', reply_to=msg.reply_to_msg_id)
|
2018-10-26 11:25:29 +03:00
|
|
|
|
|
2018-10-26 11:49:02 +03:00
|
|
|
|
name = html.escape(
|
|
|
|
|
utils.get_display_name(await msg.get_sender()) or 'A user')
|
|
|
|
|
|
2018-10-26 11:25:29 +03:00
|
|
|
|
text = msg.raw_text
|
|
|
|
|
code = ''
|
|
|
|
|
for _, string in msg.get_entities_text((
|
|
|
|
|
types.MessageEntityCode, types.MessageEntityPre)):
|
|
|
|
|
code += f'{string}\n'
|
|
|
|
|
text = text.replace(string, '')
|
|
|
|
|
|
|
|
|
|
code = code.rstrip()
|
|
|
|
|
if code:
|
|
|
|
|
text = re.sub(r'\s+', ' ', text)
|
|
|
|
|
else:
|
|
|
|
|
code = msg.raw_text
|
|
|
|
|
text = ''
|
|
|
|
|
|
|
|
|
|
async with aiohttp.ClientSession() as session:
|
2020-01-22 14:29:04 +03:00
|
|
|
|
async with session.post('https://del.dog/documents',
|
2018-10-26 11:25:29 +03:00
|
|
|
|
data=code.encode('utf-8')) as resp:
|
2018-11-15 19:53:14 +03:00
|
|
|
|
if resp.status >= 300:
|
2020-01-22 14:29:04 +03:00
|
|
|
|
await sent.edit("Dogbin seems to be down… ( ^^')")
|
2018-11-15 19:53:14 +03:00
|
|
|
|
return
|
|
|
|
|
|
2018-10-26 11:25:29 +03:00
|
|
|
|
haste = (await resp.json())['key']
|
|
|
|
|
|
|
|
|
|
await asyncio.wait([
|
|
|
|
|
msg.delete(),
|
2018-10-26 11:49:02 +03:00
|
|
|
|
sent.edit(f'<a href="tg://user?id={msg.sender_id}">{name}</a> '
|
2020-01-22 14:29:04 +03:00
|
|
|
|
f'said: {text} del.dog/{haste}.py'
|
2018-10-26 11:49:02 +03:00
|
|
|
|
.replace(' ', ' '), parse_mode='html')
|
2018-10-26 11:25:29 +03:00
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
2018-06-26 16:48:56 +03:00
|
|
|
|
# ============================== Commands ==============================
|
2018-10-12 14:33:55 +03:00
|
|
|
|
# ============================== Inline ==============================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.on(events.InlineQuery)
|
|
|
|
|
async def handler(event):
|
|
|
|
|
builder = event.builder
|
|
|
|
|
result = None
|
|
|
|
|
query = event.text.lower()
|
|
|
|
|
if query == 'ping':
|
|
|
|
|
result = builder.article('Pong!', text='This bot works inline')
|
|
|
|
|
elif query == 'group':
|
|
|
|
|
result = builder.article(
|
|
|
|
|
'Move to the right group!',
|
|
|
|
|
text='Try moving to the [right group](t.me/TelethonChat)',
|
|
|
|
|
buttons=custom.Button.url('Join the group!', 't.me/TelethonChat'),
|
|
|
|
|
link_preview=False
|
|
|
|
|
)
|
|
|
|
|
elif query in ('python', 'learn'):
|
|
|
|
|
result = builder.article(
|
|
|
|
|
'Resources to Learn Python',
|
|
|
|
|
text=GOOD_RESOURCES,
|
|
|
|
|
link_preview=False
|
|
|
|
|
)
|
|
|
|
|
|
2019-05-11 21:41:10 +03:00
|
|
|
|
# NOTE: You should always answer, but we want plugins to be able to answer
|
|
|
|
|
# too (and we can only answer once), so we don't always answer here.
|
|
|
|
|
if result:
|
|
|
|
|
await event.answer([result])
|
2018-10-12 14:33:55 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ============================== Inline ==============================
|
2018-06-26 16:48:56 +03:00
|
|
|
|
|
2019-05-11 21:41:10 +03:00
|
|
|
|
bot.start(bot_token=TOKEN)
|
2018-06-26 16:48:56 +03:00
|
|
|
|
|
2019-05-11 21:41:10 +03:00
|
|
|
|
# NOTE: This example has optional "plugins", which you can get by running:
|
|
|
|
|
#
|
|
|
|
|
# git clone https://github.com/Lonami/TelethonianBotExt plugins
|
|
|
|
|
#
|
|
|
|
|
# Into the same folder (so you would have `assistant.py` next to
|
|
|
|
|
# the now downloaded `plugins/` folder). We try importing them so
|
|
|
|
|
# that the example runs fine without them, but optionally load them.
|
|
|
|
|
try:
|
2019-05-11 21:44:35 +03:00
|
|
|
|
# Standalone script assistant.py with folder plugins/
|
2019-05-11 21:41:10 +03:00
|
|
|
|
import plugins
|
|
|
|
|
plugins.init(bot)
|
|
|
|
|
except ImportError:
|
2019-05-11 21:44:35 +03:00
|
|
|
|
try:
|
|
|
|
|
# Running as a module with `python -m assistant` and structure:
|
|
|
|
|
# assistant/
|
|
|
|
|
# __main__.py (this file)
|
|
|
|
|
# plugins/ (cloned)
|
|
|
|
|
from . import plugins
|
|
|
|
|
plugins.init(bot)
|
|
|
|
|
except ImportError:
|
|
|
|
|
plugins = None
|
2018-06-26 16:48:56 +03:00
|
|
|
|
|
|
|
|
|
bot.run_until_disconnected()
|