def importantdelete(update, context): """Show new choice of buttons""" query = update.callback_query query.answer() data = query.data.split('_') id = int(data[1]) user = UsersClass(query.from_user.id) notes = ImportantClass(user.client, None) notes.delete(id) notes.get({'page': 1, 'count': settings.COUNT_PAGE}) if(notes.state): context.bot.edit_message_media(chat_id=query.message.chat_id, message_id=query.message.message_id, reply_markup=notes.reply_markup, media=InputMediaPhoto(media=notes.important.file_patch, caption=notes.important.body, parse_mode='Markdown')) return 'TIMING' else: buttons = [ InlineKeyboardButton("π ΠΠ»Π°Π½ΠΈΡΠΎΠ²ΡΠΈΠΊ", callback_data='100'), InlineKeyboardButton("π ΠΠ°ΠΆΠ½ΡΠ΅ Π΄Π°ΡΡ", callback_data='200'), ] keyboard = settings.constructor(buttons, settings.COUNT_ROW) reply_markup = InlineKeyboardMarkup(keyboard) context.bot.deleteMessage(chat_id=query.message.chat_id, message_id=query.message.message_id) context.bot.send_message(chat_id=query.message.chat.id, text="ΠΡΠΎ Π²Π°Ρ ΠΏΠ΅ΡΡΠΎΠ½Π°Π»ΡΠ½ΡΠΉ ΠΏΠ»Π°Π½ΠΈΡΠΎΠ²ΡΠΈΠΊ Π΄Π΅Π» Π½Π° Π΄Π΅Π½Ρ, Π½Π΅Π΄Π΅Π»Ρ, ΠΌΠ΅ΡΡΡ ΠΈ ΠΊΠ²Π°ΡΡΠ°Π»", reply_markup=reply_markup, parse_mode='Markdown') return 'TIMING'
def minute_importantdetail(update, context): """Show new choice of buttons""" query = update.callback_query query.answer() data = query.data.split('_') id = int(data[1]) hour = data[2] user = UsersClass(query.from_user.id) notes = ImportantClass(user.client, id) buttons = [] for x in range(0, 60, 5): prefix = '' if(notes.important.hour == x): prefix = 'β ' buttons.append(InlineKeyboardButton('{}{}'.format(prefix, x), callback_data='212_{}_{}_{}'.format(id, hour, x))) keyboard = settings.constructor(buttons, 4) reply_markup = InlineKeyboardMarkup(keyboard) reply_markup.inline_keyboard.append([InlineKeyboardButton("β©οΈ ΠΠ°Π·Π°Π΄", callback_data='203_{}'.format(id))]) context.bot.edit_message_media(chat_id=query.message.chat_id, message_id=query.message.message_id, reply_markup=reply_markup, media=InputMediaPhoto(media=notes.important.file_patch, caption='*{} {}*\nΠΡΠ±Π΅ΡΠΈΡΠ΅ ΠΌΠΈΠ½ΡΡΡ'.format(hour, HOUR[int(hour)]), parse_mode='Markdown')) return 'TIMING'
def hour_detail(update, context): """Show new choice of buttons""" query = update.callback_query query.answer() data = query.data.split('_') id = int(data[1]) day = data[2] call = data[3] user = UsersClass(query.from_user.id) notes = NotesClass(user.client, id) print('in' in str(data)) print('edit' in str(data)) print('edittime' in str(data)) if('in' in str(data)): if('edit' in str(data)): id_date = query.data.split('edit_')[1] datesh = DateTimeScheduler.select().where(DateTimeScheduler.id == id_date) else: datesh = DateTimeScheduler.select().join(Scheduler).where(Scheduler.id == id, DateTimeScheduler.state == False) if(datesh and not 'edittime' in str(data)): datesh = datesh[0] datesh.num_day = int(day) datesh.save() buttons = [] if('edit' in str(data)): if('edittime' in str(data)): id_date = query.data.split('edittime_')[1] else: id_date = query.data.split('edit_')[1] datesh = DateTimeScheduler.select().where(DateTimeScheduler.id == id_date) else: datesh = DateTimeScheduler.select().where(DateTimeScheduler.scheduler_id == id) postfix = '' if('edit' in str(data)): postfix = 'edit_{}'.format(id_date) for x in range(1, 24): prefix = '' for y in datesh: if(y.hour == x and day == y.num_day): prefix = 'β ' buttons.append(InlineKeyboardButton('{}{}'.format(prefix, x), callback_data='111_{}_{}_{}_{}'.format(id, day, x, postfix))) keyboard = settings.constructor(buttons, 4) reply_markup = InlineKeyboardMarkup(keyboard) if('edit' not in str(data) and DateTimeScheduler.select().join(Scheduler).where(Scheduler.id == id, DateTimeScheduler.num_day != None, DateTimeScheduler.hour != None, DateTimeScheduler.minute != None, DateTimeScheduler.state == False)): reply_markup.inline_keyboard.append([InlineKeyboardButton("ΠΠΎΡΠΎΠ²ΠΎ", callback_data='114_{}'.format(id))]) reply_markup.inline_keyboard.append([InlineKeyboardButton("β©οΈ ΠΠ°Π·Π°Π΄", callback_data='103_{}'.format(id))]) context.bot.edit_message_media(chat_id=query.message.chat_id, message_id=query.message.message_id, reply_markup=reply_markup, media=InputMediaPhoto(media=notes.scheduler.file_patch, caption='ΠΠ΅Π½Ρ Π½Π΅Π΄Π΅Π»ΠΈ: *{}*\nΠΡΠ±Π΅ΡΠΈΡΠ΅ ΡΠ°Ρ'.format(DAYS[int(day)]), parse_mode='Markdown')) return 'TIMING'
def minute_detail(update, context): """Show new choice of buttons""" query = update.callback_query query.answer() data = query.data.split('_') id = int(data[1]) day = data[2] hour = data[3] user = UsersClass(query.from_user.id) notes = NotesClass(user.client, id) print('edit' in str(data)) postfix = '' if('edit' in str(data)): postfix = 'edit_{}'.format(query.data.split('edit_')[1]) datesh = DateTimeScheduler.get(DateTimeScheduler.id == query.data.split('edit_')[1]) datesh.hour = int(hour) datesh.save() else: datesh = DateTimeScheduler.select().join(Scheduler).where(Scheduler.id == id, DateTimeScheduler.num_day == int(day), DateTimeScheduler.hour == int(hour), DateTimeScheduler.state == False) if(not datesh): print(294) scheduler = Scheduler.get(Scheduler.id == id) len_sh = DateTimeScheduler.select().join(Scheduler).where(Scheduler.id == id).count() if(len_sh < 7): DateTimeScheduler.create(scheduler=scheduler, num_day=int(day), hour=int(hour)) else: print(340) # update.callback_query.answer('ΠΠ³ΡΠ°Π½ΠΈΡΠ΅Π½ΠΈΠ΅: 7 Π½Π°ΠΏΠΎΠΌΠΈΠ½Π°Π½ΠΈΠΉ Π½Π° Π·Π°ΠΌΠ΅ΡΠΊΡ', show_alert=True) context.bot.send_message(chat_id=query.message.chat_id, text='ΠΠ³ΡΠ°Π½ΠΈΡΠ΅Π½ΠΈΠ΅: 7 Π½Π°ΠΏΠΎΠΌΠΈΠ½Π°Π½ΠΈΠΉ Π½Π° Π·Π°ΠΌΠ΅ΡΠΊΡ') return 'TIMING' buttons = [] datesh = DateTimeScheduler.select().join(Scheduler).where(Scheduler.id == id) for x in range(0, 60, 5): prefix = '' for y in datesh: if(y.hour == int(hour) and day == y.num_day and y.minute == x): prefix = 'β ' buttons.append(InlineKeyboardButton('{}{}'.format(prefix, x), callback_data='112_{}_{}_{}_{}_{}'.format(id, day, hour, x, postfix))) keyboard = settings.constructor(buttons, 6) # keyboard = settings.constructor(buttons, settings.COUNT_ROW) reply_markup = InlineKeyboardMarkup(keyboard) buttons = [] if(DateTimeScheduler.select().join(Scheduler).where(Scheduler.id == id, DateTimeScheduler.num_day != None, DateTimeScheduler.hour != None, DateTimeScheduler.minute != None, DateTimeScheduler.state == False)): reply_markup.inline_keyboard.append([InlineKeyboardButton("β©οΈ Π§Π°ΡΡ", callback_data='110_{}_{}_out_{}'.format(id, day, postfix))]) reply_markup.inline_keyboard.append([InlineKeyboardButton("ΠΠΎΡΠΎΠ²ΠΎ", callback_data='114_{}'.format(id))]) else: reply_markup.inline_keyboard.append([InlineKeyboardButton("β©οΈ Π§Π°ΡΡ", callback_data='110_{}_{}_out_{}'.format(id, day, postfix))]) reply_markup.inline_keyboard.append([InlineKeyboardButton("β©οΈ ΠΠ°Π·Π°Π΄", callback_data='103_{}'.format(id))]) context.bot.edit_message_media(chat_id=query.message.chat_id, message_id=query.message.message_id, reply_markup=reply_markup, media=InputMediaPhoto(media=notes.scheduler.file_patch, caption='ΠΠ΅Π½Ρ Π½Π΅Π΄Π΅Π»ΠΈ: *{}*\n*{}* {}\nΠΡΠ±Π΅ΡΠΈΡΠ΅ ΠΌΠΈΠ½ΡΡΡ'.format(DAYS[int(day)], hour, HOUR[int(hour)]), parse_mode='Markdown')) return 'TIMING'
def detail(self, id): print(54, self.scheduler.file_patch) buttons = [] buttons.append( InlineKeyboardButton("ΠΠ΅ΡΠ΅ΠΈΠΌΠ΅Π½ΠΎΠ²Π°ΡΡ", callback_data='108_{}'.format( self.scheduler.id))) keyboard = settings.constructor(buttons, settings.COUNT_ROW) self.reply_markup = InlineKeyboardMarkup(keyboard) self.reply_markup.inline_keyboard.append([ InlineKeyboardButton( 'Π Π΅ΠΆΠΈΠΌ: ' + MODE[self.scheduler.mode] if self.scheduler.mode else "Π Π΅ΠΆΠΈΠΌ", callback_data='106_{}'.format(self.scheduler.id)) ]) self.reply_markup.inline_keyboard.append([ InlineKeyboardButton('ΠΠ΅ΡΠΈΠΎΠ΄: ' + PERIOD[self.scheduler.period] if self.scheduler.period else "ΠΠ΅ΡΠΈΠΎΠ΄", callback_data='199_{}'.format( self.scheduler.id)) ]) self.dash = DateTimeScheduler.select().join(Scheduler).where( Scheduler.id == id, DateTimeScheduler.state == True) if (self.dash): for x in self.dash: str_time = str(datetime.time(x.hour, x.minute)) if (len(str_time.split(':')) == 3): str_time = str_time.replace(':00', '') buttons = [ InlineKeyboardButton(DAYS[int(x.num_day)], callback_data='107_{}_edit_{}'.format( self.scheduler.id, x.id)), InlineKeyboardButton( str_time, callback_data='110_{}_{}_edittime_{}'.format( self.scheduler.id, x.num_day, x.id)), InlineKeyboardButton('β', callback_data='115_{}_{}'.format( x.id, self.scheduler.id)) ] self.reply_markup.inline_keyboard.append(buttons) if (len(self.dash) < 7): self.reply_markup.inline_keyboard.append([ InlineKeyboardButton("ΠΠ΅Π½Ρ/ΠΡΠ΅ΠΌΡ", callback_data='107_{}'.format( self.scheduler.id)) ]) self.reply_markup.inline_keyboard.append([ InlineKeyboardButton("β©οΈ ΠΠ°Π·Π°Π΄", callback_data='100_{}'.format( self.scheduler.id)) ])
def detail(self, id): print(54, self.important.file_patch) buttons = [] buttons.append( InlineKeyboardButton("ΠΠ΅ΡΠ΅ΠΈΠΌΠ΅Π½ΠΎΠ²Π°ΡΡ", callback_data='208_{}'.format( self.important.id))) keyboard = settings.constructor(buttons, settings.COUNT_ROW) self.reply_markup = InlineKeyboardMarkup(keyboard) buttons = [] self.reply_markup.inline_keyboard.append([ InlineKeyboardButton( 'Π Π΅ΠΆΠΈΠΌ: ' + MODE_IMPORTANT[self.important.mode] if self.important.mode else "Π Π΅ΠΆΠΈΠΌ", callback_data='206_{}'.format(self.important.id)) ]) if (self.important.day and self.important.month): now = datetime.datetime.now(pytz.timezone('Europe/Kiev')) str_day = '0' + str(self.important.day) if int( self.important.day) < 10 else str(self.important.day) str_month = '0' + str(self.important.month) if int( self.important.month) < 10 else str(self.important.month) buttons.append( InlineKeyboardButton(str_day + '.' + str_month, callback_data='207_{}'.format( self.important.id))) else: buttons.append( InlineKeyboardButton('Π£ΠΊΠ°Π·Π°ΡΡ Π΄Π°ΡΡ', callback_data='207_{}'.format( self.important.id))) if (self.important.hour and self.important.minute): str_time = str( datetime.time(int(self.important.hour), int(self.important.minute))) if (len(str_time.split(':')) == 3): str_time = str_time.replace(':00', '') buttons.append( InlineKeyboardButton(str_time, callback_data='210_{}'.format( self.important.id))) else: buttons.append( InlineKeyboardButton('Π£ΠΊΠ°Π·Π°ΡΡ Π²ΡΠ΅ΠΌΡ', callback_data='210_{}'.format( self.important.id))) self.reply_markup.inline_keyboard.append(buttons) self.reply_markup.inline_keyboard.append([ InlineKeyboardButton("β©οΈ ΠΠ°Π·Π°Π΄", callback_data='200_{}'.format( self.important.id)) ])
def end(update, context): query = update.callback_query query.answer() buttons = [ InlineKeyboardButton("β° Π’Π°ΠΉΠΌΠΈΠ½Π³", callback_data='100_1'), ] keyboard = settings.constructor(buttons, settings.COUNT_ROW) reply_markup = InlineKeyboardMarkup(keyboard) query.edit_message_text( "Π’Π°ΠΉΠΌΠΈΠ½Π³ (Π½Π°ΠΏΠΎΠΌΠΈΠ½Π°Π½ΠΈΡ, ΡΠ²Π΅Π΄ΠΎΠΌΠ»Π΅Π½ΠΈΡ, ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΡ)", reply_markup=reply_markup, parse_mode='Markdown' ) return 'START'
def importantmode(update, context): """Show new choice of buttons""" query = update.callback_query query.answer() data = query.data.split('_') id = int(data[1]) user = UsersClass(query.from_user.id) notes = ImportantClass(user.client, id) buttons = [] for x in MODE_IMPORTANT: buttons.append(InlineKeyboardButton(MODE_IMPORTANT[x], callback_data='209_{}_{}'.format(id, x))) keyboard = settings.constructor(buttons, settings.COUNT_ROW) reply_markup = InlineKeyboardMarkup(keyboard) context.bot.edit_message_media(chat_id=query.message.chat_id, message_id=query.message.message_id, reply_markup=reply_markup, media=InputMediaPhoto(media=notes.important.file_patch, caption='ΠΡΠ±Π΅ΡΠΈΡΠ΅ ΡΠ΅ΠΆΠΈΠΌ ΡΠ°Π±ΠΎΡΡ'), parse_mode='Markdown') return 'TIMING'
def period_detail(update, context): """Show new choice of buttons""" query = update.callback_query query.answer() data = query.data.split('_') id = int(data[1]) user = UsersClass(query.from_user.id) notes = NotesClass(user.client, id) buttons = [] for x in PERIOD: buttons.append(InlineKeyboardButton(PERIOD[x], callback_data='189_{}_{}'.format(id, x))) keyboard = settings.constructor(buttons, settings.COUNT_ROW) reply_markup = InlineKeyboardMarkup(keyboard) context.bot.edit_message_media(chat_id=query.message.chat_id, message_id=query.message.message_id, reply_markup=reply_markup, media=InputMediaPhoto(media=notes.scheduler.file_patch, caption='ΠΡΠ±Π΅ΡΠΈΡΠ΅ ΠΏΠ΅ΡΠΈΠΎΠ΄ ΡΠ°Π±ΠΎΡΡ'), parse_mode='Markdown') return 'TIMING'
def date_detail(update, context): """Show new choice of buttons""" query = update.callback_query query.answer() data = query.data.split('_') id = int(data[1]) user = UsersClass(query.from_user.id) notes = NotesClass(user.client, id) req = DateTimeScheduler.delete().where(DateTimeScheduler.state == False) req.execute() print(228, 'edit' in str(data)) postfix = '' if('edit' in str(data)): postfix = 'edit_{}'.format(query.data.split('edit_')[1]) dateTimeScheduler = DateTimeScheduler.get(DateTimeScheduler.id == query.data.split('edit_')[1]) scheduler = dateTimeScheduler.scheduler else: scheduler = Scheduler.get(Scheduler.id == id) len_sh = DateTimeScheduler.select().join(Scheduler).where(Scheduler.id == id).count() print(len_sh,id) if(len_sh < 7): DateTimeScheduler.create(scheduler=scheduler) else: # context.bot.answer_callback_query(callback_query_id=update.callback_query.id, text='ΠΠ³ΡΠ°Π½ΠΈΡΠ΅Π½ΠΈΠ΅: 7 Π½Π°ΠΏΠΎΠΌΠΈΠ½Π°Π½ΠΈΠΉ Π½Π° Π·Π°ΠΌΠ΅ΡΠΊΡ', show_alert=True) context.bot.send_message(chat_id=query.message.chat_id, text='ΠΠ³ΡΠ°Π½ΠΈΡΠ΅Π½ΠΈΠ΅: 7 Π½Π°ΠΏΠΎΠΌΠΈΠ½Π°Π½ΠΈΠΉ Π½Π° Π·Π°ΠΌΠ΅ΡΠΊΡ') return 'TIMING' buttons = [] for x in DAYS: buttons.append(InlineKeyboardButton(DAYS[x], callback_data='110_{}_{}_in_{}'.format(id, x, postfix))) keyboard = settings.constructor(buttons, settings.COUNT_ROW) reply_markup = InlineKeyboardMarkup(keyboard) reply_markup.inline_keyboard.append([InlineKeyboardButton("β©οΈ ΠΠ°Π·Π°Π΄", callback_data='103_{}'.format(id))]) context.bot.edit_message_media(chat_id=query.message.chat_id, message_id=query.message.message_id, reply_markup=reply_markup, media=InputMediaPhoto(media=notes.scheduler.file_patch, caption='ΠΡΠ±Π΅ΡΠΈΡΠ΅ Π΄Π΅Π½Ρ Π½Π΅Π΄Π΅Π»ΠΈ'), parse_mode='Markdown') return 'TIMING'
def start_over(update, context): user = update.message.from_user logger.info("User %s init", user.id) user = UsersClass(user.id) if(user.dialog): data = user.dialog.data.split('|') step = data[0] data = data[1] return '{}_{}'.format(step, data) else: buttons = [ InlineKeyboardButton("π ΠΠ»Π°Π½ΠΈΡΠΎΠ²ΡΠΈΠΊ", callback_data='100'), InlineKeyboardButton("β οΈ ΠΠ°ΠΆΠ½ΡΠ΅ Π΄Π°ΡΡ", callback_data='200'), ] keyboard = settings.constructor(buttons, settings.COUNT_ROW) reply_markup = InlineKeyboardMarkup(keyboard) update.message.reply_text( text="ΠΡΠΎ Π²Π°Ρ ΠΏΠ΅ΡΡΠΎΠ½Π°Π»ΡΠ½ΡΠΉ ΠΏΠ»Π°Π½ΠΈΡΠΎΠ²ΡΠΈΠΊ Π΄Π΅Π» Π½Π° Π΄Π΅Π½Ρ, Π½Π΅Π΄Π΅Π»Ρ, ΠΌΠ΅ΡΡΡ ΠΈ ΠΊΠ²Π°ΡΡΠ°Π»", reply_markup=reply_markup ) return 'TIMING'
def important(update, context): """Show new choice of buttons""" query = update.callback_query query.answer() user = UsersClass(query.from_user.id) notes = ImportantClass(user.client, None) if('_' in query.data): notes.get({'page': 1, 'count': settings.COUNT_PAGE, 'note_id': query.data.split('_')[1]}) else: notes.get({'page': 1, 'count': settings.COUNT_PAGE}) if(notes.state): if(notes.important.file_patch): # context.bot.deleteMessage(chat_id=query.message.chat.id, message_id=update.message.message_id) context.bot.sendPhoto(chat_id=query.message.chat.id, photo=notes.important.file_patch, caption=notes.important.body, reply_markup=notes.reply_markup, parse_mode='Markdown') else: query.edit_message_text( text=notes.important.body, reply_markup=notes.reply_markup, parse_mode='Markdown' ) return 'TIMING' else: user.create_dialog('TIMING|200') buttons = [ InlineKeyboardButton("ΠΡΠΌΠ΅Π½ΠΈΡΡ β", callback_data='777'), ] keyboard = settings.constructor(buttons, settings.COUNT_ROW) reply_markup = InlineKeyboardMarkup(keyboard) query.edit_message_text( 'ΠΠ²Π΅Π΄ΠΈΡΠ΅ ΡΠ΅ΠΊΡΡ Π½Π°ΠΏΠΎΠΌΠΈΠ½Π°Π½ΠΈΡ ΠΈΠ»ΠΈ ΠΎΡΠΏΡΠ°Π²ΡΡΠ΅ ΠΊΠ°ΡΡΠΈΠ½ΠΊΡ', reply_markup=reply_markup, parse_mode='Markdown' ) return 'DIALOG'
def get(self, paginate): self.state = False self.scheduler_count = Scheduler.select().join(Clients).where( Clients.id == self.client.id).count() print(paginate) if (self.scheduler_count != 0): self.state = True if ('note_id' in paginate): for x in range(1, self.scheduler_count + 1): for y in Scheduler.select().join(Clients).where( Clients.id == self.client.id).order_by( Scheduler.id.desc()).paginate( x, paginate['count']): if (int(paginate['note_id']) == y.id): self.scheduler = Scheduler.select().join( Clients).where( Clients.id == self.client.id).order_by( Scheduler.id.desc()).paginate( x, paginate['count']) page = x break else: page = paginate['page'] self.scheduler = Scheduler.select().join(Clients).where( Clients.id == self.client.id).order_by( Scheduler.id.desc()).paginate(page, paginate['count']) buttons = [] print(self.scheduler) self.scheduler = self.scheduler[0] print(self.scheduler) if page > 1: buttons.append( InlineKeyboardButton("<<", callback_data='101_{}'.format(page - 1))) else: buttons.append( InlineKeyboardButton("<<", callback_data='101_{}'.format( self.scheduler_count))) buttons.append( InlineKeyboardButton("{}/{}".format(page, self.scheduler_count), callback_data='-')) if page < self.scheduler_count: buttons.append( InlineKeyboardButton(">>", callback_data='101_{}'.format(page + 1))) else: buttons.append( InlineKeyboardButton(">>", callback_data='101_{}'.format(1))) buttons.append( InlineKeyboardButton("π§ ΠΠ°ΡΡΡΠΎΠΉΠΊΠΈ", callback_data='103_{}'.format( self.scheduler.id))) buttons.append( InlineKeyboardButton("β ΠΠΎΠ±Π°Π²ΠΈΡΡ", callback_data='104')) keyboard = settings.constructor(buttons, 3) self.reply_markup = InlineKeyboardMarkup(keyboard) self.reply_markup.inline_keyboard.append([ InlineKeyboardButton("β Π£Π΄Π°Π»ΠΈΡΡ", callback_data='105_{}'.format( self.scheduler.id)) ])
def main(context: telegram.ext.CallbackContext): now = datetime.now(pytz.timezone('Europe/Kiev')) today = now.today() day = today.weekday() hour = now.hour minute = now.minute num_days = now.day month = now.month year = now.year print(year, month, num_days, day + 1, hour, minute) datesh = DateTimeScheduler.select().where( DateTimeScheduler.num_day == str(day + 1), DateTimeScheduler.hour == hour, DateTimeScheduler.minute == minute, DateTimeScheduler.send == False, DateTimeScheduler.end == False, DateTimeScheduler.state == True) important = Important.select().where(Important.month == month, Important.day == num_days, Important.hour == hour, Important.minute == minute, Important.send == False, Important.end == False) for x in datesh: state = False if (x.scheduler.mode == 'onetime'): state = True x.end = True if (x.scheduler.period == 'week' and (x.time_send is None or now > datetime.fromisoformat(x.time_send) + relativedelta(weeks=1))): state = True x.send = True x.time_send = now x.save() elif (x.scheduler.period == '2week' and (x.time_send is None or now > datetime.fromisoformat(x.time_send) + relativedelta(weeks=2))): state = True x.send = True x.time_send = now x.save() elif (x.scheduler.period == 'month' and (x.time_send is None or now > datetime.fromisoformat(x.time_send) + relativedelta(months=1))): state = True x.send = True x.time_send = now x.save() if (state): sh = Scheduler.select().where(Scheduler.id == x.scheduler_id) buttons = [ InlineKeyboardButton("ΠΠΎΠ»ΡΡΠ΅ Π½Π΅ Π½Π°ΠΏΠΎΠΌΠΈΠ½Π°ΡΡ β", callback_data='555_{}'.format(sh.id)), ] keyboard = settings.constructor(buttons, settings.COUNT_ROW) reply_markup = InlineKeyboardMarkup(keyboard) if (sh[0].file_patch != settings.MEDIA_TECH): context.bot.sendPhoto(chat_id=sh[0].client.chat_id, photo=sh[0].file_patch, caption=sh[0].body, reply_markup=reply_markup, parse_mode='Markdown') else: context.bot.send_message( chat_id=sh[0].client.chat_id, text=sh[0].body, parse_mode='Markdown', reply_markup=reply_markup, ) req = DateTimeScheduler.update(send=False).where( DateTimeScheduler.num_day != str(day), DateTimeScheduler.hour != hour, DateTimeScheduler.minute != minute, DateTimeScheduler.send == True, DateTimeScheduler.end == False) req.execute() for x in important: state = False if (x.mode == 'onetime'): state = True x.end = True if (x.time_send is None or now > datetime.fromisoformat(x.time_send) + relativedelta(year=1)): state = True x.send = True x.time_send = now x.save() if (state): buttons = [ InlineKeyboardButton("ΠΠΎΠ»ΡΡΠ΅ Π½Π΅ Π½Π°ΠΏΠΎΠΌΠΈΠ½Π°ΡΡ β", callback_data='556_{}'.format(x.id)), ] keyboard = settings.constructor(buttons, settings.COUNT_ROW) reply_markup = InlineKeyboardMarkup(keyboard) if (x.file_patch != settings.MEDIA_TECH): context.bot.sendPhoto(chat_id=x.client.chat_id, photo=x.file_patch, caption=x.body, reply_markup=reply_markup, parse_mode='Markdown') else: context.bot.send_message( chat_id=x.client.chat_id, text=x.body, parse_mode='Markdown', reply_markup=reply_markup, )
def text(update, context): query = update.message print(query) user = UsersClass(query.from_user.id) if(user.dialog): data = user.dialog.data.split('|') print(data) step = data[0] action = data[1] if(step == 'TIMING'): if(action == '104'): notes = NotesClass(user.client, None) notes.create(update.message.text) notes.get({'page': 1, 'count': settings.COUNT_PAGE}) if(notes.state): context.bot.sendPhoto(chat_id=query.chat.id, photo=notes.scheduler.file_patch, caption=notes.scheduler.body, reply_markup=notes.reply_markup) user.delete_dialog() else: user.create_dialog('TIMING|104') update.message.reply_text('ΠΠ²Π΅Π΄ΠΈΡΠ΅ ΡΠ΅ΠΊΡΡ Π½Π°ΠΏΠΎΠΌΠΈΠ½Π°Π½ΠΈΡ') return 'DIALOG' elif(action == '108'): id = data[2] notes = NotesClass(user.client, None) notes.update(type_up='body', id=id, data=update.message.text) notes.detail(id) context.bot.sendPhoto(chat_id=query.chat.id, photo=notes.scheduler.file_patch, caption=notes.scheduler.body, reply_markup=notes.reply_markup) user.delete_dialog() elif(action == '200'): notes = ImportantClass(user.client, None) notes.create(update.message.text) notes.get({'page': 1, 'count': settings.COUNT_PAGE}) if(notes.state): # context.bot.sendPhoto(chat_id=query.chat.id, photo=notes.important.file_patch, caption=notes.important.body, reply_markup=notes.reply_markup) user = UsersClass(query.from_user.id) notes = ImportantClass(user.client, notes.important.id) user.delete_dialog() user.create_dialog('TIMING|209|{}'.format(notes.important.id)) # context.bot.deleteMessage(chat_id=query.message.chat_id, message_id=query.message.message_id) context.bot.send_message(chat_id=query.chat.id, text='ΠΠ²Π΅Π΄ΠΈΡΠ΅ Π΄Π°ΡΡ Π² ΡΠΎΡΠΌΠ°ΡΠ΅ Π΄Π΄.ΠΌΠΌ', parse_mode='Markdown') return 'DIALOG' else: user.create_dialog('TIMING|200') update.message.reply_text('ΠΠ²Π΅Π΄ΠΈΡΠ΅ ΡΠ΅ΠΊΡΡ Π½Π°ΠΏΠΎΠΌΠΈΠ½Π°Π½ΠΈΡ') return 'DIALOG' # context.bot.sendPhoto(chat_id=query.chat.id, photo=settings.MEDIA_TECH, caption=notes.important.body, reply_markup=notes.reply_markup) # user.delete_dialog() elif(action == '208'): id = data[2] notes = ImportantClass(user.client, None) notes.update(type_up='body', id=id, data=update.message.text) notes.detail(id) context.bot.sendPhoto(chat_id=query.chat.id, photo=notes.important.file_patch, caption=notes.important.body, reply_markup=notes.reply_markup) user.delete_dialog() elif(action == '209'): date = update.message.text.split('.') if(len(date) != 2): context.bot.send_message(chat_id=query.chat.id, text='ΠΠ²Π΅Π΄ΠΈΡΠ΅ Π΄Π°ΡΡ Π² ΡΠΎΡΠΌΠ°ΡΠ΅ Π΄Π΄.ΠΌΠΌ', parse_mode='Markdown') return '{}'.format(step) if(date[0][0] == '0'): day = date[0][1] else: day = date[0] if(date[1][0] == '0'): month = date[1][1] else: month = date[1] if not (1 <= int(day) <= 31): context.bot.send_message(chat_id=query.chat.id, text='ΠΠ²Π΅Π΄ΠΈΡΠ΅ Π΄Π°ΡΡ Π² ΡΠΎΡΠΌΠ°ΡΠ΅ Π΄Π΄.ΠΌΠΌ', parse_mode='Markdown') return '{}'.format(step) if not (1 <= int(month) <= 12): context.bot.send_message(chat_id=query.chat.id, text='ΠΠ²Π΅Π΄ΠΈΡΠ΅ Π΄Π°ΡΡ Π² ΡΠΎΡΠΌΠ°ΡΠ΅ Π΄Π΄.ΠΌΠΌ', parse_mode='Markdown') return '{}'.format(step) now = datetime.datetime.now() month_day = calendar.monthrange(now.year, 1)[1] if (int(day) > month_day): context.bot.send_message(chat_id=query.chat.id, text='Π Π΄Π°Π½Π½ΠΎΠΌ ΠΌΠ΅ΡΡΡΠ΅ ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ Π΄Π½Π΅ΠΉ = {}'.format(month_day), parse_mode='Markdown') return '{}'.format(step) id = data[2] notes = ImportantClass(user.client, None) notes.update(type_up='date', id=id, data=[day, month]) notes.detail(id) if(notes.important.hour == None or notes.important.minute == None): buttons = [] for x in range(1, 24): prefix = '' if(notes.important.hour == x): prefix = 'β ' buttons.append(InlineKeyboardButton('{}{}'.format(prefix, x), callback_data='211_{}_{}'.format(notes.important.id, x))) keyboard = settings.constructor(buttons, 4) reply_markup = InlineKeyboardMarkup(keyboard) context.bot.sendPhoto(chat_id=query.chat.id, photo=notes.important.file_patch, caption='ΠΡΠ±Π΅ΡΠΈΡΠ΅ ΡΠ°Ρ', reply_markup=reply_markup) user.delete_dialog() return 'DIALOG' context.bot.sendPhoto(chat_id=query.chat.id, photo=notes.important.file_patch, caption=notes.important.body, reply_markup=notes.reply_markup) user.delete_dialog() return '{}'.format(step)