@@ -22,6 +22,7 @@ export const communityWizard = new Scenes.WizardScene<CommunityContext>(
2222
2323 const {
2424 name,
25+ language,
2526 currencies,
2627 group,
2728 channels,
@@ -61,6 +62,7 @@ export const communityWizard = new Scenes.WizardScene<CommunityContext>(
6162 }
6263
6364 if ( undefined === name ) return createCommunitySteps . name ( ctx ) ;
65+ if ( undefined === language ) return createCommunitySteps . language ( ctx ) ;
6466 if ( undefined === currencies ) return createCommunitySteps . currencies ( ctx ) ;
6567 if ( undefined === group ) return createCommunitySteps . group ( ctx ) ;
6668 if ( undefined === channels ) return createCommunitySteps . channels ( ctx ) ;
@@ -71,6 +73,7 @@ export const communityWizard = new Scenes.WizardScene<CommunityContext>(
7173
7274 const community = new Community ( {
7375 name,
76+ language,
7477 currencies,
7578 group,
7679 order_channels : channels ,
@@ -150,6 +153,38 @@ const createCommunitySteps = {
150153
151154 return ctx . wizard . next ( ) ;
152155 } ,
156+ async language ( ctx : CommunityContext ) {
157+ const prompt = await createCommunityPrompts . language ( ctx ) ;
158+
159+ ctx . wizard . state . handler = async ( ctx : CommunityContext ) => {
160+ const text = ctx ?. message ?. text ;
161+ if ( ! text ) {
162+ await ctx . deleteMessage ( ) ;
163+ return ctx . telegram . deleteMessage ( prompt . chat . id , prompt . message_id ) ;
164+ }
165+
166+ ctx . wizard . state . error = null ;
167+ const lang = text . trim ( ) . toLowerCase ( ) ;
168+
169+ // Check if language is valid
170+ const validLanguages = [ 'en' , 'es' , 'fr' , 'de' , 'it' , 'pt' , 'ru' , 'uk' , 'ko' , 'fa' ] ;
171+ if ( ! validLanguages . includes ( lang ) ) {
172+ ctx . telegram . deleteMessage ( ctx . chat ! . id , ctx . message ! . message_id ) ;
173+ ctx . wizard . state . error = ctx . i18n . t ( 'wizard_community_invalid_language' ) ;
174+ return await ctx . wizard . state . updateUI ( ) ;
175+ }
176+
177+ ctx . wizard . state . language = lang ;
178+ await ctx . wizard . state . updateUI ( ) ;
179+ await ctx . telegram . deleteMessage (
180+ ctx . message ! . chat . id ,
181+ ctx . message ! . message_id
182+ ) ;
183+ return ctx . telegram . deleteMessage ( prompt . chat . id , prompt . message_id ) ;
184+ } ;
185+
186+ return ctx . wizard . next ( ) ;
187+ } ,
153188 async currencies ( ctx : CommunityContext ) {
154189 const prompt = await createCommunityPrompts . currencies ( ctx ) ;
155190
@@ -427,6 +462,9 @@ const createCommunityPrompts = {
427462 async name ( ctx : CommunityContext ) {
428463 return ctx . reply ( ctx . i18n . t ( 'wizard_community_enter_name' ) ) ;
429464 } ,
465+ async language ( ctx : CommunityContext ) {
466+ return ctx . reply ( ctx . i18n . t ( 'wizard_community_enter_language' ) ) ;
467+ } ,
430468 async currencies ( ctx : CommunityContext ) {
431469 return ctx . reply ( ctx . i18n . t ( 'wizard_community_enter_currency' ) ) ;
432470 } ,
@@ -838,6 +876,47 @@ export const updateDisputeChannelCommunityWizard = new Scenes.WizardScene(
838876 }
839877) ;
840878
879+ export const updateLanguageCommunityWizard = new Scenes . WizardScene (
880+ 'UPDATE_LANGUAGE_COMMUNITY_WIZARD_SCENE_ID' ,
881+ async ( ctx : CommunityContext ) => {
882+ try {
883+ const { community } = ctx . wizard . state ;
884+ let message = ctx . i18n . t ( 'language' ) + ': ' + ( community . language || 'en' ) + '\n\n' ;
885+ message += ctx . i18n . t ( 'wizard_community_enter_language' ) + '\n\n' ;
886+ message += ctx . i18n . t ( 'wizard_to_exit' ) ;
887+ await ctx . reply ( message ) ;
888+
889+ return ctx . wizard . next ( ) ;
890+ } catch ( error ) {
891+ logger . error ( error ) ;
892+ ctx . scene . leave ( ) ;
893+ }
894+ } ,
895+ async ( ctx : CommunityContext ) => {
896+ try {
897+ if ( ctx . message === undefined ) return ctx . scene . leave ( ) ;
898+
899+ const lang = ctx . message . text . trim ( ) . toLowerCase ( ) ;
900+ // Check if language is valid
901+ const validLanguages = [ 'en' , 'es' , 'fr' , 'de' , 'it' , 'pt' , 'ru' , 'uk' , 'ko' , 'fa' ] ;
902+ if ( ! validLanguages . includes ( lang ) ) {
903+ ctx . deleteMessage ( ) ;
904+ return await ctx . reply ( ctx . i18n . t ( 'wizard_community_invalid_language' ) ) ;
905+ }
906+
907+ const { community } = ctx . wizard . state ;
908+ community . language = lang ;
909+ await community . save ( ) ;
910+ await ctx . reply ( ctx . i18n . t ( 'operation_successful' ) ) ;
911+
912+ return ctx . scene . leave ( ) ;
913+ } catch ( error ) {
914+ logger . error ( error ) ;
915+ ctx . scene . leave ( ) ;
916+ }
917+ }
918+ ) ;
919+
841920export const addEarningsInvoiceWizard = new Scenes . WizardScene (
842921 'ADD_EARNINGS_INVOICE_WIZARD_SCENE_ID' ,
843922 async ( ctx : CommunityContext ) => {
0 commit comments