def check_messages(): unread_messages = get_unread_messages(token) # from admins conversation for message in unread_messages[0]: try: analyze_message(message, token, admin_chat_id) except MessageException: message_to_chat = u"я могу показать расписание:\n" +\ u" -> " + config.bot_name.decode('utf-8') + u" расписание показать \n\n" \ u"и установить нового ответственного:\n" +\ u" -> " + config.bot_name.decode('utf-8') + u" расписание установить 10:00 Имя Рубрика\n\n"\ u"и удалить рубрику из расписания ответственного:\n" +\ u" -> " + config.bot_name.decode('utf-8') + u" расписание удалить 10:00\n\n"\ u"и забанить провинившегося подписчика:\n" +\ u" -> " + config.bot_name.decode('utf-8') + u" забань ссылка_на_вк комментарий\n\n"\ u"и показать чьих постов на сегодня(завтра) не хватает:\n" + \ u" -> " + config.bot_name.decode('utf-8') + u" кто засранец (завтра)?\n\n" message_to_chat = message_to_chat.encode('utf-8') send_message_to_chat(message["chat_id"], message_to_chat, token) #from chats for message in unread_messages[1]: try: analyze_message(message, token, message["chat_id"]) except MessageException: message_to_chat = u"Я могу рассказать стишок:\n".encode('utf-8') +\ str(config.bot_name) + u" стих \n".encode('utf-8') + \ u'или\n'.encode('utf-8') + \ str(config.bot_name) + u' стих 18+\n'.encode('utf-8') + \ u" А еще могу рассказать анекдот, анекдот 18+,\n ".encode('utf-8') + \ u" и даже тост и тост 18+, афоризм и афоризм 18+, цитаты и цитаты 18+\n".encode('utf-8') +\ u" и показать смешную картинку по запросу:\n".encode('utf-8') +\ config.bot_name + u" шуточку в студию".encode('utf-8') send_message_to_chat(message["chat_id"], message_to_chat, token) for message in unread_messages[2]: try: analyze_message(message, token) except MessageException: message_to_chat = u"Я могу рассказать стишок:\n".encode('utf-8') +\ str(config.bot_name) + u" стих \n".encode('utf-8') + \ u'или\n'.encode('utf-8') + \ str(config.bot_name) + u' стих 18+\n'.encode('utf-8') + \ u" А еще могу рассказать анекдот, анекдот 18+,\n ".encode('utf-8') + \ u" и даже тост и тост 18+, афоризм и афоризм 18+, цитаты и цитаты 18+\n".encode('utf-8') +\ u" и показать смешную картинку по запросу:\n".encode('utf-8') +\ config.bot_name + u" шуточку в студию".encode('utf-8') vk_bot.send_message_to_user(message["uid"], message_to_chat, token)
def analyze_message(message_raw, token, fromChat=False): if fromChat: if fromChat == admin_chat_id: message_to_chat = analyze_and_get_answer_admin(message_raw["body"].lower().encode('utf-8')) if message_to_chat[0] == u"picture": return send_random_picture_to_chat_from_dir(message_raw["chat_id"], config.humor_pics_dir, token) elif message_to_chat[0] == u"gif": return vk_bot.send_random_docs_to_chat_from_hdd(message_raw["chat_id"], token, False) elif message_to_chat[0] == u"gif_best": return vk_bot.send_random_docs_to_chat_from_hdd(message_raw["chat_id"], token, True) else: return send_message_to_chat(message_raw["chat_id"], message_to_chat[1], token) else: message_to_chat = analyze_and_get_answer(message_raw["body"].lower().encode('utf-8')) if message_to_chat[0] == u"picture": return send_random_picture_to_chat_from_dir(message_raw["chat_id"], config.humor_pics_dir, token) elif message_to_chat[0] == u"gif": return vk_bot.send_random_docs_to_chat_from_hdd(message_raw["chat_id"], token, False) elif message_to_chat[0] == u"gif_best": return vk_bot.send_random_docs_to_chat_from_hdd(message_raw["chat_id"], token, True) else: return send_message_to_chat(message_raw["chat_id"], message_to_chat[1], token) else: message_to_chat = analyze_and_get_answer(message_raw["body"].lower().encode('utf-8')) if message_to_chat[0] == u"picture": return vk_bot.send_random_picture_to_user_from_dir(message_raw["uid"], config.humor_pics_dir, token) elif message_to_chat[0] == u"gif": return vk_bot.send_random_docs_to_user_from_hdd(message_raw["uid"], token, False) elif message_to_chat[0] == u"gif_best": return vk_bot.send_random_docs_to_user_from_hdd(message_raw["uid"], token, True) else: return vk_bot.send_message_to_user(message_raw["uid"], message_to_chat[1], token)
def analyze_message(message_raw, token, fromChat=False): if fromChat: if fromChat == admin_chat_id: message_to_chat = analyze_and_get_answer_admin( message_raw["body"].lower().encode('utf-8')) if message_to_chat[0] == u"picture": return send_random_picture_to_chat_from_dir( message_raw["chat_id"], config.humor_pics_dir, token) elif message_to_chat[0] == u"gif": return vk_bot.send_random_docs_to_chat_from_hdd( message_raw["chat_id"], token, False) elif message_to_chat[0] == u"gif_best": return vk_bot.send_random_docs_to_chat_from_hdd( message_raw["chat_id"], token, True) else: return send_message_to_chat(message_raw["chat_id"], message_to_chat[1], token) else: message_to_chat = analyze_and_get_answer( message_raw["body"].lower().encode('utf-8')) if message_to_chat[0] == u"picture": return send_random_picture_to_chat_from_dir( message_raw["chat_id"], config.humor_pics_dir, token) elif message_to_chat[0] == u"gif": return vk_bot.send_random_docs_to_chat_from_hdd( message_raw["chat_id"], token, False) elif message_to_chat[0] == u"gif_best": return vk_bot.send_random_docs_to_chat_from_hdd( message_raw["chat_id"], token, True) else: return send_message_to_chat(message_raw["chat_id"], message_to_chat[1], token) else: message_to_chat = analyze_and_get_answer( message_raw["body"].lower().encode('utf-8')) if message_to_chat[0] == u"picture": return vk_bot.send_random_picture_to_user_from_dir( message_raw["uid"], config.humor_pics_dir, token) elif message_to_chat[0] == u"gif": return vk_bot.send_random_docs_to_user_from_hdd( message_raw["uid"], token, False) elif message_to_chat[0] == u"gif_best": return vk_bot.send_random_docs_to_user_from_hdd( message_raw["uid"], token, True) else: return vk_bot.send_message_to_user(message_raw["uid"], message_to_chat[1], token)
__author__ = 'onotole' import config import requests from vk_bot import send_message_to_user req = "https://api.wotblitz.ru/wotb/encyclopedia/info/?application_id=" + \ config.applicationWGID + "&fields=game_version" session = requests.Session() r = session.get(req).json()["data"]["game_version"] if r != "2.0.0": print "API UPDATED!!!" send_message_to_user(config.user_for_notification_id, "API updated, version: " + r)