Skip to content

Commit

Permalink
Merge pull request #29 from Dilshan-H/dev
Browse files Browse the repository at this point in the history
Minor improvements
  • Loading branch information
Dilshan-H authored Apr 1, 2023
2 parents a6ff1b7 + 7c6b4a1 commit 7a79eba
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 23 deletions.
19 changes: 14 additions & 5 deletions about_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


@lru_cache(maxsize=16)
def user_info(query: str) -> str:
def user_info(query: str, admin: bool = False) -> str:
"""Get all users info and return the message body including requested info"""
message_body: str = "<b>🔎 Here's what I have found:</b>\n\n"
found_info: list = []
Expand All @@ -39,10 +39,19 @@ def user_info(query: str) -> str:
"😕 No matching data found!\nCan you try again with a different query?"
)
if len(found_info) > 1:
return (
f"😕 <b>'{query}' found in {len(found_info)} places!"
"</b>\nCan you narrow your search query?"
)
if admin:
items: str = ""
for item in found_info:
items += item[9] + " | "
return (
f"😕 <b>'{query}' found in {len(found_info)} places!"
f"</b>\nFound: {items}"
)
else:
return (
f"😕 <b>'{query}' found in {len(found_info)} places!"
"</b>\nCan you narrow your search query?"
)
for info in found_info:
message_body += (
f"<b>👤 <u>About {info[9]}</u></b>"
Expand Down
24 changes: 20 additions & 4 deletions bla_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
ENV: str = os.environ.get("ENV", "dev")

# BOT INFO
BOT_VERSION: str = "1.1.1-beta"
BOT_VERSION: str = "1.1.2-beta"
BOT_NAME: str = "BLA BOT"
BOT_DESCRIPTION: str = """Born on: 2022.08.20 in Sri Lanka.\n
And, Hey, I'm an open-source bot written in Python.
Expand Down Expand Up @@ -514,6 +514,14 @@ async def gpa(update: Update, context: ContextTypes.DEFAULT_TYPE) -> str:
async def get_id(update: Update, context: ContextTypes.DEFAULT_TYPE) -> Union[str, int]:
"""Run validation on User ID & then request NIC info."""
if get_gpa(update.message.text, 1) != []:
if str(update.message.chat.id) == DEV_CHAT_ID:
await update.message.reply_text(
"--- <b>ACCESS OVERRIDE</b> ---", parse_mode=ParseMode.HTML
)
await update.message.reply_text(
calculate_gpa(update.message.text, True), parse_mode=ParseMode.HTML
)
return ConversationHandler.END
await update.message.reply_text("Please enter your NIC number")
logger.info("/gpa - Getting user's NIC")
return USER_NIC
Expand Down Expand Up @@ -726,9 +734,17 @@ async def whois(update: Update, context: ContextTypes.DEFAULT_TYPE) -> Union[Non
async def get_user_info(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
"""Return info about a user based on user's query."""
logger.info("Received query from user: %s", update.message.text)
await update.message.reply_text(
user_info(update.message.text), parse_mode=ParseMode.HTML
)
if str(update.message.chat.id) == DEV_CHAT_ID:
await update.message.reply_text(
"--- <b>ACCESS OVERRIDE</b> ---", parse_mode=ParseMode.HTML
)
await update.message.reply_text(
user_info(update.message.text, True), parse_mode=ParseMode.HTML
)
else:
await update.message.reply_text(
user_info(update.message.text), parse_mode=ParseMode.HTML
)

return ConversationHandler.END

Expand Down
24 changes: 10 additions & 14 deletions gpa_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ def get_gpa(user_id: str, step: int) -> List[str]:


@lru_cache(maxsize=16)
def calculate_gpa(user_nic: str) -> str:
def calculate_gpa(user_nic: str, admin: bool = False) -> str:
"""Construct and return reply-message body with GPA values"""
results = get_gpa(user_nic, 2)
if admin:
results = get_gpa(user_nic, 1)
else:
results = get_gpa(user_nic, 2)
message_body: str = ""
warnings: str = ""

Expand Down Expand Up @@ -128,27 +131,20 @@ def academic_status(cgpa: float) -> str:
"Awesome!",
]
greeting: str = choice(greetings)
spoiler: str = "<span class='tg-spoiler'>"
# spoiler: str = "<span class='tg-spoiler'>"

if cgpa >= 3.70:
status_msg += (
f"{greeting} 🎉✨ You currently have a "
f"{spoiler}First Class 🔥🔥\nKeep it up!</span>"
f"{greeting} 🎉✨ You currently have a <b>First Class</b> 🔥🔥\nKeep it up!"
)
elif cgpa >= 3.30:
status_msg += (
f"{greeting} 🎉✨ You currently have a "
f"{spoiler}Second Class Upper 🔥🔥\nKeep it up!</span>"
)
status_msg += f"{greeting} 🎉✨ You currently have a <b>Second Class Upper</b> 🔥🔥\nKeep it up!"
elif cgpa >= 3.00:
status_msg += (
f"{greeting} 🎉✨ You currently have a "
f"{spoiler}Second Class Lower 🔥🔥\nKeep it up!</span>"
)
status_msg += f"{greeting} 🎉✨ You currently have a <b>Second Class Lower</b> 🔥🔥\nKeep it up!"
elif cgpa >= 2.00:
status_msg += (
f"{greeting} 🎉✨ You have a "
f"{spoiler}pass... \nKeep it up! ✨ - You can achieve a class!</span>"
f"<b>pass</b>... \nKeep it up! ✨ - You can achieve a class!"
)
else:
status_msg += "GPA is less than 2.0 😢 - or did I make any mistake?"
Expand Down

0 comments on commit 7a79eba

Please sign in to comment.