def prog5(id, m_id): # Удаление пользователя из списка за кем следить file = open('user/' + str(m_id) + ".txt", "r") file_c = open('user/cache.txt', 'w') che = 0 strok = appeal_vk.stroki("user", str(m_id)) if id == 0: file.close() file_c.close() return "Вы указали недействительное число" else: if strok < id: file.close() file_c.close() return "Ошибка, вы указали склишком большое число" else: for line in file.readlines(): line = line.replace('\n', '') che += 1 if che != id: file_c.write(line + '\n') else: out_5 = line file.close() file_c.close() file_c = open('user/cache.txt', 'r') file = open('user/' + str(m_id) + ".txt", "w") for line in file_c.readlines(): file.write(line) file_c.close() file.close() file_c = open('user/cache.txt', 'w') file_c.close() return ("Пользователь " +'[id'+str(int(out_5))+'|'+appeal_vk.nick(int(out_5))+']' + " был удален из вашего списка.")
def writeri(data, user_id, m_id): # Запись друзей в документ ston = 0 #добавление в un был тут, возврат сюда good = 0 ston = appeal_vk.stroki('user', str(m_id)) u_file = open('user/' + str(m_id) + ".txt", "r") for line in u_file.readlines(): # Проверка наличия проверяемого в личной папке usera и добавление его в папку 1/2 line = line.replace('\n', '') g = 0 while g < ston: if line == str(user_id): good = good + 1 g = ston g += 1 u_file.close() if good == 0: # Проверка наличия проверяемого в личной папке usera и добавление его в папку 2/2 u_file = open("user/" + str(m_id) + ".txt", "a") u_file.write(str(user_id) + '\n') u_file.close() good = 0 ston = 0 u_file.close() file = open('sql/' + str(user_id) + ".txt", "w") for i in data: file.write(str(i) + '\n') # file.write("vk.com/id") Доп команда для Вывод ссылки с именем и фамилией # f_l_name = nick(i) Доп команда для Вывод ссылки с именем и фамилией # file.write(str(i)+' '+f_l_name+'\n') Вывод ссылки с именем и фамилией D№№# file.close()
def check_add(user_id): if os.path.exists('sql/' + str(user_id) + ".txt") != True: return '1' data_pars = appeal_vk.pars(user_id) ston = 0 ostal = '' ston = appeal_vk.stroki('sql', str(user_id)) for i in data_pars: bad = 0 line = 0 g = 0 file = open('sql/' + str(user_id) + ".txt", "r") for line in file.readlines(): lineg = line.replace('\n', '') if lineg == str(i): bad += 1 g = ston file.close() if bad == 0: ostal = (ostal + str(i) + ' ') file.close() return ostal
def check_del(user_id): # Проверка друзей из файла if os.path.exists('sql/' + str(user_id) + ".txt") != True: return '1' data_pars = appeal_vk.pars(user_id) ston = 0 f = 0 ostal = '' ston = appeal_vk.stroki('sql', str(user_id)) file = open('sql/' + str(user_id) + ".txt", "r") for line in file.readlines(): line = line.replace('\n', '') good = 0 g = 0 while g < ston: for i in data_pars: if line == str(i): good = good + 1 g = ston g += 1 if good == 0: ostal = ostal + (line + ' ') file.close() return ostal
def test(): vk_session = vk_api.VkApi(token=token) longpoll = VkBotLongPoll(vk_session, 191524305) vk = vk_session.get_api() evn=mms_api.mms()#Добавление класса для сообщений check2() for event in longpoll.listen(): if event.type == VkBotEventType.MESSAGE_NEW: otv=0 text_с = event.message.text.split(' ')#Разбитие сообщения на слова id = event.message.peer_id #Получение id пользователя написавшего сообщение comand_pred = evn.mms_search(id)#Получение прежней команды if comand_pred in com: #Проверка на прежнию команду по типу add или del, если есть выполняется print(comand_pred) if comand_pred == "add": #Выполнение команды добавить пользователя text_с[0] = text_с[0].replace('https://vk.com/', '') text_с[0] = text_с[0].replace('http://vk.com/', '') text_с[0] = text_с[0].replace('vk.com/', '') text_id_dou = rentable(text_с[0])#Получение оригинального id if text_id_dou!="Close": prog2(int(text_id_dou), id)#Добавление пользователя out_l = prog4(str(id))#Получение списка за кем следит пользователь if out_l == '': mes(id, "Список за кем вы следите пуст") else: out_l = ('…:::★☆★ ★☆★:::… \nСпискок за кем вы следите:\n' + out_l+'…:::★☆★ ★☆★:::… ') mes(id, out_l) evn.mms_add(id, "non") # Отменяет значение последней команды elif text_с[0]=="Отмена": mes(id, '🔴Команда была отменена') evn.mms_add(id, "non") else: #Если ввели не цифру пишет ошибку и сбрасывает команду mes(id, "🤗Неизвестное значение, повторите команду") evn.mms_add(id, "non") if comand_pred == "del":#Удаления пользователя из списка по номеру if text_с[0].isdigit(): out_d = prog5(int(text_с[0]), id)#Удаление пользователя out_l = prog4(str(id))#Показ списка за кем следит пользователь if out_l == '': mes(id, out_d+"\nСписок за кем вы следите пуст") else: out_l = (out_d+"\n…:::★☆★ ★☆★:::… \nСписок за кем вы следите:\n" + out_l+'…:::★☆★ ★☆★:::… ') mes(id, out_l) evn.mms_add(id, "non")#Отменяет значение последней команды elif text_с[0]=="Отмена": mes(id, '🔴Команда была отменена') evn.mms_add(id, "non") else: #Если ввели не цифру пишет ошибку и сбрасывает команду mes(id,"🤗Неизвестное значение, повторите команду") evn.mms_add(id,"non") else: #Проверка новой команды if text_с[0] == 'Начать': mes(id, 'Команды для бота:\n' '●Добавить - Добавляет пользователся в список отслеживаемых\n' '●Удалить - Прекращение слежки за человеком\n' '●Список - Показывает всех за кем вы следите\n' '●Report текст - Задать вопрос') otv = 1 if text_с[0] in add_t: mes_com(id, "😈Укажите ссылку на пользователя😈") evn.mms_add(id, "add") otv = 1 if text_с[0] in help_t: mes(id, 'Команды для бота:\n' '●Добавить - Добавляет пользователся в список отслеживаемых\n' '●Удалить - Прекращение слежки за человеком\n' '●Список - Показывает всех за кем вы следите\n' '●Report текст - Задать вопрос') otv = 1 if text_с[0] in list_t: out_l = prog4(str(id)) if out_l == '': mes(id, "Список за кем вы следите пуст") else: out_l = ('…:::★☆★ ★☆★:::… \n' 'Список за кем вы следите:\n' + out_l+'…:::★☆★ ★☆★:::… ') mes(id, out_l) otv = 1 if text_с[0] in del_t: out_l = prog4(str(id)) if out_l=='': mes(id,"Вы не следите ни за кем🙀") else: out_l = ('↓Укажите номер пользователя в списке↓\n' 'Спискок за кем вы следите:\n' + out_l) evn.mms_add(id, "del") mes_com(id, out_l) otv = 1 if text_с[0] in rep_t: i2 = text_с.__len__() - 1 report = '' for i in range(i2): i += 1 report = report + text_с[i] + ' ' report = (report + 'vk.com/id' + str(id)) che = open("user/report.txt", "a") che.write(report + '\n') che.close() mes(id, ('Заявка ' + str(appeal_vk.stroki('user', 'report')) + ' принята.')) mes(207681600, report) otv = 1 if otv==0: #Если неверная команда mes(id,"👾Неверная команда👾\n" "→А кнопки для кого🤔←\n")
def check(): vk_session = vk_api.VkApi(token=token) longpoll = VkBotLongPoll(vk_session, 191524305) vk = vk_session.get_api() evn=mms_api.mms() check2() for event in longpoll.listen(): if event.type == VkBotEventType.MESSAGE_NEW: print("Идет проверка сообщений") otv = 0 text_id = "Close1" text_id_dou = 'Close' text = event.message.text.split(' ') id = event.message.peer_id if text == "": mes(id, "Я не могу ответить") text_с = text text_с[0] = text_с[0].replace('https://vk.com/', '') text_с[0] = text_с[0].replace('http://vk.com/', '') text_с[0] = text_с[0].replace('vk.com/', '') text_id_dou = rentable(text_с[0]) if text_с.__len__() != 0: if text_с.__len__() > 1: text_с[1] = text_с[1].replace('https://vk.com/', '') text_с[1] = text_с[1].replace('http://vk.com/', '') text_с[1] = text_с[1].replace('vk.com/', '') text_id = rentable(text_с[1]) else: text_с[0] = text_с[0].replace('https://vk.com/', '') text_с[0] = text_с[0].replace('http://vk.com/', '') text_с[0] = text_с[0].replace('vk.com/', '') text_id = rentable(text_с[0]) if text_с[0] == 'Начать': mes(id, 'Команды для бота:\n' '●Добавить vk.com/id207681600 - Добавляет пользователся в список отслеживаемых\n' '●Удалить номер по списку - Прекращение слежки за человеком\n' '●Список - Показывает всех за кем вы следите\n' '●Report текст - Задать вопрос') evn.mms_add(id, "non") otv = 1 if text_с[0] in add_t: if text_id != 'Close' and text_id != "Close1": prog2(int(text_id), id) out_l = prog4(str(id)) if out_l == '': mes(id, "Список за кем вы следите пуст") else: out_l = ('Спискок за кем вы следите:\n' + out_l) mes(id, out_l) otv = 1 else: mes(id, "Укажите ссылку на пользователя") evn.mms_add(id, "add") otv = 1 if text_с[0] in help_t: mes(id, 'Команды для бота:\n' '●Добавить vk.com/id207681600 - Добавляет пользователся в список отслеживаемых\n' '●Удалить номер по списку - Прекращение слежки за человеком\n' '●Список - Показывает всех за кем вы следите\n' '●Report текст - Задать вопрос') evn.mms_add(id, "non") otv = 1 if text_с[0] in list_t: out_l = prog4(str(id)) if out_l == '': mes(id, "Список за кем вы следите пуст") else: out_l = ('Список за кем вы следите:\n' + out_l) mes(id, out_l) evn.mms_add(id, "non") otv = 1 if text_с[0] in del_t: out_l = prog4(str(id)) if text_id != 'Close' and text_id != "Close1": if text_с[1].isdigit(): out_d = prog5(int(text_с[1]), id) mes(id, out_d) if out_l == '': mes(id, "Список за кем вы следите пуст") else: out_l = ('Список за кем вы следите:\n' + out_l) mes(id, out_l) otv = 1 else: mes(id, "↓Укажите номер пользователя в списке↓") out_l = ('Спискок за кем вы следите:\n' + out_l) mes(id, out_l) evn.mms_add(id, "del") otv = 1 if text_с[0] in rep_t: i2 = text_с.__len__() - 1 report = '' for i in range(i2): i += 1 report = report + text_с[i] + ' ' report = (report + 'vk.com/id' + str(id)) che = open("user/report.txt", "a") che.write(report + '\n') che.close() mes(id, ('Заявка ' + str(appeal_vk.stroki('user', 'report')) + ' принята.')) mes(207681600, report) evn.mms_add(id, "non") otv = 1 if otv == 0: former_text=evn.mms_search(id) if former_text == "add": prog2(int(text_с[0]), id) out_l = prog4(str(id)) if out_l == '': mes(id, "Список за кем вы следите пуст") else: out_l = ('Спискок за кем вы следите:\n' + out_l) mes(id, out_l) otv = 1 if former_text == "del": out_l = prog4(str(id)) out_d = prog5(int(text_с[0]), id) mes(id, out_d) if out_l == '': mes(id, "Список за кем вы следите пуст") else: out_l = ('Список за кем вы следите:\n' + out_l) mes(id, out_l) otv = 1 if otv == 1: mes(id, 'Неверная команда, напишите "help" чтобы узнать команды')
def prog1(): # Проверка всех людей в базе и отправка сообщения тем кто его внес о удаление пользователя print('Идёт проверка людей') ston = appeal_vk.stroki('user', 'un') un = open("user/un.txt", "r") for line in un.readlines(): time.sleep(4) # Проверка наличия пользователся в папке user и добавление его в папку 1/2 line = line.replace('\n', '') if appeal_vk.prof_close(line) == 0: un2 = open("user/" + line + ".txt", "r") for line2 in un2.readlines(): line2 = line2.replace('\n', '') if appeal_vk.prof_close(line2) == 0: time.sleep(1) out2 = check_add(line2) out = check_del(line2) frame = open("user/cache.txt", "w") frame.write(out2.replace(' ', '\n')) frame.close() frame = open("user/cache.txt", "r") for line_frame in frame.readlines(): line_frame = line_frame.replace('\n', '') if line_frame != '': vrem = open("user/cache_add.txt", "a") vrem.write( str(line2) + '/' + str(line_frame) + '/' + str(line) + '\n') vrem.close() frame.close() frame = open("user/cache.txt", "w") frame.write(out.replace(' ', '\n')) frame.close() frame = open("user/cache.txt", "r") for line_frame in frame.readlines(): line_frame = line_frame.replace('\n', '') if line_frame != '': vrem = open("user/cache_del.txt", "a") vrem.write( str(line2) + '/' + str(line_frame) + '/' + str(line) + '\n') vrem.close() frame.close() #Добавить ввывод того что пользователь заблокирован в список (list) un2.close() un.close() che = open("user/cache_add.txt", "r") for line_c in che.readlines(): line_c = line_c.replace('\n', '') indexs = [i for i, symb in enumerate(line_c) if symb == "/"] dlin = len(line_c) line_c1 = line_c[0:indexs[0]] line_c2 = line_c[indexs[0] + 1:indexs[1]] line_c3 = line_c[indexs[1] + 1:dlin] out = '' out = ("У " + '[id' + str(line_c1) + '|' + appeal_vk.nick(line_c1) + ']' + " появился новый друг " + '[id' + str(line_c2) + '|' + appeal_vk.nick(line_c2) + ']') mes(line_c3, out) gg = appeal_vk.pars(line_c1) file = open('sql/' + str(line_c1) + ".txt", "w") for i in gg: file.write(str(i) + '\n') file.close() che.close() che = open("user/cache_del.txt", "r") for line_c in che.readlines(): line_c = line_c.replace('\n', '') indexs = [i for i, symb in enumerate(line_c) if symb == "/"] dlin = len(line_c) line_c1 = line_c[0:indexs[0]] line_c2 = line_c[indexs[0] + 1:indexs[1]] line_c3 = line_c[indexs[1] + 1:dlin] out = '' out = ("У " + '[id' + str(line_c1) + '|' + appeal_vk.nick(line_c1) + ']' + " из друзей был удален " + '[id' + str(line_c2) + '|' + appeal_vk.nick(line_c2) + ']') mes(line_c3, out) gg = appeal_vk.pars(line_c1) file = open('sql/' + str(line_c1) + ".txt", "w") for i in gg: file.write(str(i) + '\n') file.close() che.close() che = open("user/cache_add.txt", "w") che.close() che = open("user/cache_del.txt", "w") che.close() che = open("user/cache.txt", "w") che.close() print('Конец проверки людей в цикле')