Skip to content

Commit 1f407d3

Browse files
committedNov 24, 2021
final fix
1 parent c6a4c42 commit 1f407d3

File tree

4 files changed

+10
-19
lines changed

4 files changed

+10
-19
lines changed
 

‎README.md

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
Simple telegram bot on python3 for parking booking and some statistics about parking use.
44

5-
This bot don't send unnecessary messages and just edits originally send, so no annoying phone ringing will take place.
6-
75
This bot uses the [python telegram bot](https://python-telegram-bot.org) framework to make Telegram API calls.
86

97
All messages are in russian, but you can adapt it with no effort, there about 10 of them.

‎config-sample.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"data_file_prefix": "pickle",
2+
"data_file": "data.pickle",
33
"logging": {
44
"log_file": "log.txt",
55
"log_length": "10"

‎parking_bot.py

+8-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from emoji import emojize
77
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
8-
from telegram.error import BadRequest
98
from telegram.ext import (CallbackContext, CallbackQueryHandler,
109
CommandHandler, PicklePersistence, Updater)
1110

@@ -24,7 +23,7 @@ def start(update: Update, context: CallbackContext) -> None:
2423
'\nВыберете место кнопками ниже')
2524
update.effective_message.reply_text(welcome, parse_mode='MarkdownV2')
2625
update.effective_message.reply_text(
27-
parking.state_text, reply_markup=markup, parse_mode='MarkdownV2')
26+
parking.state_text, reply_markup=markup)
2827
log_event(update, 'Отправил start')
2928

3029

@@ -47,7 +46,6 @@ def parking_handler(update: Update, context: CallbackContext) -> None:
4746
if (config['whitelist'] and str(update.effective_user.id) in users
4847
or not config['whitelist']):
4948
manage_user(update, context)
50-
context.user_data['is_in_menu'] = False
5149
number = update.callback_query.data
5250
try:
5351
parking = context.bot_data['parking']
@@ -78,7 +76,6 @@ def cancel_handler(update: Update, context: CallbackContext) -> None:
7876
if (config['whitelist'] and str(update.effective_user.id) in users
7977
or not config['whitelist']):
8078
manage_user(update, context)
81-
context.user_data['is_in_menu'] = False
8279
number = update.callback_query.data.split('.')[1]
8380
parking = context.bot_data['parking']
8481
try:
@@ -101,7 +98,6 @@ def clear_handler(update: Update, context: CallbackContext) -> None:
10198
if (config['whitelist'] and str(update.effective_user.id) in users
10299
or not config['whitelist']):
103100
manage_user(update, context)
104-
context.user_data['is_in_menu'] = False
105101
try:
106102
parking = context.bot_data['parking']
107103
places = parking.clear()
@@ -121,7 +117,7 @@ def clear_handler(update: Update, context: CallbackContext) -> None:
121117

122118

123119
def statistics_handler(update: Update, context: CallbackContext) -> None:
124-
"""Handler for statistic menu button."""
120+
"""Handler for statistic button."""
125121
if (config['whitelist'] and str(update.effective_user.id) in users
126122
or not config['whitelist']):
127123
manage_user(update, context)
@@ -133,7 +129,7 @@ def statistics_handler(update: Update, context: CallbackContext) -> None:
133129

134130
def update_state(update: Update, context: CallbackContext, info: str,
135131
personal=False) -> None:
136-
"""Sends personal or bulk messages by updating.
132+
"""Sends personal or bulk messages to users.
137133
138134
Args:
139135
update: for identifying users and getting bot for bulk send.
@@ -145,10 +141,9 @@ def update_state(update: Update, context: CallbackContext, info: str,
145141
parking = context.bot_data['parking']
146142
if personal:
147143
markup = make_keyboard(context, str(update.effective_user.id))
148-
update.effective_message.reply_text(
149-
text=info, parse_mode='MarkdownV2')
150-
update.effective_message.reply_text(
151-
text=parking.state_text, reply_markup=markup)
144+
update.effective_message.reply_text(info, parse_mode='MarkdownV2')
145+
update.effective_message.reply_text(parking.state_text,
146+
reply_markup=markup)
152147
else:
153148
for user in users:
154149
markup = make_keyboard(context, user)
@@ -317,8 +312,8 @@ def get_logs(update: Update, context: CallbackContext) -> None:
317312

318313
def main():
319314
updater = Updater(token=config['token'], persistence=PicklePersistence(
320-
filename=config['data_file_prefix'], store_chat_data=False,
321-
single_file=False, on_flush=False))
315+
filename=config['data_file'], store_chat_data=False,
316+
store_user_data=False, on_flush=False))
322317
dispatcher = updater.dispatcher
323318
dispatcher.bot_data['stats'] = dispatcher.bot_data.get('stats',
324319
Stats(users))

‎users.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
{
2-
"392677870": "Igor Bulekov"
3-
}
1+
{}

0 commit comments

Comments
 (0)
Please sign in to comment.