Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/uaudith/Userge
Browse files Browse the repository at this point in the history
  • Loading branch information
rking32 committed Mar 17, 2020
2 parents fdb9b35 + 573b77c commit 7a3e953
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,5 @@ dmypy.json
#configfile
config.ini
config.env
.vscode/settings.json
.vscode/settings.json
*.session
5 changes: 4 additions & 1 deletion config.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ API_HASH=""
#
# Get by running `bash genStr` command
#
HU_STRING_SESSION=""
HU_STRING_SESSION=""

# Mongodb url from https://cloud.mongodb.com/
DATABASE_URL = ''
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
python-dotenv
tgcrypto
https://github.com/pyrogram/pyrogram/archive/asyncio.zip
pymongo
pymongo
dnspython
7 changes: 4 additions & 3 deletions userge/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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':
Expand Down Expand Up @@ -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"))
self.log.info(self.USERGE_MAIN_STRING.format("Exiting Userge"))
81 changes: 81 additions & 0 deletions userge/plugins/welcome.py
Original file line number Diff line number Diff line change
@@ -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 <welcome message>`")
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'<a href="tg://user?id={user.id}">{uname or fname}</a>'
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)
3 changes: 1 addition & 2 deletions userge/plugins/whois.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -38,4 +37,4 @@ async def who_is(_, message):
disable_notification=True
)
os.remove(local_user_photo)
await message.delete()
await message.delete()

0 comments on commit 7a3e953

Please sign in to comment.