Skip to content

Commit

Permalink
clashking v4
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicTheDev committed Mar 27, 2024
1 parent 170270d commit 4f5096b
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 200 deletions.
116 changes: 58 additions & 58 deletions classes/roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ async def refresh_roles(self):
except:
pass


async def add_member(self, player: coc.Player, sub=False, group="No Group"):
roster_members = self.roster_result.get("members")
roster_member_tags = [member.get("tag") for member in roster_members]
Expand Down Expand Up @@ -574,34 +575,35 @@ async def other_rosters(self):
aliases.remove(self.roster_result.get("alias"))
return aliases


async def mode_components(self, mode: str, player_page: int, roster_page: int, other_roster_page: int):

dropdown = []
dropdowns = []

#both modes let u select which roster you are editing and which player(s) you are editing
other_rosters = await self.other_rosters()
if other_rosters:
length = 24
if player_page >= 1:
length = length - 1
players = self.players[(length * player_page):(length * player_page) + length]
if player_page >= 1:
player_options.append(disnake.SelectOption(label=f"Previous 25 Players", emoji=self.bot.emoji.back.partial_emoji, value=f"players_{player_page - 1}"))
for count, player in enumerate(players):
player_options.append(disnake.SelectOption(label=f"{player.get('name')}",
emoji=self.bot.fetch_emoji(name=player.get('townhall')).partial_emoji,
value=f"edit_{player.get('tag')}"))
if len(players) == length and (len(self.players) > (length * player_page) + length):
player_options.append(disnake.SelectOption(label=f"Next 25 Players", emoji=self.bot.emoji.forward.partial_emoji, value=f"players_{player_page + 1}"))

roster_options = []
for roster in other_rosters:
roster_options.append(disnake.SelectOption(label=f"{roster}", emoji=self.bot.emoji.troop.partial_emoji, value=f"roster_{roster}"))
if roster_options:

edit_roster_options = []
length = 24
if roster_page >= 1:
length = length - 1
edit_rosters = other_rosters[(length * roster_page):(length * roster_page) + length]
if roster_page >= 1:
edit_roster_options.append(disnake.SelectOption(label=f"Previous 25 Rosters", emoji=self.bot.emoji.back.partial_emoji, value=f"editrosters_{roster_page - 1}"))
for count, roster in enumerate(edit_rosters):
edit_roster_options.append(disnake.SelectOption(label=f"{roster}", emoji=self.bot.emoji.troop.partial_emoji, value=f"roster_{roster}"))
if len(edit_rosters) == length and (len(other_rosters) > (length * roster_page) + length):
edit_roster_options.append(disnake.SelectOption(label=f"Next 25 Rosters", emoji=self.bot.emoji.forward.partial_emoji, value=f"editrosters_{roster_page + 1}"))

if edit_roster_options:
roster_select = disnake.ui.Select(
options=roster_options,
options=edit_roster_options,
placeholder="Roster to Edit", # the placeholder text to show when no options have been chosen
min_values=1, # the minimum number of options a user must select
max_values=1, # the maximum number of options a user can select
)
dropdowns.append(roster_select)

if mode == "move":
button_text = "Remove Player Mode"
mode_text = "mode_remove"
Expand All @@ -611,20 +613,13 @@ async def mode_components(self, mode: str, player_page: int, roster_page: int, o
mode_text = "mode_move"
color = disnake.ButtonStyle.green

mode_buttons = [
disnake.ui.Button(label=button_text, emoji=self.bot.emoji.gear.partial_emoji,
style=color,
custom_id=mode_text)
]
buttons = disnake.ui.ActionRow()
for button in mode_buttons:
buttons.append_item(button)
buttons = disnake.ui.ActionRow(disnake.ui.Button(label=button_text, emoji=self.bot.emoji.gear.partial_emoji,style=color,custom_id=mode_text))

player_options = []
length = 24
if player_page >= 1:
length = length - 1
players = self.players[(length*player_page):(length*player_page) + length]
players = self.players[(length * player_page):(length * player_page) + length]
if player_page >= 1:
player_options.append(disnake.SelectOption(label=f"Previous 25 Players", emoji=self.bot.emoji.back.partial_emoji, value=f"players_{player_page - 1}"))
for count, player in enumerate(players):
Expand All @@ -634,50 +629,55 @@ async def mode_components(self, mode: str, player_page: int, roster_page: int, o
if len(players) == length and (len(self.players) > (length * player_page) + length):
player_options.append(disnake.SelectOption(label=f"Next 25 Players", emoji=self.bot.emoji.forward.partial_emoji, value=f"players_{player_page + 1}"))

player_select = disnake.ui.Select(
options=player_options,
placeholder=f"Select Player(s) to {mode}", # the placeholder text to show when no options have been chosen
min_values=1, # the minimum number of options a user must select
max_values=len(players), # the maximum number of options a user can select
)

if len(roster_options) > 0:
dropdown = [disnake.ui.ActionRow(roster_select), disnake.ui.ActionRow(player_select)]
else:
dropdown = [disnake.ui.ActionRow(player_select)]
if player_options:
player_select = disnake.ui.Select(
options=player_options,
placeholder=f"Select Player(s) to {mode}", # the placeholder text to show when no options have been chosen
min_values=1, # the minimum number of options a user must select
max_values=len(players), # the maximum number of options a user can select
)
dropdowns.append(player_select)

if mode == "move":
roster_options = []
move_roster_options = []

other_rosters += [self.roster_result.get("alias")]
for roster in other_rosters:
roster_options.append(disnake.SelectOption(label=f"{roster}", emoji=self.bot.emoji.troop.partial_emoji,
value=f"rostermove_{roster}"))
length = 24
if other_roster_page >= 1:
length = length - 1
move_rosters = other_rosters[(length * other_roster_page):(length * other_roster_page) + length]
if other_roster_page >= 1:
move_roster_options.append(disnake.SelectOption(label=f"Previous 25 Rosters", emoji=self.bot.emoji.back.partial_emoji, value=f"moverosters_{other_roster_page - 1}"))
for count, roster in enumerate(move_rosters):
move_roster_options.append(disnake.SelectOption(label=f"{roster}", emoji=self.bot.emoji.troop.partial_emoji, value=f"rostermove_{roster}"))
if len(move_rosters) == length and (len(other_rosters) > (length * other_roster_page) + length):
move_roster_options.append(disnake.SelectOption(label=f"Next 25 Rosters", emoji=self.bot.emoji.forward.partial_emoji, value=f"moverosters_{other_roster_page + 1}"))

if move_roster_options:
move_roster_select = disnake.ui.Select(
options=move_roster_options,
placeholder="Select Roster To Move To", # the placeholder text to show when no options have been chosen
min_values=1, # the minimum number of options a user must select
max_values=1, # the maximum number of options a user can select
)
dropdowns.append(move_roster_select)

roster_select = disnake.ui.Select(
options=roster_options,
placeholder="Select Roster To Move To", # the placeholder text to show when no options have been chosen
min_values=1, # the minimum number of options a user must select
max_values=1, # the maximum number of options a user can select
)
dropdown.append(disnake.ui.ActionRow(roster_select))

grouping_options = []
for group in await self.grouping:
grouping_options.append(disnake.SelectOption(label=f"{group}", emoji=self.bot.emoji.pin.partial_emoji,
value=f"rostergroup_{group}"))
grouping_options.append(disnake.SelectOption(label=f"{group}", emoji=self.bot.emoji.pin.partial_emoji, value=f"rostergroup_{group}"))

group_select = disnake.ui.Select(
options=grouping_options,
placeholder="Select Grouping to Move Player to", # the placeholder text to show when no options have been chosen
min_values=1, # the minimum number of options a user must select
max_values=1, # the maximum number of options a user can select
)
dropdown.append(disnake.ui.ActionRow(group_select))
dropdowns.append(disnake.ui.ActionRow(group_select))

dropdowns.append(buttons)
return dropdowns

dropdown.append(buttons)
if not self.players:
dropdown = [dropdown[0], dropdown[-1]]
return dropdown

async def export(self):
roster_id = self.roster_result.get("roster_id")
Expand Down
7 changes: 5 additions & 2 deletions commands/clan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ async def clan_activity(bot: CustomClient, clan: coc.Clan, season: str, townhall
name=player.name,
townhall=player.town_hall,
activity=clan_stats.get(tag, {}).get("activity", 0),
lastonline=player.last_online)
lastonline=player.last_online if player.last_online else 0)
)

if townhall is not None:
Expand All @@ -746,7 +746,10 @@ async def clan_activity(bot: CustomClient, clan: coc.Clan, season: str, townhall
for count, member in enumerate(hold_items, 1):
if count <= limit:
if show_last_online:
time_text = smart_convert_seconds(seconds=(now-member.player.last_online))
if member.player.last_online is not None:
time_text = smart_convert_seconds(seconds=(now-member.player.last_online))
else:
time_text = "N/A"
text += f"`{count:2} {member.activity:3} {time_text:7} {member.player.clear_name[:13]:13}`[{create_superscript(member.player.town_hall)}]({member.player.share_link})\n"
else:
text += f"`{count:2} {member.activity:4} {member.player.clear_name[:13]:13}`[{create_superscript(member.player.town_hall)}]({member.player.share_link})\n"
Expand Down
Loading

0 comments on commit 4f5096b

Please sign in to comment.