Skip to content

Commit 747b439

Browse files
move strings to their own files and unify plate info format
1 parent 9f43446 commit 747b439

File tree

7 files changed

+72
-100
lines changed

7 files changed

+72
-100
lines changed

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ Usage
1010
-----
1111

1212
- Inline: ``@InfoPlacaBot PLACA``
13-
- In chat: just send the plate on the MERCOSUL or legacy formats.
13+
- In chat: just send the plate on the Mercosul or legacy formats.

infoplaca/bot_strings.py

-39
This file was deleted.

infoplaca/plugins/callback.py

+4-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from pyrogram import Client, filters
22
from pyrogram.types import CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup
33

4-
from ..bot_strings import donate, hlp
5-
64

75
@Client.on_callback_query(filters.regex(r"donate"))
86
async def etanod(c: Client, m: CallbackQuery):
@@ -16,23 +14,12 @@ async def etanod(c: Client, m: CallbackQuery):
1614
[InlineKeyboardButton(text="◀️ Voltar", callback_data="help")],
1715
]
1816
)
19-
await m.edit_message_text(donate, reply_markup=keyboard)
20-
17+
await m.edit_message_text(
18+
"""Ajude no desenvolvimento e manutenção de nossos projetos.
2119
22-
@Client.on_callback_query(filters.regex(r"help"))
23-
async def pleh(c: Client, m: CallbackQuery):
24-
keyvoard = InlineKeyboardMarkup(
25-
inline_keyboard=[
26-
[InlineKeyboardButton(text="💵 Colabore", callback_data="donate")],
27-
[InlineKeyboardButton(text="💻 Meu desenvolvedor", url="t.me/khaledsecond")],
28-
[
29-
InlineKeyboardButton(
30-
text="🔎 Consulte inline", switch_inline_query_current_chat=""
31-
)
32-
],
33-
]
20+
Qualquer valor nos ajuda! 👋🤖""",
21+
reply_markup=keyboard,
3422
)
35-
await m.edit_message_text(hlp, reply_markup=keyvoard)
3623

3724

3825
@Client.on_callback_query(filters.regex(r"gpix"))

infoplaca/plugins/inline.py

+2-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import re
2-
from datetime import datetime as l
3-
41
import httpx
52
from pyrogram import Client, filters
63
from pyrogram.types import (
@@ -13,8 +10,7 @@
1310

1411
from config import PLATES_ENDPOINT
1512

16-
from ..bot_strings import template
17-
from ..utils import PLATE_REGEX, format_plate, hc
13+
from ..utils import PLATE_REGEX, format_plate, format_plate_info, hc
1814

1915

2016
@Client.on_inline_query(filters.regex(PLATE_REGEX))
@@ -69,19 +65,7 @@ async def plate_search_inline(c: Client, m: InlineQuery):
6965
title=f"Resultado para: {format_plate(plate)}",
7066
thumb_url="https://piics.ml/i/015.png",
7167
input_message_content=InputTextMessageContent(
72-
template.format(
73-
l.now().strftime("%d/%m/%Y às %H:%M:%S"),
74-
format_plate(plate),
75-
rjson["chassi"].rjust(17, "*")
76-
if rjson["chassi"]
77-
else "Não informado",
78-
rjson["modelo"],
79-
rjson["cor"].upper(),
80-
rjson["ano"],
81-
rjson["municipio"].upper(),
82-
rjson["uf"],
83-
rjson["situacao"],
84-
)
68+
format_plate_info(rjson)
8569
),
8670
)
8771
]

infoplaca/plugins/listen.py

+2-18
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
from datetime import datetime as l
2-
31
import httpx
42
from pyrogram import Client, filters
53
from pyrogram.types import Message
64

75
from config import PLATES_ENDPOINT
86

9-
from ..bot_strings import template
10-
from ..utils import PLATE_REGEX, format_plate, hc
7+
from ..utils import PLATE_REGEX, format_plate_info, hc
118

129

1310
@Client.on_message(filters.regex(PLATE_REGEX) & ~filters.via_bot)
@@ -28,17 +25,4 @@ async def plate_search(c: Client, m: Message):
2825
await m.reply_text(f"⚠️ <b>{rjson['mensagemRetorno']}.</b>", quote=True)
2926

3027
else:
31-
await m.reply_text(
32-
template.format(
33-
l.now().strftime("%d/%m/%Y às %H:%M:%S"),
34-
format_plate(plate),
35-
rjson["chassi"].rjust(17, "*") if rjson["chassi"] else "Não informado",
36-
rjson["modelo"],
37-
rjson["cor"].upper(),
38-
rjson["ano"],
39-
rjson["municipio"].upper(),
40-
rjson["uf"],
41-
rjson["situacao"],
42-
),
43-
quote=True,
44-
)
28+
await m.reply_text(format_plate_info(rjson), quote=True)

infoplaca/plugins/start.py

+38-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
from pyrogram import Client, filters
2-
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
2+
from pyrogram.types import (
3+
CallbackQuery,
4+
InlineKeyboardButton,
5+
InlineKeyboardMarkup,
6+
Message,
7+
)
38

4-
from ..bot_strings import hlp, strt
59
from ..database import add_user
610

711

@@ -18,16 +22,43 @@ async def start(c: Client, m: Message):
1822
]
1923
]
2024
)
21-
await m.reply_text(strt, reply_markup=keybaard)
25+
await m.reply_text(
26+
"Digite a placa ou clique no botão abaixo.", reply_markup=keybaard
27+
)
2228

2329

2430
# HELP COMMAND
2531
@Client.on_message(filters.command("help", ["/", "!"]))
26-
async def help(c: Client, m: Message):
27-
keyboard = InlineKeyboardMarkup(
32+
@Client.on_callback_query(filters.regex(r"help"))
33+
async def pleh(c: Client, m: CallbackQuery):
34+
keyvoard = InlineKeyboardMarkup(
2835
inline_keyboard=[
2936
[InlineKeyboardButton(text="💵 Colabore", callback_data="donate")],
30-
[InlineKeyboardButton(text="💻 Meu desenvolvedor", url="t.me/khaledsecond")],
37+
[
38+
InlineKeyboardButton(
39+
text="💻 Meu desenvolvedor", url="https://t.me/khaledsecond"
40+
)
41+
],
42+
[
43+
InlineKeyboardButton(
44+
text="🔎 Consulte inline", switch_inline_query_current_chat=""
45+
)
46+
],
3147
]
3248
)
33-
await m.reply_text(hlp, reply_markup=keyboard)
49+
50+
await m.edit_message_text(
51+
"""Olá 👋, aqui é a área de ajuda do <b>InfoPlaca</b>.
52+
53+
ℹ️ <b>Informações básicas:</b>
54+
Para consultar uma placa, envie no formato <code>ABC-1234</code> ou <code>ABC1234</code> (Mercosul).
55+
<i>*Disponível para qualquer veículo.</i>
56+
57+
O uso também pode ser via inline, digite: <code>@InfoPlacaBot PLACA</code> no campo de texto.
58+
<i>*Atalho na mensagem de start.</i>
59+
60+
61+
62+
🤖 Quer colaborar nossos projetos? Clique no botão abaixo e apoie o meu desenvolvimento!""",
63+
reply_markup=keyvoard,
64+
)

infoplaca/utils.py

+25
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,28 @@ def format_plate(plate: str) -> str:
1414
if groups[2].isnumeric():
1515
return f"{groups[1]}-{groups[2]}"
1616
return f"{groups[1]}{groups[2]}"
17+
18+
19+
def format_plate_info(info: dict) -> str:
20+
return """ℹ️ <b>Informações da Placa</b>
21+
📆 <i>Informações atualizadas em {}</i>
22+
23+
<b>Placa:</b> <code>{}</code>
24+
<b>Chassi:</b> <code>{}</code>
25+
<b>Modelo:</b> <code>{}</code>
26+
<b>Cor:</b> <code>{}</code>
27+
<b>Ano:</b> <code>{}</code>
28+
<b>Cidade:</b> <code>{} - {}</code>
29+
<b>Situação:</b> <code>{}</code>
30+
31+
@InfoPlacaBot""".format(
32+
info["data"],
33+
format_plate(info["placa"]),
34+
info["chassi"].rjust(17, "*") if info["chassi"] else "Não informado",
35+
info["modelo"].title(),
36+
info["cor"].title(),
37+
info["ano"],
38+
info["municipio"].title(),
39+
info["uf"],
40+
info["situacao"],
41+
)

0 commit comments

Comments
 (0)