Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
14 kB
3
Indexable
Never
import requests
import telebot
import json
import logging
from aiogram import Bot, Dispatcher, executor, types
from telethon import TelegramClient, events
from telethon.tl import types
from telethon.tl.types import PeerUser, PeerChat, PeerChannel, ChatBannedRights
from telethon.tl.functions.channels import EditBannedRequest
# Создаем экземпляр бота
bot = telebot.TeleBot('5433292879:AAEw2TvgV9LffWRyJd32YMXuwCpSSv6Z9OQ')
api_id = 13357517  # +**********
api_hash = '36b3afd6080174af207b48abe63b0ae9'
bot_token = '5433292879:AAEw2TvgV9LffWRyJd32YMXuwCpSSv6Z9OQ'
# Функция, обрабатывающая команду /start
@bot.message_handler(commands=["start"])
def start(message):
    bot.send_message(message.chat.id, "Для использования меня нужно вводить в командах m - /mstart")
@bot.message_handler(commands=["mstart"])
def start(message):
    bot.send_message(message.chat.id, "Привет, я ИИ Мико, скорее чат-бот, который много умеет и старается ради своего создателя Miko Kun (https://mikoland.tk)")
@bot.message_handler(commands=["mquestion"])
def start(message):
    bot.send_message(message.chat.id, 'Напиши вопрос (либо отправь фотографию с вопросом), на который можно ответить да или нет')
    @bot.message_handler(content_types=["text", "photo"])
    def start(message):
        response = requests.get("https://yesno.wtf/api")
        s = response.text
        d = json.loads(s)
        pardon = d['image']
        pardon1 = d['answer']
        bot.send_animation(message.chat.id, pardon)
        bot.send_message(message.chat.id, pardon1)
@bot.message_handler(commands=["mtranslate"])
def translate(message):
    bot.send_message(message.chat.id, 'Напиши слово на любом языке (кроме русского) и я переведу его на русский!')
    @bot.message_handler(content_types=["text"])
    def start(message):
        TEXT_TO_TEXT_URL = "https://fasttranslator.herokuapp.com/api/v1/text/to/text"
        LANG = "en-ru"
        TEXT = message.text
        url = f"{TEXT_TO_TEXT_URL}?source={TEXT}&lang={LANG}"
        resp = requests.get(url).json()
        resp94 = requests.get(url)
        skd9 = resp94.status_code
        if skd9 == 200:
            bot.send_message(message.chat.id, resp["data"])
        else:
            courtw1 = f"https://http.cat/{skd9}"
            bot.send_photo(message.chat.id, courtw1)
@bot.message_handler(commands=["mweather"])
def translate(message):
    bot.send_message(message.chat.id, 'Напиши город на русском языке')
    @bot.message_handler(content_types=["text"])
    def start(message):
        TEXT_TO_TEXT_URL = "https://fasttranslator.herokuapp.com/api/v1/text/to/text"
        LANG = "ru-en"
        TEXT = message.text
        url = f"{TEXT_TO_TEXT_URL}?source={TEXT}&lang={LANG}"
        resp = requests.get(url).json()
        resp94 = requests.get(url)
        skd9 = resp94.status_code
        if skd9 == 200:
            TEXT_TO_TEXT_URL1 = "https://api.openweathermap.org/data/2.5/weather"
            APPID1 = "feafbc02a888d27599aa924ae7a72073"
            TEXT1 = resp["data"]
            url = f"{TEXT_TO_TEXT_URL1}?q={TEXT1}&appid={APPID1}"
            resp = requests.get(url).json()
            d1 = 9 / 5
            resp1 = resp['main']["temp_max"] * d1
            resp2 = resp1 - 459.67
            resp1 = resp2 - 32
            resp1 = resp1 * 5
            resp1 = resp1 / 9
            respend = round(resp1)
            wresult = f"На данный момент температура города {message.text} составляет {respend} °C"
            bot.send_message(message.chat.id, wresult)
        else:
            courtw1 = f"https://http.cat/{skd9}"
            bot.send_photo(message.chat.id, courtw1)


@bot.message_handler(commands=["mwhattodo"])
def start(message):
    resp = requests.get("http://www.boredapi.com/api/activity/").json()
    resp1 = resp['activity']
    TEXT_TO_TEXT_URL = "https://fasttranslator.herokuapp.com/api/v1/text/to/text"
    LANG = "en-ru"
    TEXT = resp1
    url = f"{TEXT_TO_TEXT_URL}?source={TEXT}&lang={LANG}"
    response = requests.get(url).json()
    resp94 = requests.get(url)
    skd9 = resp94.status_code
    if skd9 == 200:
        bot.send_message(message.chat.id, response['data'])
    else:
        courtw1 = f"https://http.cat/{skd9}"
        bot.send_photo(message.chat.id, courtw1)




@bot.message_handler(commands=["mjoke"])
def start(message):
    resp = requests.get("https://geek-jokes.sameerkumar.website/api?format=json").json()
    resp1 = resp['joke']
    TEXT_TO_TEXT_URL = "https://fasttranslator.herokuapp.com/api/v1/text/to/text"
    LANG = "en-ru"
    TEXT = resp1
    url = f"{TEXT_TO_TEXT_URL}?source={TEXT}&lang={LANG}"
    resps = requests.get(url).json()
    bot.send_message(message.chat.id, resps['data'])
    resp94 = requests.get(url)
    skd9 = resp94.status_code
    if skd9 == 200:
        bot.send_message(message.chat.id, resps['data'])
    else:
        courtw13 = f"https://http.cat/{skd9}"
        bot.send_photo(message.chat.id, courtw13)

@bot.message_handler(commands=["merror"])
def translate(message):
    bot.send_message(message.chat.id, 'Введи код')
    @bot.message_handler(content_types=["text"])
    def start(message):
        bot.send_photo(message.chat.id, f"https://http.cat/{message.text}")


client = TelegramClient('my_account', api_id, api_hash)

bot1 = TelegramClient('bot', api_id, api_hash).start(bot_token=bot_token)
bad_words = ["ПОИSК", "BE4EP", "ПОИSК", "Г0PЯ4UЕ", "ЗНАK0МСTVA", "💝💝💝", "🌶🌶🌶", "💋💋💋", "СEKS", "ПAPTНЕР0B",
             "🍓🍓🍓"]


@bot1.on(events.ChatAction)
async def my_event_handler(event):
    print("Event!")
    print(event)
    print(event.action_message.from_id.user_id)
    channel = event.action_message.peer_id.channel_id
    print(channel)
    method = 'getUpdates?offset=-1'
    response = requests.post(
        url='https://api.telegram.org/bot{0}/{1}'.format(bot1_token, method),
        data={'id': event.action_message.from_id.user_id}).json()
    print(response)
    data = response.get("result")[0].get("message").get("from").get("first_name")
    user = response.get("result")[0].get("message").get("from").get("username")
    sum = response.get("result")[0].get("message").get("from")
    print(sum)
    print(user)
    print(data)
    if event.user_joined == True:
        print("!!!!!!!")
        for i in range(len(bad_words)):
            print(bad_words[i], " not in ", data)
            if bad_words[i] in data:
                print("Busted", channel, user)
                await client.edit_permissions(channel, user, view_messages=False)
                print("Deleted")

#@bot1.on(events.ChatAction)
#async def my_event_handler(event):
#    print("Event!")
#    print(event)
#    print(event.action_message.from_id.user_id)
#    channel = event.action_message.peer_id.channel_id
#    print(channel)
#    method = 'getUpdates?offset=-1'
#    response = requests.post(
#        url='https://api.telegram.org/bot{0}/{1}'.format(bot_token, method),
#        data={'id': event.action_message.from_id.user_id}).json()
#    print(response)
#    data = response.get("result")[0].get("message").get("from").get("first_name")
#    user = response.get("result")[0].get("message").get("from").get("username")
#    sum = response.get("result")[0].get("message").get("from")
#    print(sum)
#    print(user)
#    print(data)
#    await client.edit_permissions(channel, user, view_messages=False)
#    print("Deleted")

#client.start()
#client.run_until_disconnected()

@bot.message_handler(commands=["murl"])
def translate(message):
    bot.send_message(message.chat.id, 'Введи ссылку для сокращения')
    @bot.message_handler(content_types=["text"])
    def start(message):
        r1 = message.text
        url = 'https://gotiny.cc/api'
        payload = {
            "input": r1,
        }
        r = requests.post(url, json=payload)

        result = r.json()[0]['code']
        bot.send_message(message.chat.id, f"Держи сокращенную ссылку! \nhttps://gotiny.cc/{result}")
@bot.message_handler(commands=["mexchange"])
def translate(message):
    responsebynrub = requests.get('https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/byn/rub.json').json()
    responseusdrub = requests.get('https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/usd/rub.json').json()
    responseeurrub = requests.get('https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/eur/rub.json').json()
    responsebtcrub = requests.get('https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/btc/rub.json').json()
    responseuahrub = requests.get('https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/byn/rub.json').json()
    bot.send_message(message.chat.id, f"На данный момент 1 доллар это {round(responseusdrub['rub'])} рублей")
    bot.send_message(message.chat.id, f"На данный момент 1 евро это {round(responseeurrub['rub'])} рублей")
    bot.send_message(message.chat.id, f"На данный момент 1 биткоин это {round(responsebtcrub['rub'])} рублей")
    bot.send_message(message.chat.id, f"На данный момент 1 украинская гривня это {round(responseuahrub['rub'])} рублей")
    bot.send_message(message.chat.id, f"На данный момент 1 белорусский рубль это {round(responsebynrub['rub'])} рублей")

@bot.message_handler(commands=["mball"])
def translate(message):
    response9876 = requests.get("https://api.catboys.com/8ball").json()
    res13 = response9876["url"]
    bot.send_photo(message.chat.id, res13)

@bot.message_handler(commands=["mcatimg"])
def translate(message):
    response = requests.get("https://api.catboys.com/img").json()
    bot.send_photo(message.chat.id, response['url'])

@bot.message_handler(commands=["mdice"])
def translate(message):
    response = requests.get("https://api.catboys.com/dice").json()
    bot.send_message(message.chat.id, "Бросим кубики...")
    bot.send_photo(message.chat.id, response['url'])

@bot.message_handler(commands=["mbaka"])
def translate(message):
    response = requests.get("https://api.catboys.com/baka").json()
    bot.send_animation(message.chat.id, response['url'])

@bot.message_handler(commands=["mcrypto"])
def translate(message):
    bot.send_message(message.chat.id, 'Введи id_bitcoin \nПример: bitcoin, ethereum')
    @bot.message_handler(content_types=["text"])
    def start(message):
        response = requests.get("https://api.coincap.io/v2/assets").json()
        res1 = response[message.text]['priceUsd']
        bot.send_animation(message.chat.id, res1)

@bot.message_handler(commands=["debuging"])
def translate(message):
    bot.send_message(message.chat.id, message)



#@bot.message_handler(content_types=["text"])
#def start(message):
    #if message.text == "Привет":
        #bot.send_message(message.chat.id, "Привет!")
    #elif message.text == "кто злой полицай":
        #bot.send_message(message.chat.id, "Виктор :)")
    #elif message.text == "где живет Мико":
        #bot.send_message(message.chat.id, "Россия, Санкт-Петербург")
    #elif message.text == "ласт видео":
        #bot.send_message(message.chat.id, "Ссылка на видео (YouTube) \nhttps://www.youtube.com/watch?v=NdOOa-C4QZs")
    #elif message.text == "вк создателя":
        #bot.send_messsage(message.chat.id, "Ссылка на VK: https://vk.com/id298897227")
    #elif message.text == "Yes":
        #response = requests.get("https://yesno.wtf/api")
        #s = response.text
        #d = json.loads(s)
        #pardon = d['image']
        #bot.send_animation(message.chat.id, pardon)
    #elif message.text == "1 евро":
        #response = requests.get('https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/eur/rub.json').json()
        #response1 = requests.get('https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/eur/rub.json')
        #if response1.status_code == 200:
            #bot.send_message(message.chat.id, f"На данный момент 1 евро это {round(response['rub'])} рублей")
    #else:
            #bot.send_photo(message.chat.id, f'https://http.cat/{response1.status_code}')
    #elif message.text == "1 доллар":
        #response23 = requests.get('https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/usd/rub.json').json()
        #response167 = requests.get('https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/usd/rub.json')
        #if response167.status_code == 200:
            #bot.send_message(message.chat.id, f"На данный момент 1 доллар это {round(response23['rub'])} рублей")
    #else:
            #bot.send_photo(message.chat.id, f'https://http.cat/{response167.status_code}')
    #elif message.text == "1 белорусский рубль":
        #response122 = requests.get('https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/byn/rub.json').json()
        #response12 = requests.get('https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/byn/rub.json')
        #if response12.status_code == 200:
            #bot.send_message(message.chat.id, f"На данный момент 1 белорусский рубль это {round(response122['rub'])} рублей")
    #else:
            #bot.send_photo(message.chat.id, f'https://http.cat/{response12.status_code}')
    #elif message.text == "Как дела":
        #bot.send_message(message.chat.id, 'Неплохо, даже замечательно.')
    #elif message.text == "Что планируется?":
        #bot.send_message(message.chat.id, 'Мы планируем добавить статистику о человеке в WoT:Blitz, а также вы можете написать создателю для чего-то нового! @czechboyz')







bot.polling(none_stop=True)