Messenger is ready
This commit is contained in:
parent
bf7c23bb34
commit
a54d78ccb6
@ -101,6 +101,6 @@ After all of that you're good to go! Happy using :)
|
||||
|
||||
## To-Do
|
||||
|
||||
* [ ] Complete messenger between user and admins
|
||||
* [x] Complete messenger between user and admins
|
||||
* [ ] Check sponsorship on Holo girls
|
||||
* [ ] Get application by id and user_id
|
12
app.py
12
app.py
@ -1,12 +1,18 @@
|
||||
from modules.logging import logWrite
|
||||
from modules.utils import configGet
|
||||
from pyrogram.client import Client
|
||||
from pyrogram.errors import bad_request_400
|
||||
|
||||
app = Client("holochecker", bot_token=configGet("bot_token", "bot"), api_id=configGet("api_id", "bot"), api_hash=configGet("api_hash", "bot"))
|
||||
|
||||
async def isAnAdmin(admin_id):
|
||||
if (admin_id == configGet("owner")) or (admin_id in configGet("admins")):
|
||||
return True
|
||||
async for member in app.get_chat_members(configGet("admin_group")):
|
||||
if member.user.id == admin_id:
|
||||
return True
|
||||
try:
|
||||
async for member in app.get_chat_members(configGet("admin_group")):
|
||||
if member.user.id == admin_id:
|
||||
return True
|
||||
except bad_request_400.ChannelInvalid:
|
||||
logWrite(f"Could not get users in admin group to answer isAnAdmin(). Bot is likely not in the group.")
|
||||
return False
|
||||
return False
|
@ -1,6 +1,6 @@
|
||||
from app import app, isAnAdmin
|
||||
from typing import Any, List, Union
|
||||
from pyrogram.types import User, ChatMember, ChatPrivileges, Chat, Message
|
||||
from pyrogram.types import User, ChatMember, ChatPrivileges, Chat, Message, Photo, Video, Document, Animation, Voice
|
||||
from pyrogram.client import Client
|
||||
from pyrogram.errors import bad_request_400
|
||||
from modules.database import col_users, col_context, col_warnings, col_applications, col_sponsorships, col_messages
|
||||
@ -71,11 +71,97 @@ class HoloUser():
|
||||
col_users.update_one(filter={"_id": self.db_id}, update={ "$set": { key: value } }, upsert=True)
|
||||
logWrite(f"Set attribute {key} of user {self.id} to {value}")
|
||||
|
||||
async def message(self, origin: Message, text: Union[str, None] = None, photo: Union[str, None] = None, video: Union[str, None] = None, file: Union[str, None] = None):
|
||||
new_message = await app.send_message(self.id, text+locale("message_reply_notice", "message"))
|
||||
await origin.reply_text(locale("message_sent", "message"), quote=should_quote(origin))
|
||||
logWrite(f"Admin {origin.from_user.id} sent message '{' '.join(origin.command[2:])}' to {self.id}")
|
||||
col_messages.insert_one({"origin": {"chat": origin.chat.id, "id": origin.id}, "destination": {"chat": new_message.chat.id, "id": new_message.id}})
|
||||
async def message(self,
|
||||
origin: Union[Message, None] = None,
|
||||
context: Union[Message, None] = None,
|
||||
text: Union[str, None] = None,
|
||||
caption: Union[str, None] = None,
|
||||
photo: Union[str, Photo, None] = None,
|
||||
video: Union[str, Video, None] = None,
|
||||
file: Union[str, Document, None] = None,
|
||||
animation: Union[str, Animation, None] = None,
|
||||
voice: Union[str, Voice, None] = None,
|
||||
adm_origin: bool = False,
|
||||
adm_context: bool = False
|
||||
):
|
||||
|
||||
if text is not None:
|
||||
logWrite(f"{context.from_user.id} sent message '{text}' to {self.id}")
|
||||
elif caption is not None:
|
||||
logWrite(f"{context.from_user.id} sent message '{caption}' to {self.id}")
|
||||
else:
|
||||
logWrite(f"{context.from_user.id} sent message to {self.id}")
|
||||
|
||||
if text is not None:
|
||||
if adm_context:
|
||||
text += locale("message_reply_notice", "message")
|
||||
elif adm_origin:
|
||||
text = locale("message_from", "message").format(context.from_user.first_name, context.from_user.id) + text + locale("message_reply_notice", "message")
|
||||
else:
|
||||
text = locale("message_reply_notice", "message")
|
||||
|
||||
if caption is not None:
|
||||
if adm_context:
|
||||
caption += locale("message_reply_notice", "message")
|
||||
elif adm_origin:
|
||||
caption = locale("message_from", "message").format(context.from_user.first_name, context.from_user.id) + caption + locale("message_reply_notice", "message")
|
||||
else:
|
||||
caption = locale("message_reply_notice", "message")
|
||||
|
||||
if origin is not None:
|
||||
|
||||
if photo is not None:
|
||||
if isinstance(photo, Photo):
|
||||
photo = photo.file_id
|
||||
new_message = await origin.reply_photo(photo, caption=caption, quote=True)
|
||||
elif video is not None:
|
||||
if isinstance(video, Video):
|
||||
video = video.file_id
|
||||
new_message = await origin.reply_video(video, caption=caption, quote=True)
|
||||
elif file is not None:
|
||||
if isinstance(file, Document):
|
||||
file = file.file_id
|
||||
new_message = await origin.reply_document(file, caption=caption, quote=True)
|
||||
elif animation is not None:
|
||||
if isinstance(animation, Animation):
|
||||
animation = animation.file_id
|
||||
new_message = await origin.reply_animation(animation, caption=caption, quote=True)
|
||||
elif voice is not None:
|
||||
if isinstance(voice, Voice):
|
||||
voice = voice.file_id
|
||||
new_message = await origin.reply_voice(voice, caption=caption, quote=True)
|
||||
else:
|
||||
new_message = await origin.reply_text(text, quote=True)
|
||||
|
||||
else:
|
||||
|
||||
if photo is not None:
|
||||
if isinstance(photo, Photo):
|
||||
photo = photo.file_id
|
||||
new_message = await app.send_photo(self.id, photo, caption=caption)
|
||||
elif video is not None:
|
||||
if isinstance(video, Video):
|
||||
video = video.file_id
|
||||
new_message = await app.send_video(self.id, video, caption=caption)
|
||||
elif file is not None:
|
||||
if isinstance(file, Document):
|
||||
file = file.file_id
|
||||
new_message = await app.send_document(self.id, file, caption=caption)
|
||||
elif animation is not None:
|
||||
if isinstance(animation, Animation):
|
||||
animation = animation.file_id
|
||||
new_message = await app.send_animation(animation, caption=caption, quote=True)
|
||||
elif voice is not None:
|
||||
if isinstance(voice, Voice):
|
||||
voice = voice.file_id
|
||||
new_message = await app.send_voice(voice, caption=caption, quote=True)
|
||||
else:
|
||||
new_message = await app.send_message(self.id, text)
|
||||
|
||||
# new_message = await app.send_message(self.id, text+locale("message_reply_notice", "message"))
|
||||
await context.reply_text(locale("message_sent", "message"), quote=should_quote(context))
|
||||
|
||||
col_messages.insert_one({"origin": {"chat": context.chat.id, "id": context.id}, "destination": {"chat": new_message.chat.id, "id": new_message.id}})
|
||||
|
||||
async def set_label(self, chat: Chat, label: str):
|
||||
"""Set label in destination group
|
||||
|
@ -19,10 +19,12 @@ async def cmd_message(app, msg):
|
||||
except ValueError:
|
||||
destination = HoloUser(msg.command[1])
|
||||
|
||||
void = msg.command[2]
|
||||
message = " ".join(msg.command[2:])
|
||||
|
||||
await destination.message(msg, msg.command[2:])
|
||||
if ((msg.text is not None) and (len(msg.text.split()) > 2)):
|
||||
await destination.message(context=msg, text=" ".join(msg.text.split()[2:]), caption=msg.caption, photo=msg.photo, video=msg.video, file=msg.document, adm_context=True)
|
||||
elif ((msg.caption is not None) and (len(msg.caption.split()) > 2)):
|
||||
await destination.message(context=msg, text=msg.text, caption=" ".join(msg.caption.split()[2:]), photo=msg.photo, video=msg.video, file=msg.document, adm_context=True)
|
||||
else:
|
||||
await destination.message(context=msg, text=None, caption=None, photo=msg.photo, video=msg.video, file=msg.document, adm_context=True)
|
||||
|
||||
# try:
|
||||
# new_message = await app.send_message(destination.id, message+locale("message_reply_notice", "message"))
|
||||
|
@ -4,6 +4,7 @@ from app import app, isAnAdmin
|
||||
import asyncio
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import ForceReply, ReplyKeyboardMarkup, Message
|
||||
from classes.holo_user import HoloUser
|
||||
from modules.utils import configGet, configSet, jsonLoad, jsonSave, locale, logWrite, should_quote
|
||||
from modules.database import col_messages
|
||||
|
||||
@ -20,20 +21,35 @@ async def message_context(msg: Message) -> tuple:
|
||||
return 0, 0
|
||||
|
||||
# Any other input ==============================================================================================================
|
||||
# @app.on_message(~ filters.scheduled & filters.private)
|
||||
# async def any_stage(app, msg):
|
||||
@app.on_message(~ filters.scheduled & filters.private)
|
||||
async def any_stage(app, msg):
|
||||
|
||||
# if msg.via_bot is None:
|
||||
if msg.via_bot is None:
|
||||
|
||||
# if (msg.reply_to_message != None) and (await message_involved(msg)):
|
||||
# context = await message_context(msg)
|
||||
# if msg.chat.id == configGet("admin_group") or await isAnAdmin(msg.from_user.id):
|
||||
# new_message = await (await app.get_messages(context[0], context[1])).reply_text(msg.text+locale("message_reply_notice", "message"), quote=True)
|
||||
# else:
|
||||
# new_message = await (await app.get_messages(context[0], context[1])).reply_text(locale("message_from", "message").format(msg.from_user.first_name, msg.from_user.id)+msg.text+locale("message_reply_notice", "message"), quote=True)
|
||||
# await msg.reply_text(locale("message_sent", "message"), quote=should_quote(msg))
|
||||
# col_messages.insert_one({"origin": {"chat": msg.chat.id, "id": msg.id}, "destination": {"chat": new_message.chat.id, "id": new_message.id}})
|
||||
# return
|
||||
if (msg.reply_to_message != None) and (await message_involved(msg)):
|
||||
|
||||
context = await message_context(msg)
|
||||
context_message = await app.get_messages(context[0], context[1])
|
||||
|
||||
holo_user = HoloUser(msg.from_user)
|
||||
destination_user = HoloUser(context_message.from_user)
|
||||
|
||||
await destination_user.message(
|
||||
origin=context_message,
|
||||
context=msg,
|
||||
text=msg.text,
|
||||
caption=msg.caption,
|
||||
photo=msg.photo,
|
||||
video=msg.video,
|
||||
file=msg.document,
|
||||
adm_origin=await isAnAdmin(context_message.from_user.id),
|
||||
adm_context=await isAnAdmin(msg.from_user.id)
|
||||
)
|
||||
|
||||
# await msg.reply_text(locale("message_sent", "message"), quote=should_quote(msg))
|
||||
# col_messages.insert_one({"origin": {"chat": msg.chat.id, "id": msg.id}, "destination": {"chat": new_message.chat.id, "id": new_message.id}})
|
||||
|
||||
return
|
||||
|
||||
# user_stage = configGet("stage", file=str(msg.from_user.id))
|
||||
|
||||
|
Reference in New Issue
Block a user