def love(): status.messagesSend += 1 if event.from_chat: users = vk_session.method('messages.getChatUsers', { 'chat_id': event.chat_id, 'fields': 'name' }) love1, love2 = random.sample(users, 2) love = ('[id{}|{} {}] - любит - [id{}|{} {}]'.format( love1['id'], love1['first_name'], love1['last_name'], love2['id'], love2['first_name'], love2['last_name'])) vk_session.method( 'messages.send', { 'chat_id': event.chat_id, 'message': love, 'attachment': 'photo494918759_456239057' }) f.date() print('{}[Love, to chat {} (user {})]'.format(f.dat, event.chat_id, event.user_id)) else: f.write_msg( event.user_id, 'Ошибка! Данную команду можно использовать только в беседе!') f.date() print('{}[Love, to user {}]'.format(f.dat, event.user_id))
def com(): status.messagesSend += 1 if event.from_chat: f.write_msg_chat(event.chat_id, commands + chat + admin) f.date() print('{}[Help, to chat {} (user {})]'.format(f.dat, event.chat_id, event.user_id)) else: f.write_msg(event.user_id, commands + chat + admin) f.date() print('{}[Help, to user {}]'.format(f.dat, event.user_id))
def admins(): admins = 'Список админов:' status.messagesSend += 1 if event.user_id in o.admins: for i in o.admins: info = vk_session.method('users.get', {'user_ids': i}) adminName = ('\n{} {}').format(info[0]['first_name'], info[0]['last_name']) admins += adminName if event.from_chat: f.write_msg_chat(event.chat_id, admins) f.date() print('{}[Admin][Admins, to chat {} (user {})]'.format( f.dat, event.chat_id, event.user_id)) else: f.write_msg(event.user_id, admins) f.date() print('{}[Admin][Admins, to user {}]'.format(f.dat, event.user_id)) else: if event.from_chat: f.write_msg_chat(event.chat_id, 'Хмм... Но ведь ты не админ!') f.date() print('{}[Admins, to chat {} (user {})]'.format( f.dat, event.chat_id, event.user_id)) else: f.write_msg(event.user_id, 'Хмм... Но ведь ты не админ!') f.date() print('{}[Admins, to user {}]'.format(f.dat, event.user_id))
def chance(): status.messagesSend += 1 chan = event.text[10:] chanc = ('Вероятность, что ' + chan + ' составляет ' + str(random.randint(0, 100)) + '%') if event.from_chat: f.write_msg_chat(event.chat_id, chanc) f.date() print('{}[Chance, to chat {} (user {})]'.format( f.dat, event.chat_id, event.user_id)) else: f.write_msg(event.user_id, chanc) f.date() print('{}[Chance, to user {}]'.format(f.dat, event.user_id))
def bash(): status.messagesSend += 1 r = req.get('http://bash.im/random') doc = html.document_fromstring(r.text) bash = '\n'.join(doc.xpath('/html/body/div[2]/div[3]/div[2]/text()')) if event.from_chat: f.write_msg_chat(event.chat_id, bash) f.date() print('{}[Bash, to chat {} (user {})]'.format(f.dat, event.chat_id, event.user_id)) else: f.write_msg(event.user_id, bash) f.date() print('{}[Bash, to user {}]'.format(f.dat, event.user_id))
def status(): if event.user_id in o.admins: global messagesSend messagesSend += 1 global stat end_time = time.monotonic() uptime = str(timedelta(seconds=round(end_time - start_time))) stat = ('Uptime: ' + uptime + '\nИспользовано памяти ботом: ' + str(memory_usage())[1:3] + ' MB' + '\nПолучено сообщений: ' + str(messages) + '\nПолучено команд: ' + str(messagesSend)) if event.from_chat: f.write_msg_chat(event.chat_id, stat) f.date() print('{}[Status, to chat {} (user {})]'.format( f.dat, event.chat_id, event.user_id)) else: f.write_msg(event.user_id, stat) f.date() print('{}[Status, to user {}]'.format(f.dat, event.user_id)) else: if event.from_chat: f.write_msg_chat(event.chat_id, 'Хмм... Но ведь ты не админ!') f.date() print('{}[Status, to chat {} (user {})]'.format( f.dat, event.chat_id, event.user_id)) else: f.write_msg(event.user_id, 'Хмм... Но ведь ты не админ!') f.date() print('{}[Status, to user {}]'.format(f.dat, event.user_id))
def who(): status.messagesSend += 1 whois = event.text[9:] if event.from_chat: users = vk_session.method('messages.getChatUsers', { 'chat_id': event.chat_id, 'fields': 'name' }) user = random.choice(users) hypertext = '[id{}|{}]'.format( (user['id']), (user['first_name']) + ' ' + (user['last_name'])) whos = ('Кто {}? Я думаю, это {}'.format(whois, hypertext)) f.write_msg_chat(event.chat_id, whos) f.date() print('{}[Who, to chat {} (user {})]'.format(f.dat, event.chat_id, event.user_id)) else: f.write_msg( event.user_id, 'Ошибка! Данную команду можно использовать только в беседе!') f.date() print('{}[Who, to user {}]'.format(f.dat, event.user_id))
def wiki(): status.messagesSend += 1 search = event.text[10:] try: info = wikipedia.summary(search, sentences=3) except Exception: if event.from_chat: f.write_msg_chat(event.chat_id, 'Ошибка запроса!') f.date() print('{}[Wiki, to chat {} (user {})][Error!]'.format(f.dat, event.chat_id, event.user_id )) else: f.write_msg(event.user_id, 'Ошибка запроса!') f.date() print('{}[Wiki, to user {}][Error!]'.format(f.dat, event.user_id)) if event.from_chat: f.write_msg_chat(event.chat_id, info) f.date() print('{}[Wiki, to chat {} (user {})][{}]'.format(f.dat, event.chat_id, event.user_id, search)) else: f.write_msg(event.user_id, info) f.date() print('{}[Wiki, to user {}][{}]'.format(f.dat, event.user_id, search))
def wf(): status.messagesSend += 1 wf = event.text[8:] try: res = client.query(wf) answer = next(res.results).text except Exception: if event.from_chat: f.write_msg_chat(event.chat_id, 'Ошибка запроса!') f.date() print('{}[Wf, to chat {} (user {})][Error!]'.format(f.dat, event.chat_id, event.user_id )) else: f.write_msg(event.user_id, 'Ошибка запроса!') f.date() print('{}[Wf, to user {}][Error!]'.format(f.dat, event.user_id)) if event.from_chat: f.write_msg_chat(event.chat_id, answer) f.date() print('{}[Wf, to chat {} (user {})][{}]'.format(f.dat, event.chat_id, event.user_id, answer)) else: f.write_msg(event.user_id, answer) f.date() print('{}[Wf, to user {}][{}]'.format(f.dat, event.user_id, answer))
def kill(): status.messagesSend += 1 if event.user_id in o.admins: if event.from_chat: f.write_msg_chat(event.chat_id, 'Ня. Пока') f.date() print('{}[Admin][Kill, to chat {} (user {})]'.format( f.dat, event.chat_id, event.user_id)) sys.exit() else: f.write_msg(event.user_id, 'Ня. Пока') f.date() print('{}[Admin][Kill, to user {}]'.format(f.dat, event.user_id)) sys.exit() else: if event.from_chat: f.write_msg_chat(event.chat_id, 'Хмм... Но ведь ты не админ!') f.date() print('{}[Kill, to chat {} (user {})]'.format( f.dat, event.chat_id, event.user_id)) else: f.write_msg(event.user_id, 'Хмм... Но ведь ты не админ!') f.date() print('{}[Kill, to user {}]'.format(f.dat, event.user_id))
def pyth(): status.messagesSend += 1 if event.user_id in o.admins: text = event.text[4:] try: exec(text) if event.from_chat: f.date() print('{}[Admin][Python, to chat {} (user {})][{}]'.format( f.dat, event.chat_id, event.user_id, text)) else: f.date() print('{}[Admin][Python, to user {}][{}]'.format( f.dat, event.user_id, text)) except Exception as error_msg: if event.from_chat: f.write_msg_chat(event.chat_id, error_msg) f.date() print('{}[Admin][Python, to chat {} (user {})][{}]'.format( f.dat, event.chat_id, event.user_id, text)) else: f.write_msg(event.user_id, error_msg) f.date() print('{}[Admin][Python, to user {}][{}]'.format( f.dat, event.user_id, text)) else: if event.from_chat: f.write_msg_chat(event.chat_id, 'Хмм... Но ведь ты не админ!') f.date() print('{}[Python, to chat {} (user {})]'.format( f.dat, event.chat_id, event.user_id)) else: f.write_msg(event.user_id, 'Хмм... Но ведь ты не админ!') f.date() print('{}[Python, to user {}]'.format(f.dat, event.user_id))
def main(): #авторизация try: vk_session = vk_api.VkApi(o.login, o.password) f.date() print('{}[Попытка авторизации...]'.format(f.dat)) vk_session.auth() print('{}[Авторизация прошла успешно!]'.format(f.dat)) except vk_api.AuthError as error_msg: f.date() print('{}[Ошибка авторизации!][{}]'.format(f.dat, error_msg)) return f.vk_session = vk_session admin.vk_session = vk_session anime.vk_session = vk_session who.vk_session = vk_session longpoll = VkLongPoll(vk_session) #подключаем лонгпулл for event in longpoll.listen(): if event.type == VkEventType.MESSAGE_NEW: status.messages += 1 #сюда добавляем команды try: if event.text in status.command: status.event = event status.status() if event.text in c.command: c.event = event c.com() if event.text in bash.command: bash.event = event bash.bash() if event.text in kill.command: kill.event = event kill.kill() if event.text in admin.command: admin.event = event admin.admins() if event.text in anime.commandNaruto: anime.event = event anime.naruto() if event.text in anime.commandAnime: anime.event = event anime.anime() if event.text in anime.commandHentai: anime.event = event anime.hentai() if event.text[:9] in who.command: who.event = event who.who() if event.text[:10] in chance.command: chance.event = event chance.chance() if event.text[:10] in wiki.command: wiki.event = event wiki.wiki() if event.text in who.commandLove: who.event = event who.love() if event.text[:8] in wf.command: wf.event = event wf.wf() if event.text[:4] in pyth.command: pyth.event = event pyth.pyth() if event.text in quote.command: quote.event = event quote.quote() except Exception as error_msg: f.date() print('{}[Ошибка отправки сообщения!][{}]'.format( f.dat, error_msg))