Skip to content

Commit 0931dcd

Browse files
refactor project
1 parent 99d1ab4 commit 0931dcd

21 files changed

+287
-275
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 4
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,14 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
# IDEs
132+
.vscode/
133+
.idea/
134+
135+
# Config file
136+
config.py
137+
138+
# Database and session files
139+
*.session*
140+
*.db

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 Amano Team
3+
Copyright (c) 2021-2023 Amano LLC
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

-13
This file was deleted.

README.rst

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
InfoPlaca
2+
=========
3+
4+
A simple way to consult Brazilian vehicle license plates (placas).
5+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6+
7+
See `@InfoPlacaBot <https://t.me/infoplacabot>`__
8+
9+
Usage
10+
-----
11+
12+
- Inline: ``@InfoPlacaBot PLACA``
13+
- In chat: just send the plate on the MERCOSUL or legacy formats.

config.py.example

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Bot token from Bot Father
2+
TOKEN: str = "123123:YOUR_BOT_TOKEN_HERE"
3+
4+
# Telegram API ID and API hash
5+
# Get it from https://my.telegram.org/apps
6+
API_ID: int = 321321
7+
API_HASH: str = "YOUR_API_HASH_HERE"
8+
9+
# API endpoint to get plate info
10+
PLATES_ENDPOINT: str = "https://infoplaca-api.amanoteam.com/{plate}"

infoplaca/__init__.py

Whitespace-only changes.

infoplaca/__main__.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import asyncio
2+
3+
from pyrogram import Client, idle
4+
5+
from config import API_HASH, API_ID, TOKEN
6+
7+
8+
async def main():
9+
async with Client(
10+
"bot", API_ID, API_HASH, bot_token=TOKEN, plugins=dict(root="infoplaca.plugins")
11+
):
12+
await idle()
13+
14+
15+
loop = asyncio.get_event_loop()
16+
loop.run_until_complete(main())

bot_strings.py infoplaca/bot_strings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
# DONATE COMMAND
22-
donate = """Ajude no desenvolvimento e manutenção de nossos projetos.
22+
donate = """Ajude no desenvolvimento e manutenção de nossos projetos.
2323
2424
Qualquer valor nos ajuda! 👋🤖"""
2525

daba.py infoplaca/database.py

+27-23
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1-
import sqlite3
2-
3-
db = sqlite3.connect("placabot.db")
4-
cursor = db.cursor()
5-
6-
cursor.execute(
7-
"""CREATE TABLE IF NOT EXISTS users (user_id INTEGER PRIMARY KEY,
8-
historic,
9-
is_premium INTEGER)"""
10-
)
11-
12-
cursor.execute("""CREATE TABLE IF NOT EXISTS groups (chat_id INTEGER PRIMARY KEY)""")
13-
14-
15-
def add_user(user_id):
16-
try:
17-
cursor.execute("""INSERT INTO users(user_id) VALUES (?)""", (user_id,))
18-
except sqlite3.IntegrityError:
19-
pass
20-
db.commit()
21-
22-
23-
db.commit()
1+
import sqlite3
2+
3+
db = sqlite3.connect("placabot.db")
4+
cursor = db.cursor()
5+
6+
cursor.execute(
7+
"""
8+
CREATE TABLE IF NOT EXISTS users (
9+
user_id INTEGER PRIMARY KEY,
10+
historic,
11+
is_premium INTEGER
12+
)
13+
"""
14+
)
15+
16+
cursor.execute("""CREATE TABLE IF NOT EXISTS groups (chat_id INTEGER PRIMARY KEY)""")
17+
18+
19+
def add_user(user_id):
20+
try:
21+
cursor.execute("""INSERT INTO users(user_id) VALUES (?)""", (user_id,))
22+
except sqlite3.IntegrityError:
23+
pass
24+
db.commit()
25+
26+
27+
db.commit()

infoplaca/plugins/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
from pyrogram import Client, filters
2-
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
3-
4-
from bot_strings import donate, hlp
5-
6-
7-
@Client.on_callback_query(filters.regex(r"donate"))
8-
async def etanod(c, m):
9-
keyboard = InlineKeyboardMarkup(
10-
inline_keyboard=[
11-
[
12-
InlineKeyboardButton(text="💵 PicPay", url="#"),
13-
InlineKeyboardButton(text="💵 PayPal", url="#"),
14-
],
15-
[InlineKeyboardButton(text="💵 Pix", callback_data="gpix")],
16-
[InlineKeyboardButton(text="◀️ Voltar", callback_data="help")],
17-
]
18-
)
19-
await m.edit_message_text(donate, reply_markup=keyboard)
20-
21-
22-
@Client.on_callback_query(filters.regex(r"help"))
23-
async def pleh(c, m):
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-
]
34-
)
35-
await m.edit_message_text(hlp, reply_markup=keyvoard)
36-
37-
38-
@Client.on_callback_query(filters.regex(r"gpix"))
39-
async def xipg(c, m):
40-
keybaard = InlineKeyboardMarkup(
41-
inline_keyboard=[
42-
[InlineKeyboardButton(text="🗑 Apagar mensagem", callback_data="delete")]
43-
]
44-
)
45-
await c.send_photo(m.message.chat.id, photo="#", caption="#", reply_markup=keybaard)
46-
47-
48-
@Client.on_callback_query(filters.regex(r"delete"))
49-
async def eteled(c, m):
50-
await c.delete_messages(m.message.chat.id, m.message.message_id)
1+
from pyrogram import Client, filters
2+
from pyrogram.types import CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup
3+
4+
from ..bot_strings import donate, hlp
5+
6+
7+
@Client.on_callback_query(filters.regex(r"donate"))
8+
async def etanod(c: Client, m: CallbackQuery):
9+
keyboard = InlineKeyboardMarkup(
10+
inline_keyboard=[
11+
[
12+
InlineKeyboardButton(text="💵 PicPay", url="#"),
13+
InlineKeyboardButton(text="💵 PayPal", url="#"),
14+
],
15+
[InlineKeyboardButton(text="💵 Pix", callback_data="gpix")],
16+
[InlineKeyboardButton(text="◀️ Voltar", callback_data="help")],
17+
]
18+
)
19+
await m.edit_message_text(donate, reply_markup=keyboard)
20+
21+
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+
]
34+
)
35+
await m.edit_message_text(hlp, reply_markup=keyvoard)
36+
37+
38+
@Client.on_callback_query(filters.regex(r"gpix"))
39+
async def xipg(c: Client, m: CallbackQuery):
40+
keybaard = InlineKeyboardMarkup(
41+
inline_keyboard=[
42+
[InlineKeyboardButton(text="🗑 Apagar mensagem", callback_data="delete")]
43+
]
44+
)
45+
await c.send_photo(m.message.chat.id, photo="#", caption="#", reply_markup=keybaard)
46+
47+
48+
@Client.on_callback_query(filters.regex(r"delete"))
49+
async def eteled(c: Client, m: CallbackQuery):
50+
await c.delete_messages(m.message.chat.id, m.message.message_id)

infoplaca/plugins/inline.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import re
2+
from datetime import datetime as l
3+
4+
from pyrogram import Client
5+
from pyrogram.types import (
6+
InlineQuery,
7+
InlineQueryResultArticle,
8+
InputTextMessageContent,
9+
)
10+
11+
from config import PLATES_ENDPOINT
12+
13+
from ..bot_strings import template
14+
from ..utils import hc
15+
16+
17+
@Client.on_inline_query()
18+
async def inline(c: Client, m: InlineQuery):
19+
regex_m = r"((^| |\n)([a-zA-Z]{3}[0-9]{1}[a-zA-Z0-9][0-9]{2})( |\n|$))"
20+
if re.search(regex_m, m.query):
21+
pr = re.compile(regex_m)
22+
array_pl = pr.search(m.query)
23+
plac = array_pl[1]
24+
plate = re.sub("[^a-zA-Z0-9]", "", plac)
25+
26+
r = await hc.get(PLATES_ENDPOINT.format(plate=plate))
27+
rjson = r.json()
28+
29+
if rjson["codigoRetorno"] == 98:
30+
await m.answer(
31+
[
32+
InlineQueryResultArticle(
33+
title=f"⚠️ {rjson['mensagemRetorno']}",
34+
thumb_url="https://piics.ml/i/015.png",
35+
input_message_content=InputTextMessageContent(
36+
message_text=f"⚠️ <b>{rjson['mensagemRetorno']}.</b>",
37+
parse_mode="HTML",
38+
),
39+
)
40+
]
41+
)
42+
43+
else:
44+
await m.answer(
45+
[
46+
InlineQueryResultArticle(
47+
title=f"Resultado para: {plate.upper()}",
48+
thumb_url="https://piics.ml/i/015.png",
49+
input_message_content=InputTextMessageContent(
50+
str(
51+
template.format(
52+
l.now().strftime("%d/%m/%Y às %H:%M:%S"),
53+
plate.upper(),
54+
rjson["chassi"],
55+
rjson["modelo"],
56+
rjson["cor"].upper(),
57+
rjson["ano"],
58+
rjson["municipio"].upper(),
59+
rjson["uf"],
60+
rjson["situacao"],
61+
)
62+
),
63+
parse_mode="HTML",
64+
),
65+
)
66+
]
67+
)

infoplaca/plugins/listen.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import re
2+
from datetime import datetime as l
3+
4+
from pyrogram import Client, filters
5+
from pyrogram.types import Message
6+
7+
from config import PLATES_ENDPOINT
8+
9+
from ..bot_strings import template
10+
from ..utils import hc
11+
12+
pattern = "((^| |\n)([a-z]{3}-?[0-9][a-z0-9][0-9]{2})( |\n|$))"
13+
14+
15+
@Client.on_message(filters.regex(pattern))
16+
async def listen(c: Client, m: Message):
17+
p = re.compile(pattern)
18+
q = p.search(m.text)
19+
r = q[1]
20+
plate = re.sub("[^a-zA-Z0-9]", "", r).upper()
21+
22+
r = await hc.get(PLATES_ENDPOINT.format(plate=plate))
23+
rjson = r.json()
24+
25+
if rjson["codigoRetorno"] == 98:
26+
await m.reply_text(
27+
f"⚠️ <b>{rjson['mensagemRetorno']}.</b>", quote=True, parse_mode="HTML"
28+
)
29+
30+
else:
31+
await m.reply_text(
32+
template.format(
33+
l.now().strftime("%d/%m/%Y às %H:%M:%S"),
34+
plate,
35+
rjson["chassi"],
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+
parse_mode="HTML",
45+
)

plugins/start.py infoplaca/plugins/start.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
from pyrogram import Client, filters
2-
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
3-
4-
from bot_strings import strt, hlp
5-
from daba import add_user
6-
7-
2+
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
83

4+
from ..bot_strings import hlp, strt
5+
from ..database import add_user
96

107

118
# START COMMAND
129
@Client.on_message(filters.command("start", ["/", "!"]))
13-
async def start(c, m):
10+
async def start(c: Client, m: Message):
1411
add_user(user_id=m.from_user.id)
1512
keybaard = InlineKeyboardMarkup(
1613
inline_keyboard=[
@@ -26,7 +23,7 @@ async def start(c, m):
2623

2724
# HELP COMMAND
2825
@Client.on_message(filters.command("help", ["/", "!"]))
29-
async def help(c, m):
26+
async def help(c: Client, m: Message):
3027
keyboard = InlineKeyboardMarkup(
3128
inline_keyboard=[
3229
[InlineKeyboardButton(text="💵 Colabore", callback_data="donate")],

0 commit comments

Comments
 (0)