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 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 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 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 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 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 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 txt(txt): txt = str(txt) if event.from_chat: f.write_msg_chat(event.chat_id, txt) else: f.write_msg(event.user_id, txt)