1
+ # Moon-Userbot - telegram userbot
2
+ # Copyright (C) 2020-present Moon Userbot Organization
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
16
+
17
+ import asyncio
18
+ from pyrogram import Client , filters
19
+ from pyrogram .types import Message
20
+
21
+ from utils .db import db
22
+ from utils .scripts import format_exc
23
+ from utils .misc import modules_help , prefix
24
+
25
+ @Client .on_message (filters .command ("fban" , prefix ) & filters .me )
26
+ async def fban_cmd (client : Client , message : Message ):
27
+ try :
28
+ msg = await message .edit ("🌙 Starting Federation Ban..." )
29
+
30
+ # Get target and reason
31
+ args = message .text .split ()
32
+ if len (args ) < 2 and not message .reply_to_message :
33
+ return await msg .edit ("❌ Reply to user or provide ID/username and reason" )
34
+
35
+ if message .reply_to_message :
36
+ target = message .reply_to_message .from_user .id
37
+ reason = " " .join (args [1 :]) if len (args ) > 1 else ""
38
+ else :
39
+ target = args [1 ]
40
+ reason = " " .join (args [2 :]) if len (args ) > 2 else ""
41
+
42
+ # Get configuration
43
+ fban_group = db .get ("core.ats" , "FBAN_GROUP_ID" )
44
+ fed_ids = db .get ("core.ats" , "FED_IDS" , [])
45
+
46
+ if not fban_group :
47
+ return await msg .edit ("❌ FBAN group not set! Use `.set_fban_group` first" )
48
+
49
+ if not fed_ids :
50
+ return await msg .edit ("❌ No federations added! Use `.addfed` first" )
51
+
52
+ # Execute commands in FBAN group
53
+ await client .send_message (fban_group , f"/fban { target } { reason } " )
54
+ await asyncio .sleep (2 )
55
+
56
+ for fed_id in fed_ids :
57
+ await client .send_message (fban_group , f"/joinfed { fed_id } " )
58
+ await asyncio .sleep (3 )
59
+ await client .send_message (fban_group , f"/fban { target } { reason } " )
60
+ await asyncio .sleep (3 )
61
+
62
+ await msg .edit (f"✅ Successfully FBanned { target } in { len (fed_ids )} federations\n #MoonUB" )
63
+
64
+ except Exception as e :
65
+ await msg .edit (f"⚠️ Error: { format_exc (e )} " )
66
+
67
+ @Client .on_message (filters .command ("unfban" , prefix ) & filters .me )
68
+ async def unfban_cmd (client : Client , message : Message ):
69
+ try :
70
+ msg = await message .edit ("🌙 Starting Federation Unban..." )
71
+
72
+ # Get target and reason
73
+ args = message .text .split ()
74
+ if len (args ) < 2 and not message .reply_to_message :
75
+ return await msg .edit ("❌ Reply to user or provide ID/username and reason" )
76
+
77
+ if message .reply_to_message :
78
+ target = message .reply_to_message .from_user .id
79
+ reason = " " .join (args [1 :]) if len (args ) > 1 else ""
80
+ else :
81
+ target = args [1 ]
82
+ reason = " " .join (args [2 :]) if len (args ) > 2 else ""
83
+
84
+ # Get configuration
85
+ fban_group = db .get ("core.ats" , "FBAN_GROUP_ID" )
86
+ fed_ids = db .get ("core.ats" , "FED_IDS" , [])
87
+
88
+ if not fban_group :
89
+ return await msg .edit ("❌ FBAN group not set! Use `.set_fban_group` first" )
90
+
91
+ if not fed_ids :
92
+ return await msg .edit ("❌ No federations added! Use `.addfed` first" )
93
+
94
+ # Execute commands in FBAN group
95
+ await client .send_message (fban_group , f"/unfban { target } { reason } " )
96
+ await asyncio .sleep (2 )
97
+
98
+ for fed_id in fed_ids :
99
+ await client .send_message (fban_group , f"/joinfed { fed_id } " )
100
+ await asyncio .sleep (3 )
101
+ await client .send_message (fban_group , f"/unfban { target } { reason } " )
102
+ await asyncio .sleep (3 )
103
+
104
+ await msg .edit (f"✅ Successfully UnFBanned { target } in { len (fed_ids )} federations\n #MoonUB" )
105
+
106
+ except Exception as e :
107
+ await msg .edit (f"⚠️ Error: { format_exc (e )} " )
108
+
109
+ @Client .on_message (filters .command ("set_fban_group" , prefix ) & filters .me )
110
+ async def set_fban_group (_ , message : Message ):
111
+ if len (message .command ) < 2 :
112
+ return await message .edit (f"❌ Usage: `{ prefix } set_fban_group <group_id>`" )
113
+
114
+ try :
115
+ group_id = int (message .command [1 ])
116
+ db .set ("core.ats" , "FBAN_GROUP_ID" , group_id )
117
+ await message .edit (f"✅ FBAN group set to `{ group_id } `" )
118
+ except ValueError :
119
+ await message .edit ("❌ Invalid group ID. Must be a valid integer." )
120
+ except Exception as e :
121
+ await message .edit (f"⚠️ Error: { format_exc (e )} " )
122
+
123
+ @Client .on_message (filters .command ("addfed" , prefix ) & filters .me )
124
+ async def add_fed (_ , message : Message ):
125
+ if len (message .command ) < 2 :
126
+ return await message .edit (f"❌ Usage: `{ prefix } addfed <fed_id>`" )
127
+
128
+ fed_id = message .command [1 ]
129
+ current_feds = db .get ("core.ats" , "FED_IDS" , [])
130
+
131
+ if fed_id in current_feds :
132
+ await message .edit ("❌ This federation is already in the list" )
133
+ else :
134
+ current_feds .append (fed_id )
135
+ db .set ("core.ats" , "FED_IDS" , current_feds )
136
+ await message .edit (f"✅ Added federation: `{ fed_id } `" )
137
+
138
+ @Client .on_message (filters .command ("delfed" , prefix ) & filters .me )
139
+ async def del_fed (_ , message : Message ):
140
+ if len (message .command ) < 2 :
141
+ return await message .edit (f"❌ Usage: `{ prefix } delfed <fed_id>`" )
142
+
143
+ fed_id = message .command [1 ]
144
+ current_feds = db .get ("core.ats" , "FED_IDS" , [])
145
+
146
+ if fed_id not in current_feds :
147
+ await message .edit ("❌ Federation not found in list" )
148
+ else :
149
+ current_feds .remove (fed_id )
150
+ db .set ("core.ats" , "FED_IDS" , current_feds )
151
+ await message .edit (f"✅ Removed federation: `{ fed_id } `" )
152
+
153
+ @Client .on_message (filters .command ("listfed" , prefix ) & filters .me )
154
+ async def list_fed (_ , message : Message ):
155
+ current_feds = db .get ("core.ats" , "FED_IDS" , [])
156
+ if not current_feds :
157
+ return await message .edit ("❌ No federations in list" )
158
+
159
+ fed_list = "\n " .join ([f"• `{ fed } `" for fed in current_feds ])
160
+ await message .edit (f"📜 Federation List:\n { fed_list } " )
161
+
162
+ modules_help ["fedutils" ] = {
163
+ "fban [reply]/[userid]* [reason]" : "Ban user in multiple federations" ,
164
+ "unfban [reply]/[userid]* [reason]" : "Unban user from multiple federations" ,
165
+ "set_fban_group [group_id]*" : "Set group for FBAN operations" ,
166
+ "addfed [fed_id]*" : "Add federation to ban list" ,
167
+ "delfed [fed_id]*" : "Remove federation from ban list" ,
168
+ "listfed" : "Show current federation list"
169
+ }
0 commit comments