This repository has been archived by the owner on Nov 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
chat.py
81 lines (67 loc) · 2.83 KB
/
chat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Copyright (C) 2019 The Raphielscape Company LLC.
#
# Licensed under the Raphielscape Public License, Version 1.c (the "License");
# you may not use this file except in compliance with the License.
""" Userbot module containing userid, chatid and log commands"""
from time import sleep
from telethon.tl.functions.channels import LeaveChannelRequest
from userbot import BOTLOG, BOTLOG_CHATID, CMD_HELP, bot
from userbot.events import register
@register(outgoing=True, pattern="^.userid$")
async def useridgetter(target):
""" For .userid command, returns the ID of the target user. """
message = await target.get_reply_message()
if message:
if not message.forward:
user_id = message.sender.id
if message.sender.username:
name = "@" + message.sender.username
else:
name = "**" + message.sender.first_name + "**"
else:
user_id = message.forward.sender.id
if message.forward.sender.username:
name = "@" + message.forward.sender.username
else:
name = "*" + message.forward.sender.first_name + "*"
await target.edit("**Name:** {} \n**User ID:** `{}`".format(
name, user_id))
@register(outgoing=True, pattern="^.chatid$")
async def chatidgetter(chat):
""" For .chatid, returns the ID of the chat you are in at that moment. """
await chat.edit("**Chat ID:**\n`" + str(chat.chat_id) + "`")
@register(outgoing=True, pattern=r"^.log(?: |$)([\s\S]*)")
async def log(log_text):
""" For .log command, forwards a message
or the command argument to the bot logs group """
if BOTLOG:
if log_text.reply_to_msg_id:
reply_msg = await log_text.get_reply_message()
await reply_msg.forward_to(BOTLOG_CHATID)
elif log_text.pattern_match.group(1):
user = f"#LOG / Chat ID: {log_text.chat_id}\n\n"
textx = user + log_text.pattern_match.group(1)
await bot.send_message(BOTLOG_CHATID, textx)
else:
await log_text.edit("`What am I supposed to log?`")
return
await log_text.edit("`Logged Successfully`")
else:
await log_text.edit("`This feature requires Logging to be enabled!`")
sleep(2)
await log_text.delete()
@register(outgoing=True, pattern="^.kickme$")
async def kickme(leave):
""" Basically it's .kickme command """
await leave.edit("`Nope, no, no, I go away`")
await bot(LeaveChannelRequest(leave.chat_id))
CMD_HELP.update({"chatid": "Fetch the current chat's ID"})
CMD_HELP.update({
"userid":
"Fetch the ID of the user in reply or the "
"original author of a forwarded message."
})
CMD_HELP.update(
{"log": "Forward the message you've replied to to your "
"botlog group."})
CMD_HELP.update({"kickme": "Leave from a targeted group."})