randydev commited on
Commit
852b466
·
verified ·
1 Parent(s): 3bf7e7a

Update Akeno/plugins/admin.py

Browse files
Files changed (1) hide show
  1. Akeno/plugins/admin.py +62 -0
Akeno/plugins/admin.py CHANGED
@@ -10,6 +10,7 @@
10
  import asyncio
11
  import time
12
  from time import time as waktu
 
13
 
14
  from pyrogram import Client
15
  from pyrogram import Client as ren
@@ -99,6 +100,67 @@ async def extract_user_and_reason(message, sender_chat=False):
99
  async def extract_user(message):
100
  return (await extract_user_and_reason(message))[0]
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
  async def list_admins(client: Client, chat_id: int):
104
  global admins_in_chat
 
10
  import asyncio
11
  import time
12
  from time import time as waktu
13
+ from datetime import timedelta
14
 
15
  from pyrogram import Client
16
  from pyrogram import Client as ren
 
100
  async def extract_user(message):
101
  return (await extract_user_and_reason(message))[0]
102
 
103
+ @app.on_message(filters.command("ban") & filters.me)
104
+ async def test_ban_command(client: Client, message: Message):
105
+ if not message.reply_to_message and len(message.command) < 2:
106
+ return await message.reply("Please reply to a message or provide a user ID, along with a reason.")
107
+
108
+ if message.reply_to_message:
109
+ user_id = message.reply_to_message.from_user.id
110
+ else:
111
+ try:
112
+ user_id = int(message.command[1])
113
+ except ValueError:
114
+ return await message.reply("Invalid user ID provided.")
115
+
116
+ ban_duration = None
117
+ delete_message = False
118
+ reason = None
119
+ if len(message.command) > 2:
120
+ for arg in message.command:
121
+ if arg.startswith("h:"):
122
+ try:
123
+ hours = int(arg[2:])
124
+ ban_duration = timedelta(hours=hours)
125
+ except ValueError:
126
+ return await message.reply("Invalid hour duration format.")
127
+ elif arg.startswith("m:"):
128
+ try:
129
+ minutes = int(arg[2:])
130
+ ban_duration = timedelta(minutes=minutes)
131
+ except ValueError:
132
+ return await message.reply("Invalid minute duration format.")
133
+ elif arg.startswith("s:"):
134
+ try:
135
+ seconds = int(arg[2:])
136
+ ban_duration = timedelta(seconds=seconds)
137
+ except ValueError:
138
+ return await message.reply("Invalid second duration format.")
139
+
140
+ if "{del}" in message.command:
141
+ delete_message = True
142
+ message.command.remove("{del}")
143
+ if len(message.command) > 2:
144
+ reason = " ".join(message.command[2:])
145
+
146
+ try:
147
+ if ban_duration:
148
+ until_date = message.date + ban_duration
149
+ await client.ban_chat_member(message.chat.id, user_id, until_date=until_date)
150
+ else:
151
+ await client.ban_chat_member(message.chat.id, user_id)
152
+ if delete_message:
153
+ await message.delete()
154
+ if message.reply_to_message:
155
+ await message.reply_to_message.delete()
156
+ response_text = f"User {user_id} has been banned."
157
+ if ban_duration:
158
+ response_text += f" Duration: {ban_duration}"
159
+ if reason:
160
+ response_text += f" Reason: {reason}"
161
+ await message.reply(response_text)
162
+ except Exception as e:
163
+ await message.reply(f"Failed to ban user: {e}")
164
 
165
  async def list_admins(client: Client, chat_id: int):
166
  global admins_in_chat