1- from discord import Colour , DMChannel , Embed , Member , Message
1+ import discord
2+ from discord import Colour , Embed , Member , app_commands
23from discord .ext import commands
34from discord .ext .commands import Context
5+
6+ from slaobot import SlaoBot
47from utils .config import settings
58
69
10+ class SignUpModal (discord .ui .Modal , title = 'Информация о себе' ):
11+ name = discord .ui .TextInput (
12+ label = 'Твой имя' ,
13+ placeholder = 'Как тебя зовут' ,
14+ max_length = 100 ,
15+ min_length = 2 ,
16+ )
17+
18+ character = discord .ui .TextInput (
19+ label = 'Имя персонажа' ,
20+ placeholder = 'Имя основного персонажа' ,
21+ max_length = 100 ,
22+ min_length = 2 ,
23+ )
24+
25+ class_spec = discord .ui .TextInput (
26+ label = 'Класс и специализация' ,
27+ placeholder = 'Класс и основная специализация' ,
28+ max_length = 100 ,
29+ min_length = 2 ,
30+ )
31+
32+ trade_skill = discord .ui .TextInput (
33+ label = 'Профессии' ,
34+ placeholder = 'Профессии и специализация в профессии, если есть' ,
35+ style = discord .TextStyle .long ,
36+ required = False ,
37+ max_length = 100 ,
38+ min_length = 2 ,
39+ )
40+
41+ twinks = discord .ui .TextInput (
42+ label = 'Твинки' ,
43+ placeholder = 'Имена твинков и их класс' ,
44+ style = discord .TextStyle .long ,
45+ required = False ,
46+ max_length = 100 ,
47+ min_length = 2 ,
48+ )
49+
50+ async def on_submit (self , interaction : discord .Interaction ):
51+
52+ signup_channel = interaction .client .get_channel (settings .signup_channel_id )
53+
54+ if signup_channel :
55+ signup_embed = Embed (title = 'Новая заявка' ,
56+ description = 'Больше Адептов!!' ,
57+ colour = Colour .light_gray ())
58+ signup_embed .add_field (name = 'Имя' , value = self .name .value )
59+ signup_embed .add_field (name = 'Персонаж' , value = self .character .value )
60+ signup_embed .add_field (name = 'Класс' , value = self .class_spec .value )
61+ signup_embed .add_field (name = 'Профы' , value = self .trade_skill .value )
62+ signup_embed .add_field (name = 'Твинки' , value = self .twinks .value )
63+ signup_embed .add_field (name = 'Пользователь' , value = format (interaction .user .mention ))
64+ if interaction .user .avatar :
65+ signup_embed .set_thumbnail (url = interaction .user .avatar .url )
66+ await signup_channel .send (embed = signup_embed )
67+
68+ await interaction .response .send_message (
69+ f'Спасибо, { self .name .value } ! Офицеры в скором времени выдадут права в Discord' ,
70+ ephemeral = True
71+ )
72+
73+ async def on_error (self , interaction : discord .Interaction , error : Exception ) -> None :
74+ await interaction .response .send_message ('Oops! Something went wrong.' , ephemeral = True )
75+
76+
777class SignUp (commands .Cog ):
8- def __init__ (self , bot ):
78+ def __init__ (self , bot : SlaoBot ):
979 """
1080 Cog to greet newcomers and give them some basic questionnaire.
1181
1282 :param bot: Bot instance
1383 """
14- self .bot = bot
84+ self .bot : SlaoBot = bot
1585
1686 @commands .Cog .listener ()
1787 async def on_member_join (self , member : Member ) -> None :
@@ -25,47 +95,24 @@ async def on_member_join(self, member: Member) -> None:
2595 intro_message = (f'Привет, { format (member .mention )} ! \r \n '
2696 'Приветствуем тебя на Discord сервере гильдии <Адепты Катаклизма>! \r \n '
2797 'Мы играем в Wrath of the Lich King Classic за Альянс на Пламегоре. \r \n '
28- 'Если хочешь вступить к нам в гильдию, то напиши мне + в ответ. \r \n '
98+ 'Если хочешь вступить к нам в гильдию, то напиши /signup в любом \r \n '
99+ 'канале Discord сервера Адептов. \r \n '
29100 'Удачного времяпрепровождения!' )
30101
31102 await dm_channel .send (content = intro_message )
32103
33- @commands .Cog .listener ()
34- async def on_message (self , message : Message ) -> None :
35- if not isinstance (message .channel , DMChannel ):
36- return
37- if message .author .bot :
38- return
39-
40- if message .content == '+' :
41- signup_form = (
42- 'Для получения доступа к гильдейским каналам мы бы хотели узнать тебя поближе. \r \n '
43- 'Пришли мне, пожалуйста, следующую информацию: \r \n '
44- '1. Твоё имя \r \n '
45- '2. Имя персонажа \r \n '
46- '3. Класс, специализация \r \n '
47- '4. Профессии, специализация \r \n '
48- '5. Имена персонажей твинков'
49- )
50-
51- await message .channel .send (signup_form )
52- elif len (message .content ) > 5 :
53- await message .channel .send ('Спасибо! Офицеры в скором времени выдадут права в Discord' )
54- signup_channel = self .bot .get_channel (settings .signup_channel_id )
55- if signup_channel :
56- signup_embed = Embed (title = 'Новая заявка' ,
57- description = message .content ,
58- colour = Colour .light_gray ())
59- signup_embed .add_field (name = 'Пользователь' , value = format (message .author .mention ))
60- if message .author .avatar :
61- signup_embed .set_thumbnail (url = message .author .avatar .url )
62- await signup_channel .send (embed = signup_embed )
63-
64104 @commands .command (hidden = True )
65105 async def emit_join (self , ctx : Context ) -> None :
66106 """Emit member_join event."""
67107 self .bot .dispatch ('member_join' , ctx .author )
68108
109+ @app_commands .command (description = 'SignUp Form' )
110+ async def signup (self , interaction : discord .Interaction ):
111+ # Send the modal with an instance of our `Feedback` class
112+ # Since modals require an interaction, they cannot be done as a response to a text command.
113+ # They can only be done as a response to either an application command or a button press.
114+ await interaction .response .send_modal (SignUpModal ())
115+
69116
70117async def setup (bot ):
71118 await bot .add_cog (SignUp (bot ))
0 commit comments