-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
211 lines (172 loc) · 7.41 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/python3
from flask import Flask
from flask import request
from flask import jsonify
import requests
import json
import re
from threading import Thread
from MainFile import mainWork
import queue
from Makers import Print
#from flask_sslify import SSLify
print("uping file")
#listOfGame = []
#listOfMember = []
#def loopSendStrat():
#threadSendStrat = Thread(target=loopSendStrat, args=[])
#threadSendStrat.start()
app = Flask(__name__)
#sslify = SSLify(app)
http = "http"
serverIP_Port = ""
http = "http"
serverIP_Port = ""
token = ''
URL = 'https://api.telegram.org/bot' + token + '/'
def parseText(text):
pattern = r'/\w+'
ret = re.search(pattern, text).group()
return ret[1:]
@app.route('/', methods = ['POST', 'GET'])
def index():
print("u posta")
if request.method == 'POST':
req = request.get_json()
print(req)
try:
chat_id = req['message']['chat']['id']
#print("get chat id")
message = req['message']['text']
#print("get message")
name = req['message']['from']['first_name']
#print("get user id")
user_id = req['message']['from']['id']
except:
return 'hello g'
#print(listOfGame)
command = message
print("у комманд")
if (command == '/me'):
send_message(chat_id=0, text=str(chat_id)) # i'm
send_message(chat_id=0, text="from: " + getNamePrint(chat_id, user_id)) # i'm
elif (command == '/game'):
#global listOfGame
send_message(chat_id=chat_id, text=Print.getStrAboutGame(listOfGame=listOfGame))
elif (chat_id==0 and len(command.split('?')) > 0 and command.split('?')[0] == '/addshort'):
send_message(chat_id=0, text="add: " +command.split('?')[1]) # i'm
listOfMemberShort.append(int(command.split('?')[1]))
send_message(chat_id=int(command.split('?')[1]), text="вы добавлены в рассылку!")
elif (chat_id==0 and len(command.split('?')) > 0 and command.split('?')[0] == '/addall'):
send_message(chat_id=0, text="add: " +command.split('?')[1]) # i'm
listOfMemberAll.append(int(command.split('?')[1]))
send_message(chat_id=int(command.split('?')[1]), text="вы добавлены в рассылку с полной отдачей!")
elif (chat_id==0 and len(command.split('?')) > 0 and command.split('?')[0] == '/addstrat'):
send_message(chat_id=0, text="add: " +command.split('?')[1]) # i'm
listOfMemberStrat.append(int(command.split('?')[1]))
send_message(chat_id=int(command.split('?')[1]), text="вы добавлены в рассылку по стратам!")
elif (command=='/all' and checkInStrat(chat_id)):
try:
listOfMemberStrat.remove(chat_id)
listOfMemberAll.append(chat_id)
send_message(chat_id=chat_id, text="вы добавлены в рассылку с полнйо отдачей!")
except:
send_message(chat_id=0, text="alladd truble: " + str(chat_id)) # i'm
send_message(chat_id=chat_id, text="alladd truble please write @AZchDev") # i'm
elif (command=='/strat' and checkInAll(chat_id)):
try:
listOfMemberAll.remove(chat_id)
listOfMemberStrat.append(chat_id)
send_message(chat_id=chat_id, text="вы добавлены в рассылку по стратам!")
except:
send_message(chat_id=0, text="stratadd truble: " + str(chat_id)) # i'm
send_message(chat_id=chat_id, text="stratadd truble please write @0") # i'm
elif (chat_id==0 and len(command.split('?')) > 0 and command.split('?')[0] == '/delshort'):
try:
send_message(chat_id=0, text="del: " +command.split('?')[1]) # i'm
delFromShort(command.split('?')[1])
send_message(chat_id=int(command.split('?')[1]), text="вы удалены из ограниченной рассылки!")
except:
send_message(chat_id=0, text="delshort truble: " + str(chat_id)) # i'm
elif (chat_id==0 and len(command.split('?')) > 0 and command.split('?')[0] == '/dellist'):
try:
send_message(chat_id=0, text="del: " +command.split('?')[1]) # i'm
delFromLists(command.split('?')[1])
send_message(chat_id=int(command.split('?')[1]), text="вы удалены из рассылки!")
except:
send_message(chat_id=0, text="dellist truble: " + str(chat_id)) # i'm
return 'hello g'
return 'hello g'
#if (request.method == 'POST'):
#try:
#req = request.get_json()
def delFromLists(chat_id):
for oneId in listOfMemberAll:
if (oneId == chat_id):
listOfMemberAll.remove(oneId)
for oneId in listOfMemberStrat:
if (oneId == chat_id):
listOfMemberStrat.remove(oneId)
def delFromShort(chat_id):
for oneId in listOfMemberShort:
if (oneId == chat_id):
listOfMemberShort.remove(oneId)
def checkInStrat(chat_id):
for oneId in listOfMemberStrat:
if (oneId == chat_id):
return True
return False
def checkInAll(chat_id):
for oneId in listOfMemberAll:
if (oneId == chat_id):
return True
return False
def getNamePrint(chat_id, user_id):
namePrint = ''
answer = {'chat_id': chat_id, 'user_id': user_id}
user = requests.get(URL + 'getChatMember', answer).json()
try:
return " @%s (%s %s)" % (user['result']['user']['username'], user['result']['user']['first_name'], user['result']['user']['last_name'])
except Exception as e:
try:
return "@%s (%s)" % (user['result']['user']['username'], user['result']['user']['first_name'])
except Exception as e:
try:
return "%s %s" % (user['result']['user']['first_name'],
user['result']['user']['last_name'])
except Exception as e:
return "%s" % (user['result']['user']['first_name'])
def send_message(chat_id, text):
url = URL + 'sendMessage'
answer = {'chat_id': chat_id, 'text': text}
req = requests.post(url, json = answer)
return req.json()
def makelistOfMemberShort(listOfMemberShort):
listOfMemberShort.append(0)
listOfMemberShort.append()
return listOfMemberShort
def makelistOfMemberStratMore(listOfMemberStrat):
listOfMemberStrat.append(0)
listOfMemberStrat.append(0)
return listOfMemberStrat
def makelistOfMemberAllMore(listOfMemberAll):
listOfMemberAll.append(0)
return listOfMemberAll
if __name__ == '__main__':
print("start main")
global listOfMemberShort
global listOfGame
global listOfMemberStrat
global listOfMemberAll
listOfMemberShort= []
listOfMemberShort = makelistOfMemberShort(listOfMemberShort)
listOfMemberStrat = []
listOfMemeber = makelistOfMemberStratMore(listOfMemberStrat)
listOfMemberAll = []
listOfMemberAll = makelistOfMemberAllMore(listOfMemberAll)
listOfGame = []
qe = queue.Queue()
thread = Thread(target=mainWork.initFind, args=[qe, listOfGame, listOfMemberShort, listOfMemberStrat, listOfMemberAll])
thread.start()
print("start app")
app.run()