-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
81 lines (70 loc) · 3.3 KB
/
Copy pathutils.py
File metadata and controls
81 lines (70 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import discord
from datetime import datetime
def round_up_days(join_date_str: str, format="%d/%m/%Y") -> int:
"""Calculate days since join date, rounding up."""
join = datetime.strptime(join_date_str, format)
delta = datetime.now() - join
days = delta.days
if delta.seconds > 0:
days += 1
return days
def is_valid_date(date_str: str, format="%d/%m/%Y") -> bool:
"""Check if a string matches the expected date format."""
try:
datetime.strptime(date_str, format)
return True
except ValueError:
return False
def status_emoji_from_days(days_ago: int) -> str:
if days_ago < 30:
return "🟢"
elif days_ago < 60:
return "🟠"
else:
return "🔴"
def format_discord_user(user_id: str) -> str:
return f"<@{user_id}>"
def parse_recruiters(recruiter_ids_str: str) -> list:
if not recruiter_ids_str:
return []
return recruiter_ids_str.split(",")
class PaginationView(discord.ui.View):
def __init__(self, embeds: list, user_id: int, timeout=60):
super().__init__(timeout=timeout)
self.embeds = embeds
self.user_id = user_id
self.current = 0
self.update_buttons()
def update_buttons(self):
self.children[0].disabled = self.current == 0
self.children[1].disabled = self.current == 0
self.children[2].disabled = self.current == len(self.embeds) - 1
self.children[3].disabled = self.current == len(self.embeds) - 1
@discord.ui.button(label="⏮️ First", style=discord.ButtonStyle.secondary)
async def first(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
return await interaction.response.send_message("Not your pagination.", ephemeral=True)
self.current = 0
self.update_buttons()
await interaction.response.edit_message(embed=self.embeds[self.current], view=self)
@discord.ui.button(label="◀️ Prev", style=discord.ButtonStyle.primary)
async def prev(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
return await interaction.response.send_message("Not your pagination.", ephemeral=True)
self.current -= 1
self.update_buttons()
await interaction.response.edit_message(embed=self.embeds[self.current], view=self)
@discord.ui.button(label="Next ▶️", style=discord.ButtonStyle.primary)
async def next(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
return await interaction.response.send_message("Not your pagination.", ephemeral=True)
self.current += 1
self.update_buttons()
await interaction.response.edit_message(embed=self.embeds[self.current], view=self)
@discord.ui.button(label="⏭️ Last", style=discord.ButtonStyle.secondary)
async def last(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
return await interaction.response.send_message("Not your pagination.", ephemeral=True)
self.current = len(self.embeds) - 1
self.update_buttons()
await interaction.response.edit_message(embed=self.embeds[self.current], view=self)