alptangall commited on
Commit
c387ccb
·
verified ·
1 Parent(s): 4a6596d

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +142 -0
main.py ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ import os,sys
3
+ import re,json
4
+ import discord
5
+ from discord.ext import commands, tasks
6
+ from discord import app_commands
7
+ from discord.utils import get
8
+ import random
9
+ import datetime
10
+ import server
11
+ from guild import *
12
+ from acb import *
13
+ import aiohttp
14
+ USERNAME=os.environ.get('username')
15
+ PASSWORD=os.environ.get('password')
16
+
17
+ intents = discord.Intents.default()
18
+ client = discord.Client(intents=intents)
19
+ tree = app_commands.CommandTree(client)
20
+ VIETTELS='032, 033, 034, 035, 036, 037, 038, 039, 096, 097, 098, 086'
21
+ VIETTELS=VIETTELS.split(',')
22
+ VINAPHONES=' 091, 094, 088, 081, 082, 083, 084, 085'
23
+ VINAPHONES=VINAPHONES.split(',')
24
+ VIETNAMOBILE='052, 056, 058, 092'
25
+ VIETNAMOBILE=VIETNAMOBILE.split(',')
26
+ HEADERS = []
27
+ THREADS = []
28
+ USERNAMES = []
29
+ GUILDID = 1236962671824211998
30
+ RESULT=None
31
+
32
+ def correctSingleQuoteJSON(s):
33
+ rstr = ""
34
+ escaped = False
35
+
36
+ for c in s:
37
+
38
+ if c == "'" and not escaped:
39
+ c = '"' # replace single with double quote
40
+
41
+ elif c == "'" and escaped:
42
+ rstr = rstr[:-1] # remove escape character before single quotes
43
+
44
+ elif c == '"':
45
+ c = '\\' + c # escape existing double quotes
46
+
47
+ escaped = (c == "\\") # check for an escape character
48
+ rstr += c # append the correct json
49
+
50
+ return rstr
51
+ INFO=False
52
+ BASE_URL='https://bot-py-8t7nnjtaylrcjeqj8tevuh.streamlit.app/'
53
+ @client.event
54
+ async def on_ready():
55
+ global INFO,RESULT
56
+ try:
57
+ req=requests.get('http://localhost:8888')
58
+ print(req.status_code)
59
+ print('Client closed')
60
+ sys.exit('Exited')
61
+ except Exception as error:
62
+ print(error)
63
+ server.b()
64
+ guild = client.get_guild(GUILDID)
65
+ rs=await login(USERNAME,PASSWORD)
66
+ RESULT=await getBasic(guild)
67
+ if rs:
68
+ INFO=rs
69
+ if not getTransAcb.is_running():
70
+ getTransAcb.start(guild)
71
+
72
+
73
+
74
+ @client.event
75
+ async def on_disconnect():
76
+ global RESULT
77
+ if RESULT:
78
+ acbThread=None
79
+ for thread in RESULT['banksCh'].threads:
80
+ if 'acb' in thread.name:
81
+ acbThread=thread
82
+ if acbThread:
83
+ msgs=[msg async for msg in acbThread.history()]
84
+ if len(msgs)>0:
85
+ old=re.search('.*Sessions are `(.*?)`.*',msgs[0].content).group(1)
86
+ i=int(old)-1 if int(old)>0 else 0
87
+ await msgs[0].edit(content='Sessions are `'+str(i)+'` actived')
88
+
89
+ @tasks.loop(seconds=1)
90
+ async def getTransAcb(guild):
91
+ global INFO
92
+ print('getTransAcb is running')
93
+ if INFO:
94
+ try:
95
+ rs1=await getListAccount(INFO)
96
+ for item in rs1['list']:
97
+ list=await getBalance(INFO,item['accountNumber'])
98
+ basic=await getBasic(guild)
99
+ threads=basic['acbCh'].threads+[thread async for thread in basic['acbCh'].archived_threads()]
100
+ if list:
101
+ data=list['data'][::-1]
102
+ for item in data:
103
+ applied_tags=[]
104
+ if str(item['activeDatetime']) not in str(threads):
105
+ tags=basic['acbCh'].available_tags
106
+ st=''
107
+ if item['type'].lower()=='in':
108
+ for tag in tags:
109
+ if 'in' in tag.name.lower() or 'chuyển đến' in tag.name.lower():
110
+ applied_tags.append(tag)
111
+ else:
112
+ for tag in tags:
113
+ if 'out' in tag.name.lower() or 'chuyển đi' in tag.name.lower():
114
+ applied_tags.append(tag)
115
+ if 'bankName' in item and item['bankName']!='':
116
+ st+='\nĐến ngân hàng: **'+item['bankName']+'**\n'
117
+ if 'receiverAccountNumber' in item and item['receiverAccountNumber']!='':
118
+ st+='\nĐến số tài khoản: **'+item['receiverAccountNumber']+'**'
119
+ if 'receiverName' in item and item['receiverName']!='':
120
+ st+='\nĐến chủ tài khoản: **'+item['receiverName']+'**'
121
+ allowed_mentions = discord.AllowedMentions(everyone = True)
122
+ amount=str(item['amount']).split('.')[0]
123
+ amount=[f'{cur:,}' for cur in [int(amount)]][0]
124
+ time=datetime.datetime.fromtimestamp(item['activeDatetime']/1000)
125
+ day=time.day if time.day>9 else '0'+str(time.day)
126
+ month=time.month if time.month>9 else '0'+str(time.month)
127
+ hour=time.hour if time.hour>9 else '0'+str(time.hour)
128
+ minute=time.minute if time.minute>9 else '0'+str(time.minute)
129
+ second=time.second if time.second>9 else '0'+str(time.second)
130
+ timestr=f'{day}/{month}/{time.year} {hour}:{minute}:{second}'
131
+ thread=await basic['acbCh'].create_thread(name=('+ ' if item['type'].lower()=='in' else '- ')+amount+' '+item['currency']+'/ '+str(item['activeDatetime']),content='\nSố tiền: **'+amount+' '+item['currency']+'**\nNội dung: **'+item['description']+'**\nBiến động trên STK: **'+str(item['account'])+'**\nThời điểm: **'+timestr.split(' ')[1]+'** ngày **'+timestr.split(' ')[0]+'**'+st+'\n@everyone',applied_tags =applied_tags )
132
+ else:
133
+ rs=await login(USERNAME,PASSWORD)
134
+ if rs:
135
+ INFO=rs
136
+ except Exception as error:
137
+ print(error)
138
+ rs=await login(USERNAME,PASSWORD)
139
+ if rs:
140
+ INFO=rs
141
+
142
+ client.run(os.environ.get('botToken'))