Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
4.7 kB
4
Indexable
Never
@tree.command(name="plate-check", description="Akharin Bardashte Mashin", guild=discord.Object(id=884460833097273455))
async def plate_check(interaction: discord.Interaction, plate: str):
    channel = client.get_channel(1141451409087279267)
    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 = []
    bardasht_messages_sorted = []
    gozashtan_messages_sorted = []
    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 in bardasht_messages:
        bardasht_plate_match = re.search(bardasht_pattern, bardasht_message.content)
        if bardasht_plate_match.group(1) == plate:
            bardasht_messages_sorted.append(bardasht_message)

    for gozashtan_message in gozashtan_messages:
        gozashtan_plate_match = re.search(gozashtan_pattern, gozashtan_message.content)
        if gozashtan_plate_match.group(1) == plate:
            gozashtan_messages_sorted.append(gozashtan_message)    

    for bardasht in bardasht_messages_sorted:
        retry = False
        ifrun = False
        ezafecount = 0
        grouped_message = {'bardasht': bardasht, 'gozashtan': None}
        if gozashtan_messages_sorted:
            ifrun = True
            for gozashtan in gozashtan_messages_sorted:
                if gozashtan.created_at > bardasht.created_at:
                    ezafecount += 1

            for gozashtan in gozashtan_messages_sorted:
                if ezafecount != 1 and ezafecount != 0:
                    ezafecount -= 1
                    continue
                

                if bardasht.created_at > gozashtan.created_at :
                    
                    grouped_message['gozashtan'] = None
                    grouped_messages.append(grouped_message)
                    retry = False
                    break

                if gozashtan.created_at - bardasht.created_at  < timedelta(minutes=1):
                    retry = True
                    break

                if bardasht.created_at < gozashtan.created_at and  gozashtan.created_at - bardasht.created_at  > timedelta(minutes=1):
                    
                    grouped_message['gozashtan'] = gozashtan
                    grouped_messages.append(grouped_message)
                    retry = False
                    break

                
                
        if ifrun == False:
            grouped_message['gozashtan'] = None
            grouped_messages.append(grouped_message)

        if retry == False:
            break
        elif retry == True and grouped_message['gozashtan'] == None:

            continue   
        
                

    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}`\nMashin Gozashte Nashode\n[Link Bardashtan Message]({bardasht_message.jump_url})",
                                  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)