Answer the question
In order to leave comments, you need to log in
database txt?
Good afternoon! how can I implement a database using "data.txt' so that when issuing a vip, the id of the user to whom the vip was issued - his id is recorded in data.txt and checking the vip commands works with data.txt, that is, if the user id is not in data .txt, then he cannot use the wip commands.
import vk_api, random
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
from vk_api.utils import get_random_id
from jopa import popka, erotic, intimacy
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'].lower() == 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
vip = [636543580, 472956548, 598690428, 282777179]
token = 'токен'
authorize = vk_api.VkApi(token=token)
longpoll = VkBotLongPoll(authorize, group_id=группа)
getting_api = authorize.get_api()
def check(x):
file = open('data.txt', 'r', encoding='utf-8')
if x in file.read():
return 1
else:
return 0
def adder(x):
"""Запись данных"""
file = open('data.txt', 'a', encoding='utf-8')
file.write(f'{x}\n')
file.close()
print('Бот запущен!')
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').lower()
sender = event.chat_id
from_id = event.message.get('from_id')
user_id = from_id
name = get_name(from_id)
cmd_1 = ['!вадим', '!пейла', '!помощь', 'люц', '!общий сбор', '!созвать онлайн', 'позови', '!жопа', '!интим', '!эротика'] # Для команд с 1 словом
if received_message.split()[0] in cmd_1:
if check(from_id) == 0:
adder(from_id)
if received_message == '!общий сбор':
write_message(sender, 'Внимание олухи!' ' ' + name + ' ' 'Объявляет общий сбор! @all ')
elif received_message == '!созвать онлайн':
write_message(sender, 'Внимание лапиндосы!' ', ' + name + ' ', 'Говорит: не молчите! @online ')
elif received_message[0:6] == 'позови':
user_name_search = received_message[7:]
chat_member = get_chat_member(sender, id группы, user_name_search)
if chat_member is None:
write_message(sender, 'Данный пользователь отсуствует в беседе')
else:
write_message(sender, chat_member + ', вас вызывают')
elif received_message == 'люц':
write_message(sender, "✅ demon of darkness here!")
elif received_message == 'помощь':
write_message(sender, ' Полный список команд можно почитать тут: \nhttpII3')
elif received_message == '!жопа':
authorize.method('messages.send', {'chat_id': sender, 'message': 'Чтобы пополнить коллекцию,\nотправь фото сюда: vk.me/hideout01', 'attachment':
random.choice(popka), 'random_id': random.randint(30000000, 50000000)})
if received_message == '!эротика' and user_id not in vip:
write_message(sender, name + ', ' 'у вас нет вип статуса!')
elif received_message == '!эротика' and user_id in vip:
authorize.method('messages.send', {'chat_id': sender,
'message': 'Чтобы пополнить коллекцию,\nотправь фото сюда: vk.me/hideout01',
'attachment':
random.choice(erotic), 'random_id': random.randint(30000000, 50000000)})
if received_message == '!интим' and user_id not in vip:
write_message(sender, name + ', ' 'у вас нет вип статуса!')
elif received_message == '!интим' and user_id in vip:
authorize.method('messages.send', {'chat_id': sender,
'message': 'Чтобы пополнить коллекцию,\nотправь фото сюда: vk.me/hideout01',
'attachment':
random.choice(intimacy), 'random_id': random.randint(30000000, 50000000)})
if received_message == '+вип':
event = event.object.message
User_id = event['reply_message']['from_id']
if user_id in vip:
vip += [User_id]
write_message(sender, ' ✅ VIP успешно активирован!')
elif user_id not in vip:
write_message(sender, 'чел ты кто вообще?')
Answer the question
In order to leave comments, you need to log in
Forgot
But seriously, then
from jopa import siski
# добавление vip id в файл
with open('data.txt', 'a') as file:
file.write(f'{new_vip_id}\n') # a - режим открытия на дозапись
# поиск наличия id в файле
with open('data.txt', 'r') as file:
for line in file:
if user_id in line:
print('ID пользователя в базе')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question