def aux_group_details(ctx, group: discord.CategoryChannel, details: bool = False, none_if_empty: bool = False) -> Optional[str]: guild = ctx.guild members = hpf.all_students_in_group(guild, group.name) if not members and none_if_empty: return None if details: return btm.info_group_details(members, group, is_open=is_open_group(guild, group)) else: return btm.message_list_group_members( hpf.get_lab_group_number(group.name), members)
async def aux_random_join(ctx, member_mention: discord.Member, *args): member = discord.utils.get(ctx.message.mentions, name=member_mention.name) excluded_groups = hpf.get_excluded_groups(*args) if not member: await ctx.send(btm.message_member_not_exists(member_mention.nick)) elif not excluded_groups: await ctx.send("All extra arguments should be integers!") else: available_lab_groups = [] for group in hpf.all_existing_lab_groups(ctx.guild): group_number = hpf.get_lab_group_number(group.name) if group_number and group not in excluded_groups and is_open_group( ctx.guild, group): available_lab_groups.append(group) await random_assignment(ctx, member, available_lab_groups)
async def map_size_of_members_to_group( guild: discord.Guild) -> Dict[int, List[discord.CategoryChannel]]: print('Getting num of members per group') size_to_group = {} print('Created dictionary') for group in hpf.all_existing_lab_groups(guild): print('Processing group ' + group.name) group_num = hpf.get_lab_group_number(group.name) if is_open_group(guild, group): size = len(hpf.all_students_in_group(guild, group_num)) print('The group is open and it has ' + str(size) + " members") groups = size_to_group.get(size) if groups is None: groups = [] size_to_group[size] = groups groups.append(group) print('Done. The dictionary: ' + str(size_to_group)) return size_to_group
async def aux_random_join_all(ctx, *args): # Get excluded groups excluded_groups = hpf.get_excluded_groups(*args) #if not excluded_groups: # await ctx.send("All extra arguments should be integers for excluded groups.") # return # Get available groups available_lab_groups = [] for group in hpf.all_existing_lab_groups(ctx.guild): group_number = hpf.get_lab_group_number(group.name) if group_number and group not in excluded_groups and is_open_group( ctx.guild, group): available_lab_groups.append(group) no_group_members = hpf.all_students_with_no_group(ctx.guild) # Assign groups for member in no_group_members: # if member.status == discord.Status.online: available_lab_groups = await random_assignment(ctx, member, available_lab_groups)
async def aux_init_guild(guild: discord.Guild): if not guild in GUILD_CONFIG: return #print(f'{guild.name} (id: {guild.id})') print(guild.name) members = '\n - '.join([hpf.get_nick(member) for member in guild.members]) print(f'Guild Members:\n - {members}') # Create or update roles all_allow = discord.Permissions.all() almost_all = discord.Permissions(PMask.ALL_BUT_ADMIN_AND_GUILD | PMask.STREAM) text_and_voice_allow = discord.Permissions(PMask.CHANGE_NICKNAME | PMask.PARTIAL_TEXT | PMask.PARTIAL_VOICE) await create_new_role(guild, PROFESSOR_ROLE_NAME, permissions=all_allow, colour=discord.Colour.blue(), hoist=True, mentionable=True) await create_new_role(guild, HEAD_TA_ROLE_NAME, permissions=all_allow, colour=discord.Colour.red(), hoist=True, mentionable=True) await create_new_role(guild, TA_ROLE_NAME, permissions=almost_all, colour=discord.Colour.purple(), hoist=True, mentionable=True) await create_new_role(guild, STUDENT_ROLE_NAME, permissions=text_and_voice_allow, colour=discord.Colour.gold(), hoist=True, mentionable=True) # Double check existing lab groups for group in hpf.all_existing_lab_groups(guild): if not (is_open_group(guild, group) or is_closed_group(guild, group)): await open_group(guild, group)
async def clean_all_command(ctx, *args): async with ctx.channel.typing(): excluded_groups = hpf.get_excluded_groups(*args) groups_to_be_cleaned = [group for group in hpf.all_existing_lab_groups(ctx.guild) if hpf.get_lab_group_number(group.name) not in excluded_groups and is_open_group(ctx.guild, group)] for group in sorted(groups_to_be_cleaned, key=lambda c: c.name, reverse=False): await aux_clean_group(ctx, group.name)