Best Python code snippet using lisa_python
bot.py
Source:bot.py
1# Needs telethon library2# pip install telethon3#4# Dont forget to change api_id and api_hash5#6# Commands are readable by bot only in "saved messages" channel.7from telethon import TelegramClient, sync, events8import random9import sched, time10import asyncio11api_id = 0 # paste your own from https://my.telegram.org/apps12api_hash = '---'13def multiline_text(*args):14 result = ""15 for text in args:16 result += text + "\n"17 return result18help_text = multiline_text(19 "Raid bot v282",20 "/ping - ping pong command",21 "/remember_stickers - enables "remember stickers" mode. After writing this command you will need to send stickers which will be used during the raid. To disable this mode write /stop_remember_stickers.",22 "/remember_text - enables "remember text" mode which is means that bot will remember some text to send during the raid. Write to disable: /stop_remember_text",23 "/remember_media - remembers multimedia content such as images or GIFs. For disabling: /stop_remember_media",24 "/test_raid - test raid with 50 messages, its nice to raid yourself",25 "/raid [chat_name] - raids some selected chat, instead of [chat_name] you need to paste name of the chat ACCURATELY. You can stop the raid using /stop_raid",26)27client = TelegramClient('session_name', api_id, api_hash)28client.start()29async def answer_myself(text):30 await client.send_message("me", text)31 32def get_random_item(array):33 return array[random.randint(0, len(array) - 1)]34remembering_stickers = False35remembered_stickers = []36remembering_text = False37remembered_text = []38remembering_media = False39remembered_media = []40stop_raid = False41raid_target = "me"42async def send_raid_message():43 try:44 global remembered_stickers45 global remembered_text46 global remembered_media47 global raid_target48 49 random.seed(random.randint(-100, 100) * 123)50 51 variant = random.randint(1, 3)52 53 if variant == 1:54 await client.send_file(raid_target, get_random_item(remembered_stickers))55 elif variant == 2:56 await client.send_message(raid_target, get_random_item(remembered_text))57 elif variant == 3:58 await client.send_file(raid_target, get_random_item(remembered_media))59 except:60 await send_raid_message()61 62@client.on(events.NewMessage(chats = "me"))63async def handler(event):64 global remembering_stickers65 global remembered_stickers66 global remembering_text67 global remembered_text68 global remembering_media69 global remembered_media70 global raid_target71 global stop_raid 72 73 if remembering_stickers:74 if "/stop_remember_stickers" in event.text:75 remembering_stickers = False76 await answer_myself("Stickers remember mode is disabled")77 else:78 remembered_stickers.append(event.sticker)79 await answer_myself("Saved this sticker")80 return81 82 if remembering_text:83 if "/stop_remember_text" in event.text:84 remembering_text = False85 await answer_myself("Text remember mode is disabled")86 else:87 remembered_text.append(event.text)88 await answer_myself("Saved this text")89 return90 91 if remembering_media:92 if "/stop_remember_media" in event.text:93 remembering_media = False94 await answer_myself("Media remember mode is disabled")95 else:96 remembered_media.append(event.media)97 await answer_myself("Saved this media")98 return99 100 101 if "/ping" in event.text:102 await answer_myself("pong")103 104 if "/help" in event.text:105 await answer_myself(help_text)106 107 if "/remember_stickers" in event.text:108 await answer_myself("Send some stickers")109 remembering_stickers = True110 return111 112 if "/remember_text" in event.text:113 await answer_myself("Send some text")114 remembering_text = True115 return116 117 if "/remember_media" in event.text:118 await answer_myself("Send some GIFs or images")119 remembering_media = True120 return121 122 if "/test_raid" in event.text:123 raid_target = "me"124 for counter in range(1, 50):125 await asyncio.sleep(random.uniform(0.02, 0.15))126 await send_raid_message()127 128 if "/raid" in event.text:129 target_chat_name = event.text130 target_chat_name = target_chat_name.replace("/raid", "").strip()131 my_private_channel_id = None132 my_private_channel = None133 134 async for dialog in client.iter_dialogs():135 if dialog.name == target_chat_name:136 my_private_channel = dialog137 my_private_channel_id = dialog.id138 break139 140 if my_private_channel_id:141 try:142 await answer_myself("Chat is detected, starting the raid")143 raid_target = my_private_channel_id144 while True:145 if stop_raid:146 break147 await asyncio.sleep(random.uniform(0.02, 0.15))148 await send_raid_message()149 except:150 pass151 else:152 await answer_myself("Chat is not detected")153 154 if "/stop_raid" in event.text:155 stop_raid = True156 await answer_myself("Stopping the raid")157print("Raid bot v282 starts")...
chats.py
Source:chats.py
...13 async def update_tags(self, chat_id: int, new: Dict):14 return await self.db.chats.update_tags(chat_id, new)15 async def start_raid(self, chat_id: int, message_id: int) -> None:16 return await self.db.chats.start_raid(chat_id, message_id)17 async def stop_raid(self, chat_id: int) -> None:...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!