-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
241 lines (189 loc) · 7.29 KB
/
Copy pathfunctions.py
File metadata and controls
241 lines (189 loc) · 7.29 KB
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import config
import random
from database import db as session
import models
from telegram import Update, ReplyKeyboardMarkup, ReplyKeyboardRemove
def familiar(point, table: [], fam_state: []):
statement = session.query(models.Users).all()
box = []
for u in statement:
box.append(u.__dict__)
if box:
for itm in box:
if itm['chat_id'] == point:
print('success')
table.clear()
table.append(itm['chat_id'])
fam_state.clear()
fam_state.append(1)
requesting = session.query(models.Users).filter(models.Users.chat_id == point).first()
requesting.trust = itm['trust'] = int(itm['trust']) + 1
session.commit()
requested = session.query(models.Users).filter(models.Users.chat_id == point).first()
mox = [requested.__dict__]
break
else:
new_posts = models.Users(chat_id=config.my_chat_id, trust=1)
session.add(new_posts)
session.commit()
session.refresh(new_posts)
if not fam_state:
new_posts = models.Users(chat_id=point, trust=1)
session.add(new_posts)
session.commit()
session.refresh(new_posts)
# def confirm(label, chatID, bot):
# keyboard = [["YES"],
# ["NO"]]
# markup = ReplyKeyboardMarkup(keyboard)
# bot.send_message(chat_id=chatID,
# text=label,
# parse_mode='markdown', reply_markup=markup)
# def cancel(label, chatID, bot):
# marks = ReplyKeyboardRemove()
# bot.send_message(chat_id=chatID, text=label,
# parse_mode="markdown", reply_markup=marks)
# def invalid(label, chatID, bot):
# bot.send_sticker(chat_id=chatID,
# sticker="CAACAgIAAxkBAAPrYZgpuCc1LHLrxcN4T5mBMzKjXIQAAggNAAKmPTlIx6LTQyGewQciBA")
# bot.reply_text(label, parse_mode="markdown")
def ask(no_idea, source):
requesting = session.query(models.Memory).filter(models.Memory.reply == no_idea).all()
box = []
for u in requesting:
box.append(u.__dict__)
def opt():
co = 0
for items in box:
co += 1
requested = session.query(models.Memory).filter(models.Memory.listen == items['listen'],
models.Memory.Author == source).all()
box1 = []
for ui in requested:
box1.append(ui.__dict__)
if box1:
for itm in box1:
if itm['reply'] != 'no idea':
if items in box:
num = box.index(items)
box.remove(box[num])
for tins in range(len(box)):
opt()
return box
def store(asking: [], identifying: [], reply, listen: [], author, try_correct: [], try_listen: [], try_reply: [],
keyword: [],
key_reply: []):
try:
if asking:
if identifying[0] == author:
requesting = session.query(models.Memory).filter(models.Memory.listen == asking[0]).first()
requesting.reply = reply
session.commit()
else:
new_posts = models.Memory(reply=reply, listen=listen[0], Author=author)
session.add(new_posts)
session.commit()
session.refresh(new_posts)
asking.clear()
identifying.clear()
elif try_correct:
new_posts = models.Memory(reply=try_listen[0], listen=try_reply[0], Author=author)
session.add(new_posts)
session.commit()
session.refresh(new_posts)
try_correct.clear()
try_listen.clear()
try_reply.clear()
else:
new_posts = models.Memory(reply=key_reply[0], listen=keyword[0], Author=author)
session.add(new_posts)
session.commit()
session.refresh(new_posts)
return
except:
pass
def public(label, point):
post = session.query(models.Memory).filter(models.Memory.reply == label, models.Memory.listen == point).all()
box = []
for row in post:
box.append(row.__dict__)
if len(box) >= 3:
for items in box:
requesting = session.query(models.Memory).filter(models.Memory.id == items['id']).first()
requesting.published = True
session.commit()
def think(no_idea: [], try_idea: [], chatID, point):
if no_idea:
post = session.query(models.Memory).filter(models.Memory.published == 'true').all()
no_idea.clear()
elif try_idea:
post = session.query(models.Memory).filter(models.Memory.published == 'false').all()
try_idea.clear()
else:
post = session.query(models.Memory).filter(models.Memory.Author == chatID).all()
box = []
for row in post:
box.append(row.__dict__)
for itm in box:
single = itm['listen'].split(" or ")
for tins in single:
if point == tins:
grab = itm['listen']
post = session.query(models.Memory).filter(models.Memory.listen == grab).all()
box1 = []
for row in post:
box1.append(row.__dict__)
if len(box1) > 1:
ans = []
for item in box1:
ans.append(item['reply'])
final_output = random.choice(ans)
final = final_output.split(" or ")
final_say = random.choice(final)
else:
final = box1[0]['reply'].split(" or ")
final_say = random.choice(final)
try:
public(final_say, point)
except:
pass
return final_say
def keep(reply, listen, Author):
new_posts = models.Memory(reply=reply, listen=listen, Author=Author)
session.add(new_posts)
session.commit()
session.refresh(new_posts)
def delete_excess(grab, source):
post = session.query(models.Memory).filter(models.Memory.listen == grab, models.Memory.Author == source).all()
box1 = []
for row in post:
box1.append(row.__dict__)
post1 = session.query(models.Memory).filter(models.Memory.listen == grab).all()
box = []
for row in post1:
box.append(row.__dict__)
prof = []
guarantee = []
sieve = []
bases = []
for items in box1:
prof.append(items['listen'])
for itm in box:
if itm['listen'] == prof[0]:
if itm['reply'] in sieve and itm['reply'] not in bases:
bases.append(itm['reply'])
if itm['reply'] in sieve:
sieve.insert(int(sieve.index(itm['reply'])), itm['reply'])
else:
sieve.append(itm['reply'])
for tin in bases:
num = sieve.count(tin)
if num >= 3:
guarantee.append(tin)
prof.clear()
sieve.clear()
bases.clear()
if guarantee:
post = session.query(models.Memory).filter(models.Memory.listen == grab, models.Memory.Author == source).delete(
synchronize_session=False)
session.commit()