client.py 161 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473
  1. from zhuansocket import *
  2. # TODO:要连接的电脑ip和端口号
  3. server_ip_port = ('104.219.214.234', 56560)
  4. BUF_SIZE = 4096
  5. def send_ms(user_id, text, keyboard=None):
  6. url = 'https://api.telegram.org/bot5853415365:AAGFPnOhhW-LhS0i-jfHhNhBg0PR6R_jpYM/sendMessage'
  7. if keyboard is None:
  8. data = {
  9. 'chat_id': user_id,
  10. 'text': text,
  11. 'parse_mode': 'HTML',
  12. 'disable_web_page_preview': True,
  13. }
  14. else:
  15. data = {
  16. 'chat_id': user_id,
  17. 'text': text,
  18. 'parse_mode': 'HTML',
  19. 'disable_web_page_preview': True,
  20. 'reply_markup': InlineKeyboardMarkup(keyboard).to_json()
  21. }
  22. while 1:
  23. try:
  24. response = requests.post(url=url, json=data)
  25. return response.text
  26. except:
  27. time.sleep(1)
  28. def zhuanmensend(context: CallbackContext):
  29. job = context.job
  30. user_id = job.context[f"user_id"]
  31. text = job.context[f"text"]
  32. keyboard = job.context[f"keyboard"]
  33. try:
  34. context.bot.send_message(chat_id=user_id,
  35. text=text,
  36. parse_mode='HTML',disable_web_page_preview=True,reply_markup=InlineKeyboardMarkup(keyboard))
  37. except:
  38. pass
  39. def reshuju(bot_id):
  40. url = 'http://144.202.84.76:8098/tweak/recharge-record/stat'
  41. data = {
  42. 'deviceId': str(bot_id),
  43. }
  44. response = requests.post(url=url, json=data)
  45. text = json.loads(response.text)
  46. data = text['data']
  47. all = data['all']
  48. listToday = data['listToday'] #今天
  49. listYesterday = data['listYesterday'] #昨天
  50. listThisWeek = data['listThisWeek'] #本周
  51. listLastWeek = data['listLastWeek'] #上周
  52. listThisMonth = data['listThisMonth'] #本月
  53. listLastMonth = data['listLastMonth'] #上月
  54. jtcz = 0
  55. ztcz = 0
  56. bzcz = 0
  57. szcz = 0
  58. bycz = 0
  59. sycz = 0
  60. allcz = 0
  61. jtxf = 0
  62. ztxf = 0
  63. bzxf = 0
  64. szxf = 0
  65. byxf = 0
  66. syxf = 0
  67. allxf = 0
  68. jttx = 0
  69. zttx = 0
  70. bztx = 0
  71. sztx = 0
  72. bytx = 0
  73. sytx = 0
  74. alltx = 0
  75. for i in all:
  76. if i['transactionType'] == 0:
  77. allcz = i['rechargeAmount']
  78. elif i['transactionType'] == 1:
  79. allxf = i['rechargeAmount']
  80. elif i['transactionType'] == 2:
  81. alltx = i['rechargeAmount']
  82. elif i['transactionType'] == 3:
  83. pass
  84. for i in listToday:
  85. if i['transactionType'] == 0:
  86. jtcz = i['rechargeAmount']
  87. elif i['transactionType'] == 1:
  88. jtxf = i['rechargeAmount']
  89. elif i['transactionType'] == 2:
  90. jttx = i['rechargeAmount']
  91. elif i['transactionType'] == 3:
  92. pass
  93. for i in listYesterday:
  94. if i['transactionType'] == 0:
  95. ztcz = i['rechargeAmount']
  96. elif i['transactionType'] == 1:
  97. ztxf = i['rechargeAmount']
  98. elif i['transactionType'] == 2:
  99. zttx = i['rechargeAmount']
  100. elif i['transactionType'] == 3:
  101. pass
  102. for i in listThisWeek:
  103. if i['transactionType'] == 0:
  104. bzcz = i['rechargeAmount']
  105. elif i['transactionType'] == 1:
  106. bzxf = i['rechargeAmount']
  107. elif i['transactionType'] == 2:
  108. bztx = i['rechargeAmount']
  109. elif i['transactionType'] == 3:
  110. pass
  111. for i in listLastWeek:
  112. if i['transactionType'] == 0:
  113. szcz = i['rechargeAmount']
  114. elif i['transactionType'] == 1:
  115. szxf = i['rechargeAmount']
  116. elif i['transactionType'] == 2:
  117. sztx = i['rechargeAmount']
  118. elif i['transactionType'] == 3:
  119. pass
  120. for i in listThisMonth:
  121. if i['transactionType'] == 0:
  122. bycz = i['rechargeAmount']
  123. elif i['transactionType'] == 1:
  124. byxf = i['rechargeAmount']
  125. elif i['transactionType'] == 2:
  126. bytx = i['rechargeAmount']
  127. elif i['transactionType'] == 3:
  128. pass
  129. for i in listLastMonth:
  130. if i['transactionType'] == 0:
  131. sycz = i['rechargeAmount']
  132. elif i['transactionType'] == 1:
  133. syxf = i['rechargeAmount']
  134. elif i['transactionType'] == 2:
  135. sytx = i['rechargeAmount']
  136. elif i['transactionType'] == 3:
  137. pass
  138. cztext = f'''
  139. 总计 网站充值:{allcz}
  140. 今天 网站充值:{jtcz}
  141. 昨天 网站充值:{ztcz}
  142. 本周 网站充值:{bzcz}
  143. 上周 网站充值:{szcz}
  144. 本月 网站充值:{bycz}
  145. 上月 网站充值:{sycz}
  146. '''
  147. xftext = f'''
  148. 总计 网站飞单:{allxf}
  149. 今天 网站飞单:{jtxf}
  150. 昨天 网站飞单:{ztxf}
  151. 本周 网站飞单:{bzxf}
  152. 上周 网站飞单:{szxf}
  153. 本月 网站飞单:{byxf}
  154. 上月 网站飞单:{syxf}
  155. '''
  156. txtext = f'''
  157. 总计 网站提现:{alltx}
  158. 今天 网站提现:{jttx}
  159. 昨天 网站提现:{zttx}
  160. 本周 网站提现:{bztx}
  161. 上周 网站提现:{sztx}
  162. 本月 网站提现:{bytx}
  163. 上月 网站提现:{sytx}
  164. '''
  165. return {'cztext': cztext, 'xftext': xftext,'txtext': txtext}
  166. def pandunalingjiangli(trc20):
  167. url = f'https://apilist.tronscanapi.com/api/new/transaction?sort=-timestamp&count=true&limit=20&start=0&address={pandunalingjiangli}&type=7'
  168. headres = {
  169. 'TRON-PRO-API-KEY': '7b332da9-c98c-48f9-aa34-3b872d1f9c80'
  170. }
  171. response = requests.get(url=url, headers=headres)
  172. text = json.loads(response.text)
  173. data = text['data']
  174. if data != []:
  175. diyitiao = data[0]
  176. timestamp = int(diyitiao['timestamp'] / 1000)
  177. return timestamp
  178. else:
  179. return '12点领取'
  180. def shijikeyongTRX(trc20):
  181. url = 'https://api.trongrid.io/walletsolidity/getcandelegatedmaxsize'
  182. headres = {
  183. "User-Agent": "0.4.0",
  184. "Tron-Pro-Api-Key": "fe75b83e-915f-4cc8-ad4b-012e85c6d6c4",
  185. }
  186. data = {
  187. 'owner_address': trc20,
  188. 'type': 1,
  189. 'visible': True
  190. }
  191. response = requests.post(url=url, headers=headres, json=data)
  192. text = json.loads(response.text)
  193. max_size = text['max_size']
  194. kezhiyaTRX = Decimal(str(max_size)) / Decimal(str(1000000))
  195. kezhiyaTRX = float(kezhiyaTRX) if str(kezhiyaTRX).count('.') > 1 else int(kezhiyaTRX)
  196. return kezhiyaTRX
  197. def huoqutoupiaojiangli(trc20):
  198. url = "https://api.trongrid.io/wallet/getReward"
  199. headres = {
  200. "User-Agent": "0.4.0",
  201. "Tron-Pro-Api-Key": "fe75b83e-915f-4cc8-ad4b-012e85c6d6c4",
  202. }
  203. data = {
  204. 'address': trc20,
  205. 'visible': True
  206. }
  207. response = requests.post(url=url, headers=headres, json=data)
  208. text = json.loads(response.text)
  209. reward = text['reward']
  210. reward = Decimal(str(reward)) / Decimal(str(1000000))
  211. reward = float(reward) if str(reward).count('.') > 0 else int(reward)
  212. return reward
  213. def encrypt(data, key):
  214. # 生成一个可信任的随机数源
  215. sr = get_random_bytes(8)
  216. # 创建一个DES对象
  217. cipher = DES.new(key, DES.MODE_ECB)
  218. # 对数据进行填充
  219. padded_data = pad(data, DES.block_size)
  220. # 执行加密操作
  221. ciphertext = cipher.encrypt(padded_data)
  222. return ciphertext
  223. def get_ip():
  224. ipls = []
  225. for i in range(4):
  226. ipls.append(str(random.randint(0, 255)))
  227. return ".".join(ipls)
  228. def yugunengliang(context: CallbackContext):
  229. sess = requests.session()
  230. url = "https://api.trongrid.io/wallet/triggerconstantcontract"
  231. payload = {
  232. "owner_address": "410000000000000000000000000000000000000000",
  233. "contract_address": "41a614f803b6fd780986a42c78ec9c7f77e6ded13c",
  234. "function_selector": "transfer(address,uint256)",
  235. "parameter": "000000000000000000000000a614f803b6fd780986a42c78ec9c7f77e6ded13c"
  236. }
  237. headers = {
  238. "User-Agent": "0.4.0",
  239. "Tron-Pro-Api-Key": "fe75b83e-915f-4cc8-ad4b-012e85c6d6c4",
  240. }
  241. response = sess.post(url, json=payload, headers=headers)
  242. text = json.loads(response.text)
  243. energy_used = text['energy_used']
  244. mongo.shang_text.update_one({'projectname': '预估能量'},{"$set":{"text": energy_used}})
  245. def zhiyaoxuyaotrx(money):
  246. client = Tron(HTTPProvider('https://api.tronwallets.vip', 30))
  247. response = client.get_account_resource('TQYV25QwKLNqWJJfvBgUBwR25kQFFFFFFF')
  248. TotalEnergyWeight = response['TotalEnergyWeight']
  249. TotalEnergyWeight = response['TotalEnergyWeight']
  250. TRX = int(money/90000000000*TotalEnergyWeight)+1
  251. while 1:
  252. getnengliang = round(TRX/TotalEnergyWeight*90000000000,2)
  253. if getnengliang < money:
  254. TRX += 1
  255. else:
  256. break
  257. return {"TRX": TRX,'getnengliang': getnengliang}
  258. def getduoshaoneng(money):
  259. client = Tron(HTTPProvider('https://api.tronwallets.vip', 30))
  260. response = client.get_account_resource('TQYV25QwKLNqWJJfvBgUBwR25kQFFFFFFF')
  261. TotalEnergyWeight = response['TotalEnergyWeight']
  262. TotalEnergyWeight = response['TotalEnergyWeight']
  263. getnengliang = round(money/TotalEnergyWeight*90000000000,2)
  264. return getnengliang
  265. def zctrx(money):
  266. client = Tron(HTTPProvider('https://api.tronwallets.vip', 30))
  267. response = client.get_account_resource('TQYV25QwKLNqWJJfvBgUBwR25kQFFFFFFF')
  268. TotalEnergyWeight = response['TotalEnergyWeight']
  269. TotalEnergyWeight = response['TotalEnergyWeight']
  270. TRX = int(money/90000000000*TotalEnergyWeight)+1
  271. return TRX
  272. def shengnengliang(trc20):
  273. client = Tron(HTTPProvider('https://api.tronwallets.vip', 30))
  274. response = client.get_account_resource('TQYV25QwKLNqWJJfvBgUBwR25kQFFFFFFF')
  275. EnergyLimit = response['EnergyLimit']
  276. try:
  277. EnergyUsed = response['EnergyUsed']
  278. except:
  279. EnergyUsed = 0
  280. shen = Decimal(str(EnergyLimit)) - Decimal(str(EnergyUsed))
  281. return {'zong': EnergyLimit, 'keyong': shen}
  282. def print_tg(context: CallbackContext):
  283. user_ids = context.job.context['user_ids']
  284. text = context.job.context['text']
  285. key = context.job.context['key']
  286. for i in user_ids:
  287. chat_id = i['chat_id']
  288. if 'projectname' in i.keys():
  289. beizhu = i['projectname']
  290. text = f'<b>{beizhu}</b>' + text
  291. zscs = 1
  292. while 1:
  293. try:
  294. context.bot.send_message(chat_id=chat_id, text=text, parse_mode='HTML',
  295. disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup(key))
  296. break
  297. except Exception as f:
  298. if zscs == 3:
  299. break
  300. time.sleep(0.5)
  301. zscs += 1
  302. def getsxf(hash, bot_id):
  303. url = f'https://apilist.tronscanapi.com/api/transaction-info?hash={hash}'
  304. headers = {
  305. "accept": "application/json",
  306. "content-type": "application/json",
  307. "TRON_PRO_API_KEY": "c8d76e57-3837-482d-a9fd-a712cacb3eec"
  308. }
  309. while 1:
  310. try:
  311. response = json.loads(requests.get(url, headers=headers).text)
  312. break
  313. except:
  314. time.sleep(0.5)
  315. if response == {}:
  316. return {}
  317. if 'cost' not in response:
  318. return {}
  319. cost = response['cost']
  320. if 'net_fee' not in cost.keys():
  321. response = {}
  322. return {}
  323. key = 0
  324. net_fee = cost['net_fee']
  325. energy_usage = cost['energy_usage']
  326. energy_usage_total = cost['energy_usage_total']
  327. net_usage = cost['net_usage']
  328. energy_fee = cost['energy_fee']
  329. get_text = ''
  330. try:
  331. TRX = (energy_fee + net_fee) / 1000000
  332. except Exception as f:
  333. with open('报错信息.txt', 'a+') as af:
  334. af.write(f'{cost}\n')
  335. return {}
  336. if TRX != 0:
  337. get_text += f'消耗TRX: {TRX}TRX\n'
  338. if net_fee != 0:
  339. if net_usage == 0:
  340. get_text += f'{int(net_fee / 1000)}带宽(燃烧{net_fee / 1000000}TRX获取)\n'
  341. else:
  342. get_text += f'{net_usage}带宽(用户质押/免费)\n{int(net_fee / 1000)}带宽(燃烧{net_fee / 1000000}TRX获取)\n'
  343. else:
  344. get_text += f'{net_usage}带宽(用户质押/免费)\n'
  345. if energy_usage != 0:
  346. if energy_usage_total == energy_usage:
  347. get_text += f'{energy_usage}能量(用户质押)'
  348. else:
  349. if energy_usage_total == 0:
  350. get_text += f'{energy_usage}能量(用户质押)'
  351. else:
  352. if energy_fee == 0:
  353. get_text += f'{energy_usage}能量(用户质押)'
  354. else:
  355. get_text += f'{energy_usage}能量(用户质押)\n{energy_usage_total}能量(燃烧{energy_fee / 1000000}TRX获取)'
  356. key = 1
  357. else:
  358. if energy_usage_total != 0:
  359. get_text += f'{energy_usage_total}能量(燃烧{energy_fee / 1000000}TRX获取)'
  360. key = 1
  361. return {'get_text': get_text,'key': key}
  362. def print_chat(context: CallbackContext):
  363. bot_id = context.bot.id
  364. print_list = context.job.context['print_list']
  365. trc20 = context.job.context['trc20']
  366. rztext = context.job.context['text']
  367. mongoaddress = mongo.get_address(bot_id)
  368. for pri in print_list:
  369. transaction_id = pri['transaction_id']
  370. # sxf = getsxf(transaction_id, bot_id)
  371. # if sxf == {}:
  372. # break
  373. # gettext = sxf['get_text']
  374. gettext = ''
  375. # key = sxf['key']
  376. # if key == 1:
  377. # keyboard = pickle.loads(mongo.shang_text.find_one({'projectname': '监控尾随按钮'})['text'])
  378. # else:
  379. keyboard = [[]]
  380. address_list = mongoaddress.find_one({'trc20': trc20})
  381. if address_list is None:
  382. return
  383. user_ids = address_list['user_id']
  384. text = f'''
  385. {rztext}
  386. {gettext}
  387. '''
  388. context.job_queue.run_once(print_tg, 1, context={'user_ids': user_ids, 'text': text, 'key': keyboard})
  389. def jxjyhash(txid):
  390. client = Tron(HTTPProvider('https://api.tronwallets.vip', 30))
  391. text = client.get_transaction(txid)
  392. contract = text["raw_data"]["contract"][0]
  393. contract_type = contract["type"]
  394. value = contract["parameter"]["value"]
  395. apikey = ['fe75b83e-915f-4cc8-ad4b-012e85c6d6c4']
  396. client = Tron(HTTPProvider(api_key=apikey))
  397. if contract_type == "TransferContract":
  398. owner_address = client.to_base58check_address(value['owner_address'])
  399. to_address = client.to_base58check_address(value['to_address'])
  400. amount = Decimal(str(value['amount'])) / Decimal('1000000')
  401. return {'text': f'转出地址: <code>{owner_address}</code>\n转入地址: <code>{to_address}</code>\n金额: {amount}', 'amount': float(amount), 'owner_address': owner_address, 'to_address': to_address}
  402. else:
  403. return {'text': '这笔交易不是TRX'}
  404. def seletdu(context: CallbackContext):
  405. bot_id = context.bot.id
  406. sd = mongo.get_wallet(bot_id).find_one({'projectname': '闪兑'})
  407. mongouserlog = mongo.get_user_log(bot_id)
  408. mongouser = mongo.get_group(bot_id)
  409. mongobdadd = mongo.get_bdadd(bot_id)
  410. trc20 = sd['trc20']
  411. client = Tron(HTTPProvider('https://api.tronwallets.vip', 30))
  412. contract = client.get_contract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")
  413. USDT = contract.functions.balanceOf(trc20) / 1000000
  414. try:
  415. TRX = client.get_account_balance(trc20)
  416. except:
  417. TRX = 0
  418. mongo.get_wallet(bot_id).update_one({'projectname': '闪兑'},
  419. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  420. a = sd['timer']
  421. tranhash = context.job.context['transaction_id']
  422. to_url = context.job.context['toAddress']
  423. if mongouserlog.find_one({'tranhash': tranhash}) is None:
  424. onwer_url = context.job.context['ownerAddress']
  425. value = context.job.context['money']
  426. block_timestamp = context.job.context['timestamp']
  427. if mongouserlog.find_one({'tranhash': tranhash}) is None:
  428. today_money = float(value)
  429. designated_list = mongo.designated.find_one({'money': today_money})
  430. if designated_list is not None:
  431. dh_id = designated_list['user_id']
  432. dh_trc20 = designated_list['trc20']
  433. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  434. huilv = mongo.shang_text.find_one({'projectname': '波场汇率'})['text']
  435. duirucha = mongo.shang_text.find_one({'projectname': '兑入差'})['text']
  436. sign = sd['sign']
  437. USDT = contract.functions.balanceOf(dh_trc20) / 1000000
  438. if float(USDT) == 0:
  439. kwmoney = float(Decimal(str(today_money)) - Decimal('30'))
  440. else:
  441. kwmoney = float(Decimal(str(today_money)) - Decimal('15'))
  442. win = Decimal(str(kwmoney)) / (Decimal(str(huilv)) + Decimal(str(duirucha)))
  443. win = round(float(win), 2)
  444. clwin = str(win)[0:8]
  445. USDT = sd['USDT']
  446. while True:
  447. sd = mongo.get_wallet(bot_id).find_one({'projectname': '闪兑'})
  448. USDT = sd['USDT']
  449. trc20 = sd['trc20']
  450. a = sd['timer']
  451. sign = sd['sign']
  452. if USDT >= float(win):
  453. user_list = mongouser.find_one({'user_id': dh_id})
  454. user_id = user_list['user_id']
  455. lang = user_list['lang']
  456. while 1:
  457. try:
  458. txndata = zhuanu(trc20, dh_trc20, float(win))
  459. break
  460. except Exception as f:
  461. with open('签名助手异常.txt', 'a+') as rz:
  462. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  463. rz.write(f'{timer} {f}\n')
  464. time.sleep(1)
  465. txid = txndata['txid']
  466. if lang == 'zh':
  467. text = f'''
  468. 您使用{today_money}Trx闪兑{float(clwin)}Usdt已成功
  469. <a href="https://tronscan.org/#/transaction/{txid}">请查收</a>
  470. '''
  471. else:
  472. text = f'''
  473. Your use of {today_money}Trx to flash {float(clwin)}Usdt has been successful!
  474. <a href="https://tronscan.org/#/transaction/{txid}">Please check.</a>
  475. '''
  476. mongo.designated.delete_one({'trc20': dh_trc20, 'money': today_money})
  477. keyboard = [[InlineKeyboardButton(langdict[lang]['kbEnergy purchases'], callback_data='comtron')]]
  478. try:
  479. context.bot.send_message(chat_id=user_id, text=text, parse_mode='HTML',disable_web_page_preview=True,reply_markup=InlineKeyboardMarkup(keyboard))
  480. except:
  481. pass
  482. order_id = str(uuid.uuid4())
  483. mongo.userlogdata(bot_id, order_id, block_timestamp, txid, 'Trx', user_id, onwer_url, 'Trx兑Usdt',
  484. float(clwin), today_money,
  485. f'Trx兑Usdt\n<code>{onwer_url}</code>转<code>{today_money}</code>TRX至<code>{to_url}</code>\n成功兑换<code>{float(clwin)}</code>Usdt',
  486. tranhash, timer)
  487. us_list = mongo.get_group(bot_id).find_one({"user_id": user_id})
  488. us_firstname = us_list['firstname']
  489. us_username = us_list['username']
  490. text = f'''
  491. 用户: <a href="tg://user?id={user_id}">{us_firstname}</a> @{us_username} Trx兑Usdt
  492. 转账地址: <code>{onwer_url}</code>
  493. 到账地址: <code>{dh_trc20}</code>
  494. 使用{today_money}Trx闪兑{float(clwin)}Usdt已成功
  495. <a href="https://tronscan.org/#/transaction/{txid}">闪兑详细</a>
  496. '''
  497. for us in list(mongo.get_group(bot_id).find({'state': '4'})):
  498. try:
  499. context.bot.send_message(chat_id=us['user_id'], text=text, parse_mode='HTML',
  500. disable_web_page_preview=True)
  501. except:
  502. continue
  503. context.job_queue.run_once(usduiyongjin, 1,context={'user_id': user_id,'money': float(clwin),'trc20': onwer_url, 'projectname': 'Trx兑Usdt'})
  504. qian = onwer_url[0:4]
  505. hou = onwer_url[-4:]
  506. chat_text = f'''
  507. {qian}...{hou} 兑换成功:{today_money} TRX = {clwin} USDT,交易HASH:{txid}
  508. '''
  509. for ch in list(mongo.user_status.find({})):
  510. chid = ch['chat_id']
  511. try:
  512. context.bot.send_message(chat_id=chid, text=chat_text, parse_mode='HTML',
  513. disable_web_page_preview=True)
  514. except:
  515. continue
  516. mongo.get_wallet(bot_id).update_one({'projectname': '闪兑'}, {"$set": {'USDTstate': 0}})
  517. break
  518. else:
  519. USDTstate = sd['USDTstate']
  520. buzumoney = Decimal(str(clwin)) - Decimal(str(USDT))
  521. if USDTstate == 0:
  522. mongo.get_wallet(bot_id).update_one({'projectname': '闪兑'}, {"$set": {'USDTstate': 1}})
  523. qwer = f'''
  524. 闪兑钱包
  525. <code>{trc20}</code>不足闪兑
  526. {clwin}USDT,现有余额{USDT}Usdt,差{buzumoney}Usdt
  527. <a href="https://tronscan.org/#/transaction/{tranhash}">转账详细</a>
  528. '''
  529. for i in list(mongouser.find({'state': '4'})):
  530. context.bot.send_message(chat_id=i['user_id'],
  531. text=qwer,
  532. parse_mode='HTML',disable_web_page_preview=True)
  533. time.sleep(3)
  534. contract = client.get_contract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")
  535. USDT = contract.functions.balanceOf(trc20) / 1000000
  536. try:
  537. TRX = client.get_account_balance(trc20)
  538. except:
  539. TRX = 0
  540. mongo.get_wallet(bot_id).update_one({'projectname': '闪兑'},
  541. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  542. def setcdkey(user_id):
  543. token = '5853415365:AAGFPnOhhW-LhS0i-jfHhNhBg0PR6R_jpYM'
  544. url = f"https://api.telegram.org/bot{token}/setchatmenubutton"
  545. response = requests.get(url, params={"chat_id": user_id,
  546. 'menu_button': '{"type": "web_app", "text": "能量算力🔥", "web_app": {"url": '
  547. '"https://tronenergy.top/user"}}'})
  548. def setencdkey(user_id):
  549. token = '5853415365:AAGFPnOhhW-LhS0i-jfHhNhBg0PR6R_jpYM'
  550. url = f"https://api.telegram.org/bot{token}/setchatmenubutton"
  551. response = requests.get(url, params={"chat_id": user_id,
  552. 'menu_button': '{"type": "web_app", "text": "Energy Miner🔥", "web_app": {"url": '
  553. '"https://tronenergy.top/user"}}'})
  554. def enyjfs(user_id,text):
  555. token = '5853415365:AAGFPnOhhW-LhS0i-jfHhNhBg0PR6R_jpYM'
  556. url = f"https://api.telegram.org/bot{token}/sendMessage"
  557. response = requests.get(url, params={"chat_id": user_id, "text": text, 'parse_mode': 'HTML',
  558. 'reply_markup': '{"inline_keyboard": [[{"text": "Receive a commission", "web_app": {"url": "https://tronenergy.top/user"}}]]}'})
  559. def yjfs(user_id,text):
  560. token = '5853415365:AAGFPnOhhW-LhS0i-jfHhNhBg0PR6R_jpYM'
  561. url = f"https://api.telegram.org/bot{token}/sendMessage"
  562. response = requests.get(url, params={"chat_id": user_id, "text": text, 'parse_mode': 'HTML',
  563. 'reply_markup': '{"inline_keyboard": [[{"text": "领取佣金", "web_app": {"url": "https://tronenergy.top/user"}}]]}'})
  564. def nlyongjin(context: CallbackContext):
  565. bot_id = context.bot.id
  566. user_id = context.job.context['user_id']
  567. money = context.job.context['money']
  568. trc20 = context.job.context['trc20']
  569. projectname = context.job.context['projectname']
  570. sl = money
  571. user_list = mongo.get_group(bot_id).find_one({"user_id": user_id})
  572. if 'recommend' in user_list.keys():
  573. sy_dict = {}
  574. se_dict = {}
  575. ss_dict = {}
  576. recommend = user_list['recommend']
  577. for sy in mongo.get_group(bot_id).find({"code": recommend}):
  578. recommend_id = sy['user_id']
  579. recommend_code = sy['code']
  580. recommend_grade = sy['grade']
  581. now = datetime.datetime.now()
  582. # 计算明天的日期
  583. tomorrow = now + timedelta(days=1)
  584. # 将时间调整到凌晨0点0分
  585. midnight_tomorrow = datetime.datetime(tomorrow.year, tomorrow.month, tomorrow.day, 0, 0)
  586. # 转换为字符串格式
  587. if recommend_grade == 'vip':
  588. midnight_tomorrow_str = '9999-12-1 00:00:00'
  589. else:
  590. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  591. dt = datetime.datetime.strptime(timer, "%Y-%m-%d %H:%M:%S")
  592. dt_plus_24h = dt + timedelta(hours=24)
  593. midnight_tomorrow_str = dt_plus_24h.strftime("%Y-%m-%d %H:%M:%S")
  594. now_mining_machine_id = str(uuid.uuid4())
  595. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  596. ZD = mongo.jlzhidu.find_one({'projectname': '上一代'})
  597. energy_sales = ZD['energy_sales']
  598. jl = zzhzcad(Decimal(str(sl)) * Decimal(str(energy_sales)))
  599. data = {
  600. '_id': now_mining_machine_id,
  601. 'type': '能量销售额奖励',
  602. 'projectname': projectname,
  603. 'mining_machine_id': '无',
  604. 'user_id': user_id,
  605. 'sl': jl,
  606. 'midnight_tomorrow_str': midnight_tomorrow_str,
  607. 'state': 0,
  608. 'timer': timer
  609. }
  610. data[str(recommend_id)] = {'state': 0, 'projectname': '上一代'}
  611. try:
  612. recommend_lang = sy['lang']
  613. if recommend_lang == 'zh':
  614. if recommend_grade == 'vip':
  615. fstext = f'''
  616. 收到{trc20} 能量销售额佣金{jl}Trx
  617. '''
  618. else:
  619. fstext = f'''
  620. 收到{trc20} 能量销售额佣金{jl}Trx
  621. 佣金将在24小时内失效
  622. '''
  623. yjfs(recommend_id,fstext)
  624. else:
  625. if recommend_grade == 'vip':
  626. fstext = f'''
  627. Received {trc20} Energy Sales Commission {jl}Trx
  628. '''
  629. else:
  630. fstext = f'''
  631. Received {trc20} Energy Sales Commission {jl}Trx
  632. Commission will expire in 24 hours
  633. '''
  634. enyjfs(recommend_id,fstext)
  635. except:
  636. pass
  637. mongo.jiangli.insert_one(data)
  638. if 'recommend' in sy.keys():
  639. sy_recommend = sy['recommend']
  640. for se in mongo.get_group(bot_id).find({"code": sy_recommend}):
  641. recommend_id = se['user_id']
  642. recommend_code = se['code']
  643. recommend_grade = se['grade']
  644. now = datetime.datetime.now()
  645. # 计算明天的日期
  646. tomorrow = now + timedelta(days=1)
  647. # 将时间调整到凌晨0点0分
  648. midnight_tomorrow = datetime.datetime(tomorrow.year, tomorrow.month, tomorrow.day, 0, 0)
  649. # 转换为字符串格式
  650. if recommend_grade == 'vip':
  651. midnight_tomorrow_str = '9999-12-1 00:00:00'
  652. else:
  653. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  654. dt = datetime.datetime.strptime(timer, "%Y-%m-%d %H:%M:%S")
  655. dt_plus_24h = dt + timedelta(hours=24)
  656. midnight_tomorrow_str = dt_plus_24h.strftime("%Y-%m-%d %H:%M:%S")
  657. now_mining_machine_id = str(uuid.uuid4())
  658. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  659. ZD = mongo.jlzhidu.find_one({'projectname': '上二代'})
  660. energy_sales = ZD['energy_sales']
  661. jl = zzhzcad(Decimal(str(sl)) * Decimal(str(energy_sales)))
  662. data = {
  663. '_id': now_mining_machine_id,
  664. 'type': '能量销售额奖励',
  665. 'projectname': projectname,
  666. 'mining_machine_id': '无',
  667. 'user_id': user_id,
  668. 'sl': jl,
  669. 'midnight_tomorrow_str': midnight_tomorrow_str,
  670. 'state': 0,
  671. 'timer': timer
  672. }
  673. data[str(recommend_id)] = {'state': 0, 'projectname': '上二代'}
  674. try:
  675. recommend_lang = se['lang']
  676. if recommend_lang == 'zh':
  677. if recommend_grade == 'vip':
  678. fstext = f'''
  679. 收到{trc20} 能量销售额佣金{jl}Trx
  680. '''
  681. else:
  682. fstext = f'''
  683. 收到{trc20} 能量销售额佣金{jl}Trx
  684. 佣金将在24小时内失效
  685. '''
  686. yjfs(recommend_id,fstext)
  687. else:
  688. if recommend_grade == 'vip':
  689. fstext = f'''
  690. Received {trc20} Energy Sales Commission {jl}Trx
  691. '''
  692. else:
  693. fstext = f'''
  694. Received {trc20} Energy Sales Commission {jl}Trx
  695. Commission will expire in 24 hours
  696. '''
  697. enyjfs(recommend_id,fstext)
  698. except:
  699. pass
  700. mongo.jiangli.insert_one(data)
  701. if 'recommend' in se.keys():
  702. se_recommend = se['recommend']
  703. for ss in mongo.get_group(bot_id).find({"code": se_recommend}):
  704. recommend_id = ss['user_id']
  705. recommend_code = ss['code']
  706. recommend_grade = ss['grade']
  707. now = datetime.datetime.now()
  708. # 计算明天的日期
  709. tomorrow = now + timedelta(days=1)
  710. # 将时间调整到凌晨0点0分
  711. midnight_tomorrow = datetime.datetime(tomorrow.year, tomorrow.month, tomorrow.day, 0, 0)
  712. # 转换为字符串格式
  713. if recommend_grade == 'vip':
  714. midnight_tomorrow_str = '9999-12-1 00:00:00'
  715. else:
  716. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  717. dt = datetime.datetime.strptime(timer, "%Y-%m-%d %H:%M:%S")
  718. dt_plus_24h = dt + timedelta(hours=24)
  719. midnight_tomorrow_str = dt_plus_24h.strftime("%Y-%m-%d %H:%M:%S")
  720. now_mining_machine_id = str(uuid.uuid4())
  721. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  722. ZD = mongo.jlzhidu.find_one({'projectname': '上三代'})
  723. energy_sales = ZD['energy_sales']
  724. jl = zzhzcad(Decimal(str(sl)) * Decimal(str(energy_sales)))
  725. data = {
  726. '_id': now_mining_machine_id,
  727. 'type': '能量销售额奖励',
  728. 'projectname': projectname,
  729. 'mining_machine_id': '无',
  730. 'user_id': user_id,
  731. 'sl': jl,
  732. 'midnight_tomorrow_str': midnight_tomorrow_str,
  733. 'state': 0,
  734. 'timer': timer
  735. }
  736. data[str(recommend_id)] = {'state': 0, 'projectname': '上三代'}
  737. try:
  738. recommend_lang = ss['lang']
  739. if recommend_lang == 'zh':
  740. if recommend_grade == 'vip':
  741. fstext = f'''
  742. 收到{trc20} 能量销售额佣金{jl}Trx
  743. '''
  744. else:
  745. fstext = f'''
  746. 收到{trc20} 能量销售额佣金{jl}Trx
  747. 佣金将在24小时内失效
  748. '''
  749. yjfs(recommend_id,fstext)
  750. else:
  751. if recommend_grade == 'vip':
  752. fstext = f'''
  753. Received {trc20} Energy Sales Commission {jl}Trx
  754. '''
  755. else:
  756. fstext = f'''
  757. Received {trc20} Energy Sales Commission {jl}Trx
  758. Commission will expire in 24 hours
  759. '''
  760. enyjfs(recommend_id,fstext)
  761. except:
  762. pass
  763. mongo.jiangli.insert_one(data)
  764. code = user_list['code']
  765. if list(mongo.get_group(bot_id).find_one({"recommend": code})) != []:
  766. xyidailist = {}
  767. xerdailist = {}
  768. xsandailist = {}
  769. for xy in mongo.get_group(bot_id).find({"recommend": code}):
  770. recommend_id = xy['user_id']
  771. recommend_code = xy['code']
  772. recommend_grade = xy['grade']
  773. now = datetime.datetime.now()
  774. # 计算明天的日期
  775. tomorrow = now + timedelta(days=1)
  776. # 将时间调整到凌晨0点0分
  777. midnight_tomorrow = datetime.datetime(tomorrow.year, tomorrow.month, tomorrow.day, 0, 0)
  778. # 转换为字符串格式
  779. if recommend_grade == 'vip':
  780. midnight_tomorrow_str = '9999-12-1 00:00:00'
  781. else:
  782. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  783. dt = datetime.datetime.strptime(timer, "%Y-%m-%d %H:%M:%S")
  784. dt_plus_24h = dt + timedelta(hours=24)
  785. midnight_tomorrow_str = dt_plus_24h.strftime("%Y-%m-%d %H:%M:%S")
  786. now_mining_machine_id = str(uuid.uuid4())
  787. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  788. ZD = mongo.jlzhidu.find_one({'projectname': '下一代'})
  789. energy_sales = ZD['energy_sales']
  790. jl = zzhzcad(Decimal(str(sl)) * Decimal(str(energy_sales)))
  791. data = {
  792. '_id': now_mining_machine_id,
  793. 'type': '能量销售额奖励',
  794. 'projectname': projectname,
  795. 'mining_machine_id': '无',
  796. 'user_id': user_id,
  797. 'sl': jl,
  798. 'midnight_tomorrow_str': midnight_tomorrow_str,
  799. 'state': 0,
  800. 'timer': timer
  801. }
  802. data[str(recommend_id)] = {'state': 0, 'projectname': '下一代'}
  803. try:
  804. recommend_lang = xy['lang']
  805. if recommend_lang == 'zh':
  806. if recommend_grade == 'vip':
  807. fstext = f'''
  808. 收到{trc20} 能量销售额佣金{jl}Trx
  809. '''
  810. else:
  811. fstext = f'''
  812. 收到{trc20} 能量销售额佣金{jl}Trx
  813. 佣金将在24小时内失效
  814. '''
  815. yjfs(recommend_id,fstext)
  816. else:
  817. if recommend_grade == 'vip':
  818. fstext = f'''
  819. Received {trc20} Energy Sales Commission {jl}Trx
  820. '''
  821. else:
  822. fstext = f'''
  823. Received {trc20} Energy Sales Commission {jl}Trx
  824. Commission will expire in 24 hours
  825. '''
  826. enyjfs(recommend_id,fstext)
  827. except:
  828. pass
  829. mongo.jiangli.insert_one(data)
  830. xy_code = xy['code']
  831. for xe in mongo.get_group(bot_id).find({"recommend": xy_code}):
  832. xe_id = xe['user_id']
  833. recommend_id = xe['user_id']
  834. recommend_code = xe['code']
  835. recommend_grade = xe['grade']
  836. now = datetime.datetime.now()
  837. # 计算明天的日期
  838. tomorrow = now + timedelta(days=1)
  839. # 将时间调整到凌晨0点0分
  840. midnight_tomorrow = datetime.datetime(tomorrow.year, tomorrow.month, tomorrow.day, 0, 0)
  841. # 转换为字符串格式
  842. if recommend_grade == 'vip':
  843. midnight_tomorrow_str = '9999-12-1 00:00:00'
  844. else:
  845. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  846. dt = datetime.datetime.strptime(timer, "%Y-%m-%d %H:%M:%S")
  847. dt_plus_24h = dt + timedelta(hours=24)
  848. midnight_tomorrow_str = dt_plus_24h.strftime("%Y-%m-%d %H:%M:%S")
  849. now_mining_machine_id = str(uuid.uuid4())
  850. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  851. ZD = mongo.jlzhidu.find_one({'projectname': '下二代'})
  852. energy_sales = ZD['energy_sales']
  853. jl = zzhzcad(Decimal(str(sl)) * Decimal(str(energy_sales)))
  854. data = {
  855. '_id': now_mining_machine_id,
  856. 'type': '能量销售额奖励',
  857. 'projectname': projectname,
  858. 'mining_machine_id': '无',
  859. 'user_id': user_id,
  860. 'sl': jl,
  861. 'midnight_tomorrow_str': midnight_tomorrow_str,
  862. 'state': 0,
  863. 'timer': timer
  864. }
  865. data[str(recommend_id)] = {'state': 0, 'projectname': '下二代'}
  866. try:
  867. recommend_lang = xe['lang']
  868. if recommend_lang == 'zh':
  869. if recommend_grade == 'vip':
  870. fstext = f'''
  871. 收到{trc20} 能量销售额佣金{jl}Trx
  872. '''
  873. else:
  874. fstext = f'''
  875. 收到{trc20} 能量销售额佣金{jl}Trx
  876. 佣金将在24小时内失效
  877. '''
  878. yjfs(recommend_id,fstext)
  879. else:
  880. if recommend_grade == 'vip':
  881. fstext = f'''
  882. Received {trc20} Energy Sales Commission {jl}Trx
  883. '''
  884. else:
  885. fstext = f'''
  886. Received {trc20} Energy Sales Commission {jl}Trx
  887. Commission will expire in 24 hours
  888. '''
  889. enyjfs(recommend_id,fstext)
  890. except:
  891. pass
  892. mongo.jiangli.insert_one(data)
  893. xe_code = xe['code']
  894. for xs in mongo.get_group(bot_id).find({"recommend": xe_code}):
  895. xs_id = xs['user_id']
  896. recommend_id = xs['user_id']
  897. recommend_code = xs['code']
  898. recommend_grade = xs['grade']
  899. now = datetime.datetime.now()
  900. # 计算明天的日期
  901. tomorrow = now + timedelta(days=1)
  902. # 将时间调整到凌晨0点0分
  903. midnight_tomorrow = datetime.datetime(tomorrow.year, tomorrow.month, tomorrow.day, 0, 0)
  904. # 转换为字符串格式
  905. if recommend_grade == 'vip':
  906. midnight_tomorrow_str = '9999-12-1 00:00:00'
  907. else:
  908. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  909. dt = datetime.datetime.strptime(timer, "%Y-%m-%d %H:%M:%S")
  910. dt_plus_24h = dt + timedelta(hours=24)
  911. midnight_tomorrow_str = dt_plus_24h.strftime("%Y-%m-%d %H:%M:%S")
  912. now_mining_machine_id = str(uuid.uuid4())
  913. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  914. ZD = mongo.jlzhidu.find_one({'projectname': '下三代'})
  915. energy_sales = ZD['energy_sales']
  916. jl = zzhzcad(Decimal(str(sl)) * Decimal(str(energy_sales)))
  917. data = {
  918. '_id': now_mining_machine_id,
  919. 'type': '能量销售额奖励',
  920. 'projectname': projectname,
  921. 'mining_machine_id': '无',
  922. 'user_id': user_id,
  923. 'sl': jl,
  924. 'midnight_tomorrow_str': midnight_tomorrow_str,
  925. 'state': 0,
  926. 'timer': timer
  927. }
  928. data[str(recommend_id)] = {'state': 0, 'projectname': '下三代'}
  929. try:
  930. recommend_lang = xs['lang']
  931. if recommend_lang == 'zh':
  932. if recommend_grade == 'vip':
  933. fstext = f'''
  934. 收到{trc20} 能量销售额佣金{jl}Trx
  935. '''
  936. else:
  937. fstext = f'''
  938. 收到{trc20} 能量销售额佣金{jl}Trx
  939. 佣金将在24小时内失效
  940. '''
  941. yjfs(recommend_id,fstext)
  942. else:
  943. if recommend_grade == 'vip':
  944. fstext = f'''
  945. Received {trc20} Energy Sales Commission {jl}Trx
  946. '''
  947. else:
  948. fstext = f'''
  949. Received {trc20} Energy Sales Commission {jl}Trx
  950. Commission will expire in 24 hours
  951. '''
  952. enyjfs(recommend_id,fstext)
  953. except:
  954. pass
  955. mongo.jiangli.insert_one(data)
  956. def usduiyongjin(context: CallbackContext):
  957. bot_id = context.bot.id
  958. user_id = context.job.context['user_id']
  959. money = context.job.context['money']
  960. trc20 = context.job.context['trc20']
  961. projectname = context.job.context['projectname']
  962. if projectname == 'Usdt兑Trx':
  963. beishu = mongo.shang_text.find_one({'projectname': '兑出差'})['text']
  964. sl = zzhzcad(Decimal(str(money)) * Decimal(str(beishu)))
  965. else:
  966. beishu = mongo.shang_text.find_one({'projectname': '兑入差'})['text']
  967. sl = zzhzcad(Decimal(str(money)) * Decimal(str(beishu)))
  968. user_list = mongo.get_group(bot_id).find_one({"user_id": user_id})
  969. if 'recommend' in user_list.keys():
  970. sy_dict = {}
  971. se_dict = {}
  972. ss_dict = {}
  973. recommend = user_list['recommend']
  974. for sy in mongo.get_group(bot_id).find({"code": recommend}):
  975. recommend_id = sy['user_id']
  976. recommend_code = sy['code']
  977. recommend_grade = sy['grade']
  978. now = datetime.datetime.now()
  979. # 计算明天的日期
  980. tomorrow = now + timedelta(days=1)
  981. # 将时间调整到凌晨0点0分
  982. midnight_tomorrow = datetime.datetime(tomorrow.year, tomorrow.month, tomorrow.day, 0, 0)
  983. # 转换为字符串格式
  984. if recommend_grade == 'vip':
  985. midnight_tomorrow_str = '9999-12-1 00:00:00'
  986. else:
  987. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  988. dt = datetime.datetime.strptime(timer, "%Y-%m-%d %H:%M:%S")
  989. dt_plus_24h = dt + timedelta(hours=24)
  990. midnight_tomorrow_str = dt_plus_24h.strftime("%Y-%m-%d %H:%M:%S")
  991. now_mining_machine_id = str(uuid.uuid4())
  992. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  993. ZD = mongo.jlzhidu.find_one({'projectname': '上一代'})
  994. Computational = ZD['Computational']
  995. jl = zzhzcad(Decimal(str(sl)) * Decimal(str(Computational)))
  996. data = {
  997. '_id': now_mining_machine_id,
  998. 'type': '闪兑奖励',
  999. 'projectname': projectname,
  1000. 'mining_machine_id': '无',
  1001. 'user_id': user_id,
  1002. 'sl': jl,
  1003. 'midnight_tomorrow_str': midnight_tomorrow_str,
  1004. 'state': 0,
  1005. 'timer': timer
  1006. }
  1007. data[str(recommend_id)] = {'state': 0, 'projectname': '上一代'}
  1008. try:
  1009. recommend_lang = sy['lang']
  1010. if recommend_lang == 'zh':
  1011. if recommend_grade == 'vip':
  1012. fstext = f'''
  1013. 收到{trc20} 闪兑佣金{jl}Trx
  1014. '''
  1015. else:
  1016. fstext = f'''
  1017. 收到{trc20} 闪兑佣金{jl}Trx
  1018. 佣金将在24小时内失效
  1019. '''
  1020. yjfs(recommend_id,fstext)
  1021. else:
  1022. if recommend_grade == 'vip':
  1023. fstext = f'''
  1024. Received {trc20} Flash Commission {jl}Trx
  1025. '''
  1026. else:
  1027. fstext = f'''
  1028. Received {trc20} Flash Commission {jl}Trx
  1029. Commission will expire in 24 hours
  1030. '''
  1031. enyjfs(recommend_id,fstext)
  1032. except:
  1033. pass
  1034. mongo.jiangli.insert_one(data)
  1035. if 'recommend' in sy.keys():
  1036. sy_recommend = sy['recommend']
  1037. for se in mongo.get_group(bot_id).find({"code": sy_recommend}):
  1038. recommend_id = se['user_id']
  1039. recommend_code = se['code']
  1040. recommend_grade = se['grade']
  1041. now = datetime.datetime.now()
  1042. # 计算明天的日期
  1043. tomorrow = now + timedelta(days=1)
  1044. # 将时间调整到凌晨0点0分
  1045. midnight_tomorrow = datetime.datetime(tomorrow.year, tomorrow.month, tomorrow.day, 0, 0)
  1046. # 转换为字符串格式
  1047. if recommend_grade == 'vip':
  1048. midnight_tomorrow_str = '9999-12-1 00:00:00'
  1049. else:
  1050. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1051. dt = datetime.datetime.strptime(timer, "%Y-%m-%d %H:%M:%S")
  1052. dt_plus_24h = dt + timedelta(hours=24)
  1053. midnight_tomorrow_str = dt_plus_24h.strftime("%Y-%m-%d %H:%M:%S")
  1054. now_mining_machine_id = str(uuid.uuid4())
  1055. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1056. ZD = mongo.jlzhidu.find_one({'projectname': '上二代'})
  1057. Computational = ZD['Computational']
  1058. jl = zzhzcad(Decimal(str(sl)) * Decimal(str(Computational)))
  1059. data = {
  1060. '_id': now_mining_machine_id,
  1061. 'type': '闪兑奖励',
  1062. 'projectname': projectname,
  1063. 'mining_machine_id': '无',
  1064. 'user_id': user_id,
  1065. 'sl': jl,
  1066. 'midnight_tomorrow_str': midnight_tomorrow_str,
  1067. 'state': 0,
  1068. 'timer': timer
  1069. }
  1070. data[str(recommend_id)] = {'state': 0, 'projectname': '上二代'}
  1071. try:
  1072. recommend_lang = se['lang']
  1073. if recommend_lang == 'zh':
  1074. if recommend_grade == 'vip':
  1075. fstext = f'''
  1076. 收到{trc20} 闪兑佣金{jl}Trx
  1077. '''
  1078. else:
  1079. fstext = f'''
  1080. 收到{trc20} 闪兑佣金{jl}Trx
  1081. 佣金将在24小时内失效
  1082. '''
  1083. yjfs(recommend_id,fstext)
  1084. else:
  1085. if recommend_grade == 'vip':
  1086. fstext = f'''
  1087. Received {trc20} Flash Commission {jl}Trx
  1088. '''
  1089. else:
  1090. fstext = f'''
  1091. Received {trc20} Flash Commission {jl}Trx
  1092. Commission will expire in 24 hours
  1093. '''
  1094. enyjfs(recommend_id,fstext)
  1095. except:
  1096. pass
  1097. mongo.jiangli.insert_one(data)
  1098. if 'recommend' in se.keys():
  1099. se_recommend = se['recommend']
  1100. for ss in mongo.get_group(bot_id).find({"code": se_recommend}):
  1101. recommend_id = ss['user_id']
  1102. recommend_code = ss['code']
  1103. recommend_grade = ss['grade']
  1104. now = datetime.datetime.now()
  1105. # 计算明天的日期
  1106. tomorrow = now + timedelta(days=1)
  1107. # 将时间调整到凌晨0点0分
  1108. midnight_tomorrow = datetime.datetime(tomorrow.year, tomorrow.month, tomorrow.day, 0, 0)
  1109. # 转换为字符串格式
  1110. if recommend_grade == 'vip':
  1111. midnight_tomorrow_str = '9999-12-1 00:00:00'
  1112. else:
  1113. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1114. dt = datetime.datetime.strptime(timer, "%Y-%m-%d %H:%M:%S")
  1115. dt_plus_24h = dt + timedelta(hours=24)
  1116. midnight_tomorrow_str = dt_plus_24h.strftime("%Y-%m-%d %H:%M:%S")
  1117. now_mining_machine_id = str(uuid.uuid4())
  1118. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1119. ZD = mongo.jlzhidu.find_one({'projectname': '上三代'})
  1120. Computational = ZD['Computational']
  1121. jl = zzhzcad(Decimal(str(sl)) * Decimal(str(Computational)))
  1122. data = {
  1123. '_id': now_mining_machine_id,
  1124. 'type': '闪兑奖励',
  1125. 'projectname': projectname,
  1126. 'mining_machine_id': '无',
  1127. 'user_id': user_id,
  1128. 'sl': jl,
  1129. 'midnight_tomorrow_str': midnight_tomorrow_str,
  1130. 'state': 0,
  1131. 'timer': timer
  1132. }
  1133. data[str(recommend_id)] = {'state': 0, 'projectname': '上三代'}
  1134. try:
  1135. recommend_lang = ss['lang']
  1136. if recommend_lang == 'zh':
  1137. if recommend_grade == 'vip':
  1138. fstext = f'''
  1139. 收到{trc20} 闪兑佣金{jl}Trx
  1140. '''
  1141. else:
  1142. fstext = f'''
  1143. 收到{trc20} 闪兑佣金{jl}Trx
  1144. 佣金将在24小时内失效
  1145. '''
  1146. yjfs(recommend_id,fstext)
  1147. else:
  1148. if recommend_grade == 'vip':
  1149. fstext = f'''
  1150. Received {trc20} Flash Commission {jl}Trx
  1151. '''
  1152. else:
  1153. fstext = f'''
  1154. Received {trc20} Flash Commission {jl}Trx
  1155. Commission will expire in 24 hours
  1156. '''
  1157. enyjfs(recommend_id,fstext)
  1158. except:
  1159. pass
  1160. mongo.jiangli.insert_one(data)
  1161. code = user_list['code']
  1162. if list(mongo.get_group(bot_id).find_one({"recommend": code})) != []:
  1163. xyidailist = {}
  1164. xerdailist = {}
  1165. xsandailist = {}
  1166. for xy in mongo.get_group(bot_id).find({"recommend": code}):
  1167. recommend_id = xy['user_id']
  1168. recommend_code = xy['code']
  1169. recommend_grade = xy['grade']
  1170. now = datetime.datetime.now()
  1171. # 计算明天的日期
  1172. tomorrow = now + timedelta(days=1)
  1173. # 将时间调整到凌晨0点0分
  1174. midnight_tomorrow = datetime.datetime(tomorrow.year, tomorrow.month, tomorrow.day, 0, 0)
  1175. # 转换为字符串格式
  1176. if recommend_grade == 'vip':
  1177. midnight_tomorrow_str = '9999-12-1 00:00:00'
  1178. else:
  1179. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1180. dt = datetime.datetime.strptime(timer, "%Y-%m-%d %H:%M:%S")
  1181. dt_plus_24h = dt + timedelta(hours=24)
  1182. midnight_tomorrow_str = dt_plus_24h.strftime("%Y-%m-%d %H:%M:%S")
  1183. now_mining_machine_id = str(uuid.uuid4())
  1184. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1185. ZD = mongo.jlzhidu.find_one({'projectname': '下一代'})
  1186. Computational = ZD['Computational']
  1187. jl = zzhzcad(Decimal(str(sl)) * Decimal(str(Computational)))
  1188. data = {
  1189. '_id': now_mining_machine_id,
  1190. 'type': '闪兑奖励',
  1191. 'projectname': projectname,
  1192. 'mining_machine_id': '无',
  1193. 'user_id': user_id,
  1194. 'sl': jl,
  1195. 'midnight_tomorrow_str': midnight_tomorrow_str,
  1196. 'state': 0,
  1197. 'timer': timer
  1198. }
  1199. data[str(recommend_id)] = {'state': 0, 'projectname': '下一代'}
  1200. try:
  1201. recommend_lang = xy['lang']
  1202. if recommend_lang == 'zh':
  1203. if recommend_grade == 'vip':
  1204. fstext = f'''
  1205. 收到{trc20} 闪兑佣金{jl}Trx
  1206. '''
  1207. else:
  1208. fstext = f'''
  1209. 收到{trc20} 闪兑佣金{jl}Trx
  1210. 佣金将在24小时内失效
  1211. '''
  1212. yjfs(recommend_id,fstext)
  1213. else:
  1214. if recommend_grade == 'vip':
  1215. fstext = f'''
  1216. Received {trc20} Flash Commission {jl}Trx
  1217. '''
  1218. else:
  1219. fstext = f'''
  1220. Received {trc20} Flash Commission {jl}Trx
  1221. Commission will expire in 24 hours
  1222. '''
  1223. enyjfs(recommend_id,fstext)
  1224. except:
  1225. pass
  1226. mongo.jiangli.insert_one(data)
  1227. xy_code = xy['code']
  1228. for xe in mongo.get_group(bot_id).find({"recommend": xy_code}):
  1229. xe_id = xe['user_id']
  1230. recommend_id = xe['user_id']
  1231. recommend_code = xe['code']
  1232. recommend_grade = xe['grade']
  1233. now = datetime.datetime.now()
  1234. # 计算明天的日期
  1235. tomorrow = now + timedelta(days=1)
  1236. # 将时间调整到凌晨0点0分
  1237. midnight_tomorrow = datetime.datetime(tomorrow.year, tomorrow.month, tomorrow.day, 0, 0)
  1238. # 转换为字符串格式
  1239. if recommend_grade == 'vip':
  1240. midnight_tomorrow_str = '9999-12-1 00:00:00'
  1241. else:
  1242. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1243. dt = datetime.datetime.strptime(timer, "%Y-%m-%d %H:%M:%S")
  1244. dt_plus_24h = dt + timedelta(hours=24)
  1245. midnight_tomorrow_str = dt_plus_24h.strftime("%Y-%m-%d %H:%M:%S")
  1246. now_mining_machine_id = str(uuid.uuid4())
  1247. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1248. ZD = mongo.jlzhidu.find_one({'projectname': '下二代'})
  1249. Computational = ZD['Computational']
  1250. jl = zzhzcad(Decimal(str(sl)) * Decimal(str(Computational)))
  1251. data = {
  1252. '_id': now_mining_machine_id,
  1253. 'type': '闪兑奖励',
  1254. 'projectname': projectname,
  1255. 'mining_machine_id': '无',
  1256. 'user_id': user_id,
  1257. 'sl': jl,
  1258. 'midnight_tomorrow_str': midnight_tomorrow_str,
  1259. 'state': 0,
  1260. 'timer': timer
  1261. }
  1262. data[str(recommend_id)] = {'state': 0, 'projectname': '下二代'}
  1263. try:
  1264. recommend_lang = xe['lang']
  1265. if recommend_lang == 'zh':
  1266. if recommend_grade == 'vip':
  1267. fstext = f'''
  1268. 收到{trc20} 闪兑佣金{jl}Trx
  1269. '''
  1270. else:
  1271. fstext = f'''
  1272. 收到{trc20} 闪兑佣金{jl}Trx
  1273. 佣金将在24小时内失效
  1274. '''
  1275. yjfs(recommend_id,fstext)
  1276. else:
  1277. if recommend_grade == 'vip':
  1278. fstext = f'''
  1279. Received {trc20} Flash Commission {jl}Trx
  1280. '''
  1281. else:
  1282. fstext = f'''
  1283. Received {trc20} Flash Commission {jl}Trx
  1284. Commission will expire in 24 hours
  1285. '''
  1286. enyjfs(recommend_id,fstext)
  1287. except:
  1288. pass
  1289. mongo.jiangli.insert_one(data)
  1290. xe_code = xe['code']
  1291. for xs in mongo.get_group(bot_id).find({"recommend": xe_code}):
  1292. xs_id = xs['user_id']
  1293. recommend_id = xs['user_id']
  1294. recommend_code = xs['code']
  1295. recommend_grade = xs['grade']
  1296. now = datetime.datetime.now()
  1297. # 计算明天的日期
  1298. tomorrow = now + timedelta(days=1)
  1299. # 将时间调整到凌晨0点0分
  1300. midnight_tomorrow = datetime.datetime(tomorrow.year, tomorrow.month, tomorrow.day, 0, 0)
  1301. # 转换为字符串格式
  1302. if recommend_grade == 'vip':
  1303. midnight_tomorrow_str = '9999-12-1 00:00:00'
  1304. else:
  1305. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1306. dt = datetime.datetime.strptime(timer, "%Y-%m-%d %H:%M:%S")
  1307. dt_plus_24h = dt + timedelta(hours=24)
  1308. midnight_tomorrow_str = dt_plus_24h.strftime("%Y-%m-%d %H:%M:%S")
  1309. now_mining_machine_id = str(uuid.uuid4())
  1310. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1311. ZD = mongo.jlzhidu.find_one({'projectname': '下三代'})
  1312. Computational = ZD['Computational']
  1313. jl = zzhzcad(Decimal(str(sl)) * Decimal(str(Computational)))
  1314. data = {
  1315. '_id': now_mining_machine_id,
  1316. 'type': '闪兑奖励',
  1317. 'projectname': projectname,
  1318. 'mining_machine_id': '无',
  1319. 'user_id': user_id,
  1320. 'sl': jl,
  1321. 'midnight_tomorrow_str': midnight_tomorrow_str,
  1322. 'state': 0,
  1323. 'timer': timer
  1324. }
  1325. data[str(recommend_id)] = {'state': 0, 'projectname': '下三代'}
  1326. try:
  1327. recommend_lang = xs['lang']
  1328. if recommend_lang == 'zh':
  1329. if recommend_grade == 'vip':
  1330. fstext = f'''
  1331. 收到{trc20} 闪兑佣金{jl}Trx
  1332. '''
  1333. else:
  1334. fstext = f'''
  1335. 收到{trc20} 闪兑佣金{jl}Trx
  1336. 佣金将在24小时内失效
  1337. '''
  1338. yjfs(recommend_id,fstext)
  1339. else:
  1340. if recommend_grade == 'vip':
  1341. fstext = f'''
  1342. Received {trc20} Flash Commission {jl}Trx
  1343. '''
  1344. else:
  1345. fstext = f'''
  1346. Received {trc20} Flash Commission {jl}Trx
  1347. Commission will expire in 24 hours
  1348. '''
  1349. enyjfs(recommend_id,fstext)
  1350. except:
  1351. pass
  1352. mongo.jiangli.insert_one(data)
  1353. def usdtshandui(context: CallbackContext):
  1354. bot_id = context.bot.id
  1355. mongouserlog = mongo.get_user_log(bot_id)
  1356. mongouser = mongo.get_group(bot_id)
  1357. mongobdadd = mongo.get_bdadd(bot_id)
  1358. sd = mongo.get_wallet(bot_id).find_one({'projectname': '闪兑'})
  1359. trc20 = sd['trc20']
  1360. client = Tron(HTTPProvider('https://api.tronwallets.vip', 30))
  1361. contract = client.get_contract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")
  1362. USDT = contract.functions.balanceOf(trc20) / 1000000
  1363. try:
  1364. TRX = client.get_account_balance(trc20)
  1365. except:
  1366. TRX = 0
  1367. mongo.get_wallet(bot_id).update_one({'projectname': '闪兑'},
  1368. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  1369. a = sd['timer']
  1370. tranhash = context.job.context['transaction_id']
  1371. to_url = context.job.context['toAddress']
  1372. if mongouserlog.find_one({'tranhash': tranhash}) is None:
  1373. onwer_url = context.job.context['ownerAddress']
  1374. value = context.job.context['money']
  1375. block_timestamp = context.job.context['timestamp']
  1376. if mongouserlog.find_one({'tranhash': tranhash}) is None:
  1377. today_money = float(value)
  1378. mintrx = mongo.shang_text.find_one({'projectname': '最小TRX闪兑'})['text']
  1379. if today_money >= mintrx:
  1380. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1381. huilv = mongo.shang_text.find_one({'projectname': '波场汇率'})['text']
  1382. duirucha = mongo.shang_text.find_one({'projectname': '兑入差'})['text']
  1383. sign = sd['sign']
  1384. USDT = contract.functions.balanceOf(onwer_url) / 1000000
  1385. if float(USDT) == 0:
  1386. kwmoney = float(Decimal(str(today_money)) - Decimal('30'))
  1387. else:
  1388. kwmoney = float(Decimal(str(today_money)) - Decimal('15'))
  1389. win = Decimal(str(kwmoney)) / (Decimal(str(huilv)) + Decimal(str(duirucha)))
  1390. win = round(float(win), 2)
  1391. clwin = str(win)[0:8]
  1392. USDT = sd['USDT']
  1393. while True:
  1394. sd = mongo.get_wallet(bot_id).find_one({'projectname': '闪兑'})
  1395. USDT = sd['USDT']
  1396. trc20 = sd['trc20']
  1397. a = sd['timer']
  1398. sign = sd['sign']
  1399. if USDT >= float(win):
  1400. if mongouser.find_one({'trc_url': {"$regex": onwer_url}}) != None:
  1401. user_list = mongouser.find_one({'trc_url': {"$regex": onwer_url}})
  1402. user_id = user_list['user_id']
  1403. lang = user_list['lang']
  1404. while 1:
  1405. try:
  1406. txndata = zhuanu(trc20, onwer_url, float(win))
  1407. break
  1408. except Exception as f:
  1409. with open('签名助手异常.txt', 'a+') as rz:
  1410. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1411. rz.write(f'{timer} {f}\n')
  1412. time.sleep(1)
  1413. txid = txndata['txid']
  1414. if lang == 'zh':
  1415. text = f'''
  1416. 您使用{today_money}Trx闪兑{float(clwin)}Usdt已成功
  1417. <a href="https://tronscan.org/#/transaction/{txid}">请查收</a>
  1418. '''
  1419. else:
  1420. text = f'''
  1421. Your use of {today_money}Trx to flash {float(clwin)}Usdt has been successful!
  1422. <a href="https://tronscan.org/#/transaction/{txid}">Please check.</a>
  1423. '''
  1424. keyboard = [[InlineKeyboardButton(langdict[lang]['kbEnergy purchases'], callback_data='comtron')]]
  1425. try:
  1426. context.bot.send_message(chat_id=user_id, text=text, parse_mode='HTML',disable_web_page_preview=True,reply_markup=InlineKeyboardMarkup(keyboard))
  1427. except:
  1428. pass
  1429. order_id = str(uuid.uuid4())
  1430. mongo.userlogdata(bot_id, order_id, block_timestamp, txid, 'Trx', user_id, onwer_url, 'Trx兑Usdt',
  1431. float(clwin), today_money,
  1432. f'Trx兑Usdt\n<code>{onwer_url}</code>转<code>{today_money}</code>TRX至<code>{to_url}</code>\n成功兑换<code>{float(clwin)}</code>Usdt',
  1433. tranhash, timer)
  1434. us_list = mongo.get_group(bot_id).find_one({"user_id": user_id})
  1435. us_firstname = us_list['firstname']
  1436. us_username = us_list['username']
  1437. text = f'''
  1438. 用户: <a href="tg://user?id={user_id}">{us_firstname}</a> @{us_username} Trx兑Usdt
  1439. 地址: <code>{onwer_url}</code>
  1440. 使用{today_money}Trx闪兑{float(clwin)}Usdt已成功
  1441. <a href="https://tronscan.org/#/transaction/{txid}">闪兑详细</a>
  1442. '''
  1443. for us in list(mongo.get_group(bot_id).find({'state': '4'})):
  1444. try:
  1445. context.bot.send_message(chat_id=us['user_id'], text=text, parse_mode='HTML',
  1446. disable_web_page_preview=True)
  1447. except:
  1448. continue
  1449. context.job_queue.run_once(usduiyongjin, 1,context={'user_id': user_id,'money': float(clwin),'trc20': onwer_url, 'projectname': 'Trx兑Usdt'})
  1450. qian = onwer_url[0:4]
  1451. hou = onwer_url[-4:]
  1452. chat_text = f'''
  1453. {qian}...{hou} 兑换成功:{today_money} TRX = {clwin} USDT,交易HASH:{txid}
  1454. '''
  1455. for ch in list(mongo.user_status.find({})):
  1456. chid = ch['chat_id']
  1457. try:
  1458. context.bot.send_message(chat_id=chid, text=chat_text, parse_mode='HTML',
  1459. disable_web_page_preview=True)
  1460. except:
  1461. continue
  1462. else:
  1463. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1464. while 1:
  1465. try:
  1466. txndata = zhuanu(trc20, onwer_url, float(win))
  1467. break
  1468. except Exception as f:
  1469. with open('签名助手异常.txt', 'a+') as rz:
  1470. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1471. rz.write(f'{timer} {f}\n')
  1472. time.sleep(1)
  1473. txid = txndata['txid']
  1474. order_id = str(uuid.uuid4())
  1475. mongo.userlogdata(bot_id, order_id, block_timestamp, txid, 'Trx', '', onwer_url, 'Trx兑Usdt',
  1476. float(clwin), today_money,
  1477. f'Trx兑Usdt\n<code>{onwer_url}</code>转<code>{today_money}</code>TRX至<code>{to_url}</code>\n成功兑换<code>{float(clwin)}</code>Usdt',
  1478. tranhash, timer)
  1479. text = f'''
  1480. 地址: <code>{onwer_url}</code>
  1481. 使用{today_money}Trx闪兑{float(clwin)}Usdt已成功
  1482. <a href="https://tronscan.org/#/transaction/{txid}">闪兑详细</a>
  1483. '''
  1484. for us in list(mongo.get_group(bot_id).find({'state': '4'})):
  1485. try:
  1486. context.bot.send_message(chat_id=us['user_id'], text=text, parse_mode='HTML',
  1487. disable_web_page_preview=True)
  1488. except:
  1489. continue
  1490. qian = onwer_url[0:4]
  1491. hou = onwer_url[-4:]
  1492. chat_text = f'''
  1493. {qian}...{hou} 兑换成功:{today_money} TRX = {clwin} USDT,交易HASH:{txid}
  1494. '''
  1495. for ch in list(mongo.user_status.find({})):
  1496. chid = ch['chat_id']
  1497. try:
  1498. context.bot.send_message(chat_id=chid, text=chat_text, parse_mode='HTML',
  1499. disable_web_page_preview=True)
  1500. except:
  1501. continue
  1502. mongo.get_wallet(bot_id).update_one({'projectname': '闪兑'}, {"$set": {'USDTstate': 0}})
  1503. break
  1504. else:
  1505. USDTstate = sd['USDTstate']
  1506. buzumoney = Decimal(str(clwin)) - Decimal(str(USDT))
  1507. if USDTstate == 0:
  1508. mongo.get_wallet(bot_id).update_one({'projectname': '闪兑'}, {"$set": {'USDTstate': 1}})
  1509. qwer = f'''
  1510. 闪兑钱包
  1511. <code>{trc20}</code>不足闪兑
  1512. {clwin}USDT,现有余额{USDT}Usdt,差{buzumoney}Usdt
  1513. <a href="https://tronscan.org/#/transaction/{tranhash}">转账详细</a>
  1514. '''
  1515. for i in list(mongouser.find({'state': '4'})):
  1516. context.bot.send_message(chat_id=i['user_id'],
  1517. text=qwer,
  1518. parse_mode='HTML',disable_web_page_preview=True)
  1519. time.sleep(3)
  1520. contract = client.get_contract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")
  1521. USDT = contract.functions.balanceOf(trc20) / 1000000
  1522. try:
  1523. TRX = client.get_account_balance(trc20)
  1524. except:
  1525. TRX = 0
  1526. mongo.get_wallet(bot_id).update_one({'projectname': '闪兑'},
  1527. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  1528. else:
  1529. for j in list(mongobdadd.find({'today_money': today_money})):
  1530. if today_money == j['today_money']:
  1531. user_list = mongouser.find_one({'user_id': j['user_id']})
  1532. TRX = user_list['TRX']
  1533. user_money = float((Decimal(str(TRX)) + Decimal(str(today_money))).quantize(Decimal('0.001')))
  1534. if mongouser.find_one({"trc_url": {"$regex": onwer_url}}) is None:
  1535. if mongouser.find_one({'trc_url': {'$ne': None}, 'user_id': j['user_id']}) is None:
  1536. mongouser.update_one({'user_id': j['user_id']},
  1537. {'$set': {"trc_url": onwer_url, "TRX": user_money}})
  1538. mongobdadd.delete_one({'user_id': j['user_id']})
  1539. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1540. try:
  1541. context.bot.send_message(chat_id=j['user_id'],
  1542. text=f'恭喜您认证成功啦!\n\n您绑定的地址为:{onwer_url}')
  1543. order_id = str(uuid.uuid4())
  1544. mongo.userlogdata(bot_id, order_id, block_timestamp, '', 'Trx', j['user_id'], onwer_url,
  1545. '绑定地址', 0, j['today_money'],
  1546. f'用户转账{j["today_money"]}TRX绑定地址', tranhash, timer)
  1547. user_list = mongouser.find_one({'user_id': j['user_id']})
  1548. TRX = user_list['TRX']
  1549. trc_list = []
  1550. for i in list(mongouser.find({'user_id': j['user_id'], 'trc_url': {'$ne': None}})):
  1551. for tc in i['trc_url'].split(','):
  1552. trc_list.append(f'<code>{tc}</code>')
  1553. if trc_list == []:
  1554. trc_list = ''
  1555. else:
  1556. trc_list = '已绑定地址:\n' + "\n".join(trc_list)
  1557. text = f'''
  1558. 账户ID:
  1559. <code>{j["user_id"]}</code>
  1560. 余额:
  1561. <code>{TRX}</code> TRX
  1562. {trc_list}
  1563. '''
  1564. keyboard = [
  1565. [InlineKeyboardButton('闪兑报表', callback_data='usershanduibb'),
  1566. InlineKeyboardButton('闪兑明细', callback_data='flashexchange')],
  1567. [InlineKeyboardButton('能量报表', callback_data='usernengliangbaobiao'),
  1568. InlineKeyboardButton('能量明细', callback_data='usernengliangmingxi')]
  1569. ]
  1570. context.bot.send_message(chat_id=j["user_id"], text=text,
  1571. parse_mode='HTML',
  1572. reply_markup=InlineKeyboardMarkup(keyboard))
  1573. except:
  1574. pass
  1575. else:
  1576. trc20 = mongouser.find_one({'user_id': j['user_id']})['trc_url']
  1577. mongouser.update_one({'user_id': j['user_id']}, {'$set': {"TRX": user_money}})
  1578. if onwer_url not in trc20:
  1579. mongouser.update_one({'user_id': j['user_id']},
  1580. {'$set': {"trc_url": trc20 + f',{onwer_url}'}})
  1581. mongobdadd.delete_one({'user_id': j['user_id']})
  1582. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1583. try:
  1584. context.bot.send_message(chat_id=j['user_id'],
  1585. text=f'恭喜您认证成功啦!\n\n您绑定的地址为:{onwer_url}')
  1586. order_id = str(uuid.uuid4())
  1587. mongo.userlogdata(bot_id, order_id, block_timestamp, '', 'Trx', j['user_id'], onwer_url,
  1588. '绑定地址', 0, j['today_money'],
  1589. f'用户转账{j["today_money"]}TRX绑定地址', tranhash, timer)
  1590. user_list = mongouser.find_one({'user_id': j['user_id']})
  1591. TRX = user_list['TRX']
  1592. trc_list = []
  1593. for i in list(
  1594. mongouser.find({'user_id': j['user_id'], 'trc_url': {'$ne': None}})):
  1595. for tc in i['trc_url'].split(','):
  1596. trc_list.append(f'<code>{tc}</code>')
  1597. if trc_list == []:
  1598. trc_list = ''
  1599. else:
  1600. trc_list = '已绑定地址:\n' + "\n".join(trc_list)
  1601. text = f'''
  1602. 账户ID:
  1603. <code>{j["user_id"]}</code>
  1604. 余额:
  1605. <code>{TRX}</code> TRX
  1606. {trc_list}
  1607. '''
  1608. keyboard = [
  1609. [InlineKeyboardButton('闪兑报表', callback_data='usershanduibb'),
  1610. InlineKeyboardButton('闪兑明细', callback_data='flashexchange')],
  1611. [InlineKeyboardButton('能量报表', callback_data='usernengliangbaobiao'),
  1612. InlineKeyboardButton('能量明细', callback_data='usernengliangmingxi')]
  1613. ]
  1614. context.bot.send_message(chat_id=j["user_id"], text=text,
  1615. parse_mode='HTML',
  1616. reply_markup=InlineKeyboardMarkup(keyboard))
  1617. except:
  1618. pass
  1619. else:
  1620. mongobdadd.delete_one({'user_id': j['user_id']})
  1621. else:
  1622. mongobdadd.delete_one({'user_id': j['user_id']})
  1623. time.sleep(3)
  1624. contract = client.get_contract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")
  1625. USDT = contract.functions.balanceOf(trc20) / 1000000
  1626. try:
  1627. TRX = client.get_account_balance(trc20)
  1628. except:
  1629. TRX = 0
  1630. mongo.get_wallet(bot_id).update_one({'projectname': '闪兑'},
  1631. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  1632. def Numberoftransfers(update: Update, context: CallbackContext):
  1633. query = update.callback_query
  1634. user_id = query.from_user.id
  1635. query.answer()
  1636. bot_id = context.bot.id
  1637. user_list = mongo.get_group(bot_id).find_one({'user_id': user_id})
  1638. lang = user_list['lang']
  1639. if lang == 'zh':
  1640. text = f'''
  1641. ❣️提交格式:
  1642. 接收能量钱包地址|每天转账笔数|租赁天数
  1643. 换行另一个地址,可同时提交多个地址
  1644. 温馨提示:租赁天数最少5天起!
  1645. 例如:
  1646. <code>TQYV25QwKLNqWJJfvBgUBwR25kQFFFFFFF|1|3</code>
  1647. <code>TJHiSX3Nn6TLQtabyRN9chX4zkS3333333|10|30</code>
  1648. '''
  1649. else:
  1650. text = f'''
  1651. ❣️ Submission Format:
  1652. Receive Energy Wallet Address | Number of Transfers per Day | Number of Lease Days
  1653. Change the line to another address, you can submit more than one address at the same time!
  1654. Note: Lease days start at a minimum of 5 days!
  1655. Example.
  1656. <code>TQYV25QwKLNqWJJfvBgUBwR25kQFFFFFFF|1|3</code>
  1657. <code>TJHiSX3Nn6TLQtabyRN9chX4zkS3333333|10|30</code>
  1658. '''
  1659. mongo.get_group(bot_id).update_one({"user_id": user_id}, {"$set": {"sign": 'Numberoftransfers'}})
  1660. keyboard = [[InlineKeyboardButton('取消提交', callback_data=f'close {user_id}')]]
  1661. context.bot.send_message(chat_id=user_id, text=text, reply_markup=InlineKeyboardMarkup(keyboard), parse_mode='HTML')
  1662. def close(update: Update, context: CallbackContext):
  1663. query = update.callback_query
  1664. chat = query.message.chat
  1665. yh_id = query.data.replace("close ", '')
  1666. bot_id = context.bot.id
  1667. chat_id = chat.id
  1668. user_id = query.from_user.id
  1669. if yh_id == 'all':
  1670. query.answer()
  1671. elif int(yh_id) != user_id:
  1672. query.answer('这不是你的按钮', show_alert=bool("true"))
  1673. return
  1674. mongo.get_group(bot_id).update_one({'user_id': user_id}, {'$set': {'sign': 0}})
  1675. context.bot.deleteMessage(query.from_user.id, query.message.message_id)
  1676. def seleudt(context: CallbackContext):
  1677. bot_id = context.bot.id
  1678. sd = mongo.get_wallet(bot_id).find_one({'projectname': '闪兑'})
  1679. mongouserlog = mongo.get_user_log(bot_id)
  1680. mongouser = mongo.get_group(bot_id)
  1681. trc20 = sd['trc20']
  1682. client = Tron(HTTPProvider('https://api.tronwallets.vip', 30))
  1683. contract = client.get_contract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")
  1684. USDT = contract.functions.balanceOf(trc20) / 1000000
  1685. try:
  1686. TRX = client.get_account_balance(trc20)
  1687. except:
  1688. TRX = 0
  1689. mongo.get_wallet(bot_id).update_one({'projectname': '闪兑'},
  1690. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  1691. a = sd['timer']
  1692. tranhash = context.job.context['transaction_id']
  1693. to_url = context.job.context['toAddress']
  1694. zdstate = 0
  1695. if mongouserlog.find_one({'tranhash': tranhash}) is None:
  1696. onwer_url = context.job.context['ownerAddress']
  1697. value = context.job.context['money']
  1698. block_timestamp = context.job.context['timestamp']
  1699. today_money = float(value)
  1700. TRX = sd['TRX']
  1701. designated_list = mongo.designated.find_one({'money': today_money})
  1702. if designated_list is not None:
  1703. dh_id = designated_list['user_id']
  1704. dh_trc20 = designated_list['trc20']
  1705. huilv = mongo.shang_text.find_one({'projectname': '波场汇率'})['text']
  1706. zdcg = mongo.caigou.find_one({'state': 0}, sort=[("TRX", 1)])
  1707. if zdcg != None:
  1708. bianhao = zdcg['bianhao']
  1709. zdshuliang = zdcg['shuliang']
  1710. zdcgtrx = zdcg['TRX']
  1711. zdmoney = zdcg['money']
  1712. zdstate = 1
  1713. if huilv > zdcgtrx:
  1714. huilv = zdcgtrx
  1715. duichucha = mongo.shang_text.find_one({'projectname': '兑出差'})['text']
  1716. sign = sd['sign']
  1717. client = Tron(HTTPProvider('https://api.tronwallets.vip', 30))
  1718. win = Decimal(str(today_money)) * (Decimal(str(huilv)) - Decimal(str(duichucha)))
  1719. if zdstate == 1:
  1720. zdmoneysum = Decimal(str(zdmoney)) + win
  1721. mongo.caigou.update_one({'bianhao': bianhao},{"$set":{"money": float(zdmoneysum)}})
  1722. if zdmoneysum >= zdshuliang:
  1723. mongo.caigou.update_one({'bianhao': bianhao},{"$set":{"state": 1}})
  1724. win = round(float(win), 2)
  1725. clwin = str(win)[0:8]
  1726. while 1:
  1727. sd = mongo.get_wallet(bot_id).find_one({'projectname': '闪兑'})
  1728. TRX = sd['TRX']
  1729. trc20 = sd['trc20']
  1730. a = sd['timer']
  1731. sign = sd['sign']
  1732. if TRX >= float(win):
  1733. user_list = mongouser.find_one({'user_id': dh_id})
  1734. user_id = user_list['user_id']
  1735. while 1:
  1736. try:
  1737. txndata = zhuantrx(trc20, dh_trc20, float(win))
  1738. break
  1739. except Exception as f:
  1740. with open('签名助手异常.txt', 'a+') as rz:
  1741. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1742. rz.write(f'{timer} {f}\n')
  1743. time.sleep(1)
  1744. txid = txndata['txid']
  1745. text = f'''
  1746. 您使用{today_money}Usdt闪兑{float(clwin)}Trx已成功
  1747. <a href="https://tronscan.org/#/transaction/{txid}">请查收</a>
  1748. '''
  1749. mongo.designated.delete_one({'trc20': dh_trc20, 'money': today_money})
  1750. keyboard = [[InlineKeyboardButton('能量购买', callback_data='comtron')]]
  1751. context.bot.send_message(chat_id=user_id, text=text, parse_mode='HTML',disable_web_page_preview=True,reply_markup=InlineKeyboardMarkup(keyboard))
  1752. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1753. order_id = str(uuid.uuid4())
  1754. mongo.userlogdata(bot_id, order_id, block_timestamp, txid, 'Usdt', user_id, onwer_url, 'Usdt兑Trx',
  1755. today_money, float(clwin),
  1756. f'Usdt兑Trx\n<code>{onwer_url}</code>转<code>{today_money}</code>U至<code>{to_url}</code>\n成功兑换<code>{float(clwin)}</code>TRX',
  1757. tranhash, timer)
  1758. us_list = mongo.get_group(bot_id).find_one({"user_id": user_id})
  1759. us_firstname = us_list['firstname']
  1760. us_username = us_list['username']
  1761. text = f'''
  1762. 用户: <a href="tg://user?id={user_id}">{us_firstname}</a> @{us_username} Usdt兑Trx
  1763. 转账地址: <code>{onwer_url}</code>
  1764. 到账地址: <code>{dh_trc20}</code>
  1765. 使用{today_money}Usdt闪兑{float(clwin)}Trx已成功
  1766. <a href="https://tronscan.org/#/transaction/{txid}">闪兑详细</a>
  1767. '''
  1768. for us in list(mongo.get_group(bot_id).find({'state': '4'})):
  1769. try:
  1770. context.bot.send_message(chat_id=us['user_id'], text=text, parse_mode='HTML',
  1771. disable_web_page_preview=True)
  1772. except:
  1773. continue
  1774. context.job_queue.run_once(usduiyongjin, 1,context={'user_id': user_id,'money': today_money,'trc20': onwer_url, 'projectname': 'Usdt兑Trx'})
  1775. qian = onwer_url[0:4]
  1776. hou = onwer_url[-4:]
  1777. chat_text = f'''
  1778. {qian}...{hou} 兑换成功:{today_money} Usdt = {clwin} Trx,交易HASH:{txid}
  1779. '''
  1780. for ch in list(mongo.user_status.find({})):
  1781. chid = ch['chat_id']
  1782. try:
  1783. context.bot.send_message(chat_id=chid, text=chat_text, parse_mode='HTML',
  1784. disable_web_page_preview=True)
  1785. except:
  1786. continue
  1787. mongo.get_wallet(bot_id).update_one({'projectname': '闪兑'}, {"$set": {'TRXstate': 0}})
  1788. break
  1789. else:
  1790. TRXstate = sd['TRXstate']
  1791. if TRXstate == 0:
  1792. mongo.get_wallet(bot_id).update_one({'projectname': '闪兑'}, {"$set": {'TRXstate': 1}})
  1793. zlqb = mongo.get_wallet(bot_id).find_one({'projectname': '租赁'})
  1794. zltrc20 = zlqb['trc20']
  1795. zltrx = zlqb['TRX']
  1796. zlsign = zlqb['sign']
  1797. if zltrx >= float(win):
  1798. while 1:
  1799. try:
  1800. txndata = zhuantrx(trc20, dh_trc20, float(win))
  1801. break
  1802. except Exception as f:
  1803. with open('签名助手异常.txt', 'a+') as rz:
  1804. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1805. rz.write(f'{timer} {f}\n')
  1806. time.sleep(1)
  1807. txid = txndata['txid']
  1808. time.sleep(3)
  1809. context.job_queue.run_once(seleudt, 1,context={'transaction_id': tranhash,'transferType': 'USDT','ownerAddress': onwer_url,'toAddress': to_url,'money': value,'timestamp': block_timestamp})
  1810. return
  1811. else:
  1812. buzumoney = Decimal(str(clwin)) - Decimal(str(TRX))
  1813. qwer = f'''
  1814. 闪兑钱包
  1815. <code>{trc20}</code>不足闪兑
  1816. {clwin}Trx,现有余额{TRX}Trx,差{buzumoney}Trx
  1817. <a href="https://tronscan.org/#/transaction/{tranhash}">转账详细</a>
  1818. '''
  1819. for i in list(mongouser.find({'state': '4'})):
  1820. context.bot.send_message(chat_id=i['user_id'],
  1821. text=qwer,
  1822. parse_mode='HTML',disable_web_page_preview=True)
  1823. time.sleep(3)
  1824. contract = client.get_contract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")
  1825. USDT = contract.functions.balanceOf(trc20) / 1000000
  1826. try:
  1827. TRX = client.get_account_balance(trc20)
  1828. except:
  1829. TRX = 0
  1830. mongo.get_wallet(bot_id).update_one({'projectname': '闪兑'},
  1831. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  1832. time.sleep(3)
  1833. contract = client.get_contract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")
  1834. USDT = contract.functions.balanceOf(trc20) / 1000000
  1835. try:
  1836. TRX = client.get_account_balance(trc20)
  1837. except:
  1838. TRX = 0
  1839. mongo.get_wallet(bot_id).update_one({'projectname': '闪兑'},
  1840. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  1841. def trxshandui(context: CallbackContext):
  1842. bot_id = context.bot.id
  1843. sd = mongo.get_wallet(bot_id).find_one({'projectname': '闪兑'})
  1844. mongouserlog = mongo.get_user_log(bot_id)
  1845. mongouser = mongo.get_group(bot_id)
  1846. trc20 = sd['trc20']
  1847. client = Tron(HTTPProvider('https://api.tronwallets.vip', 30))
  1848. contract = client.get_contract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")
  1849. USDT = contract.functions.balanceOf(trc20) / 1000000
  1850. try:
  1851. TRX = client.get_account_balance(trc20)
  1852. except:
  1853. TRX = 0
  1854. mongo.get_wallet(bot_id).update_one({'projectname': '闪兑'},
  1855. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  1856. a = sd['timer']
  1857. tranhash = context.job.context['transaction_id']
  1858. to_url = context.job.context['toAddress']
  1859. zdstate = 0
  1860. if mongouserlog.find_one({'tranhash': tranhash}) is None:
  1861. onwer_url = context.job.context['ownerAddress']
  1862. value = context.job.context['money']
  1863. block_timestamp = context.job.context['timestamp']
  1864. today_money = float(value)
  1865. TRX = sd['TRX']
  1866. minusdt = mongo.shang_text.find_one({'projectname': '最小USDT闪兑'})['text']
  1867. if today_money >= minusdt:
  1868. huilv = mongo.shang_text.find_one({'projectname': '波场汇率'})['text']
  1869. zdcg = mongo.caigou.find_one({'state': 0}, sort=[("TRX", 1)])
  1870. if zdcg != None:
  1871. bianhao = zdcg['bianhao']
  1872. zdshuliang = zdcg['shuliang']
  1873. zdcgtrx = zdcg['TRX']
  1874. zdmoney = zdcg['money']
  1875. zdstate = 1
  1876. if huilv > zdcgtrx:
  1877. huilv = zdcgtrx
  1878. duichucha = mongo.shang_text.find_one({'projectname': '兑出差'})['text']
  1879. sign = sd['sign']
  1880. client = Tron(HTTPProvider('https://api.tronwallets.vip', 30))
  1881. win = Decimal(str(today_money)) * (Decimal(str(huilv)) - Decimal(str(duichucha)))
  1882. if zdstate == 1:
  1883. zdmoneysum = Decimal(str(zdmoney)) + win
  1884. mongo.caigou.update_one({'bianhao': bianhao},{"$set":{"money": float(zdmoneysum)}})
  1885. if zdmoneysum >= zdshuliang:
  1886. mongo.caigou.update_one({'bianhao': bianhao},{"$set":{"state": 1}})
  1887. win = round(float(win), 2)
  1888. clwin = str(win)[0:8]
  1889. while 1:
  1890. sd = mongo.get_wallet(bot_id).find_one({'projectname': '闪兑'})
  1891. TRX = sd['TRX']
  1892. trc20 = sd['trc20']
  1893. a = sd['timer']
  1894. sign = sd['sign']
  1895. if TRX >= float(win):
  1896. if mongouser.find_one({'trc_url': {"$regex": onwer_url}}) != None:
  1897. user_list = mongouser.find_one({'trc_url': {"$regex": onwer_url}})
  1898. user_id = user_list['user_id']
  1899. lang = user_list['lang']
  1900. while 1:
  1901. try:
  1902. txndata = zhuantrx(trc20, onwer_url, float(win))
  1903. break
  1904. except Exception as f:
  1905. with open('签名助手异常.txt', 'a+') as rz:
  1906. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1907. rz.write(f'{timer} {f}\n')
  1908. time.sleep(1)
  1909. txid = txndata['txid']
  1910. if lang == 'zh':
  1911. text = f'''
  1912. 您使用{today_money}Usdt闪兑{float(clwin)}Trx已成功
  1913. <a href="https://tronscan.org/#/transaction/{txid}">请查收</a>
  1914. '''
  1915. else:
  1916. text = f'''
  1917. Your use of {today_money}Usdt to flash {float(clwin)}Trx has been successful!
  1918. <a href="https://tronscan.org/#/transaction/{txid}">Please check.</a>
  1919. '''
  1920. keyboard = [[InlineKeyboardButton(langdict[lang]['kbEnergy purchases'], callback_data='comtron')]]
  1921. context.bot.send_message(chat_id=user_id, text=text, parse_mode='HTML',disable_web_page_preview=True,reply_markup=InlineKeyboardMarkup(keyboard))
  1922. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1923. order_id = str(uuid.uuid4())
  1924. mongo.userlogdata(bot_id, order_id, block_timestamp, txid, 'Usdt', user_id, onwer_url, 'Usdt兑Trx',
  1925. today_money, float(clwin),
  1926. f'Usdt兑Trx\n<code>{onwer_url}</code>转<code>{today_money}</code>U至<code>{to_url}</code>\n成功兑换<code>{float(clwin)}</code>TRX',
  1927. tranhash, timer)
  1928. us_list = mongo.get_group(bot_id).find_one({"user_id": user_id})
  1929. us_firstname = us_list['firstname']
  1930. us_username = us_list['username']
  1931. text = f'''
  1932. 用户: <a href="tg://user?id={user_id}">{us_firstname}</a> @{us_username} Usdt兑Trx
  1933. 地址: <code>{onwer_url}</code>
  1934. 使用{today_money}Usdt闪兑{float(clwin)}Trx已成功
  1935. <a href="https://tronscan.org/#/transaction/{txid}">闪兑详细</a>
  1936. '''
  1937. for us in list(mongo.get_group(bot_id).find({'state': '4'})):
  1938. try:
  1939. context.bot.send_message(chat_id=us['user_id'], text=text, parse_mode='HTML',
  1940. disable_web_page_preview=True)
  1941. except:
  1942. continue
  1943. context.job_queue.run_once(usduiyongjin, 1,context={'user_id': user_id,'money': today_money,'trc20': onwer_url, 'projectname': 'Usdt兑Trx'})
  1944. qian = onwer_url[0:4]
  1945. hou = onwer_url[-4:]
  1946. chat_text = f'''
  1947. {qian}...{hou} 兑换成功:{today_money} Usdt = {clwin} Trx,交易HASH:{txid}
  1948. '''
  1949. for ch in list(mongo.user_status.find({})):
  1950. chid = ch['chat_id']
  1951. try:
  1952. context.bot.send_message(chat_id=chid, text=chat_text, parse_mode='HTML',
  1953. disable_web_page_preview=True)
  1954. except:
  1955. continue
  1956. else:
  1957. while 1:
  1958. try:
  1959. txndata = zhuantrx(trc20, onwer_url, float(win))
  1960. break
  1961. except Exception as f:
  1962. with open('签名助手异常.txt', 'a+') as rz:
  1963. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1964. rz.write(f'{timer} {f}\n')
  1965. time.sleep(1)
  1966. txid = txndata['txid']
  1967. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  1968. order_id = str(uuid.uuid4())
  1969. mongo.userlogdata(bot_id, order_id, block_timestamp, txid, 'Usdt', '', onwer_url, 'Usdt兑Trx',
  1970. today_money, float(clwin),
  1971. f'Usdt兑Trx\n<code>{onwer_url}</code>转<code>{today_money}</code>U至<code>{to_url}</code>\n成功兑换<code>{float(clwin)}</code>TRX',
  1972. tranhash, timer)
  1973. text = f'''
  1974. 该地址未绑定机器人
  1975. 地址: <code>{onwer_url}</code>
  1976. 使用{today_money}Usdt闪兑{float(clwin)}Trx已成功
  1977. <a href="https://tronscan.org/#/transaction/{txid}">闪兑详细</a>
  1978. '''
  1979. for us in list(mongo.get_group(bot_id).find({'state': '4'})):
  1980. try:
  1981. context.bot.send_message(chat_id=us['user_id'], text=text, parse_mode='HTML',
  1982. disable_web_page_preview=True)
  1983. except:
  1984. continue
  1985. qian = onwer_url[0:4]
  1986. hou = onwer_url[-4:]
  1987. chat_text = f'''
  1988. {qian}...{hou} 兑换成功:{today_money} Usdt = {clwin} Trx,交易HASH:{txid}
  1989. '''
  1990. for ch in list(mongo.user_status.find({})):
  1991. chid = ch['chat_id']
  1992. try:
  1993. context.bot.send_message(chat_id=chid, text=chat_text, parse_mode='HTML',
  1994. disable_web_page_preview=True)
  1995. except:
  1996. continue
  1997. mongo.get_wallet(bot_id).update_one({'projectname': '闪兑'}, {"$set": {'TRXstate': 0}})
  1998. break
  1999. else:
  2000. TRXstate = sd['TRXstate']
  2001. if TRXstate == 0:
  2002. mongo.get_wallet(bot_id).update_one({'projectname': '闪兑'}, {"$set": {'TRXstate': 1}})
  2003. zlqb = mongo.get_wallet(bot_id).find_one({'projectname': '租赁'})
  2004. zltrc20 = zlqb['trc20']
  2005. zltrx = zlqb['TRX']
  2006. zlsign = zlqb['sign']
  2007. if zltrx >= float(win):
  2008. while 1:
  2009. try:
  2010. txndata = zhuantrx(zltrc20, trc20, float(win))
  2011. break
  2012. except Exception as f:
  2013. with open('签名助手异常.txt', 'a+') as rz:
  2014. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  2015. rz.write(f'{timer} {f}\n')
  2016. time.sleep(1)
  2017. txid = txndata['txid']
  2018. time.sleep(3)
  2019. context.job_queue.run_once(trxshandui, 1,context={'transaction_id': tranhash,'transferType': 'USDT','ownerAddress': onwer_url,'toAddress': to_url,'money': value,'timestamp': block_timestamp})
  2020. return
  2021. else:
  2022. buzumoney = Decimal(str(clwin)) - Decimal(str(TRX))
  2023. qwer = f'''
  2024. 闪兑钱包
  2025. <code>{trc20}</code>不足闪兑
  2026. {clwin}Trx,现有余额{TRX}Trx,差{buzumoney}Trx
  2027. <a href="https://tronscan.org/#/transaction/{tranhash}">转账详细</a>
  2028. '''
  2029. for i in list(mongouser.find({'state': '4'})):
  2030. context.bot.send_message(chat_id=i['user_id'],
  2031. text=qwer,
  2032. parse_mode='HTML',disable_web_page_preview=True)
  2033. time.sleep(3)
  2034. contract = client.get_contract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")
  2035. USDT = contract.functions.balanceOf(trc20) / 1000000
  2036. try:
  2037. TRX = client.get_account_balance(trc20)
  2038. except:
  2039. TRX = 0
  2040. mongo.get_wallet(bot_id).update_one({'projectname': '闪兑'},
  2041. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  2042. time.sleep(3)
  2043. contract = client.get_contract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")
  2044. USDT = contract.functions.balanceOf(trc20) / 1000000
  2045. try:
  2046. TRX = client.get_account_balance(trc20)
  2047. except:
  2048. TRX = 0
  2049. mongo.get_wallet(bot_id).update_one({'projectname': '闪兑'},
  2050. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  2051. def twwebyuefeidan(context: CallbackContext):
  2052. bot_id = context.bot.id
  2053. botname = context.bot.username
  2054. sd = mongo.get_wallet(bot_id).find_one({'projectname': '租赁'})
  2055. mongopledge = mongo.get_user_log(bot_id)
  2056. mongouser = mongo.get_group(bot_id)
  2057. mongolibrary = mongo.get_library(bot_id)
  2058. trc20 = sd['trc20']
  2059. client = Tron(HTTPProvider('https://api.tronwallets.vip', 30))
  2060. contract = client.get_contract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")
  2061. USDT = contract.functions.balanceOf(trc20) / 1000000
  2062. try:
  2063. TRX = client.get_account_balance(trc20)
  2064. except:
  2065. TRX = 0
  2066. mongo.get_wallet(bot_id).update_one({'projectname': '租赁'},
  2067. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  2068. mongo.get_wallet(bot_id).update_one({'projectname': '充值'},
  2069. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  2070. ss_trc20 = sd['trc20']
  2071. a = sd['timer']
  2072. tranhash = context.job.context['transaction_id']
  2073. to_url = context.job.context['toAddress']
  2074. onwer_url = context.job.context['ownerAddress']
  2075. value = context.job.context['money']
  2076. transferType = context.job.context['transferType']
  2077. block_timestamp = context.job.context['timestamp']
  2078. today_money = float(value)
  2079. client = Tron(HTTPProvider('https://api.tronwallets.vip', 30))
  2080. bal = jianceyonghu(bot_id)
  2081. if float(bal) < today_money:
  2082. text = f'''
  2083. 飞单失败,备用金已不足支付{today_money}Trx
  2084. 请充值后重试或选择直接用租赁地址代理能量
  2085. '''
  2086. if mongo.lssj.find_one({"transaction_id": tranhash}) is None:
  2087. weiyiid = str(uuid.uuid4())
  2088. else:
  2089. weiyiid = mongo.lssj.find_one({"transaction_id": tranhash})['bianhao']
  2090. mongo.lssj.update_one({"transaction_id": tranhash},{"$set":{"state": 0}})
  2091. datashuju = {'bianhao': weiyiid, 'transaction_id': tranhash,'transferType': transferType,'ownerAddress': onwer_url,'toAddress': to_url,'money': today_money,'timestamp': block_timestamp, 'state': 0}
  2092. keyboard = [
  2093. [InlineKeyboardButton('重新飞单', callback_data=f'zxfeidan {weiyiid}'), InlineKeyboardButton('直接代理', callback_data=f'zxzhiya {weiyiid}')]
  2094. ]
  2095. for us in list(mongo.get_group(bot_id).find({'state': '4'})):
  2096. context.bot.send_message(chat_id=us['user_id'], text=text, parse_mode='HTML',
  2097. disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup(keyboard))
  2098. if mongo.lssj.find_one({"transaction_id": tranhash}) is None:
  2099. mongo.lssj.insert_one(datashuju)
  2100. return
  2101. if mongopledge.find_one({'tranhash': tranhash}) is None:
  2102. library_list = mongolibrary.find_one({'today_money': today_money})
  2103. if library_list:
  2104. nenglbaifenb = mongo.shang_text.find_one({'projectname': '获利比例'})['text']
  2105. yuanprice = today_money
  2106. today_money = float(Decimal(str(today_money)) - Decimal(str(today_money)) * (Decimal(str(nenglbaifenb)) / Decimal(str(100))))
  2107. zztrc20 = library_list['trc20']
  2108. zzmoney = library_list['zzmoney']
  2109. uid = library_list['user_id']
  2110. xq = []
  2111. zongbishu = 0
  2112. for dz in zztrc20:
  2113. xq.append(
  2114. {
  2115. 'countNum': int(dz['pencount']),
  2116. 'dayNum': int(dz['days']),
  2117. 'recAddress': dz['trc20']
  2118. }
  2119. )
  2120. zongbishu += Decimal(str(dz['pencount']))*Decimal(str(dz['days']))
  2121. zongbishu = Decimal(str(13.3959))* zongbishu
  2122. rangli = int(round(Decimal(str(today_money))/zongbishu,2)*100)
  2123. data = {
  2124. "amount": today_money,
  2125. "equipmentType": 3,
  2126. "orderList": xq,
  2127. "scale": rangli,
  2128. }
  2129. # print(data)
  2130. data = json.dumps(data).encode('utf-8')
  2131. key = "Longteng".encode('utf-8')
  2132. # 调用加密函数
  2133. encrypted_data = encrypt(data, key)
  2134. encrypted_data = base64.b64encode(encrypted_data).decode('utf-8')
  2135. data = {
  2136. "key": encrypted_data
  2137. }
  2138. url = 'http://144.202.84.76:8098/tweak/purchase-energy/add'
  2139. response = requests.post(url=url,json=data)
  2140. dingdan = json.loads(response.text)['data']
  2141. data = {
  2142. 'id': int(dingdan),
  2143. 'paymentAddress': botname,
  2144. 'status': 1
  2145. }
  2146. url = 'http://144.202.84.76:8098/tweak/purchase-energy/updateStatus'
  2147. response = requests.post(url=url,json=data)
  2148. us_list = mongo.get_group(bot_id).find_one({"user_id": uid})
  2149. us_firstname = us_list['firstname']
  2150. us_username = us_list['username']
  2151. us_TRX = us_list['TRX']
  2152. us_id = us_list['user_id']
  2153. fullname = us_list['fullname']
  2154. zytrc20 = []
  2155. yuanlist = []
  2156. dzxq = []
  2157. for dz in zztrc20:
  2158. yuanlist.append(dz["trc20"])
  2159. zytrc20.append(f'<code>{dz["trc20"]}</code>')
  2160. dzxq.append(f'地址: {dz["trc20"]} 每天转账{dz["pencount"]}次,{dz["days"]}天,租赁{dz["zuzhimoney"]}Trx,省{dz["shengmoney"]}Trx')
  2161. zytrc20 = ','.join(zytrc20)
  2162. dzxq = '\n'.join(dzxq)
  2163. webxiaofei(bot_id, today_money)
  2164. bal = jianceyonghu(bot_id)
  2165. text = f'''
  2166. <b>本次订单已飞往TWUK网站</b>
  2167. <b>原价格:{yuanprice} 获利比例:{nenglbaifenb}% 提交价格:{today_money} 备用金剩余: {bal}</b>
  2168. 用户: <a href="tg://user?id={uid}">{us_firstname}</a> @{us_username} 使用余额进行租赁,消耗{value}Trx,剩{us_TRX}Trx
  2169. {dzxq}
  2170. '''
  2171. for us in list(mongo.get_group(bot_id).find({'state': '4'})):
  2172. try:
  2173. context.bot.send_message(chat_id=us['user_id'], text=text, parse_mode='HTML',
  2174. disable_web_page_preview=True)
  2175. except:
  2176. continue
  2177. fs_text = f'''
  2178. 此订单在30分钟之内完成!
  2179. '''
  2180. try:
  2181. context.bot.send_message(chat_id=uid, text=fs_text, parse_mode='HTML',
  2182. disable_web_page_preview=True)
  2183. except:
  2184. pass
  2185. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  2186. order_id = str(uuid.uuid4())
  2187. mongo.pledge_data('网站飞单',bot_id,order_id, block_timestamp, tranhash, '', uid, ss_trc20, 0,
  2188. 0, value, 0, '能量', zztrc20, 0, '', 0, timer,
  2189. '')
  2190. mongo.get_pledge(bot_id).update_one({"order_id": order_id},{"$set":{"dingdan": int(dingdan)}})
  2191. order_id = str(uuid.uuid4())
  2192. mongo.userlogdata(bot_id, order_id, block_timestamp, '', 'Trx', uid, onwer_url, '能量租赁',
  2193. 0, value,
  2194. f'飞单往网站',
  2195. tranhash, timer)
  2196. mongo.get_user_log(bot_id).update_one({"tranhash": tranhash},{"$set":{"beizhu": "网站飞单"}})
  2197. def webxiaofei(bot_id, money):
  2198. data = {
  2199. "deviceId": str(bot_id),
  2200. "transactionType": 1,
  2201. "reserveFund": money,
  2202. 'equipmentType': 3,
  2203. }
  2204. # print(data)
  2205. data = json.dumps(data).encode('utf-8')
  2206. key = "Longteng".encode('utf-8')
  2207. # 调用加密函数
  2208. encrypted_data = encrypt(data, key)
  2209. encrypted_data = base64.b64encode(encrypted_data).decode('utf-8')
  2210. data = {
  2211. "key": encrypted_data
  2212. }
  2213. url = 'http://144.202.84.76:8098/tweak/device-user/UpdateReserveFund'
  2214. response = requests.post(url=url, json=data)
  2215. text = json.loads(response.text)
  2216. return text
  2217. def del_message(message):
  2218. try:
  2219. message.delete()
  2220. except:
  2221. pass
  2222. def zxfeidan(update: Update, context: CallbackContext):
  2223. query = update.callback_query
  2224. bot_id = context.bot.id
  2225. text = query.message.text
  2226. user_id = query.from_user.id
  2227. bianhao = query.data.replace('zxfeidan ','')
  2228. bianhao_list = mongo.lssj.find_one({"bianhao": bianhao})
  2229. state = bianhao_list['state']
  2230. if state == 0:
  2231. query.answer('操作成功,已重新飞单', show_alert=bool("true"))
  2232. context.job_queue.run_once(twwebfeidan, 1,context=bianhao_list)
  2233. mongo.lssj.update_one({"bianhao": bianhao},{"$set":{"state": 1}})
  2234. del_message(query.message)
  2235. elif state == 1:
  2236. query.answer('操作失败,已重新飞单', show_alert=bool("true"))
  2237. del_message(query.message)
  2238. else:
  2239. query.answer('操作失败,已更换为自己地址出售能量', show_alert=bool("true"))
  2240. del_message(query.message)
  2241. def zxzhiya(update: Update, context: CallbackContext):
  2242. query = update.callback_query
  2243. bot_id = context.bot.id
  2244. text = query.message.text
  2245. user_id = query.from_user.id
  2246. bianhao = query.data.replace('zxzhiya ','')
  2247. bianhao_list = mongo.lssj.find_one({"bianhao": bianhao},{"_id": 0})
  2248. state = bianhao_list['state']
  2249. if state == 0:
  2250. query.answer('操作成功,已直接质押', show_alert=bool("true"))
  2251. context.job_queue.run_once(zhiyanengliang, 1,context=bianhao_list)
  2252. mongo.lssj.update_one({"bianhao": bianhao},{"$set":{"state": 2}})
  2253. del_message(query.message)
  2254. elif state == 1:
  2255. query.answer('操作失败,已重新飞单', show_alert=bool("true"))
  2256. del_message(query.message)
  2257. else:
  2258. query.answer('操作失败,已更换为自己地址出售能量', show_alert=bool("true"))
  2259. del_message(query.message)
  2260. def twwebfeidan(context: CallbackContext):
  2261. bot_id = context.bot.id
  2262. botname = context.bot.username
  2263. sd = mongo.get_wallet(bot_id).find_one({'projectname': '租赁'})
  2264. mongopledge = mongo.get_user_log(bot_id)
  2265. mongouser = mongo.get_group(bot_id)
  2266. mongolibrary = mongo.get_library(bot_id)
  2267. trc20 = sd['trc20']
  2268. client = Tron(HTTPProvider('https://api.tronwallets.vip', 30))
  2269. contract = client.get_contract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")
  2270. USDT = contract.functions.balanceOf(trc20) / 1000000
  2271. try:
  2272. TRX = client.get_account_balance(trc20)
  2273. except:
  2274. TRX = 0
  2275. mongo.get_wallet(bot_id).update_one({'projectname': '租赁'},
  2276. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  2277. mongo.get_wallet(bot_id).update_one({'projectname': '充值'},
  2278. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  2279. ss_trc20 = sd['trc20']
  2280. a = sd['timer']
  2281. tranhash = context.job.context['transaction_id']
  2282. to_url = context.job.context['toAddress']
  2283. onwer_url = context.job.context['ownerAddress']
  2284. transferType = context.job.context['transferType']
  2285. value = context.job.context['money']
  2286. block_timestamp = context.job.context['timestamp']
  2287. today_money = float(value)
  2288. client = Tron(HTTPProvider('https://api.tronwallets.vip', 30))
  2289. bal = jianceyonghu(bot_id)
  2290. if float(bal) < today_money:
  2291. text = f'''
  2292. 飞单失败,备用金已不足支付{today_money}Trx
  2293. 请充值后重试或选择直接用租赁地址代理能量
  2294. '''
  2295. if mongo.lssj.find_one({"transaction_id": tranhash}) is None:
  2296. weiyiid = str(uuid.uuid4())
  2297. else:
  2298. weiyiid = mongo.lssj.find_one({"transaction_id": tranhash})['bianhao']
  2299. mongo.lssj.update_one({"transaction_id": tranhash},{"$set":{"state": 0}})
  2300. datashuju = {'bianhao': weiyiid, 'transaction_id': tranhash,'transferType': transferType,'ownerAddress': onwer_url,'toAddress': to_url,'money': today_money,'timestamp': block_timestamp, 'state': 0}
  2301. keyboard = [
  2302. [InlineKeyboardButton('重新飞单', callback_data=f'zxfeidan {weiyiid}'), InlineKeyboardButton('直接代理', callback_data=f'zxzhiya {weiyiid}')]
  2303. ]
  2304. for us in list(mongo.get_group(bot_id).find({'state': '4'})):
  2305. try:
  2306. context.bot.send_message(chat_id=us['user_id'], text=text, parse_mode='HTML',
  2307. disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup(keyboard))
  2308. except:
  2309. continue
  2310. if mongo.lssj.find_one({"transaction_id": tranhash}) is None:
  2311. mongo.lssj.insert_one(datashuju)
  2312. return
  2313. if mongopledge.find_one({'tranhash': tranhash}) is None:
  2314. library_list = mongolibrary.find_one({'today_money': today_money})
  2315. if library_list:
  2316. nenglbaifenb = mongo.shang_text.find_one({'projectname': '获利比例'})['text']
  2317. yuanprice = today_money
  2318. today_money = float(Decimal(str(today_money)) - Decimal(str(today_money)) * (Decimal(str(nenglbaifenb)) / Decimal(str(100))))
  2319. zztrc20 = library_list['trc20']
  2320. zzmoney = library_list['zzmoney']
  2321. uid = library_list['user_id']
  2322. xq = []
  2323. zongbishu = 0
  2324. for dz in zztrc20:
  2325. xq.append(
  2326. {
  2327. 'countNum': int(dz['pencount']),
  2328. 'dayNum': int(dz['days']),
  2329. 'recAddress': dz['trc20']
  2330. }
  2331. )
  2332. zongbishu += Decimal(str(dz['pencount']))*Decimal(str(dz['days']))
  2333. zongbishu = Decimal(str(13.3959))* zongbishu
  2334. rangli = int(round(Decimal(str(today_money))/zongbishu,2)*100)
  2335. data = {
  2336. "amount": today_money,
  2337. "equipmentType": 3,
  2338. "orderList": xq,
  2339. "scale": rangli,
  2340. }
  2341. # print(data)
  2342. data = json.dumps(data).encode('utf-8')
  2343. key = "Longteng".encode('utf-8')
  2344. # 调用加密函数
  2345. encrypted_data = encrypt(data, key)
  2346. encrypted_data = base64.b64encode(encrypted_data).decode('utf-8')
  2347. data = {
  2348. "key": encrypted_data
  2349. }
  2350. url = 'http://144.202.84.76:8098/tweak/purchase-energy/add'
  2351. response = requests.post(url=url,json=data)
  2352. dingdan = json.loads(response.text)['data']
  2353. data = {
  2354. 'id': int(dingdan),
  2355. 'paymentAddress': botname,
  2356. 'status': 1
  2357. }
  2358. url = 'http://144.202.84.76:8098/tweak/purchase-energy/updateStatus'
  2359. response = requests.post(url=url,json=data)
  2360. us_list = mongo.get_group(bot_id).find_one({"user_id": uid})
  2361. us_firstname = us_list['firstname']
  2362. us_username = us_list['username']
  2363. us_id = us_list['user_id']
  2364. fullname = us_list['fullname']
  2365. zytrc20 = []
  2366. yuanlist = []
  2367. dzxq = []
  2368. for dz in zztrc20:
  2369. yuanlist.append(dz["trc20"])
  2370. zytrc20.append(f'<code>{dz["trc20"]}</code>')
  2371. dzxq.append(f'地址: {dz["trc20"]} 每天转账{dz["pencount"]}次,{dz["days"]}天,租赁{dz["zuzhimoney"]}Trx,省{dz["shengmoney"]}Trx')
  2372. zytrc20 = ','.join(zytrc20)
  2373. dzxq = '\n'.join(dzxq)
  2374. webxiaofei(bot_id, today_money)
  2375. bal = jianceyonghu(bot_id)
  2376. text = f'''
  2377. <b>本次订单已飞往TWUK网站</b>
  2378. <b>原价格:{yuanprice} 获利比例:{nenglbaifenb}% 提交价格:{today_money} 备用金剩余: {bal}</b>
  2379. <a href="https://tronscan.org/#/transaction/{tranhash}">用户转账信息</a>
  2380. 用户: <a href="tg://user?id={uid}">{us_firstname}</a> @{us_username}
  2381. {dzxq}
  2382. '''
  2383. for us in list(mongo.get_group(bot_id).find({'state': '4'})):
  2384. try:
  2385. context.bot.send_message(chat_id=us['user_id'], text=text, parse_mode='HTML',
  2386. disable_web_page_preview=True)
  2387. except:
  2388. continue
  2389. fs_text = f'''
  2390. 此订单在30分钟之内完成!
  2391. '''
  2392. try:
  2393. context.bot.send_message(chat_id=uid, text=fs_text, parse_mode='HTML',
  2394. disable_web_page_preview=True)
  2395. except:
  2396. pass
  2397. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  2398. order_id = str(uuid.uuid4())
  2399. mongo.pledge_data('网站飞单',bot_id,order_id, block_timestamp, tranhash, '', uid, ss_trc20, 0,
  2400. 0, value, 0, '能量', zztrc20, 0, '', 0, timer,
  2401. '')
  2402. mongo.get_pledge(bot_id).update_one({"order_id": order_id},{"$set":{"dingdan": int(dingdan)}})
  2403. order_id = str(uuid.uuid4())
  2404. mongo.userlogdata(bot_id, order_id, block_timestamp, '', 'Trx', uid, onwer_url, '能量租赁',
  2405. 0, value,
  2406. f'飞单往网站',
  2407. tranhash, timer)
  2408. mongo.get_user_log(bot_id).update_one({"tranhash": tranhash},{"$set":{"beizhu": "网站飞单"}})
  2409. def webczrukou(bot_id, money, tranhash):
  2410. data = {
  2411. "deviceId": str(bot_id),
  2412. "transactionType": 0,
  2413. "reserveFund": money,
  2414. "equipmentType": 3,
  2415. "rechargeHashValue": tranhash
  2416. }
  2417. # print(data)
  2418. data = json.dumps(data).encode('utf-8')
  2419. key = "Longteng".encode('utf-8')
  2420. # 调用加密函数
  2421. encrypted_data = encrypt(data, key)
  2422. encrypted_data = base64.b64encode(encrypted_data).decode('utf-8')
  2423. data = {
  2424. "key": encrypted_data
  2425. }
  2426. url = 'http://144.202.84.76:8098/tweak/device-user/UpdateReserveFund'
  2427. response = requests.post(url=url, json=data)
  2428. text = json.loads(response.text)
  2429. def jianceyonghu(bot_id):
  2430. url = 'http://144.202.84.76:8098/tweak/device-user/page'
  2431. data = {
  2432. "deviceId": str(bot_id),
  2433. 'size': 1
  2434. }
  2435. response = requests.post(url=url, json=data)
  2436. text = json.loads(response.text)
  2437. data = text['data']
  2438. records = data['records']
  2439. if records == []:
  2440. return '没有此用户'
  2441. else:
  2442. records = records[0]
  2443. reserveFund = records['reserveFund']
  2444. return reserveFund
  2445. def wanzhanczcg(context: CallbackContext):
  2446. bot_id = context.bot.id
  2447. tranhash = context.job.context['transaction_id']
  2448. to_url = context.job.context['toAddress']
  2449. onwer_url = context.job.context['ownerAddress']
  2450. value = context.job.context['money']
  2451. block_timestamp = context.job.context['timestamp']
  2452. today_money = float(value)
  2453. client = Tron(HTTPProvider('https://api.tronwallets.vip', 30))
  2454. dj_list = mongo.dj.find_one({"money": today_money})
  2455. if dj_list is not None:
  2456. weishu = dj_list['weishu']
  2457. user_id = dj_list['user_id']
  2458. text = f'''
  2459. 网站充值成功,充值{today_money}TRX
  2460. <a href="https://tronscan.org/#/transaction/{tranhash}">充值详细</a>
  2461. '''
  2462. for us in list(mongo.get_group(bot_id).find({'state': '4'})):
  2463. try:
  2464. context.bot.send_message(chat_id=us['user_id'], text=text, parse_mode='HTML',
  2465. disable_web_page_preview=True)
  2466. except:
  2467. continue
  2468. webczrukou(bot_id, today_money, tranhash)
  2469. bal = jianceyonghu(bot_id)
  2470. text = f'''
  2471. 你当前余额: {bal}
  2472. '''
  2473. keyboard = [
  2474. [InlineKeyboardButton('网站充值', callback_data='webchongzhi')],
  2475. [InlineKeyboardButton('网站接单', callback_data='webjiedanlist'),InlineKeyboardButton('网站飞单', callback_data='weburlduijie')],
  2476. [InlineKeyboardButton('返回', callback_data='backstart')]
  2477. ]
  2478. context.bot.send_message(chat_id=user_id, text=text, reply_markup=InlineKeyboardMarkup(keyboard),
  2479. disable_web_page_preview=True)
  2480. def zhiyanengliang(context: CallbackContext):
  2481. bot_id = context.bot.id
  2482. sd = mongo.get_wallet(bot_id).find_one({'projectname': '租赁'})
  2483. mongopledge = mongo.get_user_log(bot_id)
  2484. mongouser = mongo.get_group(bot_id)
  2485. mongolibrary = mongo.get_library(bot_id)
  2486. trc20 = sd['trc20']
  2487. client = Tron(HTTPProvider('https://api.tronwallets.vip', 30))
  2488. contract = client.get_contract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")
  2489. USDT = contract.functions.balanceOf(trc20) / 1000000
  2490. try:
  2491. TRX = client.get_account_balance(trc20)
  2492. except:
  2493. TRX = 0
  2494. mongo.get_wallet(bot_id).update_one({'projectname': '租赁'},
  2495. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  2496. mongo.get_wallet(bot_id).update_one({'projectname': '充值'},
  2497. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  2498. ss_trc20 = sd['trc20']
  2499. a = sd['timer']
  2500. tranhash = context.job.context['transaction_id']
  2501. to_url = context.job.context['toAddress']
  2502. transferType = context.job.context['transferType']
  2503. onwer_url = context.job.context['ownerAddress']
  2504. value = context.job.context['money']
  2505. block_timestamp = context.job.context['timestamp']
  2506. today_money = float(value)
  2507. client = Tron(HTTPProvider('https://api.tronwallets.vip', 30))
  2508. if mongopledge.find_one({'tranhash': tranhash}) is None:
  2509. library_list = mongolibrary.find_one({'today_money': today_money})
  2510. if library_list:
  2511. zztrc20 = library_list['trc20']
  2512. zzmoney = library_list['zzmoney']
  2513. uid = library_list['user_id']
  2514. mongo.shiyong.update_one({"tranhash": tranhash},{"$set":{"user_id": uid}})
  2515. TRX = sd['TRX']
  2516. try:
  2517. library_list.update({'tranhash': tranhash, 'timestamp': block_timestamp})
  2518. mongo.get_order(bot_id).insert_one(library_list)
  2519. except:
  2520. pass
  2521. while 1:
  2522. sd = mongo.get_wallet(bot_id).find_one({'projectname': '租赁'})
  2523. trc20 = sd['trc20']
  2524. sign = sd['sign']
  2525. zhiya = sd['zhiya']
  2526. yiyong = sd['shiyong']
  2527. shengyu = shijikeyongTRX(trc20)
  2528. ss_trc20 = sd['trc20']
  2529. a = sd['timer']
  2530. TRX = sd['TRX']
  2531. if shengyu >= zzmoney:
  2532. for zzzh in zztrc20:
  2533. zcmoney = zzzh['zzmoney']
  2534. zytrc20 = zzzh['trc20']
  2535. wusuijishu = zzzh['zuzhimoney']
  2536. shengmoney = zzzh['shengmoney']
  2537. pencount = zzzh['pencount']
  2538. days = zzzh['days']
  2539. if trc20 == zytrc20:
  2540. order_id = str(uuid.uuid4())
  2541. mongo.pledge_data('充值租赁本地址',bot_id,order_id, block_timestamp, tranhash, '', '', '', '', '', '', '', '能量', '',
  2542. '', '', '', '', '')
  2543. order_id = str(uuid.uuid4())
  2544. mongo.userlogdata(bot_id, order_id, block_timestamp, '', 'Trx', '', '', '能量租赁',
  2545. 0, float(today_money),
  2546. f'',
  2547. tranhash, '')
  2548. mongo.shiyong.update_one({"tranhash": tranhash},{"$set":{"state": 1}})
  2549. mongolibrary.delete_one({'today_money': today_money})
  2550. return
  2551. else:
  2552. while 1:
  2553. try:
  2554. txndata = dailineg(trc20, zytrc20, float(zcmoney))
  2555. break
  2556. except Exception as f:
  2557. with open('签名助手异常.txt', 'a+') as rz:
  2558. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  2559. rz.write(f'{timer} {f}\n')
  2560. time.sleep(1)
  2561. txid = txndata['txid']
  2562. ss_trc20 = trc20
  2563. jiashiyong = Decimal(str(zcmoney)) + Decimal(str(yiyong))
  2564. mongo.get_wallet(bot_id).update_one({'projectname': '租赁'},{
  2565. "$set": {'shiyong': float(jiashiyong)}})
  2566. getnengliang = getduoshaoneng(zcmoney)
  2567. us_list = mongo.get_group(bot_id).find_one({"user_id": uid})
  2568. lang = us_list['lang']
  2569. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  2570. tomorrow_str = (date.today() + timedelta(days=+int(days))).strftime(f"%Y-%m-%d {timer[-8:]}")
  2571. if lang == 'zh':
  2572. fs_text = f'''
  2573. 租赁成功
  2574. 你的账户: <code>{zytrc20}</code>
  2575. 每天转账{pencount}次,{days}天,租赁{wusuijishu}Trx,省{shengmoney}Trx
  2576. 过期时间: {tomorrow_str}
  2577. <a href="https://tronscan.org/#/transaction/{txid}">租赁详细</a>
  2578. '''
  2579. else:
  2580. fs_text = f'''
  2581. Rental successful
  2582. Your account: <code>{zytrc20}</code>
  2583. Transfer {pencount} times per day, {days} day, rent {wusuijishu}Trx, save {shengmoney}Trx
  2584. Expires: {tomorrow_str}
  2585. <a href="https://tronscan.org/#/transaction/{txid}">Rental details</a>
  2586. '''
  2587. context.job_queue.run_once(nlyongjin, 1,context={'user_id': uid,'money': wusuijishu,'trc20': onwer_url, 'projectname': '能量销售额奖励'})
  2588. try:
  2589. context.bot.send_message(chat_id=uid, text=fs_text, parse_mode='HTML',
  2590. disable_web_page_preview=True)
  2591. except:
  2592. pass
  2593. us_list = mongo.get_group(bot_id).find_one({"user_id": uid})
  2594. us_firstname = us_list['firstname']
  2595. us_username = us_list['username']
  2596. us_id = us_list['user_id']
  2597. fullname = us_list['fullname']
  2598. order_id = str(uuid.uuid4())
  2599. mongo.pledge_data('转账租赁', bot_id, order_id, block_timestamp, tranhash, txid, uid, ss_trc20, zcmoney,
  2600. wusuijishu, today_money, shengmoney, '能量', zytrc20, pencount, '', days, timer,
  2601. tomorrow_str)
  2602. order_id = str(uuid.uuid4())
  2603. mongo.userlogdata(bot_id, order_id, block_timestamp, txid, 'Trx', uid, onwer_url, '能量租赁',
  2604. 0, float(today_money),
  2605. f'能量租赁\n<code>{onwer_url}</code>转<code>{today_money}</code>Trx至<code>{to_url}</code>\n租赁<code>{wusuijishu}</code>TRX',
  2606. tranhash, timer)
  2607. mongo.get_wallet(bot_id).update_one({'projectname': '租赁'}, {"$set": {'TRXstate': 0}})
  2608. time.sleep(3)
  2609. liada1 = shengnengliang(trc20)
  2610. zongnl = liada1['zong']
  2611. keyong = liada1['keyong']
  2612. text = f'''
  2613. 用户: <a href="tg://user?id={uid}">{us_firstname}</a> @{us_username} 租赁成功
  2614. 地址: <code>{zytrc20}</code>
  2615. 每天转账{pencount}次,{days}天,租赁{wusuijishu}Trx,省{shengmoney}Trx
  2616. 过期时间: {tomorrow_str}
  2617. <a href="https://tronscan.org/#/transaction/{txid}">租赁详细</a>
  2618. 本次质押{zcmoney}Trx, 产生{getnengliang}能量
  2619. 总能量: {zongnl}, 可用能量: {keyong}
  2620. '''
  2621. for us in list(mongo.get_group(bot_id).find({'state': '4'})):
  2622. if us['user_id'] == uid:
  2623. continue
  2624. try:
  2625. context.bot.send_message(chat_id=us['user_id'], text=text, parse_mode='HTML',
  2626. disable_web_page_preview=True)
  2627. except:
  2628. continue
  2629. chat_text = f'''
  2630. 地址: <code>{zytrc20}</code>
  2631. 每天转账{pencount}次,{days}天,租赁{wusuijishu}Trx,省{shengmoney}Trx
  2632. 过期时间: {tomorrow_str}
  2633. '''
  2634. for ch in list(mongo.user_status.find({})):
  2635. chid = ch['chat_id']
  2636. try:
  2637. context.bot.send_message(chat_id=chid, text=chat_text, parse_mode='HTML',
  2638. disable_web_page_preview=True)
  2639. except:
  2640. continue
  2641. us_list = mongo.get_group(bot_id).find_one({"user_id": uid})
  2642. us_firstname = us_list['firstname']
  2643. us_username = us_list['username']
  2644. us_id = us_list['user_id']
  2645. text = f'''
  2646. 用户: <a href="tg://user?id={uid}">{us_firstname}</a> @{us_username}
  2647. 提交了{len(zztrc20)}笔质押,成功{len(zztrc20)}笔
  2648. '''
  2649. try:
  2650. context.bot.send_message(chat_id=uid, text=text, parse_mode='HTML',
  2651. disable_web_page_preview=True)
  2652. except:
  2653. pass
  2654. for us in list(mongo.get_group(bot_id).find({'state': '4'})):
  2655. if us['user_id'] == uid:
  2656. continue
  2657. try:
  2658. context.bot.send_message(chat_id=us['user_id'], text=text, parse_mode='HTML',
  2659. disable_web_page_preview=True)
  2660. except:
  2661. continue
  2662. mongo.shiyong.update_one({"tranhash": tranhash},{"$set":{"state": 1}})
  2663. mongolibrary.delete_one({'today_money': today_money})
  2664. break
  2665. else:
  2666. TRXstate = sd['TRXstate']
  2667. fsdztrc20 = []
  2668. for zzzh in zztrc20:
  2669. zytrc20 = zzzh['trc20']
  2670. fsdztrc20.append(zytrc20)
  2671. fsdztrc20 = ','.join(fsdztrc20)
  2672. jiaqilai = float(Decimal(str(TRX)) + Decimal(str(shengyu)))
  2673. xuyaobuqi = float(Decimal(str(zzmoney)) - (Decimal(str(shengyu)) + Decimal(str(TRX))))
  2674. if TRX >= xuyaobuqi:
  2675. while 1:
  2676. try:
  2677. txndata = sockzhiyaneng(trc20, xuyaobuqi)
  2678. break
  2679. except Exception as f:
  2680. with open('签名助手异常.txt', 'a+') as rz:
  2681. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  2682. rz.write(f'{timer} {f}\n')
  2683. time.sleep(1)
  2684. txid = txndata['txid']
  2685. jiazhiya = Decimal(str(zzmoney)) + Decimal(str(zhiya))
  2686. mongo.get_wallet(bot_id).update_one({'projectname': '租赁'}, {"$set": {'zhiya': float(jiazhiya)}})
  2687. time.sleep(3)
  2688. context.job_queue.run_once(zhiyanengliang, 1,context={'transaction_id': tranhash,'transferType': 'TRX','ownerAddress': onwer_url,'toAddress': to_url,'money': value,'timestamp': block_timestamp})
  2689. return
  2690. else:
  2691. qwer = f'''
  2692. 租赁钱包
  2693. <code>{trc20}</code>不足质押
  2694. 能量{zzmoney}Trx,剩余可用能量{shengyu}Trx,现有{TRX}TRX,需补齐{xuyaobuqi}Trx质押
  2695. <a href="https://tronscan.org/#/transaction/{tranhash}">转账详细</a>
  2696. 质押地址: {fsdztrc20}
  2697. '''
  2698. jisuanhash = tranhash[:-6]
  2699. if mongo.lssj.find_one({"transaction_id": tranhash}) is None:
  2700. weiyiid = str(uuid.uuid4())
  2701. else:
  2702. weiyiid = mongo.lssj.find_one({"transaction_id": tranhash})['bianhao']
  2703. mongo.lssj.update_one({"transaction_id": tranhash},{"$set":{"state": 0}})
  2704. datashuju = {'bianhao': weiyiid, 'transaction_id': tranhash,'transferType': transferType,'ownerAddress': onwer_url,'toAddress': to_url,'money': today_money,'timestamp': block_timestamp, 'state': 0}
  2705. keyboard = [
  2706. ]
  2707. if TRXstate == 0:
  2708. mongo.get_wallet(bot_id).update_one({'projectname': '租赁'}, {"$set": {'TRXstate': 1}})
  2709. for i in list(mongouser.find({'state': '4'})):
  2710. # context.user_data[f'{i["user_id"]}yiwai{jisuanhash}'] = {'transaction_id': tranhash,'transferType': 'TRX','ownerAddress': onwer_url,'toAddress': to_url,'money': value,'timestamp': block_timestamp}
  2711. try:
  2712. context.bot.send_message(chat_id=i['user_id'],
  2713. text=qwer,
  2714. parse_mode='HTML',disable_web_page_preview=True,reply_markup=InlineKeyboardMarkup(keyboard))
  2715. except:
  2716. pass
  2717. time.sleep(3)
  2718. contract = client.get_contract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")
  2719. USDT = contract.functions.balanceOf(trc20) / 1000000
  2720. try:
  2721. TRX = client.get_account_balance(trc20)
  2722. except:
  2723. TRX = 0
  2724. mongo.get_wallet(bot_id).update_one({'projectname': '租赁'},
  2725. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  2726. mongo.get_wallet(bot_id).update_one({'projectname': '充值'},
  2727. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  2728. elif mongouser.find_one({'trc_url': {"$regex": onwer_url}}) != None:
  2729. user_list = mongouser.find_one({'trc_url': {"$regex": onwer_url}})
  2730. user_id = user_list['user_id']
  2731. TRX = user_list['TRX']
  2732. dazhe = user_list['dazhe']
  2733. user_money = float((Decimal(str(TRX)) + Decimal(str(today_money))).quantize(Decimal('0.001')))
  2734. # if today_money >= 10000:
  2735. # mongouser.update_one({'user_id': user_id}, {"$set": {'dazhe': 0.8}})
  2736. # text = f'''
  2737. # 充值金额一次性达到10000Trx以上!
  2738. # 能量租赁享受8折优惠
  2739. # '''
  2740. # if dazhe != 0.8:
  2741. # context.bot.send_message(chat_id=user_id, text=text,
  2742. # parse_mode='HTML')
  2743. # elif today_money >= 5000:
  2744. # mongouser.update_one({'user_id': user_id}, {"$set": {'dazhe': 0.9}})
  2745. # text = f'''
  2746. # 充值金额一次性达到5000Trx以上!
  2747. # 能量租赁享受9折优惠
  2748. # '''
  2749. # if dazhe != 0.9:
  2750. # context.bot.send_message(chat_id=user_id, text=text,
  2751. # parse_mode='HTML')
  2752. # else:
  2753. # pass
  2754. mongouser.update_one({'user_id': user_id}, {"$set": {'TRX': user_money}})
  2755. text = f'''
  2756. 👏 恭喜!
  2757. 成功充值 {today_money} Trx
  2758. '''
  2759. context.bot.send_message(chat_id=user_id, text=text, parse_mode='HTML')
  2760. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  2761. order_id = str(uuid.uuid4())
  2762. mongo.userlogdata(bot_id, order_id, block_timestamp, '', 'Trx', user_id, onwer_url, '充值',
  2763. 0, today_money,
  2764. f'充值\n<code>{onwer_url}</code>转<code>{today_money}</code>TRX至<code>{to_url}</code>\n成功充值<code>{today_money}</code>Usdt',
  2765. tranhash, timer)
  2766. us_list = mongo.get_group(bot_id).find_one({"user_id": user_id})
  2767. us_firstname = us_list['firstname']
  2768. us_username = us_list['username']
  2769. text = f'''
  2770. 用户: <a href="tg://user?id={user_id}">{us_firstname}</a> @{us_username} 充值成功
  2771. 地址: <code>{onwer_url}</code>
  2772. 充值: {today_money} Trx
  2773. <a href="https://tronscan.org/#/transaction/{tranhash}">充值详细</a>
  2774. '''
  2775. for us in list(mongo.get_group(bot_id).find({'state': '4'})):
  2776. try:
  2777. context.bot.send_message(chat_id=us['user_id'], text=text, parse_mode='HTML',
  2778. disable_web_page_preview=True)
  2779. except:
  2780. continue
  2781. # user_list = mongouser.find_one({'user_id': user_id})
  2782. # TRX = user_list['TRX']
  2783. # trc_list = []
  2784. # for i in list(
  2785. # mongouser.find({'user_id': user_id, 'trc_url': {'$ne': None}})):
  2786. # for tc in i['trc_url'].split(','):
  2787. # trc_list.append(f'<code>{tc}</code>')
  2788. # if trc_list == []:
  2789. # trc_list = ''
  2790. # else:
  2791. # trc_list = '已绑定地址:\n' + "\n".join(trc_list)
  2792. # text = f'''
  2793. # 账户ID:
  2794. # <code>{user_id}</code>
  2795. # 余额:
  2796. # <code>{TRX}</code> TRX
  2797. # {trc_list}
  2798. # '''
  2799. # keyboard = [
  2800. # [InlineKeyboardButton('闪兑报表', callback_data='usershanduibb'),
  2801. # InlineKeyboardButton('闪兑明细', callback_data='flashexchange')],
  2802. # [InlineKeyboardButton('能量报表', callback_data='usernengliangbaobiao'),
  2803. # InlineKeyboardButton('能量明细', callback_data='usernengliangmingxi')]
  2804. # ]
  2805. # context.bot.send_message(chat_id=user_id, text=text,
  2806. # parse_mode='HTML',
  2807. # reply_markup=InlineKeyboardMarkup(keyboard))
  2808. time.sleep(3)
  2809. contract = client.get_contract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")
  2810. USDT = contract.functions.balanceOf(trc20) / 1000000
  2811. try:
  2812. TRX = client.get_account_balance(trc20)
  2813. except:
  2814. TRX = 0
  2815. mongo.get_wallet(bot_id).update_one({'projectname': '租赁'},
  2816. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  2817. mongo.get_wallet(bot_id).update_one({'projectname': '充值'},
  2818. {"$set": {"USDT": float(USDT), 'TRX': float(TRX)}})
  2819. def djth(update: Update, context: CallbackContext):
  2820. query = update.callback_query
  2821. user_id = query.from_user.id
  2822. bot_id = context.bot.id
  2823. jiaoyihash = query.data.replace('djth ', '')
  2824. log_list = mongo.get_user_log(bot_id).find_one({'tranhash': {'$regex': jiaoyihash}})
  2825. tranhash = log_list['tranhash']
  2826. zlstate = log_list['zlstate']
  2827. TRX = log_list['TRX']
  2828. trc20 = log_list['trc20']
  2829. if zlstate == 0:
  2830. query.answer(text=f'已操作退回{TRX}Trx', show_alert=bool("true"))
  2831. mongo.get_user_log(bot_id).update_one({'tranhash': tranhash},{"$set":{"zlstate": 1}})
  2832. mongo.get_wallet(bot_id).update_one({'projectname': '租赁'},{"$set":{f"tuihui{tranhash}": tranhash}})
  2833. elif zlstate == 1:
  2834. query.answer(text=f'管理员已操作退回,点击无效', show_alert=bool("true"))
  2835. elif zlstate == 2:
  2836. query.answer(text=f'管理员已操作飞单,操作点击无效无效', show_alert=bool("true"))
  2837. def djfd(update: Update, context: CallbackContext):
  2838. query = update.callback_query
  2839. user_id = query.from_user.id
  2840. bot_id = context.bot.id
  2841. jiaoyihash = query.data.replace('djfd ', '')
  2842. log_list = context.user_data[f'{user_id}yiwai{jiaoyihash}']
  2843. ownerAddress = log_list['ownerAddress']
  2844. toAddress = log_list['toAddress']
  2845. money = log_list['money']
  2846. transaction_id = log_list['transaction_id']
  2847. timestamp = log_list['timestamp']
  2848. nenglbaifenb = mongo.shang_text.find_one({'projectname': '获利比例'})['text']
  2849. if mongo.get_pledge(bot_id).find_one({'tranhash': transaction_id}) is None:
  2850. text = f'''
  2851. 订单已支付金额:{money}
  2852. 获利比例:{nenglbaifenb}%
  2853. 飞单支付金额:
  2854. '''
  2855. else:
  2856. query.answer(text=f'管理员已操作飞单,操作点击无效无效', show_alert=bool("true"))
  2857. class SocketClient:
  2858. def __init__(self,bot_id,context):
  2859. self.socket = None
  2860. self.emptyDataCount = 0
  2861. self.cmdstate = 1
  2862. self.bot_id = bot_id
  2863. self.cmdstate = 1
  2864. self.zxstate = 0
  2865. self.context = context
  2866. # 连接服务端
  2867. def connectServer(self) -> bool:
  2868. global server_ip_port
  2869. self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  2870. self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  2871. try:
  2872. self.socket.connect(('104.219.214.234', 56560))
  2873. except Exception as e:
  2874. print(e)
  2875. self.socket.close()
  2876. return False
  2877. try:
  2878. if self.zxstate == 0:
  2879. if mongo.get_kehuduan().find_one({}) == None:
  2880. self.regirst()
  2881. else:
  2882. self.souquan()
  2883. self.listenMsg()
  2884. # 发送心跳
  2885. self.sendHeartbeatThread()
  2886. except Exception as f:
  2887. with open('日志.txt', 'a+') as rz:
  2888. rz.write(f'{f}\n')
  2889. self.socket.close()
  2890. return False
  2891. self.zxstate = 1
  2892. return True
  2893. def souquan(self):
  2894. while 1:
  2895. khd_list = mongo.get_kehuduan().find_one({})
  2896. if khd_list != None:
  2897. break
  2898. time.sleep(1)
  2899. api = khd_list['api']
  2900. key = khd_list['key']
  2901. tcid = khd_list['tcid']
  2902. shijiancuo = int(time.time())
  2903. jiaoyanma = hashlib.md5(f'auth{key}{shijiancuo}'.encode()).hexdigest()
  2904. data = {"cmd": "auth", "api": api, "checksum": jiaoyanma, "tm": f"{shijiancuo}", "tcid": tcid}
  2905. with open('授权日记.txt','a+') as f:
  2906. f.write(f"{data}")
  2907. datalen = struct.pack('i', len(json.dumps(data, cls=MyEncoder).encode()))
  2908. self.sendMsg(datalen)
  2909. self.sendMsg(json.dumps(data, cls=MyEncoder).encode())
  2910. #添加监控地址
  2911. def addjiankong(self,trc20):
  2912. data = {"cmd":"addr-add","data":trc20}
  2913. datalen = struct.pack('i', len(json.dumps(data,cls=MyEncoder).encode()))
  2914. self.sendMsg(datalen)
  2915. self.sendMsg(json.dumps(data, cls=MyEncoder).encode())
  2916. #删除监控地址
  2917. def adddel(self,trc20):
  2918. data = {"cmd":"addr-del","data":trc20}
  2919. datalen = struct.pack('i', len(json.dumps(data,cls=MyEncoder).encode()))
  2920. self.sendMsg(datalen)
  2921. self.sendMsg(json.dumps(data, cls=MyEncoder).encode())
  2922. def cszl(self):
  2923. while 1:
  2924. if self.connectServer():
  2925. break
  2926. #注册机器人
  2927. def regirst(self):
  2928. shuju = {"cmd":"reg","rem":"bot", "name": "Tron_energybot"}
  2929. cd = len(str(shuju))
  2930. data = struct.pack('i', cd)
  2931. self.sendMsg(data)
  2932. self.sendMsg(json.dumps(shuju,cls=MyEncoder).encode())
  2933. # 监听消息
  2934. def listenMsg(self):
  2935. thread = threading.Thread(target=self.receiveMsg)
  2936. thread.start()
  2937. def receiveMsg(self):
  2938. # packet = ''
  2939. # while True:
  2940. # try:
  2941. # data = self.socket.recv(BUF_SIZE) # 接受信息
  2942. # if data == b'':
  2943. # self.socket.close()
  2944. # self.listenMsg()
  2945. # break
  2946. # packet += data
  2947. # num = struct.unpack('i', data[0:4])
  2948. # jsondata = json.loads(data[4:num[0] + 4])
  2949. packet = b''
  2950. while True:
  2951. try:
  2952. data = self.socket.recv(BUF_SIZE) # 接受信息
  2953. if data == b'':
  2954. self.close()
  2955. self.zxstate = 0
  2956. thread = threading.Thread(target=self.cszl)
  2957. thread.start()
  2958. return
  2959. packet += data
  2960. while 1:
  2961. if len(packet) < 4:
  2962. break
  2963. num = struct.unpack('i', packet[0:4])
  2964. if len(packet) < num[0]:
  2965. break
  2966. jsondata = json.loads(packet[4:num[0] + 4])
  2967. with open('日志.txt', 'a+') as rz:
  2968. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  2969. rz.write(f'{timer} {jsondata}\n')
  2970. if jsondata['cmd'] == 'transcan':
  2971. quant123 = Decimal(jsondata['data']['quant']) / Decimal('1000000')
  2972. quant = abs(float(quant123))
  2973. tcid = jsondata['data']['id']
  2974. mongo.get_kehuduan().update_one({},{"$set":{"tcid": tcid}})
  2975. type = jsondata['data']['type']
  2976. if float(quant) >= 1 and type in ['USDT', 'TRX']:
  2977. fromaddress = jsondata['data']['from']
  2978. toaddress = jsondata['data']['to']
  2979. tran_id = jsondata['data']['tran_id']
  2980. timestamp = jsondata['data']['time']
  2981. number = jsondata['data']['number']
  2982. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  2983. create_time = int(timestamp)
  2984. time_tuple_1 = time.localtime(create_time)
  2985. create_time = time.strftime("%Y/%m/%d %H:%M:%S", time_tuple_1)
  2986. starturl = fromaddress[0:3]
  2987. endurl = fromaddress[-7:]
  2988. repurl = fromaddress.replace(starturl, '', 1).replace(endurl, '', 1)
  2989. zqurl = fromaddress.replace(repurl, '**')
  2990. slownerAddress = zqurl.replace(fromaddress[3:7], '')
  2991. starturl = toaddress[0:3]
  2992. endurl = toaddress[-7:]
  2993. repurl = toaddress.replace(starturl, '', 1).replace(endurl, '', 1)
  2994. zqurl = toaddress.replace(repurl, '**')
  2995. sltrc20 = zqurl.replace(toaddress[3:7], '')
  2996. starturl = tran_id[0:3]
  2997. endurl = tran_id[-7:]
  2998. repurl = tran_id.replace(starturl, '', 1).replace(endurl, '', 1)
  2999. zqurl = tran_id.replace(repurl, '**')
  3000. sltransaction_id = zqurl.replace(tran_id[3:7], '')
  3001. rztext = f'''
  3002. <b>入账! +{quant} {type} </b>
  3003. 交易时间:<b>{create_time}</b>
  3004. 出账地址:<a href="https://tronscan.org/#/address/{fromaddress}">{slownerAddress}</a>
  3005. 入账地址:<a href="https://tronscan.org/#/address/{toaddress}">{sltrc20}</a> ←
  3006. 区块值:<a href="https://tronscan.org/#/transaction/{tran_id}">{number}</a>
  3007. '''
  3008. cztext = f'''
  3009. <b>出账! -{quant} {type} </b>
  3010. 交易时间:<b>{create_time}</b>
  3011. 出账地址:<a href="https://tronscan.org/#/address/{fromaddress}">{slownerAddress}</a> ←
  3012. 入账地址:<a href="https://tronscan.org/#/address/{toaddress}">{sltrc20}</a>
  3013. 区块值:<a href="https://tronscan.org/#/transaction/{tran_id}">{number}</a>
  3014. '''
  3015. print_list = [{'transaction_id': tran_id,'transferType': type,'ownerAddress': fromaddress,'toAddress': toaddress,'money': quant,'timestamp': timestamp,
  3016. 'rztext': rztext,'cztext': cztext}]
  3017. sd = mongo.get_wallet(self.bot_id).find_one({'projectname': '闪兑'})
  3018. sdtrc20 = sd['trc20']
  3019. zl = mongo.get_wallet(self.bot_id).find_one({'projectname': '租赁'})
  3020. zltrc20 = zl['trc20']
  3021. if toaddress == 'TN3mWbrEaiEWKAMqQ5MDz2WEGCZKKKKKKK':
  3022. if mongo.dj.find_one({"money": quant}) is not None:
  3023. self.context.job_queue.run_once(wanzhanczcg, 1,context={'transaction_id': tran_id,'transferType': type,'ownerAddress': fromaddress,'toAddress': toaddress,'money': quant,'timestamp': timestamp})
  3024. if mongo.shiyong.find_one({'tranhash': tran_id}) is None:
  3025. if type == 'TRX':
  3026. if toaddress == sdtrc20:
  3027. if mongo.designated.find_one({'duitype': 'tdu', 'money': quant}) is not None:
  3028. mongo.sydata(tran_id)
  3029. self.context.job_queue.run_once(seletdu, 1,context={'transaction_id': tran_id,'transferType': type,'ownerAddress': fromaddress,'toAddress': toaddress,'money': quant,'timestamp': timestamp})
  3030. else:
  3031. if mongo.heixiazi.find_one({'trc20': fromaddress,'$or':[{'trcstate': '1'},{'trcstate': '3'}]}) is None:
  3032. mongo.sydata(tran_id)
  3033. self.context.job_queue.run_once(usdtshandui, 1,context={'transaction_id': tran_id,'transferType': type,'ownerAddress': fromaddress,'toAddress': toaddress,'money': quant,'timestamp': timestamp})
  3034. if toaddress == zltrc20:
  3035. mongo.sydata(tran_id)
  3036. nlqx = mongo.shang_text.find_one({'projectname': '能量单飞到网站'})['text']
  3037. if nlqx == 0:
  3038. self.context.job_queue.run_once(zhiyanengliang, 1,context={'transaction_id': tran_id,'transferType': type,'ownerAddress': fromaddress,'toAddress': toaddress,'money': quant,'timestamp': timestamp})
  3039. else:
  3040. self.context.job_queue.run_once(twwebfeidan, 1,context={'transaction_id': tran_id,'transferType': type,'ownerAddress': fromaddress,'toAddress': toaddress,'money': quant,'timestamp': timestamp})
  3041. else:
  3042. if toaddress == sdtrc20:
  3043. if mongo.designated.find_one({'duitype': 'udt', 'money': quant}) is not None:
  3044. mongo.sydata(tran_id)
  3045. self.context.job_queue.run_once(seleudt, 1,context={'transaction_id': tran_id,'transferType': type,'ownerAddress': fromaddress,'toAddress': toaddress,'money': quant,'timestamp': timestamp})
  3046. else:
  3047. if mongo.heixiazi.find_one({'trc20': fromaddress,'$or':[{'trcstate': '1'},{'trcstate': '3'}]}) is None:
  3048. mongo.sydata(tran_id)
  3049. self.context.job_queue.run_once(trxshandui, 1,context={'transaction_id': tran_id,'transferType': type,'ownerAddress': fromaddress,'toAddress': toaddress,'money': quant,'timestamp': timestamp})
  3050. if float(quant123) < 0:
  3051. trc_20 = fromaddress
  3052. self.context.job_queue.run_once(print_chat, 1,
  3053. context={'trc20': trc_20, 'print_list': print_list, 'text': cztext})
  3054. # context.job_queue.run_once(print_zc, 1,context={'transaction_id': transaction_id,'trc20': trc_20,'cztext': cztext})
  3055. else:
  3056. trc_20 = toaddress
  3057. self.context.job_queue.run_once(print_chat, 1,
  3058. context={'trc20': trc_20, 'print_list': print_list, 'text': rztext})
  3059. else:
  3060. sd = mongo.get_wallet(self.bot_id).find_one({'projectname': '闪兑'})
  3061. sdtrc20 = sd['trc20']
  3062. zl = mongo.get_wallet(self.bot_id).find_one({'projectname': '租赁'})
  3063. zltrc20 = zl['trc20']
  3064. if type == 'TRX':
  3065. fromaddress = jsondata['data']['from']
  3066. toaddress = jsondata['data']['to']
  3067. tran_id = jsondata['data']['tran_id']
  3068. timestamp = jsondata['data']['time']
  3069. number = jsondata['data']['number']
  3070. timer = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
  3071. create_time = int(timestamp)
  3072. time_tuple_1 = time.localtime(create_time)
  3073. create_time = time.strftime("%Y/%m/%d %H:%M:%S", time_tuple_1)
  3074. if toaddress == sdtrc20:
  3075. mongo.sydata(tran_id)
  3076. self.context.job_queue.run_once(usdtshandui, 1,context={'transaction_id': tran_id,'transferType': type,'ownerAddress': fromaddress,'toAddress': toaddress,'money': quant,'timestamp': timestamp})
  3077. elif jsondata['cmd'] == 'regok':
  3078. if mongo.get_kehuduan().find_one({}) is None:
  3079. mongo.kehuduanurl(jsondata['id'],jsondata['key'])
  3080. elif jsondata['cmd'] == 'addr-add-ret':
  3081. mongo.get_address(self.bot_id).update_one({'trc20': jsondata['addr']},{"$set":{"syn": True}})
  3082. elif jsondata['cmd'] == 'addr-del-ret':
  3083. mongo.get_address(self.bot_id).delete_one({'trc20': jsondata['addr']})
  3084. elif jsondata['cmd'] == 'auth-err':
  3085. self.close()
  3086. self.zxstate = 0
  3087. thread = threading.Thread(target=self.cszl)
  3088. thread.start()
  3089. return
  3090. packet = packet[num[0] + 4:]
  3091. except Exception as f:
  3092. with open('日志.txt', 'a+') as rz:
  3093. rz.write(f'{f}\n')
  3094. time.sleep(1)
  3095. self.close()
  3096. self.zxstate = 0
  3097. thread = threading.Thread(target=self.cszl)
  3098. thread.start()
  3099. return
  3100. def sendMsg(self, msg):
  3101. self.socket.send(msg)
  3102. def close(self):
  3103. self.socket.close()
  3104. def sendHeartbeatThread(self):
  3105. if self.cmdstate == 1:
  3106. thread = threading.Thread(target=self.sendHeartbeat)
  3107. thread.start()
  3108. self.cmdstate = 2
  3109. #发送心跳
  3110. def sendHeartbeat(self):
  3111. global server_ip_port
  3112. while True:
  3113. data_to_server = {"cmd": "k"}
  3114. while 1:
  3115. try:
  3116. self.socket.send(struct.pack('i', len(json.dumps(data_to_server,cls=MyEncoder).encode())))
  3117. self.socket.send(json.dumps(data_to_server,cls=MyEncoder).encode())
  3118. break
  3119. except socket.error:
  3120. time.sleep(5)
  3121. time.sleep(30)
  3122. class MyEncoder(json.JSONEncoder):
  3123. def default(self, obj):
  3124. if isinstance(obj, bytes):
  3125. return str(obj, encoding='utf-8')
  3126. return json.JSONEncoder.default(self, obj)