mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-29 04:43:45 +03:00
Minor doc updates, fixes and improvements
In particular, removed code which no longer worked, made light theme easier on the eyes, added slight syntax highlightning, and fixed search for exact matches.
This commit is contained in:
parent
05e5becd78
commit
a5f5d6ef23
|
@ -447,34 +447,25 @@ However, a day is often more than enough.
|
||||||
Sending Messages with Buttons
|
Sending Messages with Buttons
|
||||||
*****************************
|
*****************************
|
||||||
|
|
||||||
You must sign in as a bot in order to add inline buttons (or normal
|
**You must sign in as a bot** in order to add inline buttons (or normal
|
||||||
keyboards) to your messages. Once you have signed in as a bot specify
|
keyboards) to your messages. Once you have signed in as a bot specify
|
||||||
the `Button <telethon.tl.custom.button.Button>` or buttons to use:
|
the `Button <telethon.tl.custom.button.Button>` or buttons to use:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
|
from telethon import events
|
||||||
from telethon.tl.custom import Button
|
from telethon.tl.custom import Button
|
||||||
|
|
||||||
async def callback(event):
|
|
||||||
await event.edit('Thank you!')
|
|
||||||
|
|
||||||
client.send_message(chat, 'Hello!',
|
|
||||||
buttons=Button.inline('Click me', callback))
|
|
||||||
|
|
||||||
|
|
||||||
You can also add the event handler yourself, or change the data payload:
|
|
||||||
|
|
||||||
.. code-block:: python
|
|
||||||
|
|
||||||
from telethon import events
|
|
||||||
|
|
||||||
@client.on(events.CallbackQuery)
|
@client.on(events.CallbackQuery)
|
||||||
async def handler(event):
|
async def callback(event):
|
||||||
await event.answer('You clicked {}!'.format(event.data))
|
await event.edit('Thank you for clicking {}!'.format(event.data))
|
||||||
|
|
||||||
client.send_message(chat, 'Pick one', buttons=[
|
client.send_message(chat, 'A single button, with "clk1" as data',
|
||||||
|
buttons=Button.inline('Click me', b'clk1'))
|
||||||
|
|
||||||
|
client.send_message(chat, 'Pick one from this grid', buttons=[
|
||||||
[Button.inline('Left'), Button.inline('Right')],
|
[Button.inline('Left'), Button.inline('Right')],
|
||||||
[Button.url('Check my site!', 'https://lonamiwebs.github.io')]
|
[Button.url('Check this site!', 'https://lonamiwebs.github.io')]
|
||||||
])
|
])
|
||||||
|
|
||||||
You can also use normal buttons (not inline) to request the user's
|
You can also use normal buttons (not inline) to request the user's
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
body {
|
body {
|
||||||
font-family: 'Nunito', sans-serif;
|
font-family: 'Nunito', sans-serif;
|
||||||
color: #333;
|
color: #333;
|
||||||
background-color:#fff;
|
background-color:#eee;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
color: #42aaed;
|
color: #329add;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ pre {
|
||||||
font-family: 'Source Code Pro', monospace;
|
font-family: 'Source Code Pro', monospace;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
color: #567;
|
color: #567;
|
||||||
background: #f0f4f8;
|
background: #e0e4e8;
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
}
|
}
|
||||||
|
@ -30,14 +30,14 @@ table {
|
||||||
}
|
}
|
||||||
|
|
||||||
table td {
|
table td {
|
||||||
border-top: 1px solid #eee;
|
border-top: 1px solid #ddd;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.horizontal {
|
.horizontal {
|
||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
list-style: none;
|
list-style: none;
|
||||||
background: #f0f4f8;
|
background: #e0e4e8;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
padding: 8px 16px;
|
padding: 8px 16px;
|
||||||
}
|
}
|
||||||
|
@ -118,14 +118,14 @@ button {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
color: #000;
|
color: #000;
|
||||||
background-color: #fff;
|
background-color: #f7f7f7;
|
||||||
border: 2px solid #42aaed;
|
border: 2px solid #329add;
|
||||||
transition-duration: 300ms;
|
transition-duration: 300ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
button:hover {
|
button:hover {
|
||||||
background-color: #42aaed;
|
background-color: #329add;
|
||||||
color: #fff;
|
color: #f7f7f7;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* https://www.w3schools.com/css/css_navbar.asp */
|
/* https://www.w3schools.com/css/css_navbar.asp */
|
||||||
|
@ -143,7 +143,7 @@ ul.together li {
|
||||||
ul.together li a {
|
ul.together li a {
|
||||||
display: block;
|
display: block;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
background: #f0f4f8;
|
background: #e0e4e8;
|
||||||
padding: 4px 8px;
|
padding: 4px 8px;
|
||||||
margin: 8px;
|
margin: 8px;
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,8 +85,8 @@ if (typeof prependPath !== 'undefined') {
|
||||||
// Returns the penalty for finding the needle in the haystack
|
// Returns the penalty for finding the needle in the haystack
|
||||||
// or -1 if the needle wasn't found at all.
|
// or -1 if the needle wasn't found at all.
|
||||||
function find(haystack, needle) {
|
function find(haystack, needle) {
|
||||||
if (needle.length == 0) {
|
if (haystack.indexOf(needle) != -1) {
|
||||||
return true;
|
return 0;
|
||||||
}
|
}
|
||||||
var hi = 0;
|
var hi = 0;
|
||||||
var ni = 0;
|
var ni = 0;
|
||||||
|
|
|
@ -43,7 +43,6 @@ class DocsWriter:
|
||||||
"""Writes the head part for the generated document,
|
"""Writes the head part for the generated document,
|
||||||
with the given title and CSS
|
with the given title and CSS
|
||||||
"""
|
"""
|
||||||
#
|
|
||||||
self.title = title
|
self.title = title
|
||||||
self.write(
|
self.write(
|
||||||
'''<!DOCTYPE html>
|
'''<!DOCTYPE html>
|
||||||
|
|
|
@ -105,13 +105,14 @@ def _generate_index(root, folder, paths,
|
||||||
filename = folder / (BOT_INDEX if bots_index else INDEX)
|
filename = folder / (BOT_INDEX if bots_index else INDEX)
|
||||||
with DocsWriter(root, filename, _get_path_for_type) as docs:
|
with DocsWriter(root, filename, _get_path_for_type) as docs:
|
||||||
# Title should be the current folder name
|
# Title should be the current folder name
|
||||||
docs.write_head(str(folder).title(),
|
docs.write_head(str(folder).replace(os.path.sep, '/').title(),
|
||||||
css_path=paths['css'],
|
css_path=paths['css'],
|
||||||
default_css=paths['default_css'])
|
default_css=paths['default_css'])
|
||||||
|
|
||||||
docs.set_menu_separator(paths['arrow'])
|
docs.set_menu_separator(paths['arrow'])
|
||||||
_build_menu(docs)
|
_build_menu(docs)
|
||||||
docs.write_title(str(filename.parent.relative_to(root)).title())
|
docs.write_title(str(filename.parent.relative_to(root))
|
||||||
|
.replace(os.path.sep, '/').title())
|
||||||
|
|
||||||
if bots_index:
|
if bots_index:
|
||||||
docs.write_text('These are the methods that you may be able to '
|
docs.write_text('These are the methods that you may be able to '
|
||||||
|
@ -379,19 +380,18 @@ def _write_html_pages(root, tlobjects, methods, layer, input_res):
|
||||||
'<code>telethon.errors</code>.')
|
'<code>telethon.errors</code>.')
|
||||||
|
|
||||||
docs.write_title('Example', id='examples')
|
docs.write_title('Example', id='examples')
|
||||||
docs.write(
|
docs.write('''<pre>\
|
||||||
'<pre>from telethon.sync import TelegramClient\n'
|
<strong>from</strong> telethon.sync <strong>import</strong> TelegramClient
|
||||||
'from telethon import functions, types\n'
|
<strong>from</strong> telethon <strong>import</strong> functions, types
|
||||||
'\n'
|
|
||||||
'with TelegramClient(name, api_id, api_hash) as client:\n'
|
<strong>with</strong> TelegramClient(name, api_id, api_hash) <strong>as</strong> client:
|
||||||
' result = client(')
|
result = client(''')
|
||||||
tlobject.as_example(docs, indent=1)
|
tlobject.as_example(docs, indent=1)
|
||||||
docs.write(')\n')
|
docs.write(')\n')
|
||||||
if tlobject.result.startswith('Vector'):
|
if tlobject.result.startswith('Vector'):
|
||||||
docs.write(
|
docs.write('''\
|
||||||
' for x in result:\n'
|
<strong>for</strong> x <strong>in</strong> result:
|
||||||
' print(x'
|
print(x''')
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
docs.write(' print(result')
|
docs.write(' print(result')
|
||||||
if tlobject.result != 'Bool' \
|
if tlobject.result != 'Bool' \
|
||||||
|
|
|
@ -1,6 +1,19 @@
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def _fmt_strings(*dicts):
|
||||||
|
for d in dicts:
|
||||||
|
for k, v in d.items():
|
||||||
|
if v in ('None', 'True', 'False'):
|
||||||
|
d[k] = '<strong>{}</strong>'.format(v)
|
||||||
|
else:
|
||||||
|
d[k] = re.sub(
|
||||||
|
r'([brf]?([\'"]).*\2)',
|
||||||
|
lambda m: '<em>{}</em>'.format(m.group(1)),
|
||||||
|
v
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
KNOWN_NAMED_EXAMPLES = {
|
KNOWN_NAMED_EXAMPLES = {
|
||||||
('message', 'string'): "'Hello there!'",
|
('message', 'string'): "'Hello there!'",
|
||||||
('expires_at', 'date'): 'datetime.timedelta(minutes=5)',
|
('expires_at', 'date'): 'datetime.timedelta(minutes=5)',
|
||||||
|
@ -41,6 +54,8 @@ KNOWN_TYPED_EXAMPLES = {
|
||||||
'InputPeer': "'username'"
|
'InputPeer': "'username'"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_fmt_strings(KNOWN_NAMED_EXAMPLES, KNOWN_TYPED_EXAMPLES)
|
||||||
|
|
||||||
SYNONYMS = {
|
SYNONYMS = {
|
||||||
'InputUser': 'InputPeer',
|
'InputUser': 'InputPeer',
|
||||||
'InputChannel': 'InputPeer',
|
'InputChannel': 'InputPeer',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user