Skip to content

Commit

Permalink
Merge pull request #2 from ufoptg/patch-1
Browse files Browse the repository at this point in the history
Patch 1
  • Loading branch information
ufoptg committed Feb 8, 2024
2 parents b2256bc + a2ceb86 commit 7688d1b
Show file tree
Hide file tree
Showing 28 changed files with 1,989 additions and 153 deletions.
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Don't use quotes( " and ' )
# Don't use quotes( " or ' )

API_ID=
API_HASH=
Expand Down
21 changes: 13 additions & 8 deletions .github/workflows/pylint.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: PyLint
name: PyLint Ultroid
on:
push:
branches: [ dev ]
branches:
- patch-1
- patch-2
paths:
- "**.py"
jobs:
Expand All @@ -12,22 +14,26 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: 3.9
cache: "pip"
- name: Install Python lint libraries
run: pip install autopep8 autoflake isort black
- name: Check for showstoppers
run: |
autopep8 --verbose --in-place --recursive --aggressive --aggressive pyUltroid/*.py
autopep8 --verbose --in-place --recursive --aggressive --aggressive assistant/*.py
autopep8 --verbose --in-place --recursive --aggressive --aggressive assistant/manager/*.py
autopep8 --verbose --in-place --recursive --aggressive --aggressive plugins/*.py
- name: Remove unused imports and variables
run: |
autoflake --in-place --recursive --remove-all-unused-imports --remove-unused-variables --ignore-init-module-imports pyUltroid/*.py
autoflake --in-place --recursive --remove-all-unused-imports --remove-unused-variables --ignore-init-module-imports assistant/*.py
autoflake --in-place --recursive --remove-all-unused-imports --remove-unused-variables --ignore-init-module-imports assistant/manager/*.py
autoflake --in-place --recursive --remove-all-unused-imports --remove-unused-variables --ignore-init-module-imports plugins/*.py
- name: lint with isort and black
run: |
isort --profile black pyUltroid/*.py
black --fast pyUltroid/*.py
isort assistant/*.py
isort assistant/manager/*.py
black --fast assistant/*.py
Expand All @@ -37,9 +43,8 @@ jobs:
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'pylint: auto fixes'
commit_options: '--no-verify'
commit_options: '--verify'
repository: .
commit_user_name: buddhhu
commit_user_email: 48654350+buddhhu@users.noreply.github.com
commit_author: Amit Sharma <48654350+buddhhu@users.noreply.github.com>

commit_user_name: ufoptg
commit_user_email: ufperth@protonmail.com
commit_author: ufoptg <ufperth@protonmail.com>
18 changes: 17 additions & 1 deletion assistant/callbackstuffs.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def text_to_url(event):
"buttons": [
[Button.inline("Remove.bg API", data="abs_rmbg")],
[Button.inline("DEEP API", data="abs_dapi")],
[Button.inline("OpenAI API", data="abs_openapi")],
[Button.inline("🌀ʊʄ⊕ք🌀 API", data="abs_uapi")],
[Button.inline("OCR API", data="abs_oapi")],
[Button.inline("« Back", data="setter")],
],
Expand All @@ -195,6 +197,18 @@ def text_to_url(event):
"text": "Get Your Deep Api from deepai.org and send here.",
"back": "cbs_apiset",
},
"uapi": {
"var": "UFOPAPI",
"name": "UFoP API Key",
"text": "Contact 🌀ʊʄ⊕ք🌀 or Visit @PerthUnity_Bot Support Group\n\n /cancel to cancel",
"back": "cbs_apiset",
},
"openapi": {
"var": "OPENAI_API",
"name": "OPENAI API Key",
"text": "Visit openai.com for an OPENAI Api key!\n\n /cancel to cancel",
"back": "cbs_apiset",
},
"oapi": {
"var": "OCR_API",
"name": "Ocr Api Key",
Expand Down Expand Up @@ -556,7 +570,9 @@ async def emoji(event):
var = "EMOJI_IN_HELP"
name = f"Emoji in `{HNDLR}help` menu"
async with event.client.conversation(pru) as conv:
await conv.send_message("Send emoji u want to set 🙃.\n\nUse /cancel to cancel.")
await conv.send_message(
"Send emoji u want to set 🙃.\n\nUse /cancel to cancel."
)
response = conv.wait_event(events.NewMessage(chats=pru))
response = await response
themssg = response.message.message
Expand Down
131 changes: 115 additions & 16 deletions assistant/pmbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

# --------------------------------------- Imports -------------------------------------------- #

import asyncio
import logging
import os

from telethon.errors.rpcerrorlist import UserNotParticipantError
Expand All @@ -25,8 +27,59 @@
from . import *

botb = KeyManager("BOTBLS", cast=list)
FSUB = udB.get_key("PMBOT_FSUB")
FSUB = Keys.PMBOT_FSUB
PMBOTGROUP = Keys.LOG_CHANNEL
CACHE = {}
SUDOS = Keys.SUDOS
PMUSERS = [OWNER_ID, SUDOS]
logging.basicConfig(
format="%(asctime)s | %(name)s [%(levelname)s] : %(message)s",
level=logging.INFO,
datefmt="%m/%d/%Y, %H:%M:%S",
)
logger = logging.getLogger("DEBUGGING")

# --------------------------------------- Functions -------------------------------------------- #


async def forward_to_multiple(event, *user_ids):
results = []
tasks = []

for user_id in user_ids:
task = asyncio.create_task(event.forward_to(user_id))
tasks.append(task)

for task in tasks:
try:
result = await task
results.append(result)
except Exception as e:
results.append(str(e))

return results


async def check_reply_from_bot(event):
if (event.is_private and event.is_reply) or (
event.chat_id == PMBOTGROUP and event.is_reply and event.reply_to_msg_id
):
if event.chat_id == PMBOTGROUP:
replied_message = await event.client.get_messages(
event.chat_id, ids=event.reply_to_msg_id
)
if replied_message.from_id:
entity = replied_message.from_id.user_id
else:
return False
return entity == 6176247391
else:
# For private messages, no need to check the entity, as it's
# already a reply
return True
return False


# --------------------------------------- Incoming -------------------------------------------- #


Expand All @@ -37,7 +90,6 @@
)
async def on_new_mssg(event):
who = event.sender_id
# doesn't reply to that user anymore
if event.text.startswith("/") or who == OWNER_ID:
return
if FSUB:
Expand Down Expand Up @@ -72,40 +124,87 @@ async def on_new_mssg(event):
if MSG and BTTS:
return await event.reply(MSG, buttons=BTTS)
xx = await event.forward_to(OWNER_ID)
zz = await event.forward_to(PMBOTGROUP)
if event.fwd_from:
await xx.reply(f"From {inline_mention(event.sender)} [`{event.sender_id}`]")
await zz.reply(f"From {inline_mention(event.sender)} [`{event.sender_id}`]")
add_stuff(xx.id, who)
add_stuff(zz.id, who)


# --------------------------------------- Outgoing -------------------------------------------- #


@asst_cmd(
load=AST_PLUGINS,
from_users=[OWNER_ID],
from_users=PMUSERS,
incoming=True,
func=lambda e: e.is_private and e.is_reply,
func=check_reply_from_bot,
)
async def on_out_mssg(event):
x = event.reply_to_msg_id
to_user = get_who(x)
logger.info(f"msg_id: {x}")
if event.chat_id == PMBOTGROUP:
group_to_user = get_who(x)
else:
to_user = get_who(x)

if event.reply_to_msg_id:
replied_message = await event.client.get_messages(
event.chat_id, ids=event.reply_to_msg_id
)
if (
replied_message
and replied_message.fwd_from
and replied_message.fwd_from.from_id
and replied_message.fwd_from.from_id.user_id != 6176247391
):
return
if event.text.startswith("/who"):
try:
k = await asst.get_entity(to_user)
photu = await event.client.download_profile_photo(k.id)
await event.reply(
f"• **Name :** {get_display_name(k)}\n• **ID :** `{k.id}`\n• **Link :** {inline_mention(k)}",
file=photu,
)
if photu:
os.remove(photu)
return
if event.is_private and to_user:
k = await asst.get_entity(to_user)
photu = await event.client.download_profile_photo(k.id)
await event.reply(
f"• **Name :** {get_display_name(k)}\n• **ID :** `{k.id}`\n• **Link :** {inline_mention(k)}",
file=photu,
)
if photu:
os.remove(photu)
return
elif event.chat_id == PMBOTGROUP and group_to_user:
k = await asst.get_entity(group_to_user)
photu = await event.client.download_profile_photo(k.id)
await event.reply(
f"• **Name :** {get_display_name(k)}\n• **ID :** `{k.id}`\n• **Link :** {inline_mention(k)}",
file=photu,
)
if photu:
os.remove(photu)
return
else:
return await event.reply(
"Unable to determine the user. Please reply to a specific message."
)
except BaseException as er:
return await event.reply(f"**ERROR : **{str(er)}")
elif event.text.startswith("/"):
return
if to_user:
await asst.send_message(to_user, event.message)

if event.chat_id == PMBOTGROUP:
if group_to_user:
await asst.send_message(group_to_user, event.message)
else:
return await event.reply(
"Unable to determine the user. Please reply to a specific message."
)
elif event.sender_id in PMUSERS:
if to_user:
await asst.send_message(to_user, event.message)
else:
return await event.reply(
"Unable to determine the user. Please reply to a specific message."
)


# --------------------------------------- Ban/Unban -------------------------------------------- #
Expand Down
16 changes: 10 additions & 6 deletions assistant/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,21 @@ async def ultroid(event):
await event.reply(
f"Hey there {mention}, this is Ultroid Assistant of {me}!\n\n{ok}",
file=udB.get_key("STARTMEDIA"),
buttons=[Button.inline("Info.", data="ownerinfo")]
if Owner_info_msg
else None,
buttons=(
[Button.inline("Info.", data="ownerinfo")]
if Owner_info_msg
else None
),
)
else:
await event.reply(
udB.get_key("STARTMSG").format(me=me, mention=mention),
file=udB.get_key("STARTMEDIA"),
buttons=[Button.inline("Info.", data="ownerinfo")]
if Owner_info_msg
else None,
buttons=(
[Button.inline("Info.", data="ownerinfo")]
if Owner_info_msg
else None
),
)
else:
name = get_display_name(event.sender)
Expand Down
Loading

0 comments on commit 7688d1b

Please sign in to comment.