Implemented add role action
							parent
							
								
									3688334de7
								
							
						
					
					
						commit
						f2a18207de
					
				
							
								
								
									
										48
									
								
								bot.py
								
								
								
								
							
							
						
						
									
										48
									
								
								bot.py
								
								
								
								
							|  | @ -383,7 +383,11 @@ class ActionAcceptEditorView(discord.ui.View): | |||
|         actions = GuildAppDB.get_actions(str(interaction.guild.id), self.application_name, action_type=ActionInteraction.ACCEPT) | ||||
|         options.set_action_type(ActionInteraction.ACCEPT) | ||||
|         for i, que in enumerate(actions): | ||||
|             options.add_option(label=f"{str(i+1)}. {que}", value=str(i)) | ||||
|             if que["action_type"] == "add_role": | ||||
|                 role = interaction.guild.get_role(que["data"]["role_id"]).name | ||||
|                 options.add_option(label=f"{str(i+1)}. {que['display_type']}: {role}", value=str(i)) | ||||
|             else: | ||||
|                 options.add_option(label=f"{str(i+1)}. {que['display_type']}", value=str(i)) | ||||
|         view.add_item(options) | ||||
|         await interaction.response.edit_message(view=view) | ||||
| 
 | ||||
|  | @ -422,7 +426,11 @@ class ActionDeclineEditorView(discord.ui.View): | |||
|         actions = GuildAppDB.get_actions(str(interaction.guild.id), self.application_name, action_type=ActionInteraction.DECLINE) | ||||
|         options.set_action_type(ActionInteraction.DECLINE) | ||||
|         for i, que in enumerate(actions): | ||||
|             options.add_option(label=f"{str(i+1)}. {que}", value=str(i)) | ||||
|             if que["action_type"] == "add_role": | ||||
|                 role = interaction.guild.get_role(que["data"]["role_id"]).name | ||||
|                 options.add_option(label=f"{str(i+1)}. {que['display_type']}: {role}", value=str(i)) | ||||
|             else: | ||||
|                 options.add_option(label=f"{str(i+1)}. {que['display_type']}", value=str(i)) | ||||
|         view.add_item(options) | ||||
|         await interaction.response.edit_message(view=view) | ||||
| 
 | ||||
|  | @ -474,7 +482,7 @@ class RemoveActionSelect(discord.ui.Select): | |||
| 
 | ||||
|     async def callback(self, interaction: discord.Interaction): | ||||
|         self.disabled = True | ||||
|         GuildAppDB.remove_action(str(interaction.guild.id), self.app_name, int(self.values[0])+1) | ||||
|         GuildAppDB.remove_action(str(interaction.guild.id), self.app_name, self.action_type, int(self.values[0])+1) | ||||
|         if self.action_type == ActionInteraction.ACCEPT: | ||||
|             editor = ActionAcceptEditorView(str(interaction.guild.id), self.app_name) | ||||
|             embed = get_actions_embed(str(interaction.guild.id), self.app_name, ActionInteraction.ACCEPT) | ||||
|  | @ -580,7 +588,7 @@ class ApplicationStartButtonView(discord.ui.View): | |||
| 
 | ||||
|         msg = await channel.send(embed=embed, view=appView) | ||||
| 
 | ||||
|         MessageDB.add_application_msg(msg.id, interaction.user.id, interaction.guild.id) | ||||
|         MessageDB.add_application_msg(msg.id, interaction.user.id, interaction.guild.id, app_name) | ||||
| 
 | ||||
|         await user.send('Thank you for applying!') | ||||
| 
 | ||||
|  | @ -598,7 +606,7 @@ class ApplicationButtonsView(discord.ui.View): | |||
|     async def accept(self, button: discord.ui.Button, interaction: discord.Interaction): | ||||
|         msg_id = str(interaction.message.id) | ||||
| 
 | ||||
|         user_id, guild_id = MessageDB.get_application_msg(msg_id) | ||||
|         user_id, guild_id, app_name = MessageDB.get_application_msg(msg_id) | ||||
| 
 | ||||
|         modal = ApplicationModal(title=f"Accepting: {bot.get_user(user_id).display_name}") | ||||
|         modal.set_action("acc") | ||||
|  | @ -613,7 +621,7 @@ class ApplicationButtonsView(discord.ui.View): | |||
|     async def decline(self, button: discord.ui.Button, interaction: discord.Interaction): | ||||
|         msg_id = str(interaction.message.id) | ||||
| 
 | ||||
|         user_id, guild_id = MessageDB.get_application_msg(msg_id) | ||||
|         user_id, guild_id, app_name = MessageDB.get_application_msg(msg_id) | ||||
| 
 | ||||
|         modal = ApplicationModal(title=f"Declining: {bot.get_user(user_id).display_name}") | ||||
|         modal.set_action("dec") | ||||
|  | @ -629,13 +637,26 @@ class ApplicationModal(discord.ui.Modal): | |||
|     async def callback(self, interaction: discord.Interaction): | ||||
|         reason = self.children[0].value | ||||
|         msg_id = str(interaction.message.id) | ||||
|         user_id, guild_id = MessageDB.get_application_msg(msg_id) | ||||
|         user_id, guild_id, app_name = MessageDB.get_application_msg(msg_id) | ||||
|         if self.action == "acc": | ||||
|             user = await bot.get_user(user_id).create_dm() | ||||
|             await user.send(f"Your application has been accepted!") | ||||
|             await user.send(f"Reason: {reason}") | ||||
|             await interaction.response.send_message(content="Application accepted", ephemeral=True) | ||||
| 
 | ||||
|             role = get(interaction.message.guild.roles, name="CreatTopian") | ||||
| 
 | ||||
|             actions = GuildAppDB.get_actions(str(guild_id), app_name, ActionInteraction.ACCEPT) | ||||
|             for i in actions: | ||||
|                 if i["action_type"] == "add_role": | ||||
|                     role = interaction.message.guild.get_role(int(i["data"]["role_id"])) | ||||
|                     user = interaction.message.guild.get_member(int(user_id)) | ||||
|                     await user.add_roles(role) | ||||
|                 else: | ||||
|                     print("unknown action") | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|             #await discord.utils.get(interaction.message.guild.members, id=int(user_id)).add_roles(role) | ||||
|             emb = interaction.message.embeds[0] | ||||
|             emb.colour = discord.Colour.green() | ||||
|  | @ -646,11 +667,24 @@ class ApplicationModal(discord.ui.Modal): | |||
|             view = discord.ui.View.from_message(interaction.message) | ||||
|             view.disable_all_items() | ||||
|             await interaction.followup.edit_message(message_id = interaction.message.id, view = view) | ||||
| 
 | ||||
| 
 | ||||
|         if self.action == "dec": | ||||
|             user = await bot.get_user(user_id).create_dm() | ||||
|             await user.send(f"Your application has been declined.") | ||||
|             await user.send(f"Reason: {reason}") | ||||
|             await interaction.response.send_message(content="Application declined", ephemeral=True) | ||||
| 
 | ||||
|             actions = GuildAppDB.get_actions(str(guild_id), app_name, ActionInteraction.DECLINE) | ||||
|             for i in actions: | ||||
|                 if i["action_type"] == "add_role": | ||||
|                     role = interaction.message.guild.get_role(int(i["data"]["role_id"])) | ||||
|                     user = interaction.message.guild.get_member(int(user_id)) | ||||
|                     await user.add_roles(role) | ||||
|                 else: | ||||
|                     print("unknown action") | ||||
| 
 | ||||
| 
 | ||||
|             emb = interaction.message.embeds[0] | ||||
|             emb.colour = discord.Colour.red() | ||||
|             embed = discord.Embed(title='Declined') | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue