Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Commit

Permalink
code maintenence
Browse files Browse the repository at this point in the history
initial redesign of code using functions and packages
  • Loading branch information
Philotheephilix committed Sep 9, 2023
1 parent 5783148 commit 1a2f01f
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 54 deletions.
4 changes: 0 additions & 4 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
E-mail_for_checking_email=
Password_for_checking_mail=
Telegram_bot_API=
Open_Weather_API=
29 changes: 29 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "enter program name, for example ${workspaceFolder}/a.exe",
"MIMode": "gdb",
"miDebuggerPath": "/path/to/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}

]
}
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ This bot can automate these following tasks

7. Commands : This command returns all the available commands

8. Reels : when the user sends the link of the instagram reel the bot retrieves the reels video from instagram and sends it to the user
9. Posts : when the user sends the link of the instagram post the bot retrieves the post from instagram and sends it to the user
8. Reels : when the user sends the link of the instagram reel, The bot retrieves the reels video from instagram and sends it to the user
9. Posts : when the user sends the link of the instagram post, The bot retrieves the post from instagram and sends it to the user
## Links
[Releases](https://github.com/Philotheephilix/Multi-funtional-telegram-bot/releases)

Expand Down Expand Up @@ -64,7 +64,6 @@ BotFather is the official bot used to create and manage Telegram bots. Here are
jpg2pdf - converts images to pdf
sos - emergency contact number
commands - list all commands
reels - download instagram reels


HOORAY Your bot is now created and ready to be configured.
Expand Down
7 changes: 7 additions & 0 deletions bot_action.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/start - greet to check life of the bot
/tell_joke - returns a random joke
/weather - view the weather of the city
/check_email - check email for unread messages
/jpg2pdf - converts images to pdf
/sos - emergency contact number
/commands - return list of commands
88 changes: 41 additions & 47 deletions multi_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,38 @@
cl = Client()
tempdir=os.getcwd()
Credentials={}


bot = ""
BASE_URL = "http://api.openweathermap.org/data/2.5/weather?"
message=""
#Code for handling credential encryption and decryption
a=1
if a==1:
try:
with open('crypt.key', 'rb') as filekey:
key = filekey.read()
def decrypt():
a=1
if a==1:
try:
with open('crypt.key', 'rb') as filekey:
key = filekey.read()

fernet = Fernet(key)
with open('.env', 'rb') as file:
original = file.read()
decrypted = fernet.decrypt(original)
with open('.env', 'wb+') as decrypted_file:
decrypted_file.write(decrypted)
dnc=decrypted_file.read()
print("decrypted")
except :
print("Invalid Key or Already decrypted")

#loading credentials and keys from env file
load_dotenv(tempdir+"\.env")
username=os.getenv("E-mail_for_checking_email")
password=os.getenv("Password_for_checking_mail")
TELE_API_KEY = os.getenv("Telegram_bot_API")
print(TELE_API_KEY)
OW_API = os.getenv("Open_Weather_API")
fernet = Fernet(key)
with open('.env', 'rb') as file:
original = file.read()
decrypted = fernet.decrypt(original)
with open('.env', 'wb+') as decrypted_file:
decrypted_file.write(decrypted)
dnc=decrypted_file.read()
print("decrypted")
except :
print("Invalid Key or Already decrypted")
decrypt()

#loading credentials and keys from env file

load_dotenv(tempdir+"\.env")
username=os.getenv("E-mail_for_checking_email")
password=os.getenv("Password_for_checking_mail")
TELE_API_KEY = os.getenv("Telegram_bot_API")
print(TELE_API_KEY)
OW_API = os.getenv("Open_Weather_API")
def encrypt():
with open(".env","r") as credentials:
Credentials=credentials.readlines()
print(Credentials)
Expand All @@ -72,9 +77,9 @@
enc=encrypted_file.read()
print("encrypted")
except:
print("encrypt failed")

print(Credentials)
print("encrypt failed")
print(Credentials)
encrypt()

# Directory creation and verification
def init_dirs():
Expand All @@ -88,9 +93,11 @@ def init_dirs():
print("dirs already exists")
init_dirs()
#Bot initialization
bot = telebot.TeleBot(TELE_API_KEY)
BASE_URL = "http://api.openweathermap.org/data/2.5/weather?"
bot = telebot.TeleBot(TELE_API_KEY)
def bot_init():
global bot
bot = telebot.TeleBot(TELE_API_KEY)
bot = telebot.TeleBot(TELE_API_KEY)
bot_init()
# Initialize Joke.txt Dataset
def remove(list):
pattern = '[0-9]'
Expand All @@ -110,14 +117,8 @@ def handle_photos(message):
#Code for handling /commands
@bot.message_handler(commands=["commands"])
def message(message):
commands="""/start - greet to check life of the bot
/tell_joke - returns a random joke
/weather - view the weather of the city
/check_email - check email for unread messages
/jpg2pdf - converts images to pdf
/sos - emergency contact number
/commands - return list of commands
"""
bot_action=open("bot_action.txt","r")
commands=bot_action.read()
bot.reply_to(message,"Here are the list of commands \n"+commands)
#Code to handle jpg2pdf conversion
@bot.message_handler(commands=["jpg2pdf"])
Expand Down Expand Up @@ -276,14 +277,6 @@ def city(message):
sos="Emergency Numbers For "+state+"\nAmbulance = "+tmplist[0]+"\nFire = "+tmplist[1]+"\nPolice = "+tmplist[2]
bot.reply_to(message,sos)
sos_active="0"
elif reels_active=="1":
ori_reel=str(message.text)
reel=ori_reel.split("https://www.instagram.com/reel/")
base_url="https://www.ddinstagram.com/reel/"
Reel_to_send=base_url+reel[1]
Reel_markup="[REEL]("+Reel_to_send+")"
print(Reel_markup)
bot.reply_to(message,Reel_markup)
else:
status = str(message.text)
if status.startswith("https://www.instagram.com/reel/"):
Expand All @@ -306,5 +299,6 @@ def city(message):
bot.reply_to(message,Post_markup)
else:
bot.reply_to(message,"Enter valid command \n type /commands to list all commands")

#polling command to receive commands from bot
bot.infinity_polling()

0 comments on commit 1a2f01f

Please sign in to comment.