Skip to content

Commit

Permalink
Merge pull request #41 from CodeXBotz/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
SHABIN-K authored Sep 12, 2021
2 parents 082ef35 + bc6ec2b commit a0b7d4a
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 16 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ I Guess This Will Be Usefull For Many People.....😇.

### Features
- Fully customisable.
- Customisable welcome messages.
- Customisable welcome & Forcesub messages.
- More than one Posts in One Link.
- Can be deployed on heroku directly.

Expand Down Expand Up @@ -69,6 +69,9 @@ python3 main.py
/genlink - create link for one post
/users - view bot statistics
/broadcast - broadcast any messages to bot users
```

### Variables
Expand All @@ -79,16 +82,17 @@ python3 main.py
* `OWNER_ID` Must enter Your Telegram Id
* `CHANNEL_ID` Your Channel ID eg:- -100xxxxxxxx
* `ADMINS` Optional: A space separated list of user_ids of Admins, they can only create links
* `START_MESSAGE` Optional: start message of bot, use HTML and <a href='https://github.com/shahsad-klr/File-Sharing-Bot/blob/main/README.md#start_message'>fillings</a>
* `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>
* `FORCE_SUB_MESSAGE`Optional:Force sub message of bot, use HTML and Fillings
* `FORCE_SUB_CHANNEL` Optional: ForceSub Channel ID, leave 0 if you want disable force sub

### Extra Variables

* `CUSTOM_CAPTION` put your Custom caption text if you want Setup Custom Caption, you can use HTML and <a href='https://github.com/shahsad-klr/File-Sharing-Bot/blob/main/README.md#custom_caption'>fillings</a> for formatting (only for documents)
* `CUSTOM_CAPTION` put your Custom caption text if you want Setup Custom Caption, you can use HTML and <a href='https://github.com/CodeXBotz/File-Sharing-Bot/blob/main/README.md#custom_caption'>fillings</a> for formatting (only for documents)
* `DISABLE_CHANNEL_BUTTON` Put True to Disable Channel Share Button, Default if False

### Fillings
#### START_MESSAGE
#### START_MESSAGE | FORCE_SUB_MESSAGE

* `{first}` - User first name
* `{last}` - User last name
Expand Down Expand Up @@ -124,3 +128,4 @@ published by the Free Software Foundation, either version 3 of the License, or
##

**Star this Repo if you Liked it ⭐⭐⭐**

4 changes: 4 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
"description": "Optional: start message of bot, use HTML parsemode format",
"value": "Hello {first}\n\nI can store private files in Specified Channel and other users can access it from special link."
},
"FORCE_SUB_MESSAGE": {
"description": "Optional: Force Sub message of bot, use HTML parsemode format",
"value": "Hello {first}\n\n<b>You need to join in my Channel/Group to use me\n\nKindly Please join Channel</b>"
},
"ADMINS": {
"description": "A space separated list of user_ids of Admins, they can only create links",
"value": "",
Expand Down
6 changes: 6 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#OWNER ID
OWNER_ID = int(os.environ.get("OWNER_ID", ""))

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

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

Expand All @@ -31,6 +34,9 @@
except ValueError:
raise Exception("Your Admins list does not contain valid integers.")

#Force sub message
FORCE_MSG = os.environ.get("FORCE_SUB_MESSAGE", "Hello {first}\n\n<b>You need to join in my Channel/Group to use me\n\nKindly Please join Channel</b>")

#set your Custom Caption here, Keep None for Disable Custom Caption
CUSTOM_CAPTION = os.environ.get("CUSTOM_CAPTION", None)

Expand Down
50 changes: 50 additions & 0 deletions database/sql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

import os
import threading
from sqlalchemy import create_engine
from sqlalchemy import Column, TEXT, Numeric
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, scoped_session
from config import DB_URI

def start() -> scoped_session:
engine = create_engine(DB_URI, client_encoding="utf8")
BASE.metadata.bind = engine
BASE.metadata.create_all(engine)
return scoped_session(sessionmaker(bind=engine, autoflush=False))


BASE = declarative_base()
SESSION = start()

INSERTION_LOCK = threading.RLock()

class Broadcast(BASE):
__tablename__ = "broadcast"
id = Column(Numeric, primary_key=True)
user_name = Column(TEXT)

def __init__(self, id, user_name):
self.id = id
self.user_name = user_name

Broadcast.__table__.create(checkfirst=True)


# Add user details -
async def add_user(id, user_name):
with INSERTION_LOCK:
msg = SESSION.query(Broadcast).get(id)
if not msg:
usr = Broadcast(id, user_name)
SESSION.add(usr)
SESSION.commit()
else:
pass

async def query_msg():
try:
query = SESSION.query(Broadcast.id).order_by(Broadcast.id)
return query
finally:
SESSION.close()
21 changes: 21 additions & 0 deletions database/support.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import asyncio
from database.sql import query_msg
from pyrogram.errors import FloodWait

async def users_info(bot):
users = 0
blocked = 0
identity = await query_msg()
for id in identity:
name = bool()
try:
name = await bot.send_chat_action(int(id[0]), "typing")
except FloodWait as e:
await asyncio.sleep(e.x)
except Exception:
pass
if bool(name):
users += 1
else:
blocked += 1
return users, blocked
2 changes: 1 addition & 1 deletion plugins/channel_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from config import ADMINS, CHANNEL_ID, DISABLE_CHANNEL_BUTTON
from helper_func import encode

@Bot.on_message(filters.private & filters.user(ADMINS) & ~filters.command(['start','batch','genlink']))
@Bot.on_message(filters.private & filters.user(ADMINS) & ~filters.command(['start','users','broadcast','batch','genlink']))
async def channel_post(client: Client, message: Message):
reply_text = await message.reply_text("Please Wait...!", quote = True)
try:
Expand Down
77 changes: 67 additions & 10 deletions plugins/start.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
#(©)Codexbotz

import os
import asyncio
from pyrogram import Client, filters, __version__
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.errors import FloodWait

from bot import Bot
from config import ADMINS, START_MSG, OWNER_ID, CUSTOM_CAPTION, DISABLE_CHANNEL_BUTTON
from config import ADMINS, FORCE_MSG, START_MSG, OWNER_ID, CUSTOM_CAPTION, DISABLE_CHANNEL_BUTTON
from helper_func import subscribed, encode, decode, get_messages
from database.support import users_info
from database.sql import add_user, query_msg


#=====================================================================================##

USERS_LIST = """<b>⭕️Total:</b>\n\n⭕️Subscribers - {}\n⭕️Blocked- {}"""

WAIT_MSG = """"<b>Processing ...</b>"""

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


#=====================================================================================##


@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
await add_user(id, user_name)
text = message.text
if len(text)>7:
try:
Expand Down Expand Up @@ -94,17 +112,56 @@ async def start_command(client: Client, message: Message):

@Bot.on_message(filters.command('start') & filters.private)
async def not_joined(client: Client, message: Message):
text = "<b>You need to join in my Channel/Group to use me\n\nKindly Please join Channel</b>"
message_text = message.text
try:
command, argument = message_text.split()
text = text + f" <b>and <a href='https://t.me/{client.username}?start={argument}'>try again</a></b>"
except ValueError:
pass
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Join Channel", url = client.invitelink)]])
await message.reply(
text = text,
text = FORCE_MSG.format(
first = message.from_user.first_name,
last = message.from_user.last_name,
username = None if not message.from_user.username else '@' + message.from_user.username,
mention = message.from_user.mention,
id = message.from_user.id
),
reply_markup = reply_markup,
quote = True,
disable_web_page_preview = True
)

@Bot.on_message(filters.private & filters.command('users'))
async def subscribers_count(bot, m: Message):
id = m.from_user.id
if id not in ADMINS:
return
msg = await m.reply_text(WAIT_MSG)
messages = await users_info(bot)
active = messages[0]
blocked = messages[1]
await m.delete()
await msg.edit(USERS_LIST.format(active, blocked))



@Bot.on_message(filters.private & filters.command('broadcast'))
async def send_text(bot, m: Message):
id = m.from_user.id
if id not in ADMINS:
return
if (" " not in m.text) and ("broadcast" in m.text) and (m.reply_to_message is not None):
query = await query_msg()
for row in query:
chat_id = int(row[0])
try:
await bot.copy_message(
chat_id=chat_id,
from_chat_id=m.chat.id,
message_id=m.reply_to_message.message_id,
caption=m.caption,
reply_markup=m.reply_markup
)
except FloodWait as e:
await asyncio.sleep(e.x)
except Exception:
pass
else:
msg = await m.reply_text(REPLY_ERROR, m.message_id)
await asyncio.sleep(8)
await msg.delete()
8 changes: 7 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Pyrogram
# --- For-Bot-Working --------- #
pyrogram
TgCrypto
Pyromod
# --- For-Database ------------ #
sqlalchemy~=1.3.23
psycopg2-binary
feedparser

0 comments on commit a0b7d4a

Please sign in to comment.