Skip to content

Commit 36621bb

Browse files
committed
fix: some intendation
1 parent 9946601 commit 36621bb

13 files changed

Lines changed: 61 additions & 38 deletions

‎examples/deep_linking.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,35 @@
3434

3535
bot = telebot.TeleBot('TOKEN')
3636

37+
3738
def extract_unique_code(text):
3839
# Extracts the unique_code from the sent /start command.
3940
return text.split()[1] if len(text.split()) > 1 else None
4041

42+
4143
def in_storage(unique_code):
4244
# (pseudo-code) Should check if a unique code exists in storage
4345
return True
4446

47+
4548
def get_username_from_storage(unique_code):
4649
# (pseudo-code) Does a query to the storage, retrieving the associated username
4750
# Should be replaced by a real database-lookup.
4851
return "ABC" if in_storage(unique_code) else None
4952

53+
5054
def save_chat_id(chat_id, username):
5155
# (pseudo-code) Save the chat_id->username to storage
5256
# Should be replaced by a real database query.
5357
pass
5458

59+
5560
@bot.message_handler(commands=['start'])
5661
def send_welcome(message):
5762
unique_code = extract_unique_code(message.text)
58-
if unique_code: # if the '/start' command contains a unique_code
63+
if unique_code: # if the '/start' command contains a unique_code
5964
username = get_username_from_storage(unique_code)
60-
if username: # if the username exists in our database
65+
if username: # if the username exists in our database
6166
save_chat_id(message.chat.id, username)
6267
reply = "Hello {0}, how are you?".format(username)
6368
else:
@@ -66,4 +71,5 @@ def send_welcome(message):
6671
reply = "Please visit me via a provided URL from the website."
6772
bot.reply_to(message, reply)
6873

74+
6975
bot.polling()

‎examples/detailed_example/detailed_example.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
userStep = {} # so they won't reset every time the bot restarts
1414

1515
commands = { # command description used in the "help" command
16-
'start': 'Get used to the bot',
17-
'help': 'Gives you information about the available commands',
18-
'sendLongText': 'A test using the \'send_chat_action\' command',
19-
'getImage': 'A test using multi-stage messages, custom keyboard, and media sending'
16+
'start' : 'Get used to the bot',
17+
'help' : 'Gives you information about the available commands',
18+
'sendLongText': 'A test using the \'send_chat_action\' command',
19+
'getImage' : 'A test using multi-stage messages, custom keyboard, and media sending'
2020
}
2121

2222
imageSelect = types.ReplyKeyboardMarkup(one_time_keyboard=True) # create the image selection keyboard
@@ -129,4 +129,5 @@ def command_default(m):
129129
# this is the standard reply to a normal message
130130
bot.send_message(m.chat.id, "I don't understand \"" + m.text + "\"\nMaybe try the help page at /help")
131131

132+
132133
bot.polling()

‎examples/echo_bot.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
bot = telebot.TeleBot(API_TOKEN)
99

10+
1011
# Handle '/start' and '/help'
1112
@bot.message_handler(commands=['help', 'start'])
1213
def send_welcome(message):
@@ -21,4 +22,5 @@ def send_welcome(message):
2122
def echo_message(message):
2223
bot.reply_to(message, message.text)
2324

25+
2426
bot.polling()

‎examples/step_example.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,4 @@ def process_sex_step(message):
8383
# WARNING It will work only if enable_save_next_step_handlers was called!
8484
bot.load_next_step_handlers()
8585

86-
8786
bot.polling()

‎examples/telebot_bot/telebot_bot.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
bot = telebot.AsyncTeleBot(os.environ["TELEBOT_BOT_TOKEN"])
3535
GROUP_CHAT_ID = int(os.environ["GROUP_CHAT_ID"])
3636

37+
3738
def is_api_group(chat_id):
38-
return chat_id== GROUP_CHAT_ID
39+
return chat_id == GROUP_CHAT_ID
40+
3941

4042
@bot.message_handler(func=lambda m: True, content_types=['new_chat_participant'])
4143
def on_user_joins(message):
@@ -51,6 +53,7 @@ def on_user_joins(message):
5153

5254
bot.reply_to(message, text_messages['welcome'].format(name=name))
5355

56+
5457
@bot.message_handler(commands=['info', 'help'])
5558
def on_info(message):
5659
if not is_api_group(message.chat.id):
@@ -59,21 +62,23 @@ def on_info(message):
5962

6063
bot.reply_to(message, text_messages['info'])
6164

65+
6266
@bot.message_handler(commands=["ping"])
6367
def on_ping(message):
6468
bot.reply_to(message, "Still alive and kicking!")
6569

70+
6671
@bot.message_handler(commands=['start'])
6772
def on_start(message):
6873
if not is_api_group(message.chat.id):
6974
bot.reply_to(message, text_messages['wrong_chat'])
7075
return
7176

77+
7278
def listener(messages):
7379
for m in messages:
7480
print(str(m))
7581

82+
7683
bot.set_update_listener(listener)
7784
bot.polling()
78-
79-

‎examples/webhook_examples/webhook_aiohttp_echo_bot.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
WEBHOOK_URL_BASE = "https://{}:{}".format(WEBHOOK_HOST, WEBHOOK_PORT)
3232
WEBHOOK_URL_PATH = "/{}/".format(API_TOKEN)
3333

34-
3534
logger = telebot.logger
3635
telebot.logger.setLevel(logging.INFO)
3736

@@ -50,6 +49,7 @@ async def handle(request):
5049
else:
5150
return web.Response(status=403)
5251

52+
5353
app.router.add_post('/{token}/', handle)
5454

5555

@@ -71,7 +71,7 @@ def echo_message(message):
7171
bot.remove_webhook()
7272

7373
# Set webhook
74-
bot.set_webhook(url=WEBHOOK_URL_BASE+WEBHOOK_URL_PATH,
74+
bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH,
7575
certificate=open(WEBHOOK_SSL_CERT, 'r'))
7676

7777
# Build ssl context

‎examples/webhook_examples/webhook_cherrypy_echo_bot.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT)
3131
WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN)
3232

33-
3433
logger = telebot.logger
3534
telebot.logger.setLevel(logging.INFO)
3635

@@ -71,7 +70,7 @@ def echo_message(message):
7170
bot.remove_webhook()
7271

7372
# Set webhook
74-
bot.set_webhook(url=WEBHOOK_URL_BASE+WEBHOOK_URL_PATH,
73+
bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH,
7574
certificate=open(WEBHOOK_SSL_CERT, 'r'))
7675

7776
# Disable CherryPy requests log
@@ -81,9 +80,9 @@ def echo_message(message):
8180

8281
# Start cherrypy server
8382
cherrypy.config.update({
84-
'server.socket_host': WEBHOOK_LISTEN,
85-
'server.socket_port': WEBHOOK_PORT,
86-
'server.ssl_module': 'builtin',
83+
'server.socket_host' : WEBHOOK_LISTEN,
84+
'server.socket_port' : WEBHOOK_PORT,
85+
'server.ssl_module' : 'builtin',
8786
'server.ssl_certificate': WEBHOOK_SSL_CERT,
8887
'server.ssl_private_key': WEBHOOK_SSL_PRIV
8988
})

‎examples/webhook_examples/webhook_cpython_echo_bot.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT)
3737
WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN)
3838

39-
4039
logger = telebot.logger
4140
telebot.logger.setLevel(logging.INFO)
4241

@@ -90,12 +89,12 @@ def echo_message(message):
9089
bot.remove_webhook()
9190

9291
# Set webhook
93-
bot.set_webhook(url=WEBHOOK_URL_BASE+WEBHOOK_URL_PATH,
92+
bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH,
9493
certificate=open(WEBHOOK_SSL_CERT, 'r'))
9594

9695
# Start server
9796
httpd = HTTPServer((WEBHOOK_LISTEN, WEBHOOK_PORT),
98-
WebhookHandler)
97+
WebhookHandler)
9998

10099
httpd.socket = ssl.wrap_socket(httpd.socket,
101100
certfile=WEBHOOK_SSL_CERT,

‎examples/webhook_examples/webhook_flask_echo_bot.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT)
3232
WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN)
3333

34-
3534
logger = telebot.logger
3635
telebot.logger.setLevel(logging.INFO)
3736

@@ -78,7 +77,7 @@ def echo_message(message):
7877
time.sleep(0.1)
7978

8079
# Set webhook
81-
bot.set_webhook(url=WEBHOOK_URL_BASE+WEBHOOK_URL_PATH,
80+
bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH,
8281
certificate=open(WEBHOOK_SSL_CERT, 'r'))
8382

8483
# Start flask server

‎examples/webhook_examples/webhook_tornado_echo_bot.py‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@
3131

3232
bot = telebot.TeleBot(API_TOKEN)
3333

34+
3435
class Root(tornado.web.RequestHandler):
3536
def get(self):
3637
self.write("Hi! This is webhook example!")
3738
self.finish()
3839

40+
3941
class webhook_serv(tornado.web.RequestHandler):
4042
def get(self):
4143
self.write("What are you doing here?")
4244
self.finish()
45+
4346
def post(self):
4447
if "Content-Length" in self.request.headers and \
4548
"Content-Type" in self.request.headers and \
@@ -54,28 +57,34 @@ def post(self):
5457
else:
5558
self.write("What are you doing here?")
5659
self.finish()
57-
60+
61+
5862
tornado.options.define("port", default=WEBHOOK_PORT, help="run on the given port", type=int)
5963
is_closing = False
64+
65+
6066
def signal_handler(signum, frame):
6167
global is_closing
6268
print("Exiting...")
6369
is_closing = True
6470

71+
6572
def try_exit():
6673
global is_closing
6774
if is_closing:
6875
# clean up here
6976
tornado.ioloop.IOLoop.instance().stop()
7077
print("Exit success!")
71-
78+
79+
7280
# Handle '/start' and '/help'
7381
@bot.message_handler(commands=['help', 'start'])
7482
def send_welcome(message):
7583
bot.reply_to(message,
7684
("Hi there, I am EchoBot.\n"
7785
"I am here to echo your kind words back to you."))
7886

87+
7988
bot.remove_webhook()
8089
bot.set_webhook(url=WEBHOOK_URL_BASE,
8190
certificate=open(WEBHOOK_CERT, 'r'))
@@ -88,9 +97,9 @@ def send_welcome(message):
8897
])
8998

9099
http_server = tornado.httpserver.HTTPServer(application, ssl_options={
91-
"certfile": WEBHOOK_CERT,
92-
"keyfile": WEBHOOK_PKEY,
93-
})
100+
"certfile": WEBHOOK_CERT,
101+
"keyfile" : WEBHOOK_PKEY,
102+
})
94103
http_server.listen(tornado.options.options.port)
95104
tornado.ioloop.PeriodicCallback(try_exit, 100).start()
96105
tornado.ioloop.IOLoop.instance().start()

0 commit comments

Comments
 (0)