merge pull request #148 from Xtao-Labs/flood

[fix] Just run once get_me
This commit is contained in:
levina 2022-02-15 13:11:23 +07:00 committed by GitHub
commit ee2a8c816b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 47 additions and 33 deletions

View File

@ -1,5 +1,6 @@
from requests import get
import asyncio
from pyrogram import Client
from pyrogram.types import User
from pytgcalls import PyTgCalls
from config import API_HASH, API_ID, BOT_TOKEN, SESSION_NAME
@ -8,11 +9,9 @@ bot = Client(
":veez:",
API_ID,
API_HASH,
bot_token=BOT_TOKEN,
plugins={"root": "program"},
bot_token=BOT_TOKEN
)
# A bad way to do it, but it works
me = get(f"https://api.telegram.org/bot{BOT_TOKEN}/getme").json()["result"]
user = Client(
SESSION_NAME,
api_id=API_ID,
@ -20,3 +19,16 @@ user = Client(
)
calls = PyTgCalls(user, overload_quiet_mode=True)
with bot as app:
me_bot = app.get_me()
with user as app:
me_user = app.get_me()
bot = Client( # type: ignore
":veez:",
API_ID,
API_HASH,
bot_token=BOT_TOKEN,
plugins={"root": "program"},
)

View File

@ -4,7 +4,7 @@ from typing import Callable, Union, Optional
from pyrogram import Client
from pyrogram.types import Message, CallbackQuery
from config import SUDO_USERS, OWNER_ID
from driver.core import bot, me
from driver.core import bot, me_bot
from driver.admins import get_administrators
from driver.database.dblockchat import blacklisted_chats
from driver.database.dbpunish import is_gbanned_user
@ -129,7 +129,7 @@ def require_admin(
async def wrapper(
client: Client, message: Union[CallbackQuery, Message], *args, **kwargs
):
has_perms = await check_perms(message, permissions, notice, me["id"] if self else None)
has_perms = await check_perms(message, permissions, notice, me_bot.id if self else None)
if has_perms:
return await func(client, message, *args, *kwargs)

View File

@ -1,6 +1,6 @@
# Copyright (C) 2021 By VeezMusicProject
from driver.core import me
from driver.core import me_bot
from driver.decorators import check_blacklist
from driver.queues import QUEUE
from driver.database.dbpunish import is_gbanned_user
@ -21,7 +21,7 @@ from config import (
@Client.on_callback_query(filters.regex("home_start"))
@check_blacklist()
async def start_set(_, query: CallbackQuery):
BOT_NAME = me["first_name"]
BOT_NAME = me_bot.first_name
await query.answer("home start")
await query.edit_message_text(
f"""✨ **Welcome [{query.message.chat.first_name}](tg://user?id={query.message.chat.id}) !**\n
@ -86,7 +86,7 @@ async def quick_set(_, query: CallbackQuery):
@Client.on_callback_query(filters.regex("user_guide"))
@check_blacklist()
async def guide_set(_, query: CallbackQuery):
ass_uname = me["username"]
ass_uname = me_bot.first_name
await query.answer("user guide")
await query.edit_message_text(
f"""❓ How to use this Bot ?, read the Guide below !
@ -145,7 +145,7 @@ All commands can be used with (`! / .`) handler""",
@Client.on_callback_query(filters.regex("user_command"))
@check_blacklist()
async def user_set(_, query: CallbackQuery):
BOT_NAME = me["first_name"]
BOT_NAME = me_bot.first_name
await query.answer("basic commands")
await query.edit_message_text(
f"""✏️ Command list for all user.
@ -172,7 +172,7 @@ async def user_set(_, query: CallbackQuery):
@Client.on_callback_query(filters.regex("admin_command"))
@check_blacklist()
async def admin_set(_, query: CallbackQuery):
BOT_NAME = me["first_name"]
BOT_NAME = me_bot.first_name
await query.answer("admin commands")
await query.edit_message_text(
f"""✏️ Command list for group admin.
@ -199,7 +199,7 @@ async def admin_set(_, query: CallbackQuery):
@check_blacklist()
async def sudo_set(_, query: CallbackQuery):
user_id = query.from_user.id
BOT_NAME = me["first_name"]
BOT_NAME = me_bot.first_name
if user_id not in SUDO_USERS:
await query.answer("⚠️ You don't have permissions to click this button\n\n» This button is reserved for sudo members of this bot.", show_alert=True)
return
@ -228,7 +228,7 @@ async def sudo_set(_, query: CallbackQuery):
@check_blacklist()
async def owner_set(_, query: CallbackQuery):
user_id = query.from_user.id
BOT_NAME = me["first_name"]
BOT_NAME = me_bot.first_name
if user_id not in OWNER_ID:
await query.answer("⚠️ You don't have permissions to click this button\n\n» This button is reserved for owner of this bot.", show_alert=True)
return

View File

@ -8,6 +8,8 @@ from pyrogram.types import Message
from pyrogram import Client, filters, __version__ as pyrover
from pytgcalls import (__version__ as pytgver)
from driver.core import me_bot
from program import __version__ as ver
from program.start import __python_version__ as pyver
@ -126,9 +128,8 @@ async def broadcast_message_pin(c: Client, message: Message):
@Client.on_message(command(["stats", f"stats@{uname}"]) & ~filters.edited)
@sudo_users_only
async def bot_statistic(c: Client, message: Message):
name = (await c.get_me()).first_name
name = me_bot.first_name
chat_id = message.chat.id
user_id = message.from_user.id
msg = await c.send_message(
chat_id, "❖ Collecting Stats..."
)

View File

@ -20,7 +20,7 @@ from driver.design.thumbnail import thumb
from driver.design.chatname import CHAT_TITLE
from driver.filters import command, other_filters
from driver.queues import QUEUE, add_to_queue
from driver.core import calls, user, bot
from driver.core import calls, user, bot, me_user
from driver.utils import bash, remove_if_exists
from driver.database.dbpunish import is_gbanned_user
from driver.database.dblockchat import blacklisted_chats
@ -74,7 +74,7 @@ async def play(c: Client, m: Message):
"you're an __Anonymous__ user !\n\n» revert back to your real user account to use this bot."
)
try:
ubot = (await user.get_me()).id
ubot = me_user.id
b = await c.get_chat_member(chat_id, ubot)
if b.status == "kicked":
await c.unban_chat_member(chat_id, ubot)

View File

@ -6,6 +6,7 @@ import asyncio
from pyrogram import Client, filters
from pyrogram.types import Message
from pyrogram.errors import FloodWait
from driver.core import me_bot
from driver.filters import command, other_filters
from driver.decorators import bot_creator
from driver.database.dbchat import get_served_chats
@ -17,7 +18,7 @@ from config import SUDO_USERS, BOT_USERNAME as bn
@Client.on_message(command(["gban", f"gban@{bn}"]) & other_filters)
@bot_creator
async def global_banned(c: Client, message: Message):
BOT_NAME = (await c.get_me()).first_name
BOT_NAME = me_bot.first_name
if not message.reply_to_message:
if len(message.command) < 2:
await message.reply_text("**usage:**\n\n/gban [username | user_id]")
@ -27,7 +28,7 @@ async def global_banned(c: Client, message: Message):
user = user.replace("@", "")
user = await c.get_users(user)
from_user = message.from_user
BOT_ID = await c.get_me()
BOT_ID = me_bot.id
if user.id == from_user.id:
return await message.reply_text(
"You can't gban yourself !"
@ -76,7 +77,7 @@ async def global_banned(c: Client, message: Message):
from_user_mention = message.from_user.mention
user_id = message.reply_to_message.from_user.id
mention = message.reply_to_message.from_user.mention
BOT_ID = await c.get_me()
BOT_ID = me_bot.id
if user_id == from_user_id:
await message.reply_text("You can't gban yourself !")
elif user_id == BOT_ID:
@ -140,7 +141,7 @@ async def ungban_global(c: Client, message: Message):
user = user.replace("@", "")
user = await c.get_users(user)
from_user = message.from_user
BOT_ID = await c.get_me()
BOT_ID = me_bot.id
if user.id == from_user.id:
await message.reply_text("You can't ungban yourself because you can't be gbanned !")
elif user.id == BOT_ID:
@ -159,7 +160,7 @@ async def ungban_global(c: Client, message: Message):
from_user_id = message.from_user.id
user_id = message.reply_to_message.from_user.id
mention = message.reply_to_message.from_user.mention
BOT_ID = await c.get_me()
BOT_ID = me_bot.id
if user_id == from_user_id:
await message.reply_text("You can't ungban yourself because you can't be gbanned !")
elif user_id == BOT_ID:

View File

@ -14,7 +14,7 @@ from config import (
)
from driver.decorators import check_blacklist
from program import __version__
from driver.core import user, bot, me
from driver.core import bot, me_bot, me_user
from driver.filters import command, other_filters
from driver.database.dbchat import add_served_chat, is_served_chat
from driver.database.dbpunish import is_gbanned_user
@ -59,7 +59,7 @@ async def _human_time_duration(seconds):
)
@check_blacklist()
async def start_(c: Client, message: Message):
BOT_NAME = me["first_name"]
BOT_NAME = me_bot.first_name
await message.reply_text(
f"""✨ **Welcome {message.from_user.mention()} !**\n
💭 [{BOT_NAME}](https://t.me/{BOT_USERNAME}) **Is a bot to play music and video in groups, through the Telegram Group video chat!**
@ -109,7 +109,7 @@ async def alive(c: Client, message: Message):
current_time = datetime.utcnow()
uptime_sec = (current_time - START_TIME).total_seconds()
uptime = await _human_time_duration(int(uptime_sec))
BOT_NAME = (await c.get_me()).first_name
BOT_NAME = me_bot.first_name
keyboard = InlineKeyboardMarkup(
[
@ -172,8 +172,8 @@ async def new_chat(c: Client, m: Message):
pass
else:
await add_served_chat(chat_id)
ass_uname = (await user.get_me()).username
bot_id = (await c.get_me()).id
ass_uname = me_user.username
bot_id = me_bot.id
for member in m.new_chat_members:
if chat_id in await blacklisted_chats():
await m.reply(

View File

@ -2,7 +2,7 @@ import asyncio
from config import BOT_USERNAME, SUDO_USERS
from driver.core import user
from driver.core import user, me_bot
from driver.filters import command, other_filters
from driver.database.dbchat import remove_served_chat
from driver.database.dbqueue import remove_active_chat
@ -91,7 +91,7 @@ async def leave_all(client, message):
@Client.on_message(filters.left_chat_member)
async def bot_kicked(c: Client, m: Message):
bot_id = (await c.get_me()).id
bot_id = me_bot.id
chat_id = m.chat.id
left_member = m.left_chat_member
if left_member.id == bot_id:

View File

@ -14,7 +14,7 @@ from driver.design.thumbnail import thumb
from driver.design.chatname import CHAT_TITLE
from driver.filters import command, other_filters
from driver.queues import QUEUE, add_to_queue
from driver.core import calls, user, bot
from driver.core import calls, user, bot, me_user
from driver.database.dbpunish import is_gbanned_user
from driver.database.dblockchat import blacklisted_chats
from driver.database.dbqueue import add_active_chat, remove_active_chat, music_on
@ -89,7 +89,7 @@ async def vplay(c: Client, m: Message):
"you're an __Anonymous__ user !\n\n» revert back to your real user account to use this bot."
)
try:
ubot = (await user.get_me()).id
ubot = me_user.id
b = await c.get_chat_member(chat_id, ubot)
if b.status == "kicked":
await c.unban_chat_member(chat_id, ubot)
@ -357,7 +357,7 @@ async def vstream(c: Client, m: Message):
"you're an __Anonymous__ user !\n\n» revert back to your real user account to use this bot."
)
try:
ubot = (await user.get_me()).id
ubot = me_user.id
b = await c.get_chat_member(chat_id, ubot)
if b.status == "kicked":
await c.unban_chat_member(chat_id, ubot)