@bot.on.chat_message(text="тест <text>", lower=True)
async def wrapper (ans: Message, text):
cont = True
id_photo = 0
phrases_read = open('links/phrases.txt', 'r', encoding="UTF-8")
for line in phrases_read:
id_photo +=1
print('text:', repr(text))
print('line:', repr(line))
print('eq without last char:', text == line[0:-1])
print('eq with strip:', text == line.strip())
print('in:', 'text in line')
n = repr(line.find("\n"))
if n == -1:
if text == line[0:-1]:
await ans("Данная цитата уже есть. Ее порядковый номер " + str(id_photo+1))
cont = False
break
else:
if text == line:
await ans("Данная цитата уже есть. Ее порядковый номер " + str(id_photo+1))
cont = False
break
if cont == True:
photo = Image.open("links/default.jpg")
font = ImageFont.truetype("arial.ttf", size=48)
draw = ImageDraw.Draw(photo)
black = (3, 8, 12)
para = textwrap.wrap(text, width=25)
length = draw.textsize(text, font=font)
if length[0] > 3375:
await ans("Слишком длинный текст")
else:
files = os.listdir(photos)
print(files)
image = files[-1]
last_image = len(files)
print(last_image)
MAX_W, MAX_H = 1000, 200
current_h, pad = 250, 10
for line in para:
w, h = draw.textsize(line, font=font)
draw.text(((MAX_W - w) / 2, current_h), line, font=font, fill=black)
current_h += h + pad
photo.save('links/images/' + str(last_image+1) + '.png')
print(length[0])
print(length[0])
photo_uploader = PhotoUploader(bot.api, generate_attachment_strings=True)
photo_end = await photo_uploader.upload_message_photo("links/images/" + str(last_image+1) + ".png")
await ans(attachment=photo_end, message=last_image+1)
phrases = open('links/phrases.txt', 'a', encoding="UTF-8")
phrases.writelines(str(text) + "\n")
phrases.close()
phrases_read.close()
text: 'б'
line: 'б\n'
eq without last char: True
eq with strip: True
in: text in line