diff --git a/.gitignore b/.gitignore index cd72ffa1b..d3f37f4ad 100644 --- a/.gitignore +++ b/.gitignore @@ -132,4 +132,5 @@ dmypy.json #configfile config.ini config.env -.vscode/settings.json \ No newline at end of file +.vscode/settings.json +*.session diff --git a/config.env.sample b/config.env.sample index 2cf798c00..af6675b27 100644 --- a/config.env.sample +++ b/config.env.sample @@ -10,4 +10,7 @@ API_HASH="" # # Get by running `bash genStr` command # -HU_STRING_SESSION="" \ No newline at end of file +HU_STRING_SESSION="" + +# Mongodb url from https://cloud.mongodb.com/ +DATABASE_URL = '' \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index cab603f2d..6863c117d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ python-dotenv tgcrypto https://github.com/pyrogram/pyrogram/archive/asyncio.zip -pymongo \ No newline at end of file +pymongo +dnspython \ No newline at end of file diff --git a/userge/client.py b/userge/client.py index 351a0c582..909bdfb13 100644 --- a/userge/client.py +++ b/userge/client.py @@ -9,9 +9,10 @@ class Userge(Client): - HELP_DICT: Dict[str, str] = {} + HELP_DICT: Dict[str, str] USERGE_MAIN_STRING = "<<>>" USERGE_SUB_STRING = "<<>>" + MSG: Message def __init__(self) -> None: self.log = logging.getLogger(__name__) @@ -22,7 +23,7 @@ def __init__(self) -> None: Config.HU_STRING_SESSION, api_id=Config.API_ID, api_hash=Config.API_HASH, - plugins = dict(root="userge/plugins") + plugins=dict(root="userge/plugins") ) def getLogger(self, name: str) -> 'logging': @@ -51,4 +52,4 @@ def get_help(self, key: str = "") -> Union[str, Dict[str, str]]: def begin(self) -> None: self.log.info(self.USERGE_MAIN_STRING.format("Starting Userge")) self.run() - self.log.info(self.USERGE_MAIN_STRING.format("Exiting Userge")) \ No newline at end of file + self.log.info(self.USERGE_MAIN_STRING.format("Exiting Userge")) diff --git a/userge/plugins/welcome.py b/userge/plugins/welcome.py new file mode 100644 index 000000000..074ea1e9a --- /dev/null +++ b/userge/plugins/welcome.py @@ -0,0 +1,81 @@ +from userge import userge +from userge.db import Database +from pyrogram import Filters + +log = userge.getLogger(__name__) +welcome_chats = Filters.chat([]) +welcome__list = Database("welcome").filter({'on': True}, {'_id': 1}) +for i in welcome__list: + welcome_chats.add(i.get('_id')) + + +@userge.on_cmd("setwelcome", about="Creates a welcome message in current chat :)") +async def setwel(_, message: userge.MSG): + welcome_db = Database("welcome") + if message.chat.type in ["private", "bot", "channel"]: + await message.edit('Are you high XO\nSet welcome in a group chat') + return + try: + welcome_string = message.text.split(" ", maxsplit=1)[1] + except IndexError: + await message.edit("wrong syntax\n`.setwelcome `") + else: + new_entry = {'_id': message.chat.id, 'data': welcome_string, 'on': True} + if welcome_db.findone('_id', message.chat.id): + welcome_db.update({'_id': message.chat.id}, new_entry, 'set') + else: + welcome_db.addnew(new_entry) + welcome_chats.add(message.chat.id) + await message.edit(f"Welcome message has been set for the \n`{message.chat.title}`") + + +@userge.on_cmd("nowelcome", about="Dissables welcome message in the current chat :)") +async def nowel(_, message: userge.MSG): + try: + welcome_chats.remove(message.chat.id) + except KeyError as e: + await message.edit(e) + else: + welcome_db = Database("welcome") + welcome_db.update({'_id': message.chat.id}, {'on': False}, 'set') + await message.edit("Dissabled Successfully !") + + +@userge.on_cmd("dowelcome", about="Turns on welcome message in the current chat :)") +async def dowel(_, message: userge.MSG): + welcome_db = Database("welcome") + if welcome_db.findone('_id', message.chat.id): + welcome_chats.add(message.chat.id) + welcome_db.update({'_id': message.chat.id}, {'on': True}, 'set') + await message.edit('I will welcome new members XD') + else: + await message.edit('Please set the welcome message with `.setwelcome`') + + +@userge.on_message(Filters.new_chat_members & welcome_chats) +async def saywel(_, message: userge.MSG): + welcome_db = Database("welcome") + welcome_message = welcome_db.findone('_id', message.chat.id)['data'] + + user = message.from_user + fname = user.first_name + lname = user.last_name + uname = user.username + chat = message.chat.title + + mention = f'{uname or fname}' + await message.reply(welcome_message.format(chat=chat, fname=fname, lname=lname, uname=uname, mention=mention)) + + +@userge.on_cmd("listwelcome", about="Shows the activated chats for welcome") +async def lswel(_, message: userge.MSG): + liststr = '' + welcome_list = Database("welcome").filter({'on': True}, {'_id': 1, 'data': 1}) + for j in welcome_list: + chatid = j.get('_id') + chatname = (await userge.get_chat(chatid)).title + welcome_msg = j.get("data") + print(chatname, welcome_msg) + # liststr.join(f'>--{chatname}--\n') + # liststr = liststr if liststr != '' else '`NO WELCOMES STARTED`' + # await message.edit(liststr) diff --git a/userge/plugins/whois.py b/userge/plugins/whois.py index f8f0ecc86..3106c94b5 100644 --- a/userge/plugins/whois.py +++ b/userge/plugins/whois.py @@ -6,7 +6,6 @@ @userge.on_cmd("whois", about="to get user details") async def who_is(_, message): - from_user = None if " " in message.text: _, user_id = message.text.split(" ") try: @@ -38,4 +37,4 @@ async def who_is(_, message): disable_notification=True ) os.remove(local_user_photo) - await message.delete() \ No newline at end of file + await message.delete()