@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(1141423607231283300)
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 = 0
i2 = 0
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 bardasht_time > gozashtan_time and i1 == 0 and bardasht_plate_match.group(1) == plate:
i1 = 1
i2 = 1
grouped_message['gozashtan'] = None
grouped_messages.append(grouped_message)
break
if bardasht_time - gozashtan_time > timedelta(minutes=1):
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 == 0:
print("{}{}".format(gozashtan_time, bardasht_time))
i2 = 1
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}`\nMessage Link : {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 Ast\nMessage Link : {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)