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: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ creds/github_token.txt
sentence_tokenizer.pickle
db.sqlite3-shm
db.sqlite3-wal
*idea
*idea
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Shani Sir Telegram Bot
A Shani Sir Telegram bot who is savage in groups, sends you clips of Sir, and can get up close and personal with you in the DMs!

Chat with him now: @shanisirbot
Chat with him now: [@shanisirbot](https://t.me/shanisirbot/)

## Commands available:
The following commands are currently available to use:
Expand Down
48 changes: 32 additions & 16 deletions bot_funcs/bday_wisher.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from datetime import datetime, date

from telegram.ext import CallbackContext
from telegram.utils.helpers import mention_html

from constants import group_ids
from constants import group_ids, class_12b
from helpers.logger import logger
from online import gcalendar

Expand All @@ -11,9 +12,10 @@ def wish(context: CallbackContext) -> None:
"""Gets the next birthday from Google Calendar and wishes you if today is your birthday."""

gcalendar.main()
days_remaining, name = gcalendar.get_next_bday()
bdays = gcalendar.get_next_bday()
days_remaining = bdays[0][0]

bday_msgs = (f"Happy birthday {name}! !🎉 I don't know why like, but I know you despise me with the burning "
bday_msgs = (f"Happy birthday (placeholder)! !🎉 I don't know why like, but I know you despise me with the burning "
f"passion of a thousand suns. I don't give a flux, like you say. I implore you to let go of "
f"hate and embrace love. Spend the rest of your days with love in your heart and faith in your "
f"soul. Life's cyclotron may sometimes send you tumbling around, but remember that it is "
Expand All @@ -22,29 +24,43 @@ def wish(context: CallbackContext) -> None:
f"straight path. I wish you the best. May your jockeys be unpressed and your apertures small. "
f"Enjoy your 18th. Forget about coronabitch. Godspeed.",

f"Happy birthday {name}! I wish you the best of luck for life. Remember: You matter. Until you "
f"Happy birthday (placeholder)! I wish you the best of luck for life. Remember: You matter. Until you "
f"multiply yourself times the speed of light squared. Then you energy, like you say!🎉 What "
f"your going to do today like?",

f"Happy birthday {name}! !🎉 What your going to do today like?")
f"Happy birthday (placeholder)! !🎉 What your going to do today like?")

# Wishes from Google Calendar-
if days_remaining == 0:
_12B = group_ids['12b']

msg = context.bot.send_message(chat_id=_12B, text=bday_msgs[2])
context.bot.pin_chat_message(chat_id=_12B, message_id=msg.message_id, disable_notification=True)
logger(message=f"Happy birthday message for {name} was just sent to the 12B group.")

now = str(date.today())
today = datetime.strptime(now, "%Y-%m-%d") # Parses today's date (time object) into datetime object
new_date = today.replace(year=today.year + 1)

gcalendar.CalendarEventManager(name=name).update_event(new_date) # Updates bday to next year
context.bot_data.setdefault('pin_msgs', [])

for _, name in bdays:
try:
mention = mention_html(class_12b[name.capitalize()], name)
except KeyError: # For those fools who don't use Telegram :(
mention = name

msg = context.bot.send_message(chat_id=_12B, text=bday_msgs[2].replace('(placeholder)', mention),
parse_mode="HTML")
context.bot.pin_chat_message(chat_id=_12B, message_id=msg.message_id, disable_notification=True)

context.bot_data['pin_msgs'].append(msg)

logger(message=f"Happy birthday message for {name} was just sent to the 12B group.")
gcalendar.CalendarEventManager(name=name).update_event(new_date) # Updates bday to next year

context.bot.send_message(chat_id=_12B, text="🎂") # Animated cake emoji :)
del _12B, now, today, new_date

elif days_remaining in {21, 69}:
for _, name in bdays:
context.bot.send_message(chat_id=group_ids['12b'], text=f"{name}'s birthday is in {days_remaining} days!!")
logger(message=f"Happy birthday reminder for {name}({days_remaining} days) was just sent to the 12B group.")

del _12B, msg, now, today, new_date
elif days_remaining in (21, 69):
context.bot.send_message(chat_id=group_ids['12b'], text=f"{name}'s birthday is in {days_remaining} days!!")
logger(message=f"Happy birthday reminder for {name}({days_remaining} days) was just sent to the 12B group.")
del days_remaining, name
# TODO: Wishes from /tell birthday input-
del days_remaining, bdays, bday_msgs
27 changes: 26 additions & 1 deletion bot_funcs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from telegram import error, InlineKeyboardButton, InlineKeyboardMarkup, Poll, Update
from telegram.ext import CallbackContext

from constants import class_12b
from helpers.logger import logger
from helpers.namer import get_chat_name
from online import util, quiz_scraper
Expand Down Expand Up @@ -153,9 +154,33 @@ def quizizz(update: Update, context: CallbackContext) -> None:
context.bot.send_poll(chat_id=update.effective_chat.id, question=question[0], options=options[0],
is_anonymous=False, type=Poll.QUIZ, correct_option_id=answer[0])

@staticmethod
def mention_all(update: Update, context: CallbackContext) -> None:
"""Bot mentions all 12B users"""

del_command(update)
msg = ''
for lad, _id in class_12b.items():
msg += f"[{lad}](tg://user?id={_id})\t"

context.bot.send_message(chat_id=update.effective_chat.id, text=msg, parse_mode="MarkdownV2")

logger(message=f"{update.message.from_user.first_name} used mention_all. Group: {update.effective_chat.title}")

# @staticmethod
# def broadcast(update: Update, context: CallbackContext) -> None:
# """Allows unclesam79 or harshil21 to broadcast a message via the bot"""
#
# if update.effective_chat.id in [samir, harshil]:
# context.bot.send_message(chat_id=update.effective_chat.id, text="Who do I broadcast to, master?")
# logger(message=f"Broadcast initiated.")
# return 0
#
# return -1

@staticmethod
def unknown(update: Update, context: CallbackContext) -> None:
"""When user uses an invalid command."""

context.bot.send_message(chat_id=update.effective_chat.id, text="I didn't say wrong I don't know.")
logger(message=f"{update.effective_user.first_name} just used something weird in {get_chat_name(update)}.")
logger(message=f"{update.effective_user.first_name} just used something weird in {get_chat_name(update)}.")
2 changes: 1 addition & 1 deletion bot_funcs/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def reply(update: Update, context: CallbackContext) -> None:

text = update.message.text
if update.message.reply_to_message.from_user.username == context.bot.username: # If the reply is to this bot:
if not (text.startswith('!r') or text.endswith('!r')): # Don't reply if this is prepended or appended.
if not (text.startswith('!r') or text.endswith('!r')): # Don't reply if !r is prepended or appended.
logger(message=f"Bot received a reply from {update.effective_user.first_name} in "
f"{update.effective_chat.title}.")
shanifier(update, context, is_group=True, the_id=update.message.message_id)
Expand Down
15 changes: 15 additions & 0 deletions bot_funcs/delete_pin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

from telegram import Update
from telegram.ext import CallbackContext

Expand All @@ -9,3 +11,16 @@ def de_pin(update: Update, context: CallbackContext) -> None:

context.bot.delete_message(chat_id=update.effective_chat.id, message_id=update.message.message_id)
logger(message=f"Bot deleted a pinned service message from {update.effective_chat.title}.")


def unpin_all(context: CallbackContext) -> None:
"""Unpins all messages pinned by bot once daily."""

pin_msgs = context.bot_data['pin_msgs']
if not pin_msgs or (pin_msgs and (datetime.now() - pin_msgs[0].date).days == 0): # del if >= 1 day has passed
return

for msg in pin_msgs: # We don't use unpin_all_chat_messages as we want to unpin msgs only from this bot
msg.unpin()

pin_msgs.clear()
28 changes: 17 additions & 11 deletions bot_funcs/morning_wisher.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import random
from datetime import datetime

from telegram.ext import CallbackContext
Expand All @@ -19,29 +20,33 @@ def morning_goodness(context: CallbackContext) -> None:
if 'last_sent' not in context.bot_data:
context.bot_data['last_sent'] = right_now

context.bot_data.setdefault('pin_msgs', [])

diff = right_now - context.bot_data['last_sent']

# Send only if it has been over a day since last good morning message and current time is between 8 and 11AM-
if diff.days < 1 or right_now >= afternoon or right_now <= eight_am:
return

with open("files/good_mourning.txt", "r") as greetings:
with open("files/good_mourning.txt", "r+") as greetings:
quotes = greetings.readlines()
position = context.bot_data['seek']
if position == 13642: # If EOF was reached
position = 0 # Start from the beginning
if position == 13642: # if EOF was reached
position = 0 # start from the beginning
random.shuffle(quotes) # randomise order of quotes
greetings.writelines(quotes)
greetings.seek(position)

greeting = greetings.readline()
logger(message=f"Today's morning quote is:\n{greeting}")
context.bot_data['seek'] = greetings.tell()
context.bot_data['seek'] = greetings.tell() # update file cursor position

query = "SELECT CHAT_ID, CHAT_NAME FROM CHAT_SETTINGS WHERE MORNING_MSGS='✅';"
ids = connection(query, fetchall=True)
logger(message=f"The query executed on the database was:\n{query}\nand the result was:\n{ids=}")

# Open mp3 from desktop as github url doesn't support thumbnails-

clip_loc = r"C:\Users\Uncle Sam\Desktop\sthyaVERAT\4 FUN ya Practice\Shanisirmodule\Assets\clips\bell.mp3"
clip_loc = r"C:/Users/Uncle Sam/Desktop/sthyaVERAT/4 FUN ya Practice/Shanisirmodule/Assets/clips/bell.mp3"

for chat_id, chat_name in ids:
try:
Expand All @@ -50,18 +55,19 @@ def morning_goodness(context: CallbackContext) -> None:

context.bot.send_chat_action(chat_id=chat_id, action='upload_audio')

context.bot.send_audio(chat_id=chat_id, title="Good morning", performer="Shani Sir",
context.bot.send_audio(chat_id=chat_id, title="Good morning", performer="Shani sir",
audio=open(clip_loc, "rb"), thumb=open("files/shanisir.jpeg", 'rb'))
logger(message=f"Today's morning audio was just sent to {chat_name}.")

context.bot.pin_chat_message(chat_id=chat_id, message_id=msg.message_id, disable_notification=True)
del msg

except Exception as e: # When chat is private, no rights to pin message, or if bot was removed.
context.bot_data['pin_msgs'].append(msg)

except Exception as e: # Insufficient permissions, bot removal/block, or any other unexpected error
logger(message=f"There was an error for {chat_name} due to: {e}.")

context.bot_data['last_sent'] = datetime(right_now.year, right_now.month, right_now.day, 8) # Set it as 8AM today
context.bot_data['last_sent'] = eight_am # Set it as 8AM today
context.dispatcher.persistence.update_bot_data(context.bot_data)
logger(message="The last_sent object was successfully updated to 8AM today.")

del right_now, afternoon, eight_am, diff, greeting, query, ids, clip_loc
del right_now, afternoon, eight_am, diff, greeting, query, ids, clip_loc
Loading