Esempio n. 1
0
 def _check(func, rss):
     logging.warning(str(subscribe))
     if subscribe:
         try:
             rss_feed = feedparser.parse(rss)
             logging.warning('checking rss')
             parsed_date = parser.parse(rss_feed.entries[0].published)
             today = utc.localize(datetime.today()).day, utc.localize(
                 datetime.today()).month
             yesterday = utc.localize(
                 datetime.today()).day - 1, utc.localize(
                     datetime.today()).month
             if (parsed_date.day, parsed_date.month) in (
                     today, yesterday) or parsed_date.day > today[0]:
                 url = rss_feed.entries[0].link
             else:
                 url = None
         except Exception:
             url = rss
         if url:
             if 'dilbert' in rss:
                 i, txt = func(rss, latest=True)
             else:
                 i, txt = func(url)
             if 'apod' in rss:
                 bot.send_message(chat_id, txt, parse_mode='Markdown')
             else:
                 bot.send_photo(chat_id, i, txt, parse_mode='Markdown')
Esempio n. 2
0
def address(message):
    bot.send_message(message.chat.id, ph.ADDRESS_MESSAGE)
    turn1 = open('D:/Бизнес/YourGoal/бот/turn1.jpg', 'rb')
    turn2 = open('D:/Бизнес/YourGoal/бот/turn2.jpg', 'rb')
    door = open('D:/Бизнес/YourGoal/бот/turn3.jpg', 'rb')
    bot.send_photo(message.chat.id, turn1)
    bot.send_photo(message.chat.id, turn2)
    bot.send_photo(message.chat.id, door)
    bot.send_location(message.chat.id, 49.953183, 36.327853)
Esempio n. 3
0
def leave_room(message):
    player_id = message.from_user.id
    room_id = users_room[player_id]
    if rooms[room_id].owner != player_id:
        rooms[room_id].remove_player(player_id)
    else:
        rooms[room_id].close_game()
        rooms.pop(room_id)
    bot.send_message(chat_id=message.chat.id, text='Вы вышли в главное меню\n')
Esempio n. 4
0
 def close_game(self):
     while len(self.players) != 0:
         player_id, info = self.status_messages.popitem()
         self.players.pop(player_id)
         users_room[player_id] = 0
         users_state[player_id] = UserState.MAIN_MENU
         bot.send_message(
             chat_id=info[0],
             text='Вы были кикнуты из комнаты, так как она была уничтожена.'
         )
def mail_image(message: telebot.types.Message):
    if message.text == "cancel":
        return bot.send_message(message.chat.id, "Ok bro")
    elif not message.photo:
        bot.send_message(message.chat.id, "Please, send a photo")
        return bot.register_next_step_handler(message, mail_image)
    users = read_users()
    photo = message.photo[0].file_id
    caption = message.caption
    send_images(users, photo, caption)
def mail_video(message: telebot.types.Message):
    if message.text == "cancel":
        return bot.send_message(message.chat.id, "Ok bro")
    elif not message.video and not message.animation:
        bot.send_message(message.chat.id, "Please, send a video")
        return bot.register_next_step_handler(message, mail_video)
    users = read_users()
    video = message.video or message.animation
    video_id = video.file_id
    caption = message.caption
    send_videos(users, video_id, caption)
Esempio n. 7
0
def find_room(message):
    room_id = message.text
    player_id = message.from_user.id
    if room_id not in rooms:
        bot.send_message(chat_id=message.chat.id,
                         text='Некорректный id комнаты.')
        users_state[player_id] = UserState.MAIN_MENU
        help_bot(message)
        return
    bot.send_message(chat_id=message.chat.id,
                     text='Вы вошли в комнату ' + str(room_id))
    _enter_room(message, room_id)
    help_bot(message)
Esempio n. 8
0
def get_text_messages(message):
    if len(message.text) >= 1 and message.text.lower() not in ('start',
                                                               'subscribe',
                                                               'unsubscribe'):
        bot.send_message(
            message.chat.id,
            "Hello there! I'm TheComicBot and I can show your some comics."
            "\nChoose a comic you want.",
            reply_markup=keyboard)
    elif message.text.lower() in ('start'):
        bot.send_message(message.chat.id,
                         "Hello there! I'm TheComicBot! What do you want?",
                         reply_markup=keyboard_start)
    elif message.text.lower() in ('subscribe', 'unsubscribe'):
        bot.send_message(message.chat.id,
                         'Do you want to change subscription?',
                         reply_markup=keyboard_sub)
    else:
        bot.send_message(message.from_user.id, "Please try again.")
Esempio n. 9
0
def return_comic(call, get_comic, link, latest=False):
    if not latest:
        img, txt = get_comic(link)
    else:
        img, txt = get_comic(link, latest)
    if 'apod' in link:
        bot.send_message(call.message.chat.id, txt, parse_mode='Markdown')
    elif 'pbf' in link:
        bot.send_message(call.message.chat.id, txt)
    elif not img:
        bot.send_message(call.message.chat.id,
                         error_msg,
                         reply_markup=keyboard_small)
    else:
        bot.send_photo(call.message.chat.id, img, txt, parse_mode='Markdown')
Esempio n. 10
0
 def kick_player(self, player_id):
     bot.send_message(chat_id=self.status_messages[player_id][0],
                      text='Вы были кикнуты из комнаты,')
     self.remove_player(player_id)
Esempio n. 11
0
 def _again():
     bot.send_message(call.message.chat.id,
                      "Again?",
                      reply_markup=keyboard_small)
Esempio n. 12
0
def callback_worker(call):
    def _again():
        bot.send_message(call.message.chat.id,
                         "Again?",
                         reply_markup=keyboard_small)

    global chat_id, subscribe
    chat_id = call.message.chat.id
    if call.data == "xkcd_random":
        return_comic(call, codo.get_xkcd, links.xkcd_random)
        _again()
    if call.data == "xkcd_latest":
        return_comic(call, codo.get_xkcd, links.xkcd_latest)
        _again()
    if call.data == "goose_random":
        return_comic(call, codo.get_goose, links.goose_random)
        _again()
    if call.data == "poorlydrawnlines_random":
        return_comic(call, codo.get_poorlydrawnlines_archive,
                     links.poorlydrawnlines_random)
        _again()
    if call.data == "poorlydrawnlines_latest":
        return_comic(call, codo.get_poorlydrawnlines,
                     links.poorlydrawnlines_latest)
        _again()
    if call.data == "smbc_random":
        return_comic(call, codo.get_smbc_from_archive, links.smbc_archive)
        _again()
    if call.data == "smbc_latest":
        return_comic(call, codo.get_smbc, links.smbc_latest)
        _again()
    if call.data == "exo_random":
        return_comic(call, codo.get_exo_archive, links.exo_archive)
        _again()
    if call.data == "exo_latest":
        return_comic(call, codo.get_exo, links.exo_latest)
        _again()
    if call.data == "tom_gauld_random":
        return_comic(call, codo.get_tom_gauld, links.tom_gauld_random)
        _again()
    if call.data == "tom_gauld_latest":
        return_comic(call, codo.get_tom_gauld, links.tom_gauld_latest)
        _again()
    if call.data == "dilbert_latest":
        return_comic(call, codo.get_dilbert, links.dilbert, latest=True)
        _again()
    if call.data == "dilbert_random":
        return_comic(call, codo.get_dilbert, links.dilbert)
        _again()
    if call.data == "phd_random":
        return_comic(call, codo.get_phd_random, links.phd_archive)
        _again()
    if call.data == "phd_latest":
        return_comic(call, codo.get_phd, links.phd_latest)
        _again()
    if call.data == "apod_latest":
        return_comic(call, apod.get_apod, links.apod_latest)
        _again()
    if call.data == "apod_random":
        return_comic(call, apod.get_apod_random, links.apod_archive)
        _again()
    if call.data == "pbf_random":
        return_comic(call, codo.get_pbf, links.pbf_random)
        _again()
    if call.data == "pbf_latest":
        return_comic(call, codo.get_pbf, links.pbf_latest, latest=True)
        _again()
    if call.data == "new_yorker":
        res = codo.get_new_yorker_rss(links.new_yorker_daily_rss)
        for item in res:
            for i, txt in item:
                if not i:
                    bot.send_message(call.message.chat.id,
                                     error_msg,
                                     reply_markup=keyboard_small,
                                     parse_mode='Markdown')
                else:
                    bot.send_photo(call.message.chat.id, i, txt)
        _again()
    if call.data == "calvinandhobbes":
        return_comic(call, codo.get_from_gocomics,
                     links.calvinandhobbes_random)
        _again()
    if call.data == "garfield":
        return_comic(call, codo.get_from_gocomics, links.garfield_random)
        _again()
    if call.data == "pearlsbeforeswine":
        return_comic(call, codo.get_from_gocomics,
                     links.pearlsbeforeswine_random)
        _again()
    if call.data in ("again", "show_all"):
        bot.send_message(call.message.chat.id,
                         'Choose wisely!',
                         reply_markup=keyboard)
    if call.data == "get_all_latest":
        return_comic(call, codo.get_xkcd, links.xkcd_latest)
        return_comic(call, codo.get_poorlydrawnlines,
                     links.poorlydrawnlines_latest)
        return_comic(call, codo.get_smbc, links.smbc_latest)
        return_comic(call, codo.get_exo, links.exo_latest)
        return_comic(call, codo.get_tom_gauld, links.tom_gauld_latest)
        return_comic(call, codo.get_dilbert, links.dilbert)
        return_comic(call, codo.get_phd, links.phd_latest)
        return_comic(call, apod.get_apod, links.apod_latest)
        bot.send_message(call.message.chat.id,
                         'Here you go! Want more?',
                         reply_markup=keyboard_small)
    if call.data == "smth_random":
        random_list = [(codo.get_xkcd, links.xkcd_random),
                       (codo.get_goose, links.goose_random),
                       (codo.get_poorlydrawnlines_archive,
                        links.poorlydrawnlines_random),
                       (codo.get_smbc_from_archive, links.smbc_archive),
                       (codo.get_exo_archive, links.exo_archive),
                       (codo.get_tom_gauld, links.tom_gauld_random),
                       (codo.get_dilbert, links.dilbert),
                       (codo.get_phd_random, links.phd_archive),
                       (apod.get_apod_random, links.apod_archive)]
        func, link = random.choice(random_list)
        return_comic(call, func, link)
        _again()
    if call.data == "subscribe":
        logging.warning("chat id " + str(chat_id))
        chat_id = call.message.chat.id
        subscribe = True
        logging.warning("You've got subscribed")
        bot.send_message(call.message.chat.id, "You've got subscribed :)")
    if call.data == "unsubscribe":
        subscribe = False
        logging.warning("You've got unsubscribed")
        bot.send_message(call.message.chat.id, "You've got unsubscribed :(")
Esempio n. 13
0
def create_room(message):
    room_id = helper.generate_id(rooms)
    rooms[room_id] = Room(room_id, message.from_user.id)
    bot.send_message(chat_id=message.chat.id,
                     text='Комната создана.\nId комнаты - ' + str(room_id))
    _enter_room(message, room_id)
def cmd_send_image(message):
    bot.send_message(message.chat.id, text="Send me an image to mailing")
    bot.register_next_step_handler(message, mail_image)
Esempio n. 15
0
 def send_user(self, player_id, text):
     bot.send_message(chat_id=self.status_messages[player_id][0], text=text)
def cmd_send_video(message):
    bot.send_message(message.chat.id, text="Send me a video to mailing")
    bot.register_next_step_handler(message, mail_video)
Esempio n. 17
0
def ice_info(message):
    bot.send_message(message.chat.id, ph.ICE_INFO_MESSAGE)
Esempio n. 18
0
def prices(message):
    bot.send_message(message.chat.id, ph.PRICES_MESSAGE)
Esempio n. 19
0
def schedule(message):
    return bot.send_message(message.chat.id,
                            ph.SCHEDULE_MESSAGE,
                            reply_markup=schedule_keyboard)
Esempio n. 20
0
def start(message):
    add_user(message.chat.id)
    return bot.send_message(message.chat.id,
                            ph.START_MESSAGE,
                            reply_markup=main_keyboard)
Esempio n. 21
0
def help_bot(message):
    state = users_state[message.from_user.id]
    bot.send_message(chat_id=message.chat.id, text=helper.helper[state])
Esempio n. 22
0
 def wrapped_handler(message):
     user_id = message.from_user.id
     if user_id in users_state:
         bot.send_message(chat_id=message.chat.id, text='Вы уже выполнили /start')
         return
     func(message)
Esempio n. 23
0
 def send_message(self, text):
     for c_id, _ in self.status_messages.values():
         bot.send_message(chat_id=c_id, text=text)
Esempio n. 24
0
 def wrapped_handler(message):
     user_id = message.from_user.id
     if user_id not in users_state:
         bot.send_message(chat_id=message.chat.id, text='Введите /start')
         return
     func(message)
def send_messages(users, message, parse_mode=None, reply_markup=None):
    for user_id in users:
        try:
            bot.send_message(chat_id=user_id, text=message, parse_mode=parse_mode, reply_markup=reply_markup)
        except telebot.apihelper.ApiException:
            logging.error(f"Message to user {user_id} was not sent")
Esempio n. 26
0
def start(message):
    player_id = message.from_user.id
    users_state[player_id] = UserState.MAIN_MENU
    users_room[player_id] = 0
    bot.send_message(chat_id=message.chat.id,
                     text='Добро пожаловать в Jacknoon.')
Esempio n. 27
0
def franchise(message):
    bot.send_message(message.chat.id, ph.FRANCHISE_MESSAGE)
Esempio n. 28
0
def _enter_room(message, room_id):
    bot_message = bot.send_message(chat_id=message.chat.id,
                                   text=rooms[room_id].info())
    rooms[room_id].add_player(message.from_user, bot_message, room_id)
Esempio n. 29
0
def ask(message):
    bot.send_message(message.chat.id, ph.ASK_MESSAGE)
Esempio n. 30
0
 def wrapped_handler(message):
     user_id = message.from_user.id
     if users_state[user_id] == UserState.MAIN_MENU:
         bot.send_message(chat_id=message.chat.id, text='Вы не находитесь в игре.')
         return
     func(message)