@bot.message_handler(func=lambda m: True)
def echo_all(message):
bot.reply_to(message, message.text)
# Handles all text messages that contains the commands '/start' or '/help'.
@bot.message_handler(commands=['start', 'help'])
def handle_start_help(message):
pass
# Handles all sent documents and audio files
@bot.message_handler(content_types=['document', 'audio'])
def handle_docs_audio(message):
pass
# Handles all text messages that match the regular expression
@bot.message_handler(regexp="SOME_REGEXP")
def handle_message(message):
pass
# Handles all messages for which the lambda returns True
@bot.message_handler(func=lambda message: message.document.mime_type == 'text/plain', content_types=['document'])
def handle_text_doc(message):
pass
# Which could also be defined as:
def test_message(message):
return message.document.mime_type == 'text/plain'
@bot.message_handler(func=test_message, content_types=['document'])
def handle_text_doc(message):
pass
# Handlers can be stacked to create a function which will be called if either message_handler is eligible
# This handler will be called if the message starts with '/hello' OR is some emoji
@bot.message_handler(commands=['hello'])
@bot.message_handler(func=lambda msg: msg.text.encode("utf-8") == SOME_FANCY_EMOJI)
def send_something(message):
pass
CMake must be installed to build the following extensions: dlib
pip install cmake
class OWM:
"""
Entry point class providing ad-hoc API clients for each OWM web API.
:param api_key: the OWM API key
:type api_key: str
:param config: the configuration dictionary (if not provided, a default one will be used)
:type config: dict
"""
def __init__(self, api_key, config=None):
assert api_key is not None, 'API Key must be set'
self.api_key = api_key
if config is None:
self.config = cfg.get_default_config()
else:
assert isinstance(config, dict)
self.config = config
owm = pyowm.OWM('a99967bc9ee70d5b4bd387902982f400', {'language': 'ru'})
event.object.text
event.text
while True:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.object.peer_id != event.object.from_id:
if event.object.text.lower() == "привет":
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "Привет! Я бот беседы. Я умею играть(команда 'Игра'), смотреть информацию с Википедии(в стадии разработки). Остально тоже в стадии разработки.",
"random_id": 0})
if event.object.text.lower() == "игра":
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "Давай сыграем в игру 'Камень, ножницы, бумага'. Напиши свой ход и я его сделаю",
"random_id": 0})
if event.object.text.lower() == "бумага" or event.object.text.lower() == "ножницы" or event.object.text.lower() == "камень":
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": random.choice(play) + ". Теперь сам думай кто выиграл, потому что разработчику лень додумывать",
"random_id": 0})
if "/вики" in event.object.text.lower():
search_query = event.object.text.lower().replace('/вики ', '')
search_result = str(wikipedia.summary(search_query))
message = "Вот что я нашёл: \n{}".format(search_result)
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": message, "random_id": 0})
import re
content = 'a:3:{s:6:"update";i:1591804805;s:8:"encoding";s:12:"utf-8";s:4:"urls";a:4:{i:991;a:2:{i:0;s:1:"/";i:1;s:66:"<a href="https://site1.com">фильмы онлайн</a>";}i:1113;a:2:{i:0;s:1:"/";i:1;s:108:"Смотреть <a href="https://site2.net">кино</a> онлайн без регистрации";}i:1793;a:2:{i:0;s:1:"/";i:1;s:149:"Советую фильмы на сайте <a href="http://site3.online">site3.online</a>";}i:1822;a:2:{i:0;s:1:"/";i:1;s:73:"<a href="https://www.site4.org/">ФИЛЬМЫ - ЛУЧШЕЕ</a> ";}}}'
chunks = re.findall(r'i:1;s:.+?:\"(.+?)";}', content)
text = ' | '.join(chunks)
print(text)