How to use check_notification method in Slash

Best Python code snippet using slash

vk_messages.py

Source:vk_messages.py Github

copy

Full Screen

...38 user = {'first_name': group['name'], 'last_name': None}39 if 'body' in m and not 'attachment' in m and not 'geo' in m and not 'fwd_messages' in m:40 data = add_user_info(m, user["first_name"], user["last_name"])[:-1] + add_reply_info(m)41 bot.send_message(chat_id, data, parse_mode='HTML', disable_web_page_preview=False,42 disable_notification=check_notification(m), reply_to_message_id=mainmessage).wait()43 if 'attachment' in m:44 attachment_handler(m, user, bot, chat_id, mainmessage)45 if 'geo' in m:46 data = add_user_info(m, user["first_name"], user["last_name"]) + '<i>Местоположение</i>' + add_reply_info(m)47 geo = bot.send_message(chat_id, data, parse_mode='HTML', disable_web_page_preview=False,48 disable_notification=check_notification(m), reply_to_message_id=mainmessage).wait()49 if 'place' in m['geo'] and 'city' in m['geo']['place'] and 'title' in m[geo]['place']:50 bot.send_venue(chat_id, m['geo']['coordinates'].split(' ')[0], m['geo']['coordinates'].split(' ')[1],51 m['geo']['place']['title'], m['geo']['place']['city'],52 disable_notification=check_notification(m),53 reply_to_message_id=geo.message_id).wait()54 else:55 bot.send_location(chat_id, m['geo']['coordinates'].split(' ')[0], m['geo']['coordinates'].split(' ')[1],56 disable_notification=check_notification(m),57 reply_to_message_id=geo.message_id).wait()58 if 'fwd_messages' in m:59 data = add_user_info(m, user["first_name"],60 user["last_name"]) + '<i>Пересланные сообщения</i>' + add_reply_info(m)61 reply = bot.send_message(chat_id, data, parse_mode='HTML', disable_web_page_preview=False,62 disable_notification=check_notification(m),63 reply_to_message_id=mainmessage).wait().message_id64 for forwared in m['fwd_messages']:65 handle_messages(forwared, vk_user, bot, chat_id, reply)66def handle_updates(vk_user, bot, chat_id, updates):67 for m in updates:68 if not m['out']:69 handle_messages(m, vk_user, bot, chat_id)70def attachment_handler(m, user, bot, chat_id, mainmessage=None):71 for attach in m['attachments']:72 if attach['type'] == 'photo':73 try:74 data = add_user_info(m, user['first_name'], user['last_name']) + '<a href="{}">Фото</a>'.format(75 get_max_src(attach['photo'])) + add_reply_info(m)76 bot.send_message(chat_id, data, parse_mode='HTML', disable_web_page_preview=False,77 disable_notification=check_notification(m), reply_to_message_id=mainmessage).wait()78 except:79 send_doc_link(attach, m, user, bot, chat_id, mainmessage)80 elif attach['type'] == 'video':81 try:82 link = 'https://vk.com/video{}_{}'.format(attach['video']['owner_id'],83 attach['video']['vid'])84 data = add_user_info(m, user['first_name'], user['last_name']) + '<a href="{}">Видео</a>'.format(85 link) + add_reply_info(m)86 bot.send_message(chat_id, data, parse_mode='HTML', disable_web_page_preview=False,87 disable_notification=check_notification(m), reply_to_message_id=mainmessage).wait()88 except:89 send_doc_link(attach, m, user, bot, chat_id, mainmessage)90 elif attach['type'] == 'audio':91 headers = {'content-type': 'application/json'}92 audio = requests.get('https://asergey.me/vkmusapi/',93 json={'aid': attach['audio']['aid'], 'owner_id': attach['audio']['owner_id']},94 headers=headers)95 try:96 if audio.status_code == 200 and audio.json()['ok']:97 audio_dict = audio.json()98 data = add_user_info(m, user["first_name"],99 user["last_name"]) + '🎧 <i>Аудиозапись</i>' + add_reply_info(m)100 audio_msg = bot.send_message(chat_id, data, parse_mode='HTML', disable_web_page_preview=False,101 disable_notification=check_notification(m),102 reply_to_message_id=mainmessage).wait()103 action = bot.send_chat_action(chat_id, 'upload_document')104 bot.send_audio(chat_id, audio_dict['vk_response']['url'],105 duration=audio_dict['vk_response']['duration'],106 title=audio_dict['vk_response']['title'],107 performer=audio_dict['vk_response']['artist'],108 disable_notification=check_notification(m),109 reply_to_message_id=audio_msg.message_id).wait()110 action.wait()111 else:112 data = add_user_info(m, user['first_name'], user[113 'last_name']) + '🎧 <a href="https://m.vk.com/audio?q={}%20-%20{}">{} - {}</a>'.format(114 attach['audio']['artist'].replace(' ', '%20'),115 attach['audio']['title'].replace(' ', '%20'), attach['audio']['artist'],116 attach['audio']['title']) + add_reply_info(m)117 bot.send_message(chat_id, data, parse_mode='HTML', disable_web_page_preview=False,118 disable_notification=check_notification(m), reply_to_message_id=mainmessage).wait()119 except Exception as e:120 print(e)121 data = add_user_info(m, user['first_name'], user[122 'last_name']) + '🎧 <a href="https://m.vk.com/audio?q={}%20-%20{}">{} - {}</a>'.format(123 attach['audio']['artist'].replace(' ', '%20'),124 attach['audio']['title'].replace(' ', '%20'), attach['audio']['artist'],125 attach['audio']['title']) + add_reply_info(m)126 bot.send_message(chat_id, data, parse_mode='HTML', disable_web_page_preview=False,127 disable_notification=check_notification(m), reply_to_message_id=mainmessage).wait()128 elif attach['type'] == 'doc':129 if attach['doc']['ext'] == 'gif':130 try:131 link = attach['doc']['url']132 data = add_user_info(m, user["first_name"], user["last_name"]) + '<a href="{}">GIF</a>'.format(133 link) + add_reply_info(m)134 bot.send_message(chat_id, data, parse_mode='HTML', disable_web_page_preview=False,135 disable_notification=check_notification(m),136 reply_to_message_id=mainmessage).wait()137 except:138 send_doc_link(attach, m, user, bot, chat_id, mainmessage)139 elif attach['doc']['ext'] == 'pdf' or attach['doc']['ext'] == 'zip':140 try:141 link = attach['doc']['url']142 data = add_user_info(m, user["first_name"],143 user["last_name"]) + '<a href="{}">Документ</a>'.format(144 link) + add_reply_info(m)145 bot.send_message(chat_id, data, parse_mode='HTML', disable_web_page_preview=False,146 disable_notification=check_notification(m),147 reply_to_message_id=mainmessage).wait()148 except:149 send_doc_link(attach, m, user, bot, chat_id, mainmessage)150 elif attach['doc']['ext'] == 'jpg' or attach['doc']['ext'] == 'png':151 try:152 link = attach['doc']['url']153 data = add_user_info(m, user["first_name"],154 user["last_name"], ) + '<i>Документ</i>' + add_reply_info(m)155 notification = bot.send_message(chat_id, data, parse_mode='HTML',156 disable_notification=check_notification(m),157 reply_to_message_id=mainmessage).wait()158 uploading = bot.send_chat_action(chat_id, 'upload_document')159 bot.send_document(chat_id, link, reply_to_message_id=notification.message_id,160 disable_notification=check_notification(m)).wait()161 uploading.wait()162 except:163 send_doc_link(attach, m, user, bot, chat_id, mainmessage)164 elif attach['doc']['ext'] == 'ogg':165 try:166 link = attach['doc']['url']167 data = add_user_info(m, user["first_name"], user["last_name"], ) + \168 '<a href="{}">Аудио</a>'.format(link) + add_reply_info(m)169 bot.send_message(chat_id, data, parse_mode='HTML', disable_web_page_preview=False,170 disable_notification=check_notification(m),171 reply_to_message_id=mainmessage).wait()172 except:173 send_doc_link(attach, m, user, bot, chat_id, mainmessage)174 elif attach['doc']['ext'] == 'doc' or attach['doc']['ext'] == 'docx':175 try:176 data = add_user_info(m, user["first_name"],177 user["last_name"], ) + '<i>Документ</i>' + add_reply_info(m)178 notification = bot.send_message(chat_id, data, parse_mode='HTML',179 disable_notification=check_notification(m),180 reply_to_message_id=mainmessage).wait()181 uploading = bot.send_chat_action(chat_id, 'upload_document')182 file = wget.download(requests.get(attach['doc']['url']).url)183 openedfile = open(file, 'rb')184 bot.send_document(chat_id, openedfile,185 reply_to_message_id=notification.message_id,186 disable_notification=check_notification(m)).wait()187 uploading.wait()188 openedfile.close()189 os.remove(file)190 except:191 send_doc_link(attach, m, user, bot, chat_id, mainmessage)192 else:193 send_doc_link(attach, m, user, bot, chat_id, mainmessage)194 elif attach['type'] == 'sticker':195 link = attach['sticker']['photo_512']196 data = add_user_info(m, user["first_name"], user["last_name"]) + '<a href="{}">Стикер</a>'.format(197 link) + add_reply_info(m)198 bot.send_message(chat_id, data, parse_mode='HTML', disable_web_page_preview=False,199 disable_notification=check_notification(m), reply_to_message_id=mainmessage).wait()200 elif attach['type'] == 'wall':201 link = 'https://vk.com/wall{}_{}'.format(attach['wall']['from_id'], attach['wall']['id'])202 data = add_user_info(m, user["first_name"], user["last_name"]) + '<a href="{}">Запись на стене</a>'.format(203 link) + add_reply_info(m)204 bot.send_message(chat_id, data, parse_mode='HTML', disable_web_page_preview=False,205 disable_notification=check_notification(m), reply_to_message_id=mainmessage).wait()206 elif attach['type'] == 'wall_reply':207 data = add_user_info(m, user["first_name"],208 user["last_name"]) + '<i>Комментарий на стене</i>' + add_reply_info(m)209 comment = bot.send_message(chat_id, data, parse_mode='HTML', disable_web_page_preview=False,210 disable_notification=check_notification(m),211 reply_to_message_id=mainmessage).wait()212 try:213 api = vk.API(get_session(vk_tokens.get(str(chat_id))), v=VK_POLLING_VERSION)214 user = api.users.get(user_ids=attach['wall_reply']["uid"], fields=[])[0]215 if attach['wall_reply']['text']:216 data = add_user_info(m, user["first_name"], user["last_name"]) + \217 attach['wall_reply']['text'].replace('<br>', '\n') + add_reply_info(m)218 bot.send_message(chat_id, data, parse_mode='HTML', disable_web_page_preview=False,219 disable_notification=check_notification(m),220 reply_to_message_id=comment.message_id).wait()221 if 'attachments' in attach['wall_reply']:222 attachment_handler(attach['wall_reply'], user, bot, chat_id, mainmessage=comment.message_id)223 except:224 link = 'https://vk.com/wall{}_{}'.format(attach['wall']['owner_id'], attach['wall']['cid'])225 data = add_user_info(m, user["first_name"],226 user["last_name"]) + '<a href="{}">Комментарий</a>'.format(227 link) + add_reply_info(m)228 bot.send_message(chat_id, data, parse_mode='HTML', disable_web_page_preview=False,229 disable_notification=check_notification(m),230 reply_to_message_id=comment.message_id).wait()231def check_expansion(document):232 if len(document['doc']['title'].split('.')) - 1:233 return document['doc']['title']234 else:235 return document['doc']['title'] + '.' + document['doc']['ext']236def send_doc_link(doc, m, user, bot, chat_id, mainmessage=None):237 link = doc['doc']['url']238 data = add_user_info(m, user["first_name"], user["last_name"]) + \239 '<i>Документ</i>\n<a href="{}">{}</a>'.format(link, check_expansion(doc)) + add_reply_info(m)240 bot.send_message(chat_id, data, parse_mode='HTML', disable_web_page_preview=False,241 disable_notification=check_notification(m), reply_to_message_id=mainmessage).wait()242def check_forward_id(msg):243 if 'mid' in msg:244 return msg['mid']245 else:246 return None247def add_reply_info(m):248 if 'chat_id' in m:249 return '<a href="x{}.{}.{}">&#8203;</a>'.format(m['uid'], m['chat_id'], check_forward_id(m))250 else:251 return '<a href="x{}.{}.00">&#8203;</a>'.format(m['uid'], check_forward_id(m))252def add_user_info(m, first_name, last_name):253 if 'body' in m and m['body']:254 if last_name:255 if 'chat_id' in m:256 return '<b>{} {} @ {}:</b>\n{}\n'.format(first_name, last_name, m['title'],257 m['body'].replace('<br>', '\n'))258 else:259 return '<b>{} {}:</b>\n{}\n'.format(first_name, last_name, m['body'].replace('<br>', '\n'))260 else:261 if 'chat_id' in m:262 return '<b>{} @ {}:</b>\n{}\n'.format(first_name, m['title'],263 m['body'].replace('<br>', '\n'))264 else:265 return '<b>{}:</b>\n{}\n'.format(first_name, m['body'].replace('<br>', '\n'))266 else:267 if last_name:268 if 'chat_id' in m:269 return '<b>{} {} @ {}:</b>\n'.format(first_name, last_name, m['title'])270 else:271 return '<b>{} {}:</b>\n'.format(first_name, last_name)272 else:273 if 'chat_id' in m:274 return '<b>{} @ {}:</b>\n'.format(first_name, m['title'])275 else:276 return '<b>{}:</b>\n'.format(first_name)277def check_notification(value):278 if 'push_settings' in value:279 return True280 else:281 return False282def get_max_src(attachment):283 if 'src_xxbig' in attachment:284 return attachment['src_xxbig']285 if 'src_xbig' in attachment:286 return attachment['src_xbig']287 if 'src_big' in attachment:288 return attachment['src_big']289 if 'src' in attachment:290 return attachment['src']291class VkMessage:...

Full Screen

Full Screen

push-notifications

Source:push-notifications Github

copy

Full Screen

...17 res = self.__notifications18 self.__notifications = []19 return res20with Meta(force_admin = True) as meta:21 def check_notification(recipient):22 notifications = meta.notifier.notifications23 assertEq(len(notifications), 1)24 assertEq(notifications[0][0], bson.ObjectId(recipient.id))25 def check_no_notification():26 notifications = meta.notifier.notifications27 assertEq(len(notifications), 0)28 def notify(user):29 meta.notifier.notify_some(30 0, recipient_ids = set((bson.ObjectId(user.id),)), message = {})31 meta.notifier = Notifier(meta.database, False)32 # Check push token is set33 user1 = User(meta)34 user1.login(device_push_token = 'token')35 notify(user1)36 check_notification(user1)37 # Check device creation overrides push token38 user2 = User(meta)39 user2.login(device_push_token = 'token')40 notify(user1)41 check_no_notification()42 notify(user2)43 check_notification(user2)44 # Check login overrides push token45 user1.login(device_push_token = 'token')46 notify(user2)47 check_no_notification()48 notify(user1)49 check_notification(user1)50 # Check logout unsets push token51 user1.logout()52 notify(user1)53 check_no_notification()54 notify(user2)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful