fix
This commit is contained in:
parent
d196d144ea
commit
02b2336b98
20
main.py
20
main.py
@ -83,17 +83,21 @@ def catch(message):
|
||||
db = read_db()
|
||||
chat_id = str(message.chat.id)
|
||||
user_id = str(message.from_user.id)
|
||||
username = str(message.from_user.username)
|
||||
if chat_id not in db:
|
||||
db[chat_id] = {}
|
||||
if user_id not in db[chat_id]:
|
||||
db[chat_id][user_id] = 1
|
||||
elif user_id in db[chat_id]:
|
||||
db[chat_id][user_id] += 1
|
||||
db[chat_id][user_id] = {}
|
||||
db[chat_id][user_id]["lunch"] = 0
|
||||
if username not in db[chat_id][user_id]:
|
||||
db[chat_id][user_id]["username"] = username
|
||||
if user_id in db[chat_id]:
|
||||
db[chat_id][user_id]["lunch"] += 1
|
||||
#bot.delete_message(message.chat.id, message.id)
|
||||
bot.send_message(message.chat.id,
|
||||
f'Пользователь [{telebot.util.user_link(message.from_user)}] использовал непечатное выражение.\n'\
|
||||
f'Кол-во потерянных обедов пользователя: {db[chat_id][user_id]}',
|
||||
parse_mode='HTML')
|
||||
# bot.send_message(message.chat.id,
|
||||
# f'Пользователь [{telebot.util.user_link(message.from_user)}] использовал непечатное выражение.\n'\
|
||||
# f'Кол-во потерянных обедов пользователя: {db[chat_id][user_id]}',
|
||||
# parse_mode='HTML')
|
||||
write_db(db)
|
||||
|
||||
@bot.message_handler(commands=['stats'])
|
||||
@ -102,7 +106,7 @@ def send_stats(message):
|
||||
chat_id = str(message.chat.id)
|
||||
user_id = str(message.from_user.id)
|
||||
#if str(message.from_user.id)==db[str(message.chat.id)]:
|
||||
bot.send_message(chat_id, f"Количество потраченных обедов [{telebot.util.user_link(message.from_user)}]: {db[chat_id][user_id]}😿", parse_mode='HTML')
|
||||
bot.send_message(chat_id, f"Количество потраченных обедов [{telebot.util.user_link(message.from_user)}]: {db[chat_id][user_id]['lunch']}😿", parse_mode='HTML')
|
||||
|
||||
@bot.message_handler()
|
||||
def catch_all_messages(message):
|
||||
|
@ -1,22 +1,25 @@
|
||||
from datetime import datetime
|
||||
import schedule
|
||||
import time
|
||||
import telebot
|
||||
from db import *
|
||||
db = read_db()
|
||||
bot = telebot.TeleBot(db['token'])
|
||||
|
||||
|
||||
def send_message():
|
||||
db = read_db()
|
||||
for i in db:
|
||||
if i != "token":
|
||||
text = 'Статистика обедов за 24 часа:\n'
|
||||
for j in db[i]:
|
||||
text += f'@{db[i][j]["username"]} - {db[i][j]["lunch"]} 😿\n'
|
||||
db[i][j]["lunch"] = 0
|
||||
write_db(db)
|
||||
bot.send_message(int(i), text, parse_mode='HTML')
|
||||
|
||||
schedule.every().day.at("21:00","Europe/Moscow").do(send_message)
|
||||
while True:
|
||||
now = datetime.now()
|
||||
current_time = now.strftime("%H:%M")
|
||||
if current_time == "21:00":
|
||||
db = read_db()
|
||||
for i in db:
|
||||
if i != "token":
|
||||
text = 'Статистика обедов за 24 часа::\n'
|
||||
for j in i:
|
||||
text += f'<a href="tg://user?id={j}">Пользователь</a>: {db[i][j]} обедов.\n'
|
||||
db[i][j] = 0
|
||||
write_db(db)
|
||||
bot.send_message(int(i),
|
||||
text,
|
||||
parse_mode='HTML')
|
||||
time.sleep(61)
|
||||
try:
|
||||
schedule.run_pending()
|
||||
time.sleep(1)
|
||||
except: exit()
|
||||
|
23
send_message.py.save
Normal file
23
send_message.py.save
Normal file
@ -0,0 +1,23 @@
|
||||
import schedule
|
||||
import time
|
||||
import telebot
|
||||
from db import *
|
||||
db = read_db()
|
||||
bot = telebot.TeleBot(db['token'])
|
||||
|
||||
|
||||
def send_message():
|
||||
db = read_db()
|
||||
for i in db:
|
||||
if i != "token":
|
||||
text = 'Статистика обедов за 24 часа:\n'
|
||||
for j in i:
|
||||
text += f'<a href="tg://user?id={j}">Пользователь</a>: {db[i][j]} обедов.\n'
|
||||
db[i][j] = 0
|
||||
write_db(db)
|
||||
bot.send_message(int(i), text, parse_mode='HTML')
|
||||
|
||||
schedule.every().day.at("21:24","Europe/Moscow").do(send_message)
|
||||
while True:
|
||||
schedule.run_pending()
|
||||
time.sleep(1)
|
Loading…
Reference in New Issue
Block a user