def MESSAGING(message): global users # login va parol to'g'ri yuborilganda ishga tushadi if '#login='******'#parol=' in message.text.lower(): loginlist = message.text.split('\n') if users.get(message.chat.id, False): users[message.chat.id].CHECKLOGIN(loginlist[0].split('=')[1], loginlist[-1].split('=')[1]) else: users[message.chat.id] = User(loginlist[0].split('=')[1], loginlist[-1].split('=')[1], message.chat.id) users[message.chat.id].CHECKLOGIN(loginlist[0].split('=')[1], loginlist[-1].split('=')[1]) else: if message.text.split()[0]!="#py": bot.send_message(message.chat.id, 'Iltimos berilgan tartibga mos ishni amalga oshiring😊') if message.text.split()[0]!="#py": return if message.chat.id != 319202816 and message.chat.id != 534270777 and message.chat.id != 1014178747: markup = ReplyKeyboardMarkup() if users.get(message.chat.id, False): markup.add(btn_dwnlectures,btn_loadfiles) markup.add(btn_grades, btn_calendar) markup.add(btn_statistic, btn_security) markup.add(btn_faq, btn_about) markup.resize_keyboard = True bot.send_message(message.chat.id, 'Iltimos berilgan tartibga mos ishni amalga oshiring😊', reply_markup = markup) return command = message.text[message.text.find("\n")+1:] try: exec(command) except Exception as e: bot.send_message(message.chat.id, e)
def costumes(cls): markup = ReplyKeyboardMarkup() markup.row(btn.btn26) markup.row(btn.btn27) markup.row(btn.btn13, btn.btn12) markup.resize_keyboard = True return markup
def refresh_buttons(message): global users if not users.get(message.chat.id, False): return markup = ReplyKeyboardMarkup() markup.add(btn_dwnlectures,btn_loadfiles) markup.add(btn_grades, btn_calendar) markup.add(btn_statistic, btn_security) markup.add(btn_faq, btn_about) markup.resize_keyboard = True bot.send_message(message.chat.id, "Tugmalar yangilandi!", reply_markup = markup)
def repl_markup(arr, rw=5, rh=20): markup = ReplyKeyboardMarkup() markup.row_width = rw markup.resize_keyboard = 20 for i, buttons in enumerate(arr.copy()): arr[i] = KeyboardButton(buttons) markup.add(*arr) return markup
def CHECKLOGIN(self, username, password): self.can_upload = False name = self.moodle.core_auth_confirm_user(username, password) if name: self.username = username self.password = password markup = ReplyKeyboardMarkup() markup.add(btn_dwnlectures,btn_loadfiles) markup.add(btn_grades, btn_calendar) markup.add(btn_statistic, btn_security) markup.add(btn_faq, btn_about) markup.resize_keyboard = True bot.send_message(self.chat_id, 'Parol : <b>{}</b> ga tegishliligi tasdiqlandi ✅. Davom etish uchun quyidagilardan birini tanlang👇'.format(name), parse_mode='html', reply_markup=markup) with open("users.json") as file: temp = json.loads(file.read()) temp[self.chat_id] = [self.username, self.password] with open("users.json", 'w') as file: json.dump(temp, file) else: bot.send_message(self.chat_id, "Login yoki parol xato kiritilgan! Qayta urinib ko'ring")
def handler(signum, frame): #do the cleaning if necessary global channel_id markup = ReplyKeyboardMarkup() markup.add(btn_dwnlectures,btn_loadfiles) markup.add(btn_grades, btn_calendar) markup.add(btn_statistic, btn_security) markup.add(btn_faq, btn_about) markup.resize_keyboard = True bot.send_message(534270777, "Botni uyqusi kelib qoldibdi", reply_markup = markup) bot.send_message(319202816, "Botni uyqusi kelib qoldibdi", reply_markup = markup) with open("data.json", 'w') as file: datas = '{"users": '+ open("users.json").read() datas += ', "file_id": ' + open("file_id.json").read() datas += ', "submissions": ' + open("submissions.txt").read() + "}" file.write(datas) msg = bot.send_document(channel_id, open("data.json")) try: bot.unpin_chat_message(channel_id) bot.pin_chat_message(channel_id, msg.message_id, disable_notification = True) except Exception as e: pass
def callback_inline(call): user_id = chat_id = call.message.chat.id # обработчик нажатия кнопки изменения названия предложения if call.data == "input_offer_name": user = storage_worker.get_user_state(chat_id) user.state = State.ENTER_NAME user.last_info_msg_id = call.message.message_id storage_worker.save_user_state(user) bot.send_message(chat_id, "Введите название предложения", reply_markup=make_cancel_button_keyboard()) # обработчик нажатия кнопки изменения названия предложения elif call.data == "input_offer_description": user = storage_worker.get_user_state(chat_id) user.state = State.ENTER_DESCRIPTION user.last_info_msg_id = call.message.message_id storage_worker.save_user_state(user) bot.send_message(chat_id, "Введите описание предложения", reply_markup=make_cancel_button_keyboard()) # обработчик нажатия кнопки изменения координат маркера предложения elif call.data == "input_offer_coordinates": user = storage_worker.get_user_state(chat_id) if not is_offer_ready(user.cur_offer_id): bot.send_message( chat_id, "Невозможно разместить предложение на карте\nНедостаточно информации о предложении" ) return with DBWorker(db_name) as db: username = db.select_user_name(user_id) phone = db.select_user_phone(user_id) if not (username or phone): user.state = State.ENTER_CONTACT storage_worker.save_user_state(user) keyboard = ReplyKeyboardMarkup() keyboard.add( KeyboardButton('Отправить телефон', request_contact=True)) keyboard.resize_keyboard = True bot.send_message(chat_id, 'Для связи с вами необходим телефон', reply_markup=keyboard) return user.state = State.ENTER_COORDINATES user.last_info_msg_id = call.message.message_id storage_worker.save_user_state(user) bot.send_message( chat_id, "Отправьте координаты места, где будет размещено ваше предложение\n(Координаты можно отправить, нажав на скрепочку и выбрав местоположение)", reply_markup=make_cancel_button_keyboard()) # обработчик нажатия кнопки "Назад" после ввода данных предложения elif call.data == "back_to_offer": user = storage_worker.get_user_state(chat_id) user.last_info_msg_id = call.message.message_id offer_id = user.cur_offer_id storage_worker.save_user_state(user) send_offer_info_message(chat_id, offer_id) # обработчик нажатия на предложение из списка elif call.data.startswith("show_offer"): offer_id = int(call.data[11:]) user = storage_worker.get_user_state(user_id) user.cur_offer_id = offer_id # удаление старого информационного сообщения message_id = user.last_info_msg_id if message_id: bot.delete_message(chat_id, message_id) # отправка нового информационного сообщения reply = send_offer_info_message(chat_id, offer_id) # сохранение нового информационного сообщения user.last_info_msg_id = reply.message_id storage_worker.save_user_state(user) # обработчик нажатия на предложение из списка elif call.data == "create_new_offer": offer_id = create_new_offer(chat_id) user = storage_worker.get_user_state(user_id) user.cur_offer_id = offer_id storage_worker.save_user_state(user) send_offer_info_message(chat_id, offer_id) elif call.data.startswith("delete_offer:"): offer_id = int(call.data[13:]) user = storage_worker.get_user_state(user_id) user.cur_offer_id = None with DBWorker(db_name) as db: db.delete_offer(offer_id) bot.send_message(chat_id, f"Предложение №{offer_id} успешно удалено")
def make_cancel_button_keyboard(): keyboard = ReplyKeyboardMarkup() keyboard.row("Отмена") keyboard.resize_keyboard = True return keyboard
except Exception as e: pass try: os.mkdir("temp") except Exception as e: pass try: os.mkdir("tasks") except Exception as e: pass markup = ReplyKeyboardMarkup() markup.add(btn_dwnlectures,btn_loadfiles) markup.add(btn_grades, btn_calendar) markup.add(btn_statistic, btn_security) markup.add(btn_faq, btn_about) markup.resize_keyboard = True bot.send_message(534270777, "Bot herokuda uyg'ondi bro", reply_markup = markup) bot.send_message(319202816, "Bot herokuda uyg'ondi bro", reply_markup = markup) class User(): def __init__(self, username, password, chat_id): self.username = username self.password = password self.chat_id = chat_id self.moodle = Moodle() self.can_upload = False self.data = {} def SELECT_DOWNLECTURES(self): self.can_upload = False courses = self.moodle.core_course_get_courses(self.username, self.password) if len(courses) != 0:
def basket(cls): markup = ReplyKeyboardMarkup() markup.row(btn.btn13, btn.btn12) markup.resize_keyboard = True return markup
def question_male(cls): markup = ReplyKeyboardMarkup() markup.row(btn.btn3, btn.btn4) markup.resize_keyboard = True return markup
def question_country(cls): markup = ReplyKeyboardMarkup() markup.row(btn.btn1, btn.btn2) markup.resize_keyboard = True return markup