コード例 #1
0
ファイル: bot_handlers.py プロジェクト: ayudov/IK61bot
def send_all(message):
    result = sheet.get_all_records()
    send_all = 'Я знайшов ось кого:\n'
    count = 0

    bot.send_photo(message.chat.id, photo=open('photo/group_ik61.png', 'rb'))
    bot.send_message(
        message.chat.id,
        "<a href='https://docs.google.com/spreadsheets/d/1jdARV_Thoq19gII-CK1sHkcmK-s8ePa5Jf9aOoSP2i0"
        "/edit?usp=sharing'>Посилання на список групи</a>",
        parse_mode='HTML')

    for x in result:

        send_all = send_all + str(
            '\n' + '<b>ПІБ</b>: ' + str(x.get('All name')) +
            '\n<b>Посилання на Телеграм: </b>' + str(x.get('TG')) +
            '\n<b>e-mail</b>: ' + str(x.get('e-mail')) +
            '\n<b>Номер телефону</b>: ' + '0' + str(x.get('tel.')) +
            '\n<b>День народження</b>: ' + str(x.get('Birth date')) +
            '\n<b>Гуртожиток</b>: ' + str(x.get('info')) + '\n--')
        count = count + 1
        if count == len(result) / 2:
            bot.send_message(message.chat.id, send_all, parse_mode='HTML')
            send_all = ''
        elif count == len(result):
            bot.send_message(message.chat.id, send_all, parse_mode='HTML')
コード例 #2
0
ファイル: Akcia.py プロジェクト: bratslav/SlawaBot
def Akcii(message, tekUser):
    try:
        ftp = FTP('vs1960.mirohost.net')
        ftp.login('itteam', '1ShRHAgk0EEU')
        ftp.cwd(get_url())
        filenames = ftp.nlst()
        kolfiles = 0
        filenames.sort()
        for filename in filenames:
            if len(filename) == 5:
                s = filename[2:5]
                print(s)
                if s == 'png':
                    host_file = os.path.join(pth, filename)
                    try:
                        with open(host_file, 'wb') as local_file:
                            kolfiles = kolfiles + 1
                            ftp.retrbinary('RETR ' + filename,
                                           local_file.write)
                    except ftplib.error_perm:
                        print('Ошибка')
                        pass
                    bot.send_photo(message.chat.id, open(host_file, 'rb'), '.')
        if kolfiles == 0:
            tekUser.Last_message = bot.send_message(message.chat.id,
                                                    'Акцій немає ')
        ftp.close()
        main_menu(message, tekUser, 'Діючі акції')
    except:
        print("Нет доступа к FTP")
        tekUser.Last_message = bot.send_message(message.chat.id,
                                                'Нет доступа к FTP ')
コード例 #3
0
ファイル: bot_handlers.py プロジェクト: ayudov/IK61bot
def send_schedule(message):
    bot.send_photo(message.chat.id,
                   photo=open('photo/schedule ik-61.png', 'rb'))
    bot.send_message(
        message.chat.id,
        "<a href='http://rozklad.kpi.ua/Schedules/ViewSchedule.aspx?g=2c7c806a-e8c2-4dac-a36e"
        "-f53c2b9a51f6'>Посилання на розклад</a>",
        parse_mode='HTML')
コード例 #4
0
ファイル: online.py プロジェクト: BlackenedJustice/LizzzyBot
def send_task(message):
    user = players.users.get(message.chat.id)
    num = user.curr_online_task
    if text.t_format[num] == 'txt':
        bot.send_message(message.chat.id, text.task[num])
    elif text.t_format[num] == 'pic':
        bot.send_photo(message.chat.id, text.pic_id, caption=text.task[num])
    elif text.t_format[num] == 'audio':
        bot.send_audio(message.chat.id, text.audio_id, caption=text.task[num])
コード例 #5
0
def entry_point_statistics(update: Update, context: CallbackContext):
    user = session.query(User).filter(
        User.telegram_user_id == update.message.from_user.id).first()
    path_to_graph = make_default_graph(user)
    graph_controller = GraphController(
        path_to_graph, get_lifetime_user(user, now=datetime.datetime.now()),
        TypeTransaction.CONSUMPTION)
    context.user_data['statistics'] = graph_controller
    bot.send_photo(chat_id=update.message.from_user.id,
                   photo=open(path_to_graph, 'rb'),
                   reply_markup=reply_main_keyboard)
コード例 #6
0
ファイル: user_handlers.py プロジェクト: dmkalash/quest
def send_task(chat_id):
    point = view.point.cur_point(chat_id)
    bot.send_message(chat_id, point.task)
    for file in view.file.get_files_with_point(point):
        if file.file_type == PHOTO_TYPE:
            bot.send_photo(chat_id, file.file_id)
        elif file.file_type == DOCUMENT_TYPE:
            bot.send_document(chat_id, file.file_id)
        elif file.file_type == AUDIO_TYPE:
            bot.send_audio(chat_id, file.file_id)
        else:
            print('send_task problem: ', point, file.file_id, file.file_type)
コード例 #7
0
ファイル: photos.py プロジェクト: Macket/paidagogos_bot
def new_photo(message):
    teacher = Teacher.get(message.chat.id)
    if teacher:
        bot.delete_message(message.chat.id, message.message_id)

        ru_text = "Нажмите, чтобы исправить ошибки 👇🏻"
        en_text = "Tap to review 👇🏻"
        text = ru_text if teacher.language_code == 'ru' else en_text

        bot.send_photo(teacher.id,
                       message.photo[-1].file_id,
                       caption=text,
                       reply_markup=get_drawer_markup(
                           message.photo[-1].file_id, teacher))
コード例 #8
0
ファイル: views.py プロジェクト: Macket/paidagogos_bot
def submission_message_list_view(user, submission, task):
    student = Student.get(submission.student_id)

    text = f"Выполненное задание: *{task.name}*. Ученик: _{student.fullname}_" if \
        user.language_code == 'ru' else f"Submission: *{task.name}*. Student: _{student.fullname}_"
    bot.send_message(user.id, text, parse_mode='Markdown')

    ru_text = "Нажмите, чтобы исправить ошибки 👇🏻"
    en_text = "Tap to review 👇🏻"
    text = ru_text if user.language_code == 'ru' else en_text

    for submission_message in submission.messages:
        message = bot.forward_message(user.id, submission_message.student_id,
                                      submission_message.message_id)
        if type(user) is Teacher and message.photo:
            bot.delete_message(message.chat.id, message.message_id)
            message_with_button = bot.send_photo(
                user.id,
                message.photo[-1].file_id,
            )
            bot.send_message(user.id,
                             text,
                             reply_markup=get_drawer_markup(
                                 message.photo[-1].file_id, user,
                                 message_with_button.message_id,
                                 submission.id))
コード例 #9
0
def get_photo(message, search_term, n=1):
    try:
        req = requests.get(
            f'http://www.bing.com/images/search?q={search_term}&qs=n&form=QBLH&scope=images&sp=-1&pq={search_term}&sc=8-6&sk=&cvid={cvid}'
        )
        req.encoding = 'cp1251'
        soup = BeautifulSoup(req.text, 'html.parser')
        thumbnail_url = (soup.find_all('img')[n + 1]).get('src')

        bot.send_photo(message.chat.id, photo=thumbnail_url)
        return thumbnail_url

    except Exception as e:
        lang_num = language_define(message)
        n += 1
        if n == 6:
            bot.send_message(message.chat.id,
                             take_phrase_2('errors', 'photo_error', lang_num))
            return ''
        else:
            get_photo(message, search_term, n + 1)
コード例 #10
0
def handle_docs_document(message):
    file_info = bot.get_file(message.photo[len(message.photo) - 1].file_id)
    chat_id = message.chat.id
    downloaded_file = bot.download_file(file_info.file_path)
    photo_to_change = io.BytesIO(downloaded_file)
    img = Image.open(photo_to_change)
    (width, height) = img.size
    drawing = ImageDraw.Draw(img)
    random_phrase = random.choice(
        list(open('lyrics/meat.txt', encoding="utf8")))
    bot.send_message(chat_id, random_phrase)
    number_of_symbols = len(random_phrase)
    font = ImageFont.truetype('font.Ttf', int(
        (width / number_of_symbols) * 1.8))
    font_color = (255, 255, 255)
    shadow_color = (0, 0, 0)
    x, y = (width / 20, height / 1.3)
    drawing.text((x - 1, y - 1), random_phrase, font=font, fill=shadow_color)
    drawing.text((x + 1, y - 1), random_phrase, font=font, fill=shadow_color)
    drawing.text((x - 1, y + 1), random_phrase, font=font, fill=shadow_color)
    drawing.text((x + 1, y + 1), random_phrase, font=font, fill=shadow_color)
    drawing.text((x, y), random_phrase, font=font, fill=font_color)
    bot.send_photo(chat_id, photo=img)
コード例 #11
0
def repeat_all_messages(message):
    # Получаем информацию о пользователе
    user = users_db.find_one({USER_ID: message.from_user.id})

    # Ввод имени
    if user[STATE] == ENTER_NAME:
        if user[SEX] == '':
            users_db.update_one({USER_ID: message.from_user.id}, {"$set": {NAME: message.text, STATE: ENTER_SEX}})
            bot.send_message(message.chat.id, NAME_UPDATED + "\n" + CHOOSE_SEX_ASKING.format(
                users_db.find_one({USER_ID: user[USER_ID]})[NAME]), reply_markup=keyboard_choose_sex)
        else:
            if message.text == BACK_B:
                bot.send_message(message.chat.id, CHOOSE_OPTION_ASKING, reply_markup=keyboard_choose_option)
                users_db.update_one({USER_ID: user[USER_ID]}, {"$set": {STATE: CHOOSE_OPTION}})
            else:
                users_db.update_one({USER_ID: user[USER_ID]},
                                    {"$set": {NAME: message.text, STATE: CONTINUE_CONVERSATION}})
                bot.send_message(message.chat.id, NAME_UPDATED, reply_markup=keyboard_continue_conversation)

    # Ввод пола
    elif user[STATE] == ENTER_SEX:
        if any([message.text == MALE_B, message.text == FEMALE_B, message.text == OTHER_B]):
            users_db.update_one({USER_ID: user[USER_ID]}, {"$set": {SEX: message.text, STATE: CONTINUE_CONVERSATION}})
            bot.send_message(message.chat.id,
                             SEX_UPDATED + '\n' + YOUR_SEX.format(users_db.find_one({USER_ID: user[USER_ID]})[SEX]),
                             reply_markup=keyboard_continue_conversation)
        # elif re.search('[a-zA-Z\d]', message.text):
        #    bot.send_message(message.chat.id, CHAR_ASKING)
        else:
            bot.send_message(message.chat.id, KEYBOARD_USAGE_ASKING)

    # Продолжение диалога
    elif user[STATE] == CONTINUE_CONVERSATION:
        if message.text == SETTINGS_B:
            bot.send_message(message.chat.id, CHOOSE_OPTION_ASKING, reply_markup=keyboard_choose_option)
            users_db.update_one({USER_ID: user[USER_ID]}, {"$set": {STATE: CHOOSE_OPTION}})
        elif message.text == HELLO_B:
            my_friend_dict = {MALE_B: MY_FRIEND_M, FEMALE_B: MY_FRIEND_F, OTHER_B: MY_FRIEND_NA}
            if 0 <= datetime.now().hour < 6:
                time_recourse = GOOD_NIGHT
            elif 6 <= datetime.now().hour < 12:
                time_recourse = GOOD_MORNING
            elif 12 <= datetime.now().hour < 18:
                time_recourse = GOOD_DAY
            elif 16 <= datetime.now().hour < 24:
                time_recourse = GOOD_EVENING
            bot.send_message(message.chat.id, time_recourse + my_friend_dict[user[SEX]] + user[NAME],
                             reply_markup=keyboard_continue_conversation)
        elif message.text == CAT_B:
            bot.send_photo(message.chat.id, photo=web())
        else:
            bot.send_message(message.chat.id, KEYBOARD_USAGE_ASKING)

    # Смена имени и пола
    elif user[STATE] == CHOOSE_OPTION:
        if message.text == CHANGE_SEX_B:
            bot.send_message(message.chat.id, CHOOSE_SEX_ASKING.format(user[NAME]), reply_markup=keyboard_choose_sex)
            users_db.update_one({USER_ID: user[USER_ID]}, {"$set": {SEX: '', STATE: ENTER_SEX}})
        elif message.text == CHANGE_NAME_B:
            bot.send_message(message.chat.id, CHOOSE_NAME_ASKING.format(user[NAME]), reply_markup=keyboard_back)
            users_db.update_one({USER_ID: user[USER_ID]}, {"$set": {STATE: ENTER_NAME}})
        else:
            bot.send_message(message.chat.id, KEYBOARD_USAGE_ASKING)

    # Неверный ввод
    else:
        bot.send_message(message.chat.id, KEYBOARD_USAGE_ASKING)
コード例 #12
0
def send_cat(message):
    cat = get_cat()
    if str(cat).split('.')[-1] == 'gif':
        bot.send_document(message.chat.id, cat)
    else:
        bot.send_photo(message.chat.id, cat)
コード例 #13
0
ファイル: users.py プロジェクト: bratslav/SlawaBot
def drawing(message, tekUser):
    im = open(pth + str(tekUser.chat_id) + '.png', 'rb').read()
    tekUser.Last_message = bot.send_photo(message.chat.id, im, 'Це ваша картка. Щоб використатись покажіть цей екран поперед оплати''')
    AfterAvtor(message, tekUser)