@@ -160,5 +160,50 @@ function updateBot(){
160160 }
161161 }
162162 }
163+
164+ $ stmt = $ connection ->prepare ("SELECT * FROM `setting` WHERE `type` = 'BOT_STATES' " );
165+ $ stmt ->execute ();
166+ $ isExists = $ stmt ->get_result ();
167+ $ stmt ->close ();
168+ if ($ isExists ->num_rows >0 ){
169+
170+ $ botState = $ isExists ->fetch_assoc ()['value ' ];
171+ if (!is_null ($ botState )) $ botState = json_decode ($ botState ,true );
172+ else $ botState = array ();
173+
174+ if (!isset ($ botState ['USDRate ' ]) && !isset ($ botState ['TRXRate ' ])){
175+ $ query = "UPDATE `setting` SET `value` = ? WHERE `type` = 'BOT_STATES' " ;
176+
177+ $ rate = json_decode (file_get_contents ("https://api.changeto.technology/api/rate " ),true )['result ' ];
178+ if (!empty ($ rate ['USD ' ])) $ botState ['USDRate ' ] = $ rate ['USD ' ];
179+ if (!empty ($ rate ['TRX ' ])) $ botState ['TRXRate ' ] = $ rate ['TRX ' ];
180+
181+ $ newData = json_encode ($ botState );
182+
183+ $ stmt = $ connection ->prepare ($ query );
184+ $ stmt ->bind_param ("s " , $ newData );
185+ $ stmt ->execute ();
186+ $ stmt ->close ();
187+ }
188+ }
189+ else {
190+ $ query = "INSERT INTO `setting` (`type`, `value`) VALUES ('BOT_STATES', ?) " ;
191+
192+ $ botState = array ();
193+
194+ $ rate = json_decode (file_get_contents ("https://api.changeto.technology/api/rate " ),true )['result ' ];
195+ if (!empty ($ rate ['USD ' ])) $ botState ['USDRate ' ] = $ rate ['USD ' ];
196+ if (!empty ($ rate ['TRX ' ])) $ botState ['TRXRate ' ] = $ rate ['TRX ' ];
197+
198+ $ newData = json_encode ($ botState );
199+
200+ $ stmt = $ connection ->prepare ($ query );
201+ $ stmt ->bind_param ("s " , $ newData );
202+ $ stmt ->execute ();
203+ $ stmt ->close ();
204+ }
205+
206+
207+
163208}
164209?>
0 commit comments