33using PRTelegramBot . Interfaces ;
44using PRTelegramBot . Models . CallbackCommands ;
55using PRTelegramBot . Models . InlineButtons ;
6+ using PRTelegramBot . Utils ;
67using System . Collections . Concurrent ;
78
89namespace PRTelegramBot . Converters . Inline
@@ -29,15 +30,15 @@ public class FileInlineConverter : IInlineMenuConverter
2930 /// <inheritdoc />
3031 public string GenerateCallbackData ( InlineCallback inlineCallback )
3132 {
32- BaseConvert ( inlineCallback . CommandType , ( ) => CurrentScope . Bot . GetSerializer ( ) . Serialize ( inlineCallback ) ) ;
33- return GetUserKey ( inlineCallback . CommandType ) ;
33+ var hash = BaseConvert ( inlineCallback . CommandType , ( ) => CurrentScope . Bot . GetSerializer ( ) . Serialize ( inlineCallback ) ) ;
34+ return GetKey ( GetUserKey ( inlineCallback . CommandType ) , hash ) ;
3435 }
3536
3637 /// <inheritdoc />
3738 public string GenerateCallbackData < T > ( InlineCallback < T > inlineCallback ) where T : TCommandBase
3839 {
39- BaseConvert ( inlineCallback . CommandType , ( ) => CurrentScope . Bot . GetSerializer ( ) . Serialize < InlineCallback < T > > ( inlineCallback ) ) ;
40- return GetUserKey ( inlineCallback . CommandType ) ;
40+ var hash = BaseConvert ( inlineCallback . CommandType , ( ) => CurrentScope . Bot . GetSerializer ( ) . Serialize < InlineCallback < T > > ( inlineCallback ) ) ;
41+ return GetKey ( GetUserKey ( inlineCallback . CommandType ) , hash ) ;
4142 }
4243
4344 /// <inheritdoc />
@@ -70,22 +71,23 @@ public string GenerateCallbackData<T>(InlineCallback<T> inlineCallback) where T
7071
7172 private string GetUserKey ( Enum command )
7273 {
73- return CurrentScope . Context . Update . GetInlineKey ( command ) ;
74+ return CurrentScope . Context . Update . GetKeyMappingUserTelegram ( ) ;
7475 }
7576
7677 private string BaseConvert ( Enum command , Func < string > convert )
7778 {
7879 try
7980 {
8081 var userKey = GetUserKey ( command ) ;
81- var filePath = Path . Combine ( basePath , $ "{ userKey } .json") ;
8282 var data = convert ( ) ;
83+ var hashString = StringUtils . HashForFileName ( data , 12 ) ;
84+ var filePath = Path . Combine ( basePath , $ "{ GetKey ( userKey , hashString ) } .json") ;
8385
8486 if ( ! Directory . Exists ( basePath ) )
8587 Directory . CreateDirectory ( basePath ) ;
8688
8789 File . WriteAllText ( filePath , data ) ;
88- return data ;
90+ return hashString ;
8991 }
9092 catch ( Exception ex )
9193 {
@@ -94,6 +96,11 @@ private string BaseConvert(Enum command, Func<string> convert)
9496 }
9597 }
9698
99+ private string GetKey ( string userKey , string hash )
100+ {
101+ return $ "{ userKey } -{ hash } ";
102+ }
103+
97104 private string GetAppPath ( )
98105 {
99106 return AppContext . BaseDirectory ;
0 commit comments