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 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 check_missed_posts_for_tomorrow(group_for_post_id, schedule_dict, token): missed_posts_time = vk_bot.check_postpones_posts_for_tomorrow( group_for_post_id, schedule_dict, token) if missed_posts_time: message = u'Товарищи! на ЗАВТРА отсутствуют несколько постов:\n\n' schedule = vk_bot.get_schedule() for post_time in missed_posts_time: message += post_time + u" - товарищ: " + schedule[post_time][0].title() + u", рубрика: " + \ schedule[post_time][1] + "\n" message += u'\nСделайте, пожалуйста, на благо группы' message = message.encode('utf-8') vk_bot.send_message_to_chat(config.chat_for_notification_id, message, token) else: message = u'Все молодцы! Предьяв нет! Валера доволен' message = message.encode('utf-8') vk_bot.send_message_to_chat(config.chat_for_notification_id, message, token)
# -*- coding: utf-8 -*- __author__ = 'onotole' from vk_bot import check_postponed_posts_for_today, send_message_to_chat import random import config phrases = [u", нам нужен твой пост на ", u", от твоего поста зависит будущее, не забудь: ", u", будь добр, удели время для постика на ", u", просто сделай пост на ", u", понимаю твою занятость, но пост нужен. ", u", ты ведь не забыл про ", u", пост сам себя не поставит: ", u", just do it ", u", be a good boy, create a post for time: "] for missing_post in check_postponed_posts_for_today(): phrase = phrases[random.randrange(len(phrases))] missing_post_time = missing_post[0] missing_post_info = missing_post[1] missing_post_info[0].encode('utf-8') missing_post_info[1].encode('utf-8') message = missing_post_info[0] + phrase \ + missing_post_time \ + u' Рубрика: ' \ + missing_post_info[1] send_message_to_chat(config.chat_for_notification_id, message.encode('utf-8'))
# -*- coding: utf-8 -*- __author__ = 'onotole' import vk_bot import config #vk_group_url = "https://vk.com/wotblitz" token = vk_bot.token if __name__ == "__main__": likes = 0 reposts = 0 comments = 0 likes_for_yest, reposts_for_yest, comments_for_yest = vk_bot.get_all_posts_from_group_by_url("https://vk.com/x_community", vk_bot.processing_post_count_likes_and_repost, [likes, reposts, comments], vk_bot.processing_post_stop_on_yesterdays_post, token) text_about_new_members = vk_bot.check_for_new_old_members_of_group(config.group_for_post_url, config.group_members_filename, token) text = "Товарищи! Хорошо вчера поработали: " + str(likes_for_yest) + " лайков, " + str(comments_for_yest) + \ " комментов и " + str(reposts_for_yest) + " репостов!\n" + text_about_new_members vk_bot.send_message_to_chat(config.chat_for_notification_id, text, token)
# -*- coding: utf-8 -*- __author__ = 'onotole' from main import load_helper import vk_bot import requests import config url_for_watching = u'http://riseofcontinents.com/' r = requests.get(url_for_watching) if len(r.text) != 71502: message_to_chat = u"Алярм! сайт ожил. http://riseofcontinents.com/".encode( 'utf-8') vk_bot.send_message_to_chat(config.chat_for_notification_id, message_to_chat)
# -*- coding: utf-8 -*- __author__ = "onotole" from main import load_helper import vk_bot import requests import config url_for_watching = u"http://riseofcontinents.com/" r = requests.get(url_for_watching) if len(r.text) != 71502: message_to_chat = u"Алярм! сайт ожил. http://riseofcontinents.com/".encode("utf-8") vk_bot.send_message_to_chat(config.chat_for_notification_id, message_to_chat)
# -*- coding: utf-8 -*- __author__ = 'onotole' import vk_bot import config #vk_group_url = "https://vk.com/wotblitz" token = vk_bot.token if __name__ == "__main__": likes = 0 reposts = 0 comments = 0 likes_for_yest, reposts_for_yest, comments_for_yest = vk_bot.get_all_posts_from_group_by_url( "https://vk.com/x_community", vk_bot.processing_post_count_likes_and_repost, [likes, reposts, comments], vk_bot.processing_post_stop_on_yesterdays_post, token) text_about_new_members = vk_bot.check_for_new_old_members_of_group( config.group_for_post_url, config.group_members_filename, token) text = "Товарищи! Хорошо вчера поработали: " + str(likes_for_yest) + " лайков, " + str(comments_for_yest) + \ " комментов и " + str(reposts_for_yest) + " репостов!\n" + text_about_new_members vk_bot.send_message_to_chat(config.chat_for_notification_id, text, token)
# -*- coding: utf-8 -*- __author__ = 'onotole' from vk_bot import check_postponed_posts_for_today, send_message_to_chat import random import config phrases = [ u", нам нужен твой пост на ", u", от твоего поста зависит будущее, не забудь: ", u", будь добр, удели время для постика на ", u", просто сделай пост на ", u", понимаю твою занятость, но пост нужен. ", u", ты ведь не забыл про ", u", пост сам себя не поставит: ", u", just do it ", u", be a good boy, create a post for time: " ] for missing_post in check_postponed_posts_for_today(): phrase = phrases[random.randrange(len(phrases))] missing_post_time = missing_post[0] missing_post_info = missing_post[1] missing_post_info[0].encode('utf-8') missing_post_info[1].encode('utf-8') message = missing_post_info[0] + phrase \ + missing_post_time \ + u' Рубрика: ' \ + missing_post_info[1] send_message_to_chat(config.chat_for_notification_id, message.encode('utf-8'))