| 145 | |
| 146 | @Client.on_message(filters.private & filters.command("ban") & filters.user(Config.ADMIN)) |
| 147 | async def ban(c: Client, m: Message): |
| 148 | if len(m.command) == 1: |
| 149 | await m.reply_text( |
| 150 | f"Use this command to ban any user from the bot.\n\n" |
| 151 | f"Usage:\n\n" |
| 152 | f"`/ban user_id ban_duration ban_reason`\n\n" |
| 153 | f"Eg: `/ban 1234567 28 You misused me.`\n" |
| 154 | f"This will ban user with id `1234567` for `28` days for the reason `You misused me`.", |
| 155 | quote=True |
| 156 | ) |
| 157 | return |
| 158 | |
| 159 | try: |
| 160 | user_id = int(m.command[1]) |
| 161 | ban_duration = int(m.command[2]) |
| 162 | ban_reason = ' '.join(m.command[3:]) |
| 163 | ban_log_text = f"Banning user {user_id} for {ban_duration} days for the reason {ban_reason}." |
| 164 | try: |
| 165 | await c.send_message(user_id, |
| 166 | f"You are banned to use this bot for **{ban_duration}** day(s) for the reason __{ban_reason}__ \n\n" |
| 167 | f"**Message from the admin**" |
| 168 | ) |
| 169 | ban_log_text += '\n\nUser notified successfully!' |
| 170 | except: |
| 171 | traceback.print_exc() |
| 172 | ban_log_text += f"\n\nUser notification failed! \n\n`{traceback.format_exc()}`" |
| 173 | |
| 174 | await digital_botz.ban_user(user_id, ban_duration, ban_reason) |
| 175 | await m.reply_text(ban_log_text, quote=True) |
| 176 | except: |
| 177 | traceback.print_exc() |
| 178 | await m.reply_text( |
| 179 | f"Error occoured! Traceback given below\n\n`{traceback.format_exc()}`", |
| 180 | quote=True |
| 181 | ) |
| 182 | |
| 183 | |
| 184 | @Client.on_message(filters.private & filters.command("unban") & filters.user(Config.ADMIN)) |