Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions requirement.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python-telegram-bot
qrcode
16 changes: 16 additions & 0 deletions src/QR.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import qrcode

# qr code image generation function
def QR(text):
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=15,
border=4,
)

qr.add_data(text)
qr.make(fit=True)

img = qr.make_image(fill_color="black", back_color="white")
img.save("qrcode.png")
25 changes: 5 additions & 20 deletions src/telegram_py_bot.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,20 @@
from telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, filters
import qrcode

# qr code image generation function
def QR(text):
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=15,
border=4,
)

qr.add_data(text)
qr.make(fit=True)

img = qr.make_image(fill_color="black", back_color="white")
img.save("qrcode.png")
from QR import QR

# telegram bot start command handler
async def start(update, context):
async def start(update, context) -> None:
await context.bot.send_message(chat_id=update.effective_chat.id, text="Welcome to the QR generator bot!\nSend /help to see the usage")

# telegram bot help command handler
async def help(update, context):
async def help(update, context) -> None:
await context.bot.send_message(chat_id=update.effective_chat.id, text="Usage:\nwrite the string you want to convert into a QR code image")

# telegram bot user string printer
async def printing(update, context, text):
async def printing(update, context, text) -> None:
await context.bot.send_message(chat_id=update.effective_chat.id, text=f'You requested the following string: "{text}"\n\nThis is the generated QR code image:')

# telegram bot qr code image sender function
async def qr_generator(update, context):
async def qr_generator(update, context) -> None:
QR(update.message.text)
await printing(update, context, update.message.text)

Expand Down