Esempio n. 1
0
def run(bot, admin_list, logfile, slackbot):
    global LAST_UPDATE_ID
    for update in bot.getUpdates(offset=LAST_UPDATE_ID, timeout=10):
        message = update.message
        primary_id, silent_mode = update_chat_db(message)
        log_update(update, logfile, slackbot, primary_id)
        is_admin = str(primary_id) in admin_list
        reply_markup = KEYBOARD_ADMIN if is_admin else KEYBOARD
        if not silent_mode:
            reply_markup = reply_markup.replace(START_CMD, STOP_CMD)
    
        if message.left_chat_participant:
            pass
        elif message.text == HELP_CMD:
                bot.sendMessage(chat_id=message.chat_id, \
                                text=MESSAGE_HELP_ADMIN if is_admin else MESSAGE_HELP)
        elif message.text == HELLO_CMD:
            if message.from_user != None:
                username = message.from_user.first_name + ' ' + message.from_user.last_name
            else:
                username = '******'
            bot.sendMessage(chat_id=message.chat_id, text=u'Hello, {}!'.format(username))
        elif message.text == START_CMD:
            bot.sendMessage(chat_id=message.chat_id, text=MESSAGE_START, reply_markup=reply_markup)
        elif message.text == STOP_CMD:
            bot.sendMessage(chat_id=message.chat_id, text=MESSAGE_STOP, reply_markup=reply_markup)
        elif message.text == NEXT_CMD:
            timepad_token = open('.timepad_token').readline().strip()
            next_event_message=timepad.get_next_event(timepad_token)
            bot.sendMessage(chat_id=message.chat_id, text=next_event_message, reply_markup=reply_markup)
        elif message.text == FLOOD_CMD:
            bot.sendMessage(chat_id=message.chat_id, text=FLOOD_CHAT_LINK, reply_markup=reply_markup)
        elif message.text == PROMO_CMD:
            promo = PROMO_MESSAGE.format(message.from_user.username, primary_id)
            promo = 'Пока что никаких промоакций нет. Следите за анонсами мероприятий.'
            if primary_id > 209:
                promo = 'Спасибо, что недавно добавились ко мне в друзья! Позвольте мне предоставить вам скидку на следующее (/next) мероприятие. Ваш промокод: promo_{}. Если что-то не работает, пишите прямо сюда.'.format(primary_id)
            bot.sendMessage(chat_id=message.chat_id, text=promo, reply_markup=reply_markup)
        elif message.text.lower() == TIMING_CMD:
            timing_message = get_timing_message()
            bot.sendMessage(chat_id=message.chat_id, text=timing_message, reply_markup=reply_markup)
        elif is_admin and message.text.startswith(SEND_BROAD_CMD):
            send_broad(bot, message.text[len(SEND_BROAD_CMD) + 1:], admin_list)
        elif is_admin and message.text.startswith(SEND_MSG_CMD):
            send_message(bot, message)
        elif is_admin and message.text == SECRET_LIST_CMD:
            timepad_token = open('.timepad_token').readline().strip()
            timepad_list_filename = timepad.save_list_to_file(timepad_token)
            bot.sendDocument(chat_id=message.chat_id, document=open(timepad_list_filename, 'rb'))
            os.remove(timepad_list_filename)
        elif is_admin and message.text == USER_LIST_CMD:
            print_userlist(bot, message)
        else:
            pass
            
        LAST_UPDATE_ID = update.update_id + 1
Esempio n. 2
0
def run(bot, admin_list, logfile, slackbot):
    global LAST_UPDATE_ID
    for update in bot.getUpdates(offset=LAST_UPDATE_ID, timeout=10):
        message = update.message
        # print message
        log_update(update, logfile, slackbot)
        is_admin = str(message.from_user.id) in admin_list
    
        if message.left_chat_participant:
            pass
        elif message.text == HELP_CMD:
            bot.sendMessage(chat_id=message.chat_id, text=MESSAGE_HELP)
        elif message.text == HELLO_CMD:
            if message.from_user != None:
                username = message.from_user.first_name + ' ' + message.from_user.last_name
            else:
                username = '******'
            bot.sendMessage(chat_id=message.chat_id, text="Hello " + username)
        elif message.text == STOP_CMD:
            bot.sendMessage(chat_id=message.chat_id, text=MESSAGE_STOP)
        elif is_admin and message.text.startswith(SEND_BROAD_CMD):
            send_broad(bot, message.text[len(SEND_BROAD_CMD):])
        elif is_admin and message.text.startswith(SEND_MSG_CMD):
            send_message(bot, message)
        elif is_admin and message.text == SECRET_LIST_CMD:
            timepad_token = open('.timepad_token').readline().strip()
            timepad_list_filename = timepad.save_list_to_file(timepad_token)
            bot.sendDocument(chat_id=message.chat_id, document=open(timepad_list_filename, 'rb'))
            os.remove(timepad_list_filename)
        elif is_admin and message.text == USER_LIST_CMD:
            print_userlist(bot,message)
        elif is_admin and message.text != '':
            bot.sendMessage(chat_id=message.chat_id, text=MESSAGE)
        else:
            pass
            
        LAST_UPDATE_ID = update.update_id + 1