Skip to content

Instantly share code, notes, and snippets.

@kaecy
Last active July 1, 2022 14:38
Show Gist options
  • Save kaecy/4043b71c9a6e01ff530b2d1989af5c22 to your computer and use it in GitHub Desktop.
Save kaecy/4043b71c9a6e01ff530b2d1989af5c22 to your computer and use it in GitHub Desktop.

Read Me

Part of the Raey-Core project. Our plan is to build a core set of modules that everyone can use.

import raey.core.module
from telethon.tl import types
from telethon import helpers
from telethon.utils import get_display_name
moduleInfo = raey.core.module.ModuleInfo("chat-info")
def getChatInfo(chat):
"Get basic info of a chat."
entityType = helpers._entity_type(chat)
CHAT = helpers._EntityType.CHAT
CHANNEL = helpers._EntityType.CHANNEL
info = "Basic Info\n`"
info += " Id %d\n" % chat.id
if entityType == CHAT:
info += " Type Chat\n"
else:
if chat.broadcast:
info += " Type Channel\n"
else:
info += " Type SuperChat\n"
info += " Name %s\n" % chat.title
if entityType == CHAT or chat.left:
info += "Created %s\n" % chat.date.date()
if entityType == CHAT:
info += " Users %d" % chat.participants_count
info += "`"
return info
async def chat(event, params):
"Gives you basic chat info."
chat = event.chat
if len(params) == 1:
chat = await event.client.get_entity(params[0])
if type(chat) == types.User:
await event.respond("Didn't find anything.")
else:
await event.respond(getChatInfo(chat))
async def get_creator(event, params):
participants = await event.client.get_participants(
event.chat,
filter=types.ChannelParticipantsAdmins
)
if type(event.chat) == types.Chat:
for user in participants:
if type(user.participant.participants[0]) == types.ChatParticipantCreator:
await event.respond("[%s](tg://user?id=%s) (Creator)" %
(get_display_name(user), user.id))
break
else:
for user in participants:
if type(user.participant) == types.ChannelParticipantCreator:
await event.respond("[%s](tg://user?id=%s) (Creator)" %
(get_display_name(user), user.id))
break
async def get_msg_link(event, params):
if event.is_reply:
replyMsg = await event.get_reply_message()
await event.respond(str("t.me/{0}/{1.id}").format(
vars(replyMsg.chat).get("username", None) or "c/" + replyMsg.chat.id,
replyMsg
))
async def inspect_msg(event, params):
if event.reply:
await event.respond(str(await event.get_reply_message()))
moduleInfo.add_command(chat)
moduleInfo.add_command(get_creator)
moduleInfo.add_command(get_msg_link)
moduleInfo.add_command(inspect_msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment