Если еще поможете с adder(база данных, как можно укоротить, чтобы под каждым смс не вставлять код) буду благодарен)
import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
from vk_api.utils import get_random_id
def write_message(sender, message):
authorize.method('messages.send', {'chat_id': sender, 'message': message,
'random_id': get_random_id()
})
# Упоминание участника в беседе
def get_name(from_id):
if from_id > 0:
sender_info = getting_api.users.get(user_ids=from_id)[0]
full_name = sender_info.get('first_name') + ' ' + sender_info['last_name']
return full_name
else:
return '174105461'
# код на позвать пользователя в беседе. работает.
def get_chat_member(sender, group_id, user_name_search):
members = getting_api.messages.getConversationMembers(peer_id=2000000000 + sender, group_id=group_id)['profiles']
for i in range(len(members)):
if members[i]['first_name'] == user_name_search:
user_id = members[i]['id']
full_name = members[i]['first_name'] + ' ' + members[i]['last_name']
appeal = '@id' + str(user_id) + ' (' + full_name + ')'
return appeal
# База данных.
def adder(x):
file = open('data.txt', 'a', encoding='utf-8')
file.write(F'{x}\n')
file.close()
token = '00000'
authorize = vk_api.VkApi(token=token)
longpoll = VkBotLongPoll(authorize, group_id=0000)
getting_api = authorize.get_api()
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW and event.from_chat and event.message.get('text') != '':
received_message = event.message.get('text')
sender = event.chat_id
from_id = event.message.get('from_id')
name = get_name(from_id)
if received_message == '!Лейла':
write_message(sender, 'Соска')
adder(name + received_message)
elif received_message == 'Спокойной ночи':
write_message(sender, 'Добрых снова, зайка!' + ', ' + name)
adder(name + received_message)
elif received_message == 'Общий сбор':
write_message(sender, 'Внимание олухи!' ' ' + name + ' ' 'Объявляет общий сбор! @all ')
adder(name + received_message)
elif received_message == 'Созвать онлайн':
write_message(sender, 'Внимание лапиндосы!' ', ' + name + 'Говорит: не молчите! @online ')
adder(name + received_message)
elif received_message == '!Кофе':
write_message(sender, 'Кофе и кофе, че бубнить то... ')
adder(name + received_message)
elif received_message == '!Инсайдер':
write_message(sender, 'Самый крутой чел на планете ')
adder(name + received_message)
elif received_message == '!Эмили':
write_message(sender, 'Солнышко ')
adder(name + received_message)
elif received_message == '!Виктор':
write_message(sender, 'Злобный пёс ')
adder(name + received_message)
elif received_message[0:6] == 'Позови':
user_name_search = received_message[7:]
chat_member = get_chat_member(sender, 000000, user_name_search)
if chat_member is None:
write_message(sender, 'Данный пользователь отсуствует в беседе')
adder(name + received_message)
else:
write_message(sender, chat_member + ', вас вызывают')
adder(name + received_message)
elif received_message == 'Люц':
write_message(sender, "✅ i'll be back")
adder(name + ',' + received_message)
elif received_message == 'Помощь':
write_message(sender, ' Полный список команд можно почитать тут: \nhttps231213bZeII3')
adder(name + received_message)
elif received_message == '!Вадим':
write_message(sender, 'Цыган ряльна ')
adder(name + received_message)
elif received_message == 'Ринат':
write_message(sender, ' *faster_228 Конь педальный')
adder(name + received_message)