def on_write(message): """Receives message on db.write queue """ print('Write received', message) body = json.loads(message.body) try: db_write(body['key'], body['value']) finally: message.ack()
async def start(client, message): chek = db_chek_blocklist(message) if chek == False: await message.reply_text("<b>Ты заблокирован в этом боте навсегда</b>", reply_to_message_id=message.message_id) else: db_write(message) await message.reply_text(f"<b>Добро пожаловать, {message.from_user.mention}</b>", reply_to_message_id=message.message_id)
def write(): d = request.json try: name = d.get("name").strip() date = d.get("date").strip() location = d.get("location").strip() items = d.get("items") except Exception as E: return str(E), 402 if len(name) == 0: return "name is required", 402 if not valid_date(date): return "date is required and must be valid", 402 if len(location) == 0 or not is_location(l): return "location is required and must be defined", 402 last_transaction_id = db.db_read("last_transaction_id") data = { last_transaction_id + 1: { "name": name, "date": date, "location": location, "items": items } } return db.db_write("transactions".data)
def __init__(self, root, name=None, head='task', body='description'): """""" self.root = root self.name = name self.head = head self.body = body self.sub_win = None self.frame = tk.Frame(self.root, bd=5, relief='sunken') self.lab = tk.Label(self.frame, text=self.head) self.lab.pack(side=tk.LEFT) tk.Button(self.frame, text='O', command=self.put_off).pack(side=tk.RIGHT) tk.Button(self.frame, text='V', command=self.done).pack(side=tk.RIGHT) tk.Button(self.frame, text='text', command=self.text).pack(side=tk.RIGHT) if not self.name: self.name = hash(datetime.now()) self.task_dict[self.name] = Task(self.head, self.body) db.db_write(self.task_dict)
def done(self): """""" del self.task_dict[self.name] db.db_write(self.task_dict) self.frame.destroy()
def change(self, head, body): """""" self.task_dict[self.name].head = head.get() self.task_dict[self.name].body = body.get(0.1, tk.END) self.lab.config(text=head.get()) db.db_write(self.task_dict)
async def feedback(client, message): chek = db_chek_blocklist(message) flood = await flood_control(message) if message.from_user.username != me_chat_id \ and flood != False: if chek == False: await message.reply_text("<b>Ты заблокирован в этом боте навсегда</b>", reply_to_message_id=message.message_id) else: db_write(message) db = createDB["message_ids"] if message.media_group_id != None: msg_find = db.find_one({"MEDIA_GROUP_ID": f"{message.media_group_id}"}) if msg_find == None: message_media_group_id = {"MEDIA_GROUP_ID": f"{message.media_group_id}"} db.insert_one(message_media_group_id).inserted_id msg_list = await client.get_media_group(message.chat.id, message.message_id) list_ids = [] for _ in msg_list: list_ids.append(_.message_id) forward = await client.forward_messages(chat_id=me_chat_id, from_chat_id=message.chat.id, message_ids=list_ids) message_id = ({"MESSAGE_DATE": f"{forward[0].forward_date}", "USER_ID": f"{message.from_user.id}"}) db.insert_one(message_id).inserted_id print(f"Сообщение {message_id['MESSAGE_DATE']} добавлено в БД") else: forward = await message.forward(me_chat_id) message_id = ({"MESSAGE_DATE": f"{forward.forward_date}", "USER_ID": f"{message.from_user.id}"}) db.insert_one(message_id).inserted_id print(f"Сообщение {message_id['MESSAGE_DATE']} добавлено в БД") elif message.from_user.username == me_chat_id and message.reply_to_message: try: db = createDB["message_ids"] user_id = db.find_one({"MESSAGE_DATE": f"{message.reply_to_message.forward_date}"}) print(f"Пользователь {user_id['USER_ID']} найден") if message.media_group_id != None: msg_find = db.find_one({"MEDIA_GROUP_ID": f"{message.media_group_id}"}) if msg_find == None: message_media_group_id = {"MEDIA_GROUP_ID": f"{message.media_group_id}"} db.insert_one(message_media_group_id).inserted_id await client.copy_media_group(user_id["USER_ID"], me_chat_id, message_id=message.message_id) else: await client.copy_message(user_id["USER_ID"], me_chat_id, message_id=message.message_id) except Exception as e: await message.reply_text(f"<b>{e}</b>", reply_to_message_id=message.message_id) elif message.from_user.username == me_chat_id and message.reply_to_message == None: promote_button = InlineKeyboardButton("Рассылать?", callback_data="promote") delete_button = InlineKeyboardButton("Удалить", callback_data="delete") promote_keyboard = InlineKeyboardMarkup([[promote_button], [delete_button]]) if message.media_group_id != None: db = createDB["message_ids"] msg_find = db.find_one({"MEDIA_GROUP_ID": f"{message.media_group_id}"}) if msg_find == None: message_media_group_id = {"MEDIA_GROUP_ID": f"{message.media_group_id}"} db.insert_one(message_media_group_id).inserted_id msg_list = await client.copy_media_group(me_chat_id, me_chat_id, message_id=message.message_id) await msg_list[1].reply_text("<b>Подтвердите рассылку медиа группы</b>", reply_markup=promote_keyboard, reply_to_message_id=msg_list[1].message_id) else: await client.copy_message(me_chat_id, me_chat_id, message_id=message.message_id, reply_markup=promote_keyboard)
def fill_db(iteration=1000): for hop in range(iteration): db_write(gen_mail(), gen_pass(), local_time(), 'none', 'false', gen_name())
def foo(): x = db_write() return x