Skip to content

Commit febebe2

Browse files
authored
Merge pull request #183 from SHABIN-K/main
Added mongo db support
2 parents 8dec82d + 066cf50 commit febebe2

File tree

8 files changed

+106
-86
lines changed

8 files changed

+106
-86
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ python3 main.py
8383
### Variables
8484

8585
* `API_HASH` Your API Hash from my.telegram.org
86-
* `API_ID` Your API ID from my.telegram.org
86+
* `APP_ID` Your API ID from my.telegram.org
8787
* `TG_BOT_TOKEN` Your bot token from @BotFather
8888
* `OWNER_ID` Must enter Your Telegram Id
8989
* `CHANNEL_ID` Your Channel ID eg:- -100xxxxxxxx
90+
* `DATABASE_URL` Your mongo db url
91+
* `DATABASE_NAME` Your mongo db session name
9092
* `ADMINS` Optional: A space separated list of user_ids of Admins, they can only create links
9193
* `START_MESSAGE` Optional: start message of bot, use HTML and <a href='https://github.com/codexbotz/File-Sharing-Bot/blob/main/README.md#start_message'>fillings</a>
9294
* `FORCE_SUB_MESSAGE`Optional:Force sub message of bot, use HTML and Fillings

app.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"sharing"
88
],
99
"repository": "https://github.com/CodeXBotz/File-Sharing-Bot",
10-
"logo": "https://telegra.ph/file/14d3013fda21281c54b61.jpg",
10+
"logo": "https://ibb.co/FgPVtzw",
1111
"env": {
1212
"TG_BOT_TOKEN": {
1313
"description": "Your Bot token, Get it from @Botfather",
@@ -21,6 +21,14 @@
2121
"description": "your app id, take it from my.telegram.org",
2222
"value": ""
2323
},
24+
"DATABASE_URL": {
25+
"description": "Paste your mongo db url",
26+
"value": "url"
27+
},
28+
"DATABASE_NAME":{
29+
"description": "Enter your DATABASE_NAME ",
30+
"value": "filesharexbot"
31+
},
2432
"API_HASH":{
2533
"description": "your api hash, take it from my.telegram.org",
2634
"value": ""
@@ -52,14 +60,6 @@
5260
"required": false
5361
}
5462
},
55-
"addons": [
56-
{
57-
"plan": "heroku-postgresql",
58-
"options": {
59-
"version": "12"
60-
}
61-
}
62-
],
6363
"buildpacks": [
6464
{
6565
"url": "heroku/python"

bot.py

+19
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88

99
from config import API_HASH, APP_ID, LOGGER, TG_BOT_TOKEN, TG_BOT_WORKERS, FORCE_SUB_CHANNEL, CHANNEL_ID
1010

11+
12+
name ="""
13+
░█████╗░░█████╗░██████╗░███████╗██╗░░██╗██████╗░░█████╗░████████╗███████╗
14+
██╔══██╗██╔══██╗██╔══██╗██╔════╝╚██╗██╔╝██╔══██╗██╔══██╗╚══██╔══╝╚════██║
15+
██║░░╚═╝██║░░██║██║░░██║█████╗░░░╚███╔╝░██████╦╝██║░░██║░░░██║░░░░░███╔═╝
16+
██║░░██╗██║░░██║██║░░██║██╔══╝░░░██╔██╗░██╔══██╗██║░░██║░░░██║░░░██╔══╝░░
17+
╚█████╔╝╚█████╔╝██████╔╝███████╗██╔╝╚██╗██████╦╝╚█████╔╝░░░██║░░░███████╗
18+
░╚════╝░░╚════╝░╚═════╝░╚══════╝╚═╝░░╚═╝╚═════╝░░╚════╝░░░░╚═╝░░░╚══════╝
19+
"""
20+
21+
1122
class Bot(Client):
1223
def __init__(self):
1324
super().__init__(
@@ -53,6 +64,14 @@ async def start(self):
5364

5465
self.set_parse_mode(ParseMode.HTML)
5566
self.LOGGER(__name__).info(f"Bot Running..!\n\nCreated by \nhttps://t.me/CodeXBotz")
67+
self.LOGGER(__name__).info(f""" \n\n
68+
░█████╗░░█████╗░██████╗░███████╗██╗░░██╗██████╗░░█████╗░████████╗███████╗
69+
██╔══██╗██╔══██╗██╔══██╗██╔════╝╚██╗██╔╝██╔══██╗██╔══██╗╚══██╔══╝╚════██║
70+
██║░░╚═╝██║░░██║██║░░██║█████╗░░░╚███╔╝░██████╦╝██║░░██║░░░██║░░░░░███╔═╝
71+
██║░░██╗██║░░██║██║░░██║██╔══╝░░░██╔██╗░██╔══██╗██║░░██║░░░██║░░░██╔══╝░░
72+
╚█████╔╝╚█████╔╝██████╔╝███████╗██╔╝╚██╗██████╦╝╚█████╔╝░░░██║░░░███████╗
73+
░╚════╝░░╚════╝░╚═════╝░╚══════╝╚═╝░░╚═╝╚═════╝░░╚════╝░░░░╚═╝░░░╚══════╝
74+
""")
5675
self.username = usr_bot_me.username
5776

5877
async def stop(self, *args):

config.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
#(©)CodeXBotz
2+
3+
4+
5+
16
import os
27
import logging
38
from logging.handlers import RotatingFileHandler
49

10+
11+
512
#Bot token @Botfather
613
TG_BOT_TOKEN = os.environ.get("TG_BOT_TOKEN", "")
714

@@ -19,6 +26,7 @@
1926

2027
#Database
2128
DB_URI = os.environ.get("DATABASE_URL", "")
29+
DB_NAME = os.environ.get("DATABASE_NAME", "filesharexbot")
2230

2331
#force sub channel id, if you want enable force sub
2432
FORCE_SUB_CHANNEL = int(os.environ.get("FORCE_SUB_CHANNEL", "0"))

database/database.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#(©)CodeXBotz
2+
3+
4+
5+
6+
import pymongo, os
7+
from config import DB_URI, DB_NAME
8+
9+
10+
dbclient = pymongo.MongoClient(DB_URI)
11+
database = dbclient[DB_NAME]
12+
13+
14+
user_data = database['users']
15+
16+
17+
18+
async def present_user(user_id : int):
19+
found = user_data.find_one({'_id': user_id})
20+
if found:
21+
return True
22+
else:
23+
return False
24+
25+
async def add_user(user_id: int):
26+
user_data.insert_one({'_id': user_id})
27+
return
28+
29+
async def full_userbase():
30+
user_docs = user_data.find()
31+
user_ids = []
32+
for doc in user_docs:
33+
user_ids.append(doc['_id'])
34+
35+
return user_ids
36+
37+
async def del_user(user_id: int):
38+
user_data.delete_one({'_id': user_id})
39+
return

database/sql.py

-55
This file was deleted.

plugins/start.py

+26-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#(©)CodeXBotz
2+
3+
4+
5+
26
import os
37
import asyncio
48
from pyrogram import Client, filters, __version__
@@ -7,28 +11,21 @@
711
from pyrogram.errors import FloodWait, UserIsBlocked, InputUserDeactivated
812

913
from bot import Bot
10-
from config import ADMINS, FORCE_MSG, START_MSG, OWNER_ID, CUSTOM_CAPTION, DISABLE_CHANNEL_BUTTON, PROTECT_CONTENT
14+
from config import ADMINS, FORCE_MSG, START_MSG, CUSTOM_CAPTION, DISABLE_CHANNEL_BUTTON, PROTECT_CONTENT
1115
from helper_func import subscribed, encode, decode, get_messages
12-
from database.sql import add_user, query_msg, full_userbase
13-
14-
15-
#=====================================================================================##
16-
17-
WAIT_MSG = """"<b>Processing ...</b>"""
16+
from database.database import add_user, del_user, full_userbase, present_user
1817

19-
REPLY_ERROR = """<code>Use this command as a replay to any telegram message with out any spaces.</code>"""
2018

21-
#=====================================================================================##
2219

2320

2421
@Bot.on_message(filters.command('start') & filters.private & subscribed)
2522
async def start_command(client: Client, message: Message):
2623
id = message.from_user.id
27-
user_name = '@' + message.from_user.username if message.from_user.username else None
28-
try:
29-
await add_user(id, user_name)
30-
except:
31-
pass
24+
if not await present_user(id):
25+
try:
26+
await add_user(id)
27+
except:
28+
pass
3229
text = message.text
3330
if len(text)>7:
3431
try:
@@ -110,6 +107,17 @@ async def start_command(client: Client, message: Message):
110107
)
111108
return
112109

110+
111+
#=====================================================================================##
112+
113+
WAIT_MSG = """"<b>Processing ...</b>"""
114+
115+
REPLY_ERROR = """<code>Use this command as a replay to any telegram message with out any spaces.</code>"""
116+
117+
#=====================================================================================##
118+
119+
120+
113121
@Bot.on_message(filters.command('start') & filters.private)
114122
async def not_joined(client: Client, message: Message):
115123
buttons = [
@@ -153,7 +161,7 @@ async def get_users(client: Bot, message: Message):
153161
@Bot.on_message(filters.private & filters.command('broadcast') & filters.user(ADMINS))
154162
async def send_text(client: Bot, message: Message):
155163
if message.reply_to_message:
156-
query = await query_msg()
164+
query = await full_userbase()
157165
broadcast_msg = message.reply_to_message
158166
total = 0
159167
successful = 0
@@ -162,8 +170,7 @@ async def send_text(client: Bot, message: Message):
162170
unsuccessful = 0
163171

164172
pls_wait = await message.reply("<i>Broadcasting Message.. This will Take Some Time</i>")
165-
for row in query:
166-
chat_id = int(row[0])
173+
for chat_id in query:
167174
try:
168175
await broadcast_msg.copy(chat_id)
169176
successful += 1
@@ -172,8 +179,10 @@ async def send_text(client: Bot, message: Message):
172179
await broadcast_msg.copy(chat_id)
173180
successful += 1
174181
except UserIsBlocked:
182+
await del_user(chat_id)
175183
blocked += 1
176184
except InputUserDeactivated:
185+
await del_user(chat_id)
177186
deleted += 1
178187
except:
179188
unsuccessful += 1

requirements.txt

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@ pyrogram
33
TgCrypto
44
Pyromod
55
# --- For-Database ------------ #
6-
sqlalchemy~=1.3.23
7-
psycopg2-binary
8-
feedparser
9-
6+
pymongo
7+
dnspython

0 commit comments

Comments
 (0)