2018-08-28 08:44:33 +00:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2019-09-03 19:50:39 +00:00
|
|
|
import html
|
2018-08-28 08:44:33 +00:00
|
|
|
|
|
|
|
from telethon import events
|
2018-08-28 10:16:17 +00:00
|
|
|
from telethon import utils
|
2018-08-28 08:44:33 +00:00
|
|
|
from telethon.tl import types
|
|
|
|
|
|
|
|
|
2019-09-07 07:31:43 +00:00
|
|
|
def get_who_string(who):
|
|
|
|
who_string = html.escape(utils.get_display_name(who))
|
|
|
|
if isinstance(who, (types.User, types.Channel)) and who.username:
|
|
|
|
who_string += f" <i>(@{who.username})</i>"
|
|
|
|
who_string += f", <a href='tg://user?id={who.id}'>#{who.id}</a>"
|
|
|
|
return who_string
|
|
|
|
|
|
|
|
|
2018-08-28 08:44:33 +00:00
|
|
|
@borg.on(events.NewMessage(pattern=r"\.who", outgoing=True))
|
|
|
|
async def _(event):
|
|
|
|
if not event.message.is_reply:
|
|
|
|
who = await event.get_chat()
|
|
|
|
else:
|
|
|
|
msg = await event.message.get_reply_message()
|
|
|
|
if msg.forward:
|
2019-05-20 07:53:16 +00:00
|
|
|
# FIXME forward privacy memes
|
2018-08-28 08:44:33 +00:00
|
|
|
who = await borg.get_entity(
|
|
|
|
msg.forward.from_id or msg.forward.channel_id)
|
|
|
|
else:
|
2018-08-28 10:16:17 +00:00
|
|
|
who = await msg.get_sender()
|
2018-08-28 08:44:33 +00:00
|
|
|
|
2019-09-07 07:31:43 +00:00
|
|
|
await event.edit(get_who_string(who), parse_mode='html')
|
|
|
|
|
|
|
|
|
|
|
|
@borg.on(events.NewMessage(pattern=r"\.members", outgoing=True))
|
|
|
|
async def _(event):
|
|
|
|
members = [
|
|
|
|
get_who_string(m) async for m in borg.iter_participants(event.chat_id)
|
|
|
|
]
|
2018-08-28 08:44:33 +00:00
|
|
|
|
2019-09-07 07:31:43 +00:00
|
|
|
await event.edit("\n".join(members), parse_mode='html')
|