Skip to content

Commit

Permalink
Merge branch 'alpha' of https://github.com/UsergeTeam/Userge into alpha
Browse files Browse the repository at this point in the history
new update
  • Loading branch information
code-rgb committed Jul 10, 2020
2 parents 77b9446 + c9493db commit ded12b4
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 61 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async def testing(message: Message):
### Video Tutorial 🎥

[![Tutorial](resources/tutorial.jpg)](https://youtu.be/-XJj686zeiY "Tutorial")
[![Tutorial](resources/tutorial.jpg)](https://youtu.be/M4T_BJvFqkc "Tutorial")

### Support & Discussions 👥

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pytz
rarfile
removebg
requests
search-engine-parser
search-engine-parser==0.5.4
selenium==3.141.0
setuptools>=40.3.0
spamwatch
Expand Down
Binary file removed resources/mongo_help/1.jpg
Binary file not shown.
Binary file removed resources/mongo_help/2.jpg
Binary file not shown.
Binary file removed resources/mongo_help/3.jpg
Binary file not shown.
Binary file removed resources/mongo_help/4.jpg
Binary file not shown.
Binary file removed resources/mongo_help/5.jpg
Binary file not shown.
Binary file removed resources/mongo_help/6.jpg
Binary file not shown.
Binary file removed resources/mongo_help/7.jpg
Binary file not shown.
Binary file removed resources/mongo_help/8.jpg
Binary file not shown.
Binary file modified resources/tutorial.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 10 additions & 7 deletions userge/core/types/new/channel_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def _gen_string(name: str) -> str:
return "**logger** : #" + name.split('.')[-1].upper() + "\n\n{}"


def _get_file_id_and_ref(message: '_message.Message') -> Tuple[Optional[str], Optional[str]]:
def _get_file_id_and_ref(
message: '_message.Message') -> Tuple[Optional[str], Optional[str]]:
if message.audio:
file_ = message.audio
elif message.animation:
Expand All @@ -52,7 +53,8 @@ def _get_file_id_and_ref(message: '_message.Message') -> Tuple[Optional[str], Op
return None, None


def _parse_buttons(markdown_note: str):
def _parse_buttons(
markdown_note: str) -> Tuple[str, List[Optional[List[InlineKeyboardButton]]]]:
prev = 0
note_data = ""
buttons: List[Tuple[str, str, str]] = []
Expand All @@ -77,7 +79,8 @@ def _parse_buttons(markdown_note: str):
return note_data.strip(), _build_keyboard(buttons)


def _build_keyboard(buttons: List[Tuple[str, str, str]]):
def _build_keyboard(
buttons: List[Tuple[str, str, str]]) -> List[Optional[List[InlineKeyboardButton]]]:
keyb: List[List[InlineKeyboardButton]] = []
for btn in buttons:
if btn[2] and keyb:
Expand Down Expand Up @@ -209,10 +212,10 @@ async def store(self,
if message and message.media and file_id and file_ref:
if caption:
caption = self._string.format(caption.strip())
msg = await self._client.send_cached_media(chat_id=Config.LOG_CHANNEL_ID,
file_id=file_id,
file_ref=file_ref,
caption=caption)
msg = await message.client.send_cached_media(chat_id=Config.LOG_CHANNEL_ID,
file_id=file_id,
file_ref=file_ref,
caption=caption)
message_id = msg.message_id
else:
message_id = await self.log(caption)
Expand Down
45 changes: 26 additions & 19 deletions userge/plugins/utils/sudo.py → userge/plugins/tools/sudo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

from userge import userge, Message, Config, get_collection

CHANNEL = userge.getCLogger(__name__)

SUDO_USERS_COLLECTION = get_collection("sudo_users")
SUDO_CMDS_COLLECTION = get_collection("sudo_cmds")

Expand Down Expand Up @@ -51,8 +49,7 @@ async def add_sudo(message: Message):
Config.SUDO_USERS.add(user['id'])
await asyncio.gather(
SUDO_USERS_COLLECTION.insert_one({'_id': user['id'], 'men': user['mention']}),
CHANNEL.log(f"user : `{user['id']}` added to **SUDO**!"),
message.edit(f"user : `{user['id']}` added to **SUDO**!", del_in=5))
message.edit(f"user : `{user['id']}` added to **SUDO**!", del_in=5, log=__name__))


@userge.on_cmd("delsudo", about={
Expand All @@ -61,15 +58,15 @@ async def add_sudo(message: Message):
'usage': "{tr}delsudo [user_id | reply to msg]\n{tr}delsudo -all"}, allow_channels=False)
async def del_sudo(message: Message):
""" delete sudo user """
user_id = message.filtered_input_str
if message.reply_to_message:
user_id = message.reply_to_message.from_user.id
if '-all' in message.flags:
Config.SUDO_USERS.clear()
await asyncio.gather(
SUDO_USERS_COLLECTION.drop(),
message.edit("**SUDO** users cleared!", del_in=5))
return
user_id = message.filtered_input_str
if message.reply_to_message:
user_id = message.reply_to_message.from_user.id
if not user_id:
await message.err(f'user: `{user_id}` not found!')
return
Expand All @@ -84,8 +81,7 @@ async def del_sudo(message: Message):
Config.SUDO_USERS.remove(user_id)
await asyncio.gather(
SUDO_USERS_COLLECTION.delete_one({'_id': user_id}),
CHANNEL.log(f"user : `{user_id}` removed from **SUDO**!"),
message.edit(f"user : `{user_id}` removed from **SUDO**!", del_in=5))
message.edit(f"user : `{user_id}` removed from **SUDO**!", del_in=5, log=__name__))


@userge.on_cmd("vsudo", about={'header': "view sudo users"}, allow_channels=False)
Expand All @@ -102,9 +98,22 @@ async def view_sudo(message: Message):

@userge.on_cmd("addscmd", about={
'header': "add sudo command",
'usage': "{tr}addscmd [command name]"}, allow_channels=False)
'flags': {'-all': "add all commands to sudo"},
'usage': "{tr}addscmd [command name]\n{tr}addscmd -all"}, allow_channels=False)
async def add_sudo_cmd(message: Message):
""" add sudo cmd """
if '-all' in message.flags:
Config.ALLOWED_COMMANDS.clear()
tmp_ = []
for c_d in list(userge.manager.enabled_commands):
t_c = c_d.lstrip(Config.CMD_TRIGGER)
tmp_.append({'_id': t_c})
Config.ALLOWED_COMMANDS.add(t_c)
await asyncio.gather(
SUDO_CMDS_COLLECTION.insert_many(tmp_),
message.edit(f"Added all(`{len(tmp_)}`) commands to **SUDO** cmds!",
del_in=5, log=__name__))
return
cmd = message.input_str
if not cmd:
await message.err('input not found!')
Expand All @@ -119,8 +128,7 @@ async def add_sudo_cmd(message: Message):
Config.ALLOWED_COMMANDS.add(cmd)
await asyncio.gather(
SUDO_CMDS_COLLECTION.insert_one({'_id': cmd}),
CHANNEL.log(f"cmd : `{cmd}` added to **SUDO**!"),
message.edit(f"cmd : `{cmd}` added to **SUDO**!", del_in=5))
message.edit(f"cmd : `{cmd}` added to **SUDO**!", del_in=5, log=__name__))


@userge.on_cmd("delscmd", about={
Expand All @@ -129,13 +137,13 @@ async def add_sudo_cmd(message: Message):
'usage': "{tr}delscmd [command name]\n{tr}delscmd -all"}, allow_channels=False)
async def del_sudo_cmd(message: Message):
""" delete sudo cmd """
cmd = message.filtered_input_str
if '-all' in message.flags:
Config.ALLOWED_COMMANDS.clear()
await asyncio.gather(
SUDO_CMDS_COLLECTION.drop(),
message.edit("**SUDO** cmds cleared!", del_in=5))
return
cmd = message.filtered_input_str
if not cmd:
await message.err('input not found!')
return
Expand All @@ -145,8 +153,7 @@ async def del_sudo_cmd(message: Message):
Config.ALLOWED_COMMANDS.remove(cmd)
await asyncio.gather(
SUDO_CMDS_COLLECTION.delete_one({'_id': cmd}),
CHANNEL.log(f"cmd : `{cmd}` removed from **SUDO**!"),
message.edit(f"cmd : `{cmd}` removed from **SUDO**!", del_in=5))
message.edit(f"cmd : `{cmd}` removed from **SUDO**!", del_in=5, log=__name__))


@userge.on_cmd("vscmd", about={'header': "view sudo cmds"}, allow_channels=False)
Expand All @@ -155,7 +162,7 @@ async def view_sudo_cmd(message: Message):
if not Config.ALLOWED_COMMANDS:
await message.edit("**SUDO** cmds not found!", del_in=5)
return
out_str = '⛔ **SUDO CMDS** ⛔\n\n'
async for cmd in SUDO_CMDS_COLLECTION.find():
out_str += f" 🔹 `{cmd['_id']}`\n"
await message.edit(out_str + f"\n**trigger** : `{Config.SUDO_TRIGGER}`", del_in=0)
out_str = f"⛔ **SUDO CMDS** ⛔\n\n**trigger** : `{Config.SUDO_TRIGGER}`\n\n"
async for cmd in SUDO_CMDS_COLLECTION.find().sort('_id'):
out_str += f"`{cmd['_id']}` "
await message.edit_or_send_as_file(out_str, del_in=0)
39 changes: 25 additions & 14 deletions userge/plugins/utils/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#
# All rights reserved.

import asyncio
from typing import Dict

from userge import userge, Message, Filters, get_collection
Expand Down Expand Up @@ -61,10 +62,17 @@ async def filters_active(message: Message) -> None:
@userge.on_cmd(
"delfilter", about={
'header': "Deletes a filter by name",
'usage': "{tr}delfilter [filter name]"},
'flags': {'-all': "remove all filters"},
'usage': "{tr}delfilter [filter name]\n{tr}delfilter -all"},
allow_channels=False, allow_bots=False)
async def delete_filters(message: Message) -> None:
""" delete filter in current chat """
if '-all' in message.flags:
FILTERS_DATA.clear()
await asyncio.gather(
FILTERS_COLLECTION.drop(),
message.edit("`All Filters cleared!`", del_in=5))
return
filter_ = message.input_str
if not filter_:
out = "`Wrong syntax`\nNo arguements"
Expand All @@ -77,19 +85,22 @@ async def delete_filters(message: Message) -> None:
await message.edit(text=out, del_in=3)


@userge.on_cmd(r"addfilter ([^\s\|][^\|]*)(?:\s?\|\s?([\s\S]+))?",
about={
'header': "Adds a filter by name",
'options': {
'{fname}': "add first name",
'{lname}': "add last name",
'{flname}': "add full name",
'{uname}': "username",
'{chat}': "chat name",
'{count}': "chat members count",
'{mention}': "mention user"},
'usage': "{tr}addfilter [filter name] | [content | reply to msg]"},
allow_channels=False, allow_bots=False)
@userge.on_cmd(
r"addfilter ([^\s\|][^\|]*)(?:\s?\|\s?([\s\S]+))?", about={
'header': "Adds a filter by name",
'options': {
'{fname}': "add first name",
'{lname}': "add last name",
'{flname}': "add full name",
'{uname}': "username",
'{chat}': "chat name",
'{count}': "chat members count",
'{mention}': "mention user"},
'usage': "{tr}addfilter [filter name] | [content | reply to msg]",
'buttons': "<code>[name][buttonurl:link]</code> - <b>add a url button</b>\n"
"<code>[name][buttonurl:link:same]</code> - "
"<b>add a url button to same row</b>"},
allow_channels=False, allow_bots=False)
async def add_filter(message: Message) -> None:
""" add filter to current chat """
filter_ = message.matches[0].group(1).strip()
Expand Down
45 changes: 28 additions & 17 deletions userge/plugins/utils/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#
# All rights reserved.

import asyncio

from userge import userge, Message, get_collection, Config

NOTES_COLLECTION = get_collection("notes")
Expand Down Expand Up @@ -35,10 +37,16 @@ async def view_notes(message: Message) -> None:
@userge.on_cmd(
"delnote", about={
'header': "Deletes a note by name",
'usage': "{tr}delnote [note name]"},
'flags': {'-all': "remove all notes"},
'usage': "{tr}delnote [note name]\n{tr}delnote -all"},
allow_channels=False, allow_bots=False)
async def remove_note(message: Message) -> None:
""" delete note in current chat """
if '-all' in message.flags:
await asyncio.gather(
NOTES_COLLECTION.drop(),
message.edit("`All Notes cleared!`", del_in=5))
return
notename = message.input_str
if not notename:
out = "`Wrong syntax`\nNo arguements"
Expand Down Expand Up @@ -105,6 +113,8 @@ async def get_note(message: Message) -> None:
if not message.from_user:
return
can_access = message.from_user.is_self or message.from_user.id in Config.SUDO_USERS
if Config.OWNER_ID:
can_access = can_access or message.from_user.id == Config.OWNER_ID
notename = message.matches[0].group(1)
found = await NOTES_COLLECTION.find_one(
{'chat_id': message.chat.id, 'name': notename}, {'mid': 1, 'global': 1})
Expand All @@ -123,29 +133,30 @@ async def get_note(message: Message) -> None:
reply_to_message_id=reply_to_message_id)


@userge.on_cmd(r"addnote (\S+)(?:\s([\s\S]+))?",
about={
'header': "Adds a note by name",
'options': {
'{fname}': "add first name",
'{lname}': "add last name",
'{flname}': "add full name",
'{uname}': "username",
'{chat}': "chat name",
'{count}': "chat members count",
'{mention}': "mention user"},
'usage': "{tr}addnote [note name] [content | reply to msg]"},
allow_channels=False,
allow_bots=False)
@userge.on_cmd(
r"addnote (\S+)(?:\s([\s\S]+))?", about={
'header': "Adds a note by name",
'options': {
'{fname}': "add first name",
'{lname}': "add last name",
'{flname}': "add full name",
'{uname}': "username",
'{chat}': "chat name",
'{count}': "chat members count",
'{mention}': "mention user"},
'usage': "{tr}addnote [note name] [content | reply to msg]",
'buttons': "<code>[name][buttonurl:link]</code> - <b>add a url button</b>\n"
"<code>[name][buttonurl:link:same]</code> - "
"<b>add a url button to same row</b>"},
allow_channels=False, allow_bots=False)
async def add_note(message: Message) -> None:
""" add note to curent chat """
notename = message.matches[0].group(1)
content = message.matches[0].group(2)
replied = message.reply_to_message
if replied and replied.text:
content = replied.text.html
if content:
content = "📝 **--{}--** 📝\n\n{}".format(notename, content)
content = "📝 **Note** : `{}`\n\n{}".format(notename, content or '')
if not (content or (replied and replied.media)):
await message.err(text="No Content Found!")
return
Expand Down
8 changes: 6 additions & 2 deletions userge/plugins/utils/welcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ async def _init() -> None:
'examples': [
"{tr}setwelcome Hi {mention}, <b>Welcome</b> to {chat} chat\n"
"or reply to supported media",
"reply {tr}setwelcome to text message or supported media with text"]},
"reply {tr}setwelcome to text message or supported media with text"],
'buttons': "<code>[name][buttonurl:link]</code> - <b>add a url button</b>\n"
"<code>[name][buttonurl:link:same]</code> - <b>add a url button to same row</b>"},
allow_channels=False, allow_bots=False, allow_private=False)
async def setwel(msg: Message):
""" set welcome message """
Expand All @@ -63,7 +65,9 @@ async def setwel(msg: Message):
'examples': [
"{tr}setleft {flname}, Why you left :(\n"
"or reply to supported media",
"reply {tr}setleft to text message or supported media with text"]},
"reply {tr}setleft to text message or supported media with text"],
'buttons': "<code>[name][buttonurl:link]</code> - <b>add a url button</b>\n"
"<code>[name][buttonurl:link:same]</code> - <b>add a url button to same row</b>"},
allow_channels=False, allow_bots=False, allow_private=False)
async def setleft(msg: Message):
""" set left message """
Expand Down

0 comments on commit ded12b4

Please sign in to comment.