Untitled
unknown
plain_text
a year ago
3.7 kB
4
Indexable
Never
@bot.tree.command(name="pelak", description="Akharin Bardashte Mashin", guilds=bot.guilds) async def pelak(interaction: discord.Interaction, plate: str): channel = bot.get_channel(1140961195327754302) bardasht_pattern = r'^```css\nBardasht mashin\nPelak\s*:\s*([^\s]+)\b' gozashtan_pattern = r'^```css\nGozashtan mashin\nPelak\s*:\s*([^\s]+)\b' bardasht_messages = [] gozashtan_messages = [] grouped_messages = [] i1 = False i2 = False async for message in channel.history(limit=None): bardasht_match = re.search(bardasht_pattern, message.content) gozashtan_match = re.search(gozashtan_pattern, message.content) if bardasht_match: bardasht_messages.append(message) elif gozashtan_match: gozashtan_messages.append(message) bardasht_messages.sort(key=lambda msg: msg.created_at, reverse=True) gozashtan_messages.sort(key=lambda msg: msg.created_at, reverse=True) for bardasht_message, gozashtan_message in zip(bardasht_messages, gozashtan_messages): bardasht_time = bardasht_message.created_at grouped_message = {'bardasht': bardasht_message, 'gozashtan': None} bardasht_plate_match = re.search(bardasht_pattern, bardasht_message.content) gozashtan_plate_match = re.search(gozashtan_pattern, gozashtan_message.content) gozashtan_time = gozashtan_message.created_at if i1 == False and bardasht_plate_match.group(1) == plate and bardasht_time > gozashtan_time or bardasht_plate_match.group(1) == plate and i1 == False and bardasht_time < gozashtan_time and gozashtan_plate_match.group(1) != plate: i1 = True i2 = True grouped_message['gozashtan'] = None grouped_messages.append(grouped_message) break if bardasht_time - gozashtan_time > timedelta(minutes=1.0): break if bardasht_plate_match and gozashtan_plate_match and bardasht_plate_match.group(1) == gozashtan_plate_match.group(1) == plate: if gozashtan_time - bardasht_time > timedelta(minutes=1) and i2 == False: print("{}{}".format(gozashtan_time, bardasht_time)) i2 = True grouped_message['gozashtan'] = gozashtan_message grouped_messages.append(grouped_message) break if grouped_messages: for grouped_message in grouped_messages: bardasht_message = grouped_message['bardasht'] gozashtan_message = grouped_message['gozashtan'] if grouped_message['gozashtan'] != None: embed = discord.Embed(title=f"Akharin Bardasht Mashin", description=f"Pelak : `{plate}`\n [Link Bardashtan Message]({bardasht_message.jump_url})", color=discord.Color.green()) await interaction.response.send_message(embed=embed, ephemeral=True) else: embed = discord.Embed(title=f"Akharin Bardasht Mashin", description=f"Pelak : `{plate}`\n [Link Bardashtan Message]({bardasht_message.jump_url}) goz", color=discord.Color.green()) await interaction.response.send_message(embed=embed, ephemeral=True) else: embed2 = discord.Embed(title=f"Akharin Bardasht Mashin", description=f"Pelak : `{plate}`\nMessage Link : Abuse Az Pelak Mored Nazar Peyda Nashod", color=discord.Color.red()) await interaction.response.send_message(embed=embed2, ephemeral=True)