async def go_for_help_from_message(member: discord.Member, message: discord.Message, group: Union[int, str]) -> bool: guild = member.guild if hpf.existing_member_lab_role(member): await leave_group(guild, member, hpf.existing_member_lab_role(member), hpf.existing_member_lab_group(member)) lab_group = hpf.get_lab_group(guild, group) async with help_queue_lock: message_id = GUILD_CONFIG.help_queue(guild).extract_group(group) if not message_id: return False if message.channel: await message.channel.send( btm.info_on_the_way_to(member, lab_group.name)) group_text_channel = hpf.get_lab_text_channel(guild, lab_group.name) if group_text_channel: await group_text_channel.send( btm.message_help_on_the_way(member, show_mention=True)) if hpf.get_lab_role(guild, group): await join_group(guild, member, hpf.get_lab_role(guild, group), lab_group, group_message=False) return True return False
async def aux_delete_group(ctx, group: Union[int, str], show_bot_message: bool = True): async with create_delete_lock: guild = ctx.guild category = hpf.get_lab_group(guild, group) role = hpf.get_lab_role(guild, group) success = False if category: channels = category.channels for group_member in (role.members if role else []): await aux_leave_group(ctx, group_member, show_not_in_group_error=False) for channel in channels: print(f'Deleting channel: {channel.name}') await channel.delete() print(f'Deleting category: {category.name}') await category.delete() await aux_remove_group(guild, category) success = True elif show_bot_message: await ctx.send(btm.message_group_not_exists_error(category.name)) if role: print(f'Deleting role: {role.name}') await role.delete() if success and show_bot_message: general_text_channel = hpf.get_general_text_channel(guild) if general_text_channel: await general_text_channel.send( btm.message_group_deleted(category.name))
async def convert(self, ctx, group): try: name = hpf.get_lab_group_name(int(group)) except ValueError: name = group existing_group = hpf.get_lab_group(ctx.guild, name) if existing_group: return existing_group raise commands.BadArgument(btm.message_group_not_exists_error(name))
async def aux_deny_to_role(ctx, role_mention: discord.Role, group: int, *args): role = discord.utils.get(ctx.guild.roles, mention=role_mention.name) if role and hpf.get_lab_role(ctx.guild, role.name): lab_group = hpf.get_lab_group(ctx.guild, group) print(f"Updating deny permissions of {role} on {lab_group}...") overwrite_mask = get_permission_mask(*args) if not overwrite_mask: await ctx.send(btm.message_permission_mask_not_valid("|".join(*args))) else: await cdg.update_permission(role, lab_group, deny_mask=overwrite_mask) await ctx.send(btm.message_deny_to_success(list(*args), role, lab_group)) elif not role: await ctx.send(btm.message_lab_role_not_exists(role_mention.name)) else: await ctx.send(btm.message_role_permissions_not_modificable_error(role))
async def aux_join_group(ctx, member: discord.Member, group: Union[int, str], group_message: bool = True, general_message: bool = True) -> bool: guild = ctx.guild new_role = hpf.get_lab_role(guild, group) new_lab_group = hpf.get_lab_group(guild, group) existing_lab_group = hpf.existing_member_lab_group(member) max_group_size = GUILD_CONFIG.max_students_per_group(guild) if GUILD_CONFIG.require_nickname(guild) and not member.nick: await ctx.send(btm.message_member_need_name_error(member)) elif existing_lab_group: await ctx.send( btm.error_member_already_in_group(hpf.get_nick(member), existing_lab_group.name)) elif not new_role: await ctx.send(btm.message_lab_group_not_exists(new_lab_group.name)) elif not hpf.member_in_teaching_team(member, guild) and len( hpf.all_students_in_group(guild, group)) >= max_group_size: await ctx.send( btm.message_max_members_in_group_error(new_lab_group.name, max_group_size)) else: if not hpf.member_in_teaching_team(member, guild): group_num = hpf.get_lab_group_number(new_lab_group.name) async with invites_lock: invite_list = GUILD_CONFIG.group_invites(guild) invited = invite_list.has_invite(member.id, group_num) if is_closed_group(guild, new_lab_group) and not invited: text_channel = hpf.get_lab_text_channel(guild, group) if text_channel: await text_channel.send( btm.error_someone_try_to_enter(member)) await ctx.send(btm.error_lab_group_is_closed(new_lab_group) ) return False if invited: invite_list.remove_invite(member.id, group_num) await join_group(guild, member, new_role, new_lab_group, group_message=group_message, general_message=general_message) else: await join_group(guild, member, new_role, new_lab_group, group_message=group_message, general_message=general_message) # Remove other invitations async with invites_lock: invite_list = GUILD_CONFIG.group_invites(guild) old_invites = invite_list.retrieve_invites(member.id) for group_invite in old_invites: text_channel = hpf.get_lab_text_channel(guild, group_invite) await text_channel.send( btm.info_member_accepted_another_invite(member)) return True return False