def play_message(message): global players # default bot's message if nothing works mess_str = 'я забыл, что хотел сказать. хе-хе' # set a user to work with and init him as a player ahead curr_user = message.from_user # check and add first time user into game and create message for him if players.get(message.from_user.id) is None: if curr_user.first_name is None: players[curr_user.id] = pl.Player(default_player_name, default_player_money, default_player_property) else: players[curr_user.id] = pl.Player(curr_user.first_name, default_player_money, default_player_property) # player added mess_str = 'Игрок ' + players[curr_user.id].name + ' успешно добавлен в игру. \nФинансовое состояние:\n' + \ str(players[curr_user.id].money) + '\nСобственность:\n' + players[curr_user.id].get_properties_stat() else: # player has been already added mess_str = '' + players[curr_user.id].name + ' уже был добавлен в игру. \nФинансовое состояние:\n' + \ str(players[curr_user.id].money) + '\nСобственность:\n' + players[curr_user.id].get_properties_stat() # bot's message for each user bot.send_message(message.chat.id, mess_str)
def send_welcome(message): markup = types.ReplyKeyboardMarkup(row_width=1) itembtn1 = types.KeyboardButton('/allPopularMovie') itembtn2 = types.KeyboardButton('/newSinceLastUpdate') itembtn3 = types.KeyboardButton('/updateList') markup.add(itembtn1, itembtn2, itembtn3) telebot.send_message(chat_id, "Pick a function:", reply_markup=markup)
def getUpdate(): text, chat_id, update_id = telebot.parseText(request.body.read()) telebot.sendChatAction(URL, chat_id, 'typing') non_bmp_map = dict.fromkeys(range(0x10000, sys.maxunicode + 1), 0xfffd) print("IP: " + text.translate(non_bmp_map)) resp = curiouscomm.communicate(session_id, CLIENT_ACCESS_TOKEN, text) print("OP: " + resp) telebot.send_message(URL, resp.replace("&", ""), chat_id)
def start_message(message): # without sense, just for practice and fun :) # get name from user's message, if first time add to dict global pl_name curr_user = message.from_user if pl_name.get(curr_user.id) is None: pl_name[curr_user.id] = curr_user.first_name bot.send_message(message.chat.id, pl_name[curr_user.id] + ', чего тебе?')
def ValidateInputedValues(telebot, message, strDryTemp, strWetTemp="0"): if isFloat(strDryTemp) == False: telebot.send_message( message.from_user.id, "The value is not numeric. Please enter correct Dry measure") print(str(datetime.datetime.now()), " ", "Error: Incorrect Dry value - ", strDryTemp) bot.register_next_step_handler(message, SetDryTemp) return False elif isFloat(strWetTemp) == False: telebot.send_message( message.from_user.id, "The value is not numeric. Please enter correct Wet measure") print(str(datetime.datetime.now()), " ", "Error: Incorrect Wet value - ", strWetTemp) bot.register_next_step_handler(message, SetWetTemp) return False elif float(strWetTemp) >= float(strDryTemp): telebot.send_message( message.from_user.id, "The Wet measure should be less than Dry measure. Please enter correct Wet measure" ) print(str(datetime.datetime.now()), " ", "Error: Wet value more or equally then Dry - ", strWetTemp) bot.register_next_step_handler(message, SetWetTemp) return False return True
def send_notification( user_id, pincode, age, # these two fields need to be as latest as possible, stale info could cause wrong/more notifications respectively pincode_info, user_info, min_time_diff_btw_pos=12 * 3600, min_time_diff_btw_neg=24 * 3600): curr_time = datetime.utcnow() notification_state = get_key(user_info, ['notificationState', f'{pincode}_{age}'], {}) notification_type, response = check_slot_get_response( pincode_info, pincode, age) if notification_type == 'positive': logger.log( DEBUG, f'Slots found for user [{user_id}], pincode [{pincode}], age [{age}].' ) logger.log(DATA, response) if len(response) > 1: message = f"You have slots available in pincode area {pincode}, for {age} year olds, use command 'request {pincode} {age}' to check centers." elif len(response) > 0: message = f"You have slots available in pincode area {pincode}, for {age} year olds." \ f"\n\n{response[0]}" else: logger.log( WARNING, '******** Impossible event, debug immediately. ********') return None, None elif notification_type == 'negative': logger.log( DEBUG, f'Slots NOT found for user [{user_id}], pincode [{pincode}], age [{age}].' ) message = f"No slots available in pincode area {pincode}, for {age} year olds." else: return None, None notify = False if len(notification_state) > 0: last_time_sent = notification_state['timestamp'] last_notification_type = notification_state['type'] time_diff_seconds = (curr_time - last_time_sent).total_seconds() logger.log( DEBUG, f'Found notification state for user [{user_id}], ' f'last time sent [{last_time_sent}], ' f'last notification type [{last_notification_type}], ' f'current notification type [{notification_type}], time difference in seconds [{time_diff_seconds}].' ) if last_notification_type == 'negative' and notification_type == 'positive': notify = True elif last_notification_type == 'negative' and notification_type == 'negative': # send negative notifications repeatedly not closer than 24 hours if time_diff_seconds > min_time_diff_btw_neg: notify = True elif last_notification_type == 'positive' and notification_type == 'negative': notify = True elif last_notification_type == 'positive' and notification_type == 'positive': # send positive notifications repeatedly not closer than 6 hours if time_diff_seconds > min_time_diff_btw_pos: notify = True else: notify = True else: notify = True if notify: logger.log(INFO, f'Notifying user [{user_id}], message [{message}].') telebot.send_message(user_id, message) dbHelper.update_user_info_set( user_id, { f'notificationState.{pincode}_{age}': { 'timestamp': curr_time, 'type': notification_type } }) return notification_type, curr_time else: logger.log(INFO, f'Not notifying user [{user_id}].') return None, None
def send_test_message(message, disable_link_preview=True): if message == '': return telebot.send_message(telebot.err_channel_id, message, disable_link_preview)
async def telegram_webhook(update=Body(...)): # help if is_message_update(update, 'help'): commands = '\nping\nphoto\nphoto_file\nbuttoms\naudio\naudio_file\ndocument\ndocument_file\nvideo\nvideo_fie\nlocation\nvenue\ncontact\npoll\ndice\nreply\ndisable_notification' telebot.send_message(bot, update['message']['chat']['id'], f'commands:{commands}') # ping pong example if is_message_update(update, 'ping'): telebot.send_message(bot, update['message']['chat']['id'], 'pong') # send photo example if is_message_update(update, 'photo'): optinals = telebot.optinal_caption('this is a moose?') telebot.send_photo(bot, update['message']['chat']['id'], 'https://source.unsplash.com/random', optinals) # inline bottons example if is_message_update(update, 'buttons'): buttons = [[{ 'text': 'button wide', 'callback_data': 'button wide' }], [{ 'text': 'button half', 'callback_data': 'button half left' }, { 'text': 'button half', 'callback_data': 'button half right' }]] buttons_options = telebot.optinal_inline_keyboard(buttons) telebot.send_message(bot, update['message']['chat']['id'], 'buttons', buttons_options) if is_callback_data_update(update): chat_id = update['callback_query']['message']['chat']['id'] data = update['callback_query']['data'] telebot.send_message(bot, chat_id, f'you choosed: {data}') # audio if is_message_update(update, 'audio'): telebot.send_audio(bot, update['message']['chat']['id'], 'https://sounds-mp3.com/mp3/0005635.mp3') # document if is_message_update(update, 'document'): telebot.send_document( bot, update['message']['chat']['id'], 'https://www.rfc-editor.org/rfc/pdfrfc/rfc7231.txt.pdf') # video if is_message_update(update, 'video'): telebot.send_video( bot, update['message']['chat']['id'], 'https://cdn.videvo.net/videvo_files/video/premium/video0037/large_watermarked/docklands_clocks06_preview.mp4' ) # location if is_message_update(update, 'location'): telebot.send_location(bot, update['message']['chat']['id'], 32.2655662, -112.7396284) # venue if is_message_update(update, 'venue'): telebot.send_venue(bot, update['message']['chat']['id'], 32.2655662, -112.7396284, 'Best City Ever', 'Why, Arizona, USA') # contact if is_message_update(update, 'contact'): telebot.send_contact(bot, update['message']['chat']['id'], '1-234-457-89', 'John', 'Doe') # poll if is_message_update(update, 'poll'): telebot.send_poll(bot, update['message']['chat']['id'], 'am I a gopollod Bot ;3', ['Yes', 'No', 'Maybe']) # dice if is_message_update(update, 'dice'): telebot.send_dice(bot, update['message']['chat']['id'], '🎯') # reply if is_message_update(update, 'reply'): options = telebot.optinal_reply_to_message( update['message']['message_id']) telebot.send_message(bot, update['message']['chat']['id'], 'replying to message', options) # disable notification if is_message_update(update, 'disable_notification'): options = telebot.optinal_disable_notification() telebot.send_message(bot, update['message']['chat']['id'], 'no notification', options) # using multipart/form-data if is_message_update(update, 'audio_file'): # dont for get to and binary flag in open() telebot.send_audio(bot, update['message']['chat']['id'], open('../files/example_audio.mp3', 'rb')) if is_message_update(update, 'document_file'): # dont for get to and binary flag in open() telebot.send_document(bot, update['message']['chat']['id'], open('../files/example_document.txt', 'rb')) if is_message_update(update, 'video_file'): # dont for get to and binary flag in open() telebot.send_video(bot, update['message']['chat']['id'], open('../files/example_video.mp4', 'rb')) if is_message_update(update, 'photo_file'): # dont for get to and binary flag in open() telebot.send_photo(bot, update['message']['chat']['id'], open('../files/example_photo.jpg', 'rb'))
from telethon.tl.types import ChannelParticipantsAdmins from userbot.cmdhelp import CmdHelp from telethon.events import NewMessage from userbot.events import register from userbot import bot from asyncio import sleep import telebot bot = telebot.TeleBot('1753134503:AAHPxfcMLv8ucVMJAoaIFkqn6z4uWvmwXdY') @bot.message_handler(content_types=['cmd_call_admins']) def cmd_call_admins(bot, update): users = telebot.get_participants(1001326131404) print(users[0].first_name) for user in users: if user.username is not None: print(user.username) telebot.send_message(1001326131404, "@{}".format(user.username)) time.sleep(2) bot.polling()
def ping(message: List[str], context: Any) -> bool: telebot.send_message(context['bot'], context['chat_id'], 'pong') return True