async def aux_go_for_help_from_command(ctx, member: discord.Member) -> bool: await aux_leave_group(ctx, member, show_not_in_group_error=False) # Get next group guild = member.guild async with help_queue_lock: group, message_id = GUILD_CONFIG.help_queue(guild).next() if not group: return False # If group found general_text_channel = hpf.get_general_text_channel(guild) try: message = await general_text_channel.fetch_message(message_id) await message.add_reaction(get_unicode_emoji_from_alias('thumbsup')) except discord.NotFound: pass if general_text_channel: await general_text_channel.send( btm.info_on_the_way_to(member, hpf.get_lab_group_name(group))) # Go for help group_text_channel = hpf.get_lab_text_channel(guild, group) if group_text_channel: await group_text_channel.send( btm.message_help_on_the_way(member, show_mention=True)) await aux_join_group(ctx, member, group, group_message=False) return True
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_invite_member(ctx, host_member: discord.Member, invited_member: discord.Member): guild = ctx.guild existing_lab_group = hpf.existing_member_lab_group(host_member) if not existing_lab_group: await ctx.send(btm.error_not_in_group_for_invite(host_member)) elif hpf.member_in_teaching_team(invited_member, guild): await ctx.send(btm.error_can_not_invite_teaching_team()) else: async with invites_lock: group_num = hpf.get_lab_group_number(existing_lab_group.name) invite_list = GUILD_CONFIG.group_invites(guild) if hpf.existing_member_lab_group(invited_member): await ctx.send( btm.error_member_already_in_group(invited_member.name, existing_lab_group.name)) elif invite_list.has_invite(invited_member.id, group_num): await ctx.send(btm.error_invite_already_sent(invited_member)) else: # Add invitation invite_list.add_invite(invited_member.id, group_num) general_text_channel = hpf.get_general_text_channel(guild) if general_text_channel: await general_text_channel.send( btm.success_invite_sent_to_group( invited_member, existing_lab_group, group_num)) group_channel = hpf.get_lab_text_channel(guild, group_num) if group_channel: await group_channel.send( btm.success_invite_sent(invited_member))
async def join_group(guild: discord.Guild, member: discord.Member, new_role: discord.Role, new_lab_group: discord.CategoryChannel, group_message: bool = True, general_message: bool = True): await member.add_roles(new_role) print(f'Role "{new_role}" assigned to {member}') # Move to voice channel if connected voice_channel = hpf.get_lab_voice_channel(guild, new_lab_group.name) if voice_channel and member.voice and member.voice.channel: await member.move_to(voice_channel) # Message to group text channel text_channel = hpf.get_lab_text_channel(guild, new_lab_group.name) if group_message and text_channel: await text_channel.send( btm.message_mention_member_when_join_group(member, new_lab_group.name)) # Message to general channel general_text_channel = hpf.get_general_text_channel(guild) if general_message and general_text_channel and not hpf.member_in_teaching_team( member, guild): await general_text_channel.send( btm.message_member_joined_group(hpf.get_nick(member), new_lab_group.name))
async def close_group(guild: discord.Guild, group: discord.CategoryChannel): async with open_close_lock: if is_open_group(guild, group): GUILD_CONFIG.open_groups(guild).remove(group.name) GUILD_CONFIG.closed_groups(guild).add(group.name) text_channel = hpf.get_lab_text_channel(guild, group.name) if text_channel: await text_channel.send(btm.success_group_closed(group))
async def aux_broadcast(ctx, message: str): guild = ctx.guild general_text_channel = hpf.get_general_text_channel(guild) if general_text_channel: await general_text_channel.send( btm.broadcast_message_from(ctx.author, message)) for group in hpf.all_existing_lab_groups(guild): text_channel = hpf.get_lab_text_channel(guild, group.name) if GUILD_CONFIG.broadcast_to_empty_groups(guild) or len( hpf.all_students_in_group(guild, group.name)) > 0: await text_channel.send( btm.broadcast_message_from(ctx.author, message))
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