Skip to content
This repository was archived by the owner on May 15, 2021. It is now read-only.

Commit

Permalink
New Warns Plugin in plugins/admin + ytsearch in Inline youtube-dl (#73)
Browse files Browse the repository at this point in the history
* fixes

* Added heroku.yml

* Update utube_inline.py

* Added warns to rebase (#72)

* Warns.py

Co-authored-by: sabbyX <61574665+sabbyX@users.noreply.github.com>
Co-authored-by: pqhaz <me@pqhaz.dev>
Co-authored-by: MrYacha <36996396+mryacha@users.noreply.github.com>
Co-authored-by: Maverick <maver_ck@outlook.com>
  • Loading branch information
5 people authored Nov 27, 2020
1 parent 0754b18 commit 6d9f4f0
Show file tree
Hide file tree
Showing 17 changed files with 684 additions and 90 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ vendor/
config.ini
config.env
.vscode/
.idea/
*.session
log.txt
unknown_errors.txt
Expand All @@ -145,6 +146,8 @@ bin/
resources/base_profile_pic.jpg
resources/mdfy_profile_pic.jpg
pictest.py
resources/MutantAcademyBB.ttf
userge/plugins/dev/
resources/ProductSans-BoldItalic.ttf
resources/ProductSans-Light.ttf
resources/Roboto-Regular.ttf
Expand Down
17 changes: 12 additions & 5 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ FROM gitpod/workspace-full
RUN sudo apt-get update \
&& sudo apt-get install -y --no-install-recommends \
tree \
wget2 \
pv \
p7zip-full \
mediainfo \
neofetch \
ffmpeg \
&& sudo rm -rf /var/lib/apt/lists/*
ibasound2-dev \
libgtk-3-dev \
libnss3-dev \
curl \
git \
gnupg2 \
unzip \
wget \
jq

RUN curl https://cli-assets.heroku.com/install.sh | sh
RUN curl -sO https://cli-assets.heroku.com/install.sh && bash install.sh && rm install.sh

RUN sudo rm -rf /var/lib/apt/lists/*
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ RUN pip install -r requirements.txt
COPY . .

# command to run on container start
CMD [ "bash", "./run" ]
CMD [ "bash", "./run" ]
5 changes: 5 additions & 0 deletions heroku.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build:
docker:
worker: Dockerfile
run:
worker: bash run
4 changes: 2 additions & 2 deletions init/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ upgradePip() {
}

installReq() {
pip3 install -r $1/requirements.txt &> /dev/null
pip3 install --use-feature=2020-resolver -r $1/requirements.txt &> /dev/null
}

printLine() {
Expand Down Expand Up @@ -120,4 +120,4 @@ printLogo() {
XXXXXXX XXXXXXX
'
printLine
}
}
Binary file added resources/logo_x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# pylint: disable=missing-module-docstring
#
# Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >.
#
# This file is part of < https://github.com/UsergeTeam/Userge > project,
# and is released under the "GNU v3.0 License Agreement".
# Please see < https://github.com/uaudith/Userge/blob/master/LICENSE >
#
# All rights reserved.
23 changes: 23 additions & 0 deletions tests/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# pylint: disable=missing-module-docstring
#
# Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >.
#
# This file is part of < https://github.com/UsergeTeam/Userge > project,
# and is released under the "GNU v3.0 License Agreement".
# Please see < https://github.com/uaudith/Userge/blob/master/LICENSE >
#
# All rights reserved.

import os

from userge import userge


async def _worker() -> None:
chat_id = int(os.environ.get("CHAT_ID") or 0)
type_ = 'unofficial' if os.path.exists("../userge/plugins/unofficial") else 'main'
await userge.send_message(chat_id, f'`{type_} build completed !`')

if __name__ == "__main__":
userge.begin(_worker())
print('USERGE-X test has been finished!')
99 changes: 57 additions & 42 deletions userge/core/methods/decorators/raw_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from pyrogram import StopPropagation, ContinuePropagation
from pyrogram.filters import Filter as RawFilter
from pyrogram.types import Message as RawMessage, ChatMember
from pyrogram.errors.exceptions.bad_request_400 import ChatAdminRequired, PeerIdInvalid
from pyrogram.errors import ChatAdminRequired, PeerIdInvalid

from userge import logging, Config
from ...ext import RawClient
Expand All @@ -42,6 +42,10 @@
_U_AD_CHT: Dict[int, ChatMember] = {}
_U_NM_CHT: Dict[int, ChatMember] = {}

_CH_LKS: Dict[str, asyncio.Lock] = {}
_CH_LKS_LK = asyncio.Lock()
_INIT_LK = asyncio.Lock()


async def _update_u_cht(r_m: RawMessage) -> ChatMember:
if r_m.chat.id not in {**_U_AD_CHT, **_U_NM_CHT}:
Expand Down Expand Up @@ -88,20 +92,21 @@ async def _init(r_c: Union['_client.Userge', '_client._UsergeBot'],
global _U_ID, _B_ID # pylint: disable=global-statement
if r_m.from_user and (r_m.from_user.is_self
or (r_m.from_user.id in Config.SUDO_USERS)
or (r_m.from_user.id == Config.OWNER_ID)):
or (r_m.from_user.id in Config.OWNER_ID)):
RawClient.LAST_OUTGOING_TIME = time.time()
if _U_ID and _B_ID:
return
if isinstance(r_c, _client.Userge):
if not _U_ID:
_U_ID = (await r_c.get_me()).id
if RawClient.DUAL_MODE and not _B_ID:
_B_ID = (await r_c.bot.get_me()).id
else:
if not _B_ID:
_B_ID = (await r_c.get_me()).id
if RawClient.DUAL_MODE and not _U_ID:
_U_ID = (await r_c.ubot.get_me()).id
async with _INIT_LK:
if _U_ID and _B_ID:
return
if isinstance(r_c, _client.Userge):
if not _U_ID:
_U_ID = (await r_c.get_me()).id
if RawClient.DUAL_MODE and not _B_ID:
_B_ID = (await r_c.bot.get_me()).id
else:
if not _B_ID:
_B_ID = (await r_c.get_me()).id
if RawClient.DUAL_MODE and not _U_ID:
_U_ID = (await r_c.ubot.get_me()).id


async def _raise_func(r_c: Union['_client.Userge', '_client._UsergeBot'],
Expand Down Expand Up @@ -130,6 +135,26 @@ async def _is_admin(r_c: Union['_client.Userge', '_client._UsergeBot'],
return r_m.chat.id in _B_AD_CHT


def _get_chat_member(r_c: Union['_client.Userge', '_client._UsergeBot'],
r_m: RawMessage) -> Optional[ChatMember]:
if r_m.chat.type in ("private", "bot"):
return None
if isinstance(r_c, _client.Userge):
if r_m.chat.id in _U_AD_CHT:
return _U_AD_CHT[r_m.chat.id]
return _U_NM_CHT[r_m.chat.id]
if r_m.chat.id in _B_AD_CHT:
return _B_AD_CHT[r_m.chat.id]
return _B_NM_CHT[r_m.chat.id]


async def _get_lock(key: str) -> asyncio.Lock:
async with _CH_LKS_LK:
if key not in _CH_LKS:
_CH_LKS[key] = asyncio.Lock()
return _CH_LKS[key]


async def _bot_is_present(r_c: Union['_client.Userge', '_client._UsergeBot'],
r_m: RawMessage) -> bool:
global _TASK_2_START_TO # pylint: disable=global-statement
Expand All @@ -149,19 +174,6 @@ async def _bot_is_present(r_c: Union['_client.Userge', '_client._UsergeBot'],
return r_m.chat.id in _B_CMN_CHT


def _get_chat_member(r_c: Union['_client.Userge', '_client._UsergeBot'],
r_m: RawMessage) -> Optional[ChatMember]:
if r_m.chat.type in ("private", "bot"):
return None
if isinstance(r_c, _client.Userge):
if r_m.chat.id in _U_AD_CHT:
return _U_AD_CHT[r_m.chat.id]
return _U_NM_CHT[r_m.chat.id]
if r_m.chat.id in _B_AD_CHT:
return _B_AD_CHT[r_m.chat.id]
return _B_NM_CHT[r_m.chat.id]


async def _both_are_admins(r_c: Union['_client.Userge', '_client._UsergeBot'],
r_m: RawMessage) -> bool:
if not await _bot_is_present(r_c, r_m):
Expand Down Expand Up @@ -197,8 +209,10 @@ async def _both_have_perm(flt: Union['types.raw.Command', 'types.raw.Filter'],
if flt.check_invite_perm and not (
(user.can_all or user.can_invite_users) and bot.can_invite_users):
return False
return bool(not flt.check_pin_perm or (
(user.can_all or user.can_pin_messages) and bot.can_pin_messages))
if flt.check_pin_perm and not (
(user.can_all or user.can_pin_messages) and bot.can_pin_messages):
return False
return True


class RawDecorator(RawClient):
Expand Down Expand Up @@ -276,18 +290,19 @@ async def template(r_c: Union['_client.Userge', '_client._UsergeBot'],
if (flt.check_client
or (r_m.from_user and r_m.from_user.id in Config.SUDO_USERS)):
cond = True
if flt.only_admins:
cond = cond and await _both_are_admins(r_c, r_m)
if flt.check_perm:
cond = cond and await _both_have_perm(flt, r_c, r_m)
if cond:
if Config.USE_USER_FOR_CLIENT_CHECKS:
# pylint: disable=protected-access
if isinstance(r_c, _client._UsergeBot):
return
elif await _bot_is_present(r_c, r_m):
if isinstance(r_c, _client.Userge):
return
async with await _get_lock(str(flt)):
if flt.only_admins:
cond = cond and await _both_are_admins(r_c, r_m)
if flt.check_perm:
cond = cond and await _both_have_perm(flt, r_c, r_m)
if cond:
if Config.USE_USER_FOR_CLIENT_CHECKS:
# pylint: disable=protected-access
if isinstance(r_c, _client._UsergeBot):
return
elif await _bot_is_present(r_c, r_m):
if isinstance(r_c, _client.Userge):
return
if flt.check_downpath and not os.path.isdir(Config.DOWN_PATH):
os.makedirs(Config.DOWN_PATH)
try:
Expand All @@ -308,4 +323,4 @@ async def template(r_c: Union['_client.Userge', '_client._UsergeBot'],
_LOG.debug(_LOG_STR, f"Imported => [ async def {func.__name__}(message) ] "
f"from {func.__module__} {flt}")
return func
return decorator
return decorator
2 changes: 1 addition & 1 deletion userge/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
def get_all_plugins() -> List[str]:
""" list all plugins """
plugins = get_import_path(
ROOT, "/" if len(sys.argv) == 2 and sys.argv[1] == "dev" else "/**/"
ROOT, "/dev/" if len(sys.argv) == 2 and sys.argv[1] == "dev" else "/**/"
)
_LOG.debug("All Available Plugins: %s", plugins)
return list(plugins)
Loading

0 comments on commit 6d9f4f0

Please sign in to comment.