-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from SHABIN-K/main
add broadcast command
- Loading branch information
Showing
7 changed files
with
144 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|