«❤ magic» Повторяем тренд из тиктока

Штука забавная, и даже туториал есть, НО … почему код обсуфицирован ? а не улетят наши токены куда не надо? Будем исправлять… напишем свой скрипт с Блекджеком и Ш…

Мы с вами уже работали с Telethon  и научили телеграмм продолжать за вами монолог из Рокки (Прокачай свой Telegram), по этому не будем останавливаться на установке библиотеки и получении токена. 

from telethon import TelegramClient, events, sync
import time
import random
import numpy as np
#? белое сердце
#❤  красное
#? зел
#? синее
#? черное
#? фиолетовое
#? желтое
#? оранж
#api_id полученный ранее.
api_id = ВАШ APP_ID
api_hash = 'ВАШ API_HASH'
chat_id=ВАШ CHAT_ID
colors=["❤","?","?","?","?","?","?"]
matrix = [["?", "?", "?", "?", "?","?","?","?","?"], 
         ["?", "?", "❤", "❤", "?","❤","❤","?","?"],
         ["?", "❤", "❤", "❤", "❤","❤","❤","❤","?"],
         ["?", "❤", "❤", "❤", "❤","❤","❤","❤","?"],
         ["?", "❤", "❤", "❤", "❤","❤","❤","❤","?"],
         ["?", "?", "❤", "❤", "❤","❤","❤","?","?"],
         ["?", "?", "?", "❤", "❤","❤","?","?","?"],
         ["?", "?", "?", "?", "❤","?","?","?","?"],
         ["?", "?", "?", "?", "?","?","?","?","?"]]

def mix_color(heart):
    A=matrix
    A[1][2] = heart
    A[1][3] = heart
    A[1][5] = heart
    A[1][6] = heart
    A[2][1] = heart
    A[2][2] = heart
    A[2][3] = heart
    A[2][4] = heart
    A[2][5] = heart
    A[2][6] = heart
    A[2][7] = heart
    A[3][1] = heart
    A[3][2] = heart
    A[3][3] = heart
    A[3][4] = heart
    A[3][5] = heart
    A[3][6] = heart
    A[3][7] = heart
    A[4][1] = heart
    A[4][2] = heart
    A[4][3] = heart
    A[4][4] = heart
    A[4][5] = heart
    A[4][6] = heart
    A[4][7] = heart
    A[5][2] = heart
    A[5][3] = heart
    A[5][4] = heart
    A[5][5] = heart   
    A[5][6] = heart  
    A[6][3] = heart
    A[6][4] = heart
    A[6][5] = heart
    A[7][4] = heart
    return '\n'.join(['\t'.join([str(cell) for cell in row]) for row in A])


def random_color():
    A=matrix
    A[1][2] = random.choice(colors)
    A[1][3] = random.choice(colors)
    A[1][5] = random.choice(colors)
    A[1][6] = random.choice(colors)
    A[2][1] = random.choice(colors)
    A[2][2] = random.choice(colors)
    A[2][3] = random.choice(colors)
    A[2][4] = random.choice(colors)
    A[2][5] = random.choice(colors)
    A[2][6] = random.choice(colors)
    A[2][7] = random.choice(colors)
    A[3][1] = random.choice(colors)
    A[3][2] = random.choice(colors)
    A[3][3] = random.choice(colors)
    A[3][4] = random.choice(colors)
    A[3][5] = random.choice(colors)
    A[3][6] = random.choice(colors)
    A[3][7] = random.choice(colors)
    A[4][1] = random.choice(colors)
    A[4][2] = random.choice(colors)
    A[4][3] = random.choice(colors)
    A[4][4] = random.choice(colors)
    A[4][5] = random.choice(colors)
    A[4][6] = random.choice(colors)
    A[4][7] = random.choice(colors)
    A[5][2] = random.choice(colors)
    A[5][3] = random.choice(colors)
    A[5][4] = random.choice(colors)
    A[5][5] = random.choice(colors)   
    A[5][6] = random.choice(colors)  
    A[6][3] = random.choice(colors)
    A[6][4] = random.choice(colors)
    A[6][5] = random.choice(colors)
    A[7][4] = random.choice(colors)
    return '\n'.join(['\t'.join([str(cell) for cell in row]) for row in A])

async def clear():
    for row in range(9): 
        for x in range(9): 
                   matrix[row][x]="?"
async def  fill_color(msg):
   
    await client.edit_message(msg,mix_color("❤"))
    A=matrix
    for row in range(9): 
        for x in range(9): 
               if (A[row][x]!="❤"):
                   A[row][x]="❤"
                   time.sleep(0.050)
                   await client.edit_message(msg,'\n'.join(['\t'.join([str(cell) for cell in row]) for row in A]))


with TelegramClient('CLIENT_ID', api_id, api_hash) as client:

   @client.on(events.NewMessage())
   async def handler(event):
      sender = await event.get_sender()
#Если это вы пишете сообщение
      if(sender.id==chat_id):
#И сообщение содержит 

        if("❤️ magic" in event.message.message):
            msg=event.message
            await clear()
            # гирлянда
            for color in colors:
                await client.edit_message(msg,mix_color(color))
                time.sleep(0.3)
            #Рандомный цвет
            i=0
            while i<7:
                await client.edit_message(msg,random_color())
                i=i+1
                time.sleep(0.3)
            #закрашиваем матрицу
            await fill_color(msg);
           # Удаляем столбцы и строки
            A=matrix
            i=0
            while i<8:               
                
                A=np.delete(A, 1, 1)  
                A = np.delete(A, 1, 0)  
                await client.edit_message(msg,'\n'.join(['\t'.join([str(cell) for cell in row]) for row in A]))
                time.sleep(0.3)
                i=i+1
            time.sleep(0.5)
            #выводим надпись
            await client.edit_message(msg,"❤ Люблю тебя! ❤")
          
   client.run_until_disconnected()


Читайте также:

комментария 3

  1. Алекс:

    Получилось, спасибо!

  2. Юрий:

    Traceback (most recent call last):
    File «main.py», line 121, in
    with TelegramClient(‘CLIENT_ID’, api_id, api_hash) as client:
    File «/home/runner/111/venv/lib/python3.8/site-packages/telethon/helpers.py», line 219, in _sync_enter
    return loop.run_until_complete(self.__aenter__())
    File «/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/asyncio/base_events.py», line 616, in run_until_complete
    return future.result()
    File «/home/runner/111/venv/lib/python3.8/site-packages/telethon/client/auth.py», line 736, in __aenter__
    return await self.start()
    File «/home/runner/111/venv/lib/python3.8/site-packages/telethon/client/auth.py», line 190, in _start
    await self.send_code_request(phone, force_sms=force_sms)
    File «/home/runner/111/venv/lib/python3.8/site-packages/telethon/client/auth.py», line 519, in send_code_request
    result = await self(functions.auth.SendCodeRequest(
    File «/home/runner/111/venv/lib/python3.8/site-packages/telethon/client/users.py», line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
    File «/home/runner/111/venv/lib/python3.8/site-packages/telethon/client/users.py», line 84, in _call
    result = await future
    telethon.errors.rpcerrorlist.ApiIdInvalidError: The api_id/api_hash combination is invalid (caused by SendCodeRequest)

    Когда ввёл номер телефона, вылазит это

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *