Skip to content

Commit

Permalink
remove sql support and added mongo db support
Browse files Browse the repository at this point in the history
  • Loading branch information
SHABIN-K committed Nov 5, 2022
1 parent 8dec82d commit d229362
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
8 changes: 8 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#(©)CodeXBotz




import os
import logging
from logging.handlers import RotatingFileHandler



#Bot token @Botfather
TG_BOT_TOKEN = os.environ.get("TG_BOT_TOKEN", "")

Expand All @@ -19,6 +26,7 @@

#Database
DB_URI = os.environ.get("DATABASE_URL", "")
DB_NAME = os.environ.get("DATABASE_NAME", "filesharexbot")

#force sub channel id, if you want enable force sub
FORCE_SUB_CHANNEL = int(os.environ.get("FORCE_SUB_CHANNEL", "0"))
Expand Down
39 changes: 39 additions & 0 deletions database/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#(©)CodeXBotz




import pymongo, os
from config import DB_URI, DB_NAME


dbclient = pymongo.MongoClient(DB_URI)
database = dbclient[DB_NAME]


user_data = database['users']



async def present_user(user_id : int):
found = user_data.find_one({'_id': user_id})
if found:
return True
else:
return False

async def add_user(user_id: int):
user_data.insert_one({'_id': user_id})
return

async def full_userbase():
user_docs = user_data.find()
user_ids = []
for doc in user_docs:
user_ids.append(doc['_id'])

return user_ids

async def del_user(user_id: int):
user_data.delete_one({'_id': user_id})
return
19 changes: 10 additions & 9 deletions plugins/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from bot import Bot
from config import ADMINS, FORCE_MSG, START_MSG, OWNER_ID, CUSTOM_CAPTION, DISABLE_CHANNEL_BUTTON, PROTECT_CONTENT
from helper_func import subscribed, encode, decode, get_messages
from database.sql import add_user, query_msg, full_userbase
from database.database import add_user, del_user, full_userbase, present_user


#=====================================================================================##
Expand All @@ -24,11 +24,11 @@
@Bot.on_message(filters.command('start') & filters.private & subscribed)
async def start_command(client: Client, message: Message):
id = message.from_user.id
user_name = '@' + message.from_user.username if message.from_user.username else None
try:
await add_user(id, user_name)
except:
pass
if not await present_user(id):
try:
await add_user(id)
except:
pass
text = message.text
if len(text)>7:
try:
Expand Down Expand Up @@ -153,7 +153,7 @@ async def get_users(client: Bot, message: Message):
@Bot.on_message(filters.private & filters.command('broadcast') & filters.user(ADMINS))
async def send_text(client: Bot, message: Message):
if message.reply_to_message:
query = await query_msg()
query = await full_userbase()
broadcast_msg = message.reply_to_message
total = 0
successful = 0
Expand All @@ -162,8 +162,7 @@ async def send_text(client: Bot, message: Message):
unsuccessful = 0

pls_wait = await message.reply("<i>Broadcasting Message.. This will Take Some Time</i>")
for row in query:
chat_id = int(row[0])
for chat_id in query:
try:
await broadcast_msg.copy(chat_id)
successful += 1
Expand All @@ -172,8 +171,10 @@ async def send_text(client: Bot, message: Message):
await broadcast_msg.copy(chat_id)
successful += 1
except UserIsBlocked:
await del_user(chat_id)
blocked += 1
except InputUserDeactivated:
await del_user(chat_id)
deleted += 1
except:
unsuccessful += 1
Expand Down
6 changes: 2 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@ pyrogram
TgCrypto
Pyromod
# --- For-Database ------------ #
sqlalchemy~=1.3.23
psycopg2-binary
feedparser

pymongo
dnspython

0 comments on commit d229362

Please sign in to comment.