Skip to content

Commit

Permalink
add -s and -d flags for kang + reset option in setpmmsg and setbpmmsg…
Browse files Browse the repository at this point in the history
… + update python
  • Loading branch information
rking32 committed Oct 15, 2020
1 parent 8f6919c commit aec4eac
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 165 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

# Userge 🔥

[![Build Status](https://travis-ci.com/UsergeTeam/Userge.svg?branch=dev)](https://travis-ci.com/UsergeTeam/Userge)
[![Build Status](https://travis-ci.com/UsergeTeam/Userge.svg?branch=alpha)](https://travis-ci.com/UsergeTeam/Userge)
![Python Version](https://img.shields.io/badge/python-3.8-lightgrey)
![Release](https://img.shields.io/github/v/release/UsergeTeam/Userge)
![Stars](https://img.shields.io/github/stars/UsergeTeam/Userge)
Expand Down Expand Up @@ -124,6 +124,7 @@ async def test_filter(message: Message):

* With Docker 🐳
- [**See Detailed Guide**](resources/radmeDocker.md)

* With Git, Python and pip 🔧
```bash
# clone the repo
Expand Down
5 changes: 3 additions & 2 deletions init/checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ _checkBashReq() {

_checkPythonVersion() {
log "Checking Python Version ..."
( test -z $pVer || test $(sed 's/\.//g' <<< $pVer) -lt 380 ) \
&& quit "You MUST have a python version of at least 3.8.0 !"
getPythonVersion
( test -z $pVer || test $(sed 's/\.//g' <<< $pVer) -lt 3${minPVer}0 ) \
&& quit "You MUST have a python version of at least 3.$minPVer.0 !"
log "\tFound PYTHON - v$pVer ..."
}

Expand Down
14 changes: 13 additions & 1 deletion init/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@
#
# All rights reserved.

declare -r pVer=$(sed -E 's/\w+ 3\.8\.([0-9]+)/3.8.\1/g' < <(python3.8 -V 2> /dev/null))
declare -r minPVer=8
declare -r maxPVer=10

getPythonVersion() {
local -i count=$minPVer
local tmp
while true; do
tmp=$(python3.$count -V 2> /dev/null)
[[ -n $tmp || $count -gt $maxPVer ]] && break
count+=1
done
declare -gr pVer=$(sed -E 's/Python (3\.[0-9]{1,2}\.[0-9]{1,2}).*/\1/g' <<< $tmp)
}

log() {
local text="$*"
Expand Down
2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.8.5
python-3.9.0
2 changes: 1 addition & 1 deletion userge/core/methods/messages/edit_message_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async def edit_message_text(self, # pylint: disable=arguments-differ
parse_mode=parse_mode,
disable_web_page_preview=disable_web_page_preview,
reply_markup=reply_markup)
module = inspect.getmodule(inspect.currentframe().f_back).__name__
module = inspect.currentframe().f_back.f_globals['__name__']
if log:
if isinstance(log, bool):
args = (msg, module)
Expand Down
2 changes: 1 addition & 1 deletion userge/core/methods/messages/send_as_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async def send_as_file(self,
disable_notification=True,
reply_to_message_id=reply_to_message_id)
os.remove(filename)
module = inspect.getmodule(inspect.currentframe().f_back).__name__
module = inspect.currentframe().f_back.f_globals['__name__']
if log:
if isinstance(log, bool):
args = (msg, module)
Expand Down
2 changes: 1 addition & 1 deletion userge/core/methods/messages/send_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async def send_message(self, # pylint: disable=arguments-differ
reply_to_message_id=reply_to_message_id,
schedule_date=schedule_date,
reply_markup=reply_markup)
module = inspect.getmodule(inspect.currentframe().f_back).__name__
module = inspect.currentframe().f_back.f_globals['__name__']
if log:
if isinstance(log, bool):
args = (msg, module)
Expand Down
7 changes: 6 additions & 1 deletion userge/core/methods/utils/get_channel_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

__all__ = ['GetCLogger']

import inspect

from userge import logging
from ...ext import RawClient
from ... import types
Expand All @@ -19,7 +21,10 @@


class GetCLogger(RawClient): # pylint: disable=missing-class-docstring
def getCLogger(self, name: str) -> 'types.new.ChannelLogger': # pylint: disable=invalid-name
# pylint: disable=invalid-name
def getCLogger(self, name: str = '') -> 'types.new.ChannelLogger':
""" This returns new channel logger object """
if not name:
name = inspect.currentframe().f_back.f_globals['__name__']
_LOG.debug(_LOG_STR, f"Creating CLogger => {name}")
return types.new.ChannelLogger(self, name)
6 changes: 5 additions & 1 deletion userge/core/methods/utils/get_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

__all__ = ['GetLogger']

import inspect

from userge import logging

_LOG = logging.getLogger(__name__)
Expand All @@ -18,7 +20,9 @@

class GetLogger: # pylint: disable=missing-class-docstring
@staticmethod
def getLogger(name: str) -> logging.Logger: # pylint: disable=invalid-name
def getLogger(name: str = '') -> logging.Logger: # pylint: disable=invalid-name
""" This returns new logger object """
if not name:
name = inspect.currentframe().f_back.f_globals['__name__']
_LOG.debug(_LOG_STR, f"Creating Logger => {name}")
return logging.getLogger(name)
3 changes: 2 additions & 1 deletion userge/core/types/raw/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def _parse(allow_private: bool,
allow_bots: bool,
allow_groups: bool,
allow_channels: bool,
**kwargs: Union[RawFilter, '_client.Userge', int, bool]) -> Dict[str, object]:
**kwargs: Union[RawFilter, '_client.Userge', int, bool]
) -> Dict[str, Union[RawFilter, '_client.Userge', int, bool]]:
kwargs['check_client'] = kwargs['allow_via_bot'] and kwargs['check_client']
kwargs['scope']: List[str] = []
if allow_bots:
Expand Down
23 changes: 17 additions & 6 deletions userge/plugins/fun/kang.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@
@userge.on_cmd(
"kang", about={
'header': "kangs stickers or creates new ones",
'flags': {
'-s': "without link",
'-d': "without trace"},
'usage': "Reply {tr}kang [emoji('s)] [pack number] to a sticker or "
"an image to kang it to your userbot pack.",
'examples': ["{tr}kang", "{tr}kang 🤔", "{tr}kang 2", "{tr}kang 🤔 2"]},
'examples': ["{tr}kang", "{tr}kang -s", "{tr}kang -d",
"{tr}kang 🤔", "{tr}kang 2", "{tr}kang 🤔 2"]},
allow_channels=False, allow_via_bot=False)
async def kang_(message: Message):
""" kang a sticker """
Expand Down Expand Up @@ -136,10 +140,12 @@ async def kang_(message: Message):
await conv.get_response(mark_read=True)
await conv.send_message(packname)
await conv.get_response(mark_read=True)
await message.edit(
f"`Sticker added in a Different Pack !\n"
"This Pack is Newly created!\n"
f"Your pack can be found [here](t.me/addstickers/{packname})")
if '-d' in message.flags:
await message.delete()
else:
out = "__kanged__" if '-s' in message.flags else \
f"[kanged](t.me/addstickers/{packname})"
await message.edit(f"**Sticker** {out} __in a Different Pack__**!**")
return
await conv.send_document(photo)
rsp = await conv.get_response(mark_read=True)
Expand Down Expand Up @@ -179,7 +185,12 @@ async def kang_(message: Message):
await conv.get_response(mark_read=True)
await conv.send_message(packname)
await conv.get_response(mark_read=True)
await message.edit(f"**Sticker** [kanged](t.me/addstickers/{packname})!")
if '-d' in message.flags:
await message.delete()
else:
out = "__kanged__" if '-s' in message.flags else \
f"[kanged](t.me/addstickers/{packname})"
await message.edit(f"**Sticker** {out}**!**")
if os.path.exists(str(photo)):
os.remove(photo)

Expand Down
48 changes: 32 additions & 16 deletions userge/plugins/utils/pmpermit.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

pmCounter: Dict[int, int] = {}
allowAllFilter = filters.create(lambda _, __, ___: Config.ALLOW_ALL_PMS)
noPmMessage = ("Hello {fname} this is an automated message\n"
"Please wait until you get approved to direct message "
"And please dont spam until then ")
blocked_message = "**You were automatically blocked**"
noPmMessage = bk_noPmMessage = ("Hello {fname} this is an automated message\n"
"Please wait until you get approved to direct message "
"And please dont spam until then ")
blocked_message = bk_blocked_message = "**You were automatically blocked**"


async def _init() -> None:
Expand Down Expand Up @@ -130,6 +130,7 @@ async def pmguard(message: Message):
@userge.on_cmd("setpmmsg", about={
'header': "Sets the reply message",
'description': "You can change the default message which userge gives on un-invited PMs",
'flags': {'-r': "reset to default"},
'options': {
'{fname}': "add first name",
'{lname}': "add last name",
Expand All @@ -140,18 +141,26 @@ async def pmguard(message: Message):
async def set_custom_nopm_message(message: Message):
""" setup custom pm message """
global noPmMessage # pylint: disable=global-statement
await message.edit('`Custom NOpm message saved`', del_in=3, log=__name__)
string = message.input_or_reply_raw
if string:
noPmMessage = string
await SAVED_SETTINGS.update_one(
{'_id': 'CUSTOM NOPM MESSAGE'}, {"$set": {'data': string}}, upsert=True)
if '-r' in message.flags:
await message.edit('`Custom NOpm message reset`', del_in=3, log=True)
noPmMessage = bk_noPmMessage
await SAVED_SETTINGS.find_one_and_delete({'_id': 'CUSTOM NOPM MESSAGE'})
else:
string = message.input_or_reply_raw
if string:
await message.edit('`Custom NOpm message saved`', del_in=3, log=True)
noPmMessage = string
await SAVED_SETTINGS.update_one(
{'_id': 'CUSTOM NOPM MESSAGE'}, {"$set": {'data': string}}, upsert=True)
else:
await message.err("invalid input!")


@userge.on_cmd("setbpmmsg", about={
'header': "Sets the block message",
'description': "You can change the default blockPm message "
"which userge gives on un-invited PMs",
'flags': {'-r': "reset to default"},
'options': {
'{fname}': "add first name",
'{lname}': "add last name",
Expand All @@ -162,12 +171,19 @@ async def set_custom_nopm_message(message: Message):
async def set_custom_blockpm_message(message: Message):
""" setup custom blockpm message """
global blocked_message # pylint: disable=global-statement
await message.edit('`Custom BLOCKpm message saved`', del_in=3, log=__name__)
string = message.input_or_reply_raw
if string:
blocked_message = string
await SAVED_SETTINGS.update_one(
{'_id': 'CUSTOM BLOCKPM MESSAGE'}, {"$set": {'data': string}}, upsert=True)
if '-r' in message.flags:
await message.edit('`Custom BLOCKpm message reset`', del_in=3, log=True)
blocked_message = bk_blocked_message
await SAVED_SETTINGS.find_one_and_delete({'_id': 'CUSTOM BLOCKPM MESSAGE'})
else:
string = message.input_or_reply_raw
if string:
await message.edit('`Custom BLOCKpm message saved`', del_in=3, log=True)
blocked_message = string
await SAVED_SETTINGS.update_one(
{'_id': 'CUSTOM BLOCKPM MESSAGE'}, {"$set": {'data': string}}, upsert=True)
else:
await message.err("invalid input!")


@userge.on_cmd(
Expand Down
132 changes: 0 additions & 132 deletions userge/plugins/utils/welcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,135 +260,3 @@ async def raw_say(message: Message, name, collection):
reply_to_message_id=message.message_id,
del_in=Config.WELCOME_DELETE_TIMEOUT)
message.stop_propagation()


# async def send_proper_type(message: Message,
# caption: str,
# file_type: str,
# media: str,
# file_ref: str = None) -> tuple:
# """sent proper type"""
# thumb = None
# if os.path.exists(THUMB_PATH):
# thumb = THUMB_PATH
# tmp_msgs = []
# if file_type == 'audio':
# duration = 0
# if os.path.exists(media):
# duration = extractMetadata(createParser(media)).get("duration").seconds
# msg = await userge.send_audio(chat_id=message.chat.id,
# audio=media,
# file_ref=file_ref,
# caption=caption,
# duration=duration,
# thumb=thumb,
# reply_to_message_id=message.message_id)

# file_id = msg.audio.file_id
# file_ref = msg.audio.file_ref
# tmp_msgs.append(msg)

# elif file_type == 'animation':
# duration = 0
# if os.path.exists(media):
# duration = extractMetadata(createParser(media)).get("duration").seconds
# if not thumb:
# thumb = take_screen_shot(media, duration)
# msg = await userge.send_animation(chat_id=message.chat.id,
# animation=media,
# file_ref=file_ref,
# caption=caption,
# duration=duration,
# thumb=thumb,
# reply_to_message_id=message.message_id)
# file_id = msg.animation.file_id
# file_ref = msg.animation.file_ref
# tmp_msgs.append(msg)

# elif file_type == 'photo':
# msg = await userge.send_photo(chat_id=message.chat.id,
# photo=media,
# file_ref=file_ref,
# caption=caption,
# reply_to_message_id=message.message_id)
# file_id = msg.photo.file_id
# file_ref = msg.photo.file_ref
# tmp_msgs.append(msg)

# elif file_type == 'sticker':
# msg = await userge.send_sticker(chat_id=message.chat.id,
# sticker=media,
# file_ref=file_ref,
# reply_to_message_id=message.message_id)
# if caption:
# tmp_msgs.append(await message.reply(caption))
# file_id = msg.sticker.file_id
# file_ref = msg.sticker.file_ref
# tmp_msgs.append(msg)

# elif file_type == 'voice':
# duration = 0
# if os.path.exists(media):
# duration = extractMetadata(createParser(media)).get("duration").seconds
# msg = await userge.send_voice(chat_id=message.chat.id,
# voice=media,
# file_ref=file_ref,
# caption=caption,
# duration=duration,
# reply_to_message_id=message.message_id)
# file_id = msg.voice.file_id
# file_ref = msg.voice.file_ref
# tmp_msgs.append(msg)

# elif file_type == 'video_note':
# duration = 0
# if os.path.exists(media):
# duration = extractMetadata(createParser(media)).get("duration").seconds
# if not thumb:
# thumb = take_screen_shot(media, duration)
# msg = await userge.send_video_note(chat_id=message.chat.id,
# video_note=media,
# file_ref=file_ref,
# duration=duration,
# thumb=thumb,
# reply_to_message_id=message.message_id)
# if caption:
# tmp_msgs.append(await message.reply(caption))
# file_id = msg.video_note.file_id
# file_ref = msg.video_note.file_ref
# tmp_msgs.append(msg)

# elif file_type == 'video':
# duration = 0
# if os.path.exists(media):
# duration = extractMetadata(createParser(media)).get("duration").seconds
# if not thumb:
# thumb = take_screen_shot(media, duration)
# msg = await userge.send_video(chat_id=message.chat.id,
# video=media,
# file_ref=file_ref,
# caption=caption,
# duration=duration,
# thumb=thumb,
# reply_to_message_id=message.message_id)
# file_id = msg.video.file_id
# file_ref = msg.video.file_ref
# tmp_msgs.append(msg)

# else:
# msg = await userge.send_document(chat_id=message.chat.id,
# document=media,
# file_ref=file_ref,
# thumb=thumb,
# caption=caption,
# reply_to_message_id=message.message_id)
# file_id = msg.document.file_id
# file_ref = msg.document.file_ref
# tmp_msgs.append(msg)

# if Config.WELCOME_DELETE_TIMEOUT:
# await asyncio.sleep(Config.WELCOME_DELETE_TIMEOUT)
# for msg_ in tmp_msgs:
# if isinstance(msg_, RawMessage):
# await msg_.delete()
# return file_id, file_ref

0 comments on commit aec4eac

Please sign in to comment.