Skip to content

Commit

Permalink
add .ub
Browse files Browse the repository at this point in the history
  • Loading branch information
rking32 committed Mar 18, 2020
1 parent 123903c commit 69283aa
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 23 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ https://github.com/pyrogram/pyrogram/archive/asyncio.zip
pymongo
dnspython
hachoir
Pillow
Pillow
urbandict
2 changes: 1 addition & 1 deletion userge/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def on_cmd(

return self.__build_decorator(
log=f"On .{command} Command",
filters=Filters.regex(pattern=f"^.{command}") & Filters.me,
filters=Filters.regex(pattern=f"^.{command}(?: (.+))?") & Filters.me,
group=group
)

Expand Down
6 changes: 2 additions & 4 deletions userge/plugins/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,9 @@ async def term_(_, message):

async def init_func(message):
await message.edit("Processing ...")
cmd = message.matches[0].group(1)

try:
cmd = message.text.split(" ", maxsplit=1)[1]

except IndexError:
if cmd is None:
await message.edit("__No Command Found!__")
return None

Expand Down
5 changes: 2 additions & 3 deletions userge/plugins/purge.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
async def purge_(_, message):
if message.reply_to_message:
start_t = datetime.now()
recvd_commands = message.text.split(" ")
user_id = message.matches[0].group(1)
from_user = None

if len(recvd_commands) > 1:
user_id = recvd_commands[1]
if user_id:
from_user = await userge.get_users(user_id)

start_message = message.reply_to_message.message_id
Expand Down
63 changes: 56 additions & 7 deletions userge/plugins/tools.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import urbandict
from datetime import datetime
from . import get_all_plugins
from userge import userge
from urllib.error import HTTPError
from userge import userge, Config


@userge.on_cmd("ping", about="check how long it takes to ping your userbot")
Expand All @@ -18,12 +20,10 @@ async def pingme(_, message):

@userge.on_cmd("help", about="to know how to use this")
async def helpme(_, message):
cmd = message.matches[0].group(1)
out_str = ""

try:
cmd = message.text.split(" ", maxsplit=1)[1]

except IndexError:
if cmd is None:
out_str += "**which command you want ?**\n`.help command_name`\n\n"

for cmd in sorted(userge.get_help()):
Expand Down Expand Up @@ -125,9 +125,9 @@ async def getids(_, message):
@userge.on_cmd("admins", about="to mention admins")
async def mentionadmins(client, message):
mentions = "🛡 **Admin List** 🛡\n"
input_str = message.text[8:]
input_str = message.matches[0].group(1)

if not input_str:
if input_str is None:
input_str = message.chat.id

try:
Expand All @@ -143,3 +143,52 @@ async def mentionadmins(client, message):

await message.reply(mentions)
await message.delete()


@userge.on_cmd("ub", about="Searches Urban Dictionary for the query")
async def urban_dict(_, message):
await message.edit("Processing...")
query = message.matches[0].group(1)

if query is None:
await message.edit(f"use `.ub query`")
return

try:
mean = urbandict.define(query)

except HTTPError:
await message.edit(f"Sorry, couldn't find any results for: `{query}``")
return

meanlen = len(mean[0]["def"]) + len(mean[0]["example"])

if meanlen == 0:
await message.edit(f"No result found for **{query}**")
return

OUTPUT = f"**Query:** `{query}`\n\n**Meaning:** __{mean[0]['def']}__\n\n**Example:**\n__{mean[0]['example']}__"

if len(OUTPUT) >= Config.MAX_MESSAGE_LENGTH:
with open("output.txt", "w+", encoding="utf8") as out_file:
out_file.write(str(OUTPUT))

reply_to_id = message.reply_to_message.message_id \
if message.reply_to_message \
else message.message_id

await userge.send_document(
chat_id=message.chat.id,
document="output.txt",
caption=query,
disable_notification=True,
reply_to_message_id=reply_to_id
)

if os.path.exists("output.txt"):
os.remove("output.txt")

await message.delete()

else:
await message.edit(OUTPUT)
11 changes: 5 additions & 6 deletions userge/plugins/welcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ async def wrapper(_, message):
await message.edit(f'Are you high XO\nSet {name} in a group chat')
return

try:
string = message.text.split(" ", maxsplit=1)[1]
string = message.matches[0].group(1)

except IndexError:
if string is None:
await message.edit(f"wrong syntax\n`.set{name.lower()} <{name.lower()} message>`")

else:
Expand All @@ -51,7 +50,7 @@ async def wrapper(_, message):
return decorator


def raw_on(name, table, chats):
def raw_no(name, table, chats):
def decorator(func):

@functools.wraps(func)
Expand Down Expand Up @@ -151,12 +150,12 @@ def setleft(): pass


@userge.on_cmd("nowelcome", about="Disables welcome message in the current chat :)")
@raw_on('Welcome', WELCOME_TABLE, WELCOME_CHATS)
@raw_no('Welcome', WELCOME_TABLE, WELCOME_CHATS)
def nowel(): pass


@userge.on_cmd("noleft", about="Disables left message in the current chat :)")
@raw_on('Left', LEFT_TABLE, LEFT_CHATS)
@raw_no('Left', LEFT_TABLE, LEFT_CHATS)
def noleft(): pass


Expand Down
2 changes: 1 addition & 1 deletion userge/utils/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ async def progress(current, total, client, message_id, chat_id, start, status):
)
)

except Exception as e:
except Exception:
pass

0 comments on commit 69283aa

Please sign in to comment.