Small update on notifications
This commit is contained in:
parent
753510b109
commit
9431bf2234
3
.gitignore
vendored
3
.gitignore
vendored
@ -137,3 +137,6 @@ $RECYCLE.BIN/
|
|||||||
|
|
||||||
# Windows shortcuts
|
# Windows shortcuts
|
||||||
*.lnk
|
*.lnk
|
||||||
|
|
||||||
|
# Bot credentials
|
||||||
|
credentials.py
|
32
bot.py
32
bot.py
@ -4,12 +4,13 @@ from vk_messages import VkMessage, VkPolling
|
|||||||
import vk
|
import vk
|
||||||
import threading
|
import threading
|
||||||
import re
|
import re
|
||||||
|
from credentials import token, vk_app_id
|
||||||
|
|
||||||
vk_threads = {}
|
vk_threads = {}
|
||||||
|
|
||||||
vk_tokens = {}
|
vk_tokens = {}
|
||||||
|
|
||||||
vk_app_id = "5988748"
|
bot = telebot.AsyncTeleBot(token)
|
||||||
|
|
||||||
link = 'https://oauth.vk.com/authorize?client_id={}&' \
|
link = 'https://oauth.vk.com/authorize?client_id={}&' \
|
||||||
'display=page&redirect_uri=https://oauth.vk.com/blank.html&scope=friends,messages' \
|
'display=page&redirect_uri=https://oauth.vk.com/blank.html&scope=friends,messages' \
|
||||||
@ -29,7 +30,19 @@ def create_thread(message, vk_token):
|
|||||||
vk_tokens[str(message.from_user.id)] = vk_token
|
vk_tokens[str(message.from_user.id)] = vk_token
|
||||||
|
|
||||||
|
|
||||||
bot = telebot.AsyncTeleBot('**********')
|
def check_thread(message):
|
||||||
|
for th in threading.enumerate():
|
||||||
|
if th.getName() == 'vk' + str(message.from_user.id):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def stop_thread(message):
|
||||||
|
for th in threading.enumerate():
|
||||||
|
if th.getName() == 'vk' + str(message.from_user.id):
|
||||||
|
t = vk_threads[str(message.from_user.id)]
|
||||||
|
t.terminate()
|
||||||
|
th.join()
|
||||||
|
|
||||||
|
|
||||||
def extract_unique_code(text):
|
def extract_unique_code(text):
|
||||||
@ -53,21 +66,6 @@ def info_extractor(info):
|
|||||||
return info
|
return info
|
||||||
|
|
||||||
|
|
||||||
def check_thread(message):
|
|
||||||
for th in threading.enumerate():
|
|
||||||
if th.getName() == 'vk' + str(message.from_user.id):
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def stop_thread(message):
|
|
||||||
for th in threading.enumerate():
|
|
||||||
if th.getName() == 'vk' + str(message.from_user.id):
|
|
||||||
t = vk_threads[str(message.from_user.id)]
|
|
||||||
t.terminate()
|
|
||||||
th.join()
|
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(commands=['stop'])
|
@bot.message_handler(commands=['stop'])
|
||||||
def stop_command(message):
|
def stop_command(message):
|
||||||
if not check_thread(message):
|
if not check_thread(message):
|
||||||
|
@ -15,7 +15,11 @@ class VkPolling:
|
|||||||
messages = vk_user.get_new_messages()
|
messages = vk_user.get_new_messages()
|
||||||
if messages:
|
if messages:
|
||||||
for m in messages:
|
for m in messages:
|
||||||
|
if m.split('">​</a>')[0][-1]:
|
||||||
|
bot.send_message(chat_id, m, parse_mode='HTML', disable_notification=True)
|
||||||
|
else:
|
||||||
bot.send_message(chat_id, m, parse_mode='HTML')
|
bot.send_message(chat_id, m, parse_mode='HTML')
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('Error: {}'.format(e))
|
print('Error: {}'.format(e))
|
||||||
for i in range(35):
|
for i in range(35):
|
||||||
@ -42,7 +46,6 @@ class VkMessage:
|
|||||||
if count == 0:
|
if count == 0:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
print(msgs)
|
|
||||||
messages = msgs[1:]
|
messages = msgs[1:]
|
||||||
for m in messages:
|
for m in messages:
|
||||||
if not m['out'] and m['body']:
|
if not m['out'] and m['body']:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user