Skip to content
Merged

Beta #92

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions tronx/modules/pastebin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,27 @@
@app.on_message(gen(["paste", "bin"], allow = ["sudo"]))
async def paster(_, m: Message):
reply = m.reply_to_message
m = await app.send_edit(m, "`Pasting to nekobin ...`")

if reply:
text = reply.text
if reply and reply.text or reply.caption:
text = reply.text or reply.caption
elif not reply and app.long(m) > 1:
text = m.text.split(None, 1)[1]
else:
return await app.send_edit(m, "Please reply to a message or give some text after command.", delme=2)
elif not reply and app.long(m) == 1:
return await app.send_edit(m, "Please reply to a message or give some text after command.", mono=True, delme=4)

try:
async with aiohttp.ClientSession() as session:
async with session.post(
"https://nekobin.com/api/documents", json={"content": text}, timeout=3
"https://www.toptal.com/developers/hastebin/documents", data=text.encode("utf-8"), timeout=3
) as response:
key = (await response.json())["result"]["key"]
key = (await response.json())["key"]
except Exception as e:
return await app.send_edit(m, "Pasting failed, Try again . . .", delme=2, mono=True)
print(e)
await app.error(m, e)
return await app.send_edit(m, "Pasting failed, Try again later . . .", delme=4, mono=True)

else:
url = f"https://nekobin.com/{key}"
reply_text = f"**Nekobin** : [Here]({url})"
url = f"https://hastebin.com/raw/{key}"
reply_text = f"**Hastebin** : [Click Here]({url})"
delete = (True if app.long(m) > 1 and m.command[1] in ["d", "del"] and reply.from_user.is_self else False)
if delete:
await asyncio.gather(
Expand Down
2 changes: 1 addition & 1 deletion tronx/modules/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ async def get_word_links(_, m: Message):
return await app.send_edit(m, "Please give some text to search in chat ...")

else:
m = await app.send_edit(m, "Finding word in this chat . . .", mono=True)
info = await app.get_history(m.chat.id)
query = m.text.split(None, 1)[1]
m = await app.send_edit(m, "Finding word in this chat . . .", mono=True)
for words in info:
if query in words.text:
links.append(words.link)
Expand Down
1 change: 0 additions & 1 deletion tronx/modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ async def tag_all_users(app, m: Message):
async for x in app.iter_chat_members(m.chat.id):
if x.user.is_bot is False:
text += app.MentionHtml(x.user.id, "\u200b")
await m.delete()
if reply:
await app.send_message(m.chat.id, text, reply_to_message_id=reply.message_id, parse_mode="html")
else:
Expand Down
27 changes: 17 additions & 10 deletions tronx/modules/welcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,27 @@
)


IgnoreList = []
IgnoreChat = []




@app.on_message(filters.new_chat_members & filters.group & ~filters.chat(IgnoreList))
@app.on_message(filters.new_chat_members & filters.group & ~filters.chat(IgnoreChat))
async def send_welcome(_, m: Message):
chat = app.get_welcome(str(m.chat.id))
if bool(chat) is True:
if chat["file_id"] is None:
IgnoreList.append(m.chat.id) # decrease the number of updates per chat
return
if not m.chat.id in IgnoreChat:
IgnoreChat.append(m.chat.id) # decrease the number of updates per chat
return

try:
file_id = chat["file_id"] if chat["file_id"] else False
caption = chat["caption"] if chat["caption"] else False
if file_id and not file_id.startswith("#"):
if file_id and not file_id.startswith("#"): # as a text
return await app.send_message(m.chat.id, f"{file_id}", reply_to_message_id=m.message_id)

elif file_id and file_id.startswith("#"):
elif file_id and file_id.startswith("#"): # as a file id
file_id = file_id.replace("#", "")

if caption:
Expand All @@ -68,7 +69,9 @@ async def send_welcome(_, m: Message):

@app.on_message(gen(["setwelcome", "setwc"], allow = ["sudo", "channel"]))
async def save_welcome(_, m: Message):
await app.private(m)
if await app.private(m):
return

await app.send_edit(m, "Setting this media as a welcome message . . .", mono=True)
reply = m.reply_to_message
if reply:
Expand All @@ -84,7 +87,7 @@ async def save_welcome(_, m: Message):
app.set_welcome(str(m.chat.id), "#" + file_id)
await app.send_edit(m, "Added this media to welcome message . . .", delme=2, mono=True)
elif bool(reply.media) is False:
app.set_welcome(str(m.chat.id), reply.text)
app.set_welcome(str(m.chat.id), reply.text.markdown)
await app.send_edit(m, "Added this text to welcome message . . .", delme=2, mono=True)
except Exception as e:
await app.error(m, e)
Expand All @@ -97,7 +100,9 @@ async def save_welcome(_, m: Message):

@app.on_message(gen(["delwelcome", "delwc"], allow = ["sudo", "channel"]))
async def delete_welcome(_, m: Message):
await app.private(m)
if await app.private(m):
return

try:
await app.send_edit(m, "Checking welcome message for this group . . .", mono=True)
app.del_welcome(str(m.chat.id))
Expand All @@ -110,7 +115,9 @@ async def delete_welcome(_, m: Message):

@app.on_message(gen(["getwelcome", "getwc"], allow = ["sudo", "channel"]))
async def delete_welcome(_, m: Message):
await app.private(m)
if await app.private(m):
return

try:
await app.send_edit(m, "Getting welcome message of this group . . .")
data = app.get_welcome(str(m.chat.id))
Expand Down