Captain Ezio commited on
Commit
5367261
·
2 Parent(s): e6eeb72 7db17dc

Merge branch 'beta' of https://github.com/Gojo-Bots/Gojo_Satoru into beta

Browse files
Powers/database/flood_db.py CHANGED
@@ -1,5 +1,7 @@
1
  from threading import RLock
 
2
 
 
3
  from Powers.database import MongoDB
4
  from Powers.utils.msg_types import Types
5
 
@@ -7,11 +9,11 @@ INSERTION_LOCK = RLock()
7
 
8
  class Floods(MongoDB):
9
  """Class to store flood limit and action of a chat"""
 
 
10
 
11
- db_name = "flood"
12
-
13
- def __init__(self):
14
- super().__init__(self.db_name)
15
 
16
  def save_flood(
17
  self,
@@ -21,7 +23,7 @@ class Floods(MongoDB):
21
  action: str,
22
  ):
23
  with INSERTION_LOCK:
24
- curr = self.find_one({"chat_id": chat_id})
25
  if curr:
26
  if not(limit == int(curr['limit']) or within == int(curr['within']) or action == str(curr['action'])):
27
  return self.update(
@@ -32,17 +34,14 @@ class Floods(MongoDB):
32
  "action": action,
33
  }
34
  )
35
- else:
36
- return False
37
- else:
38
- return self.insert_one(
39
- {
40
- "chat_id" : chat_id,
41
- "limit": limit,
42
- "within": within,
43
- "action" : action
44
- },
45
- )
46
 
47
  def is_chat(self, chat_id: int):
48
  with INSERTION_LOCK:
 
1
  from threading import RLock
2
+ from traceback import format_exc
3
 
4
+ from Powers import LOGGER
5
  from Powers.database import MongoDB
6
  from Powers.utils.msg_types import Types
7
 
 
9
 
10
  class Floods(MongoDB):
11
  """Class to store flood limit and action of a chat"""
12
+ try:
13
+ db_name = "flood"
14
 
15
+ def __init__(self):
16
+ super().__init__(self.db_name)
 
 
17
 
18
  def save_flood(
19
  self,
 
23
  action: str,
24
  ):
25
  with INSERTION_LOCK:
26
+ curr = self.find_one({"chat_id": chat_id, "limit": limit, "within": within, "action": action})
27
  if curr:
28
  if not(limit == int(curr['limit']) or within == int(curr['within']) or action == str(curr['action'])):
29
  return self.update(
 
34
  "action": action,
35
  }
36
  )
37
+ return self.insert_one(
38
+ {
39
+ "chat_id" : chat_id,
40
+ "limit": limit,
41
+ "within": within,
42
+ "action" : action
43
+ },
44
+ )
 
 
 
45
 
46
  def is_chat(self, chat_id: int):
47
  with INSERTION_LOCK:
Powers/plugins/flood.py CHANGED
@@ -21,7 +21,7 @@ from Powers.vars import Config
21
 
22
  Flood = Floods()
23
 
24
- approve = Approve()
25
 
26
  on_key = ["on", "start", "disable"]
27
  off_key = ["off", "end", "enable", "stop"]
@@ -31,7 +31,7 @@ close_kb =InlineKeyboardMarkup(
31
  [
32
  InlineKeyboardButton(
33
  "Close ❌",
34
- callback_data="close"
35
  )
36
  ]
37
  ]
@@ -42,15 +42,15 @@ action_kb = InlineKeyboardMarkup(
42
  [
43
  InlineKeyboardButton(
44
  "Mute 🔇",
45
- callback_data="mute"
46
  ),
47
  InlineKeyboardButton(
48
  "Ban 🚷",
49
- callback_data="ban"
50
  ),
51
  InlineKeyboardButton(
52
- "Kick",
53
- callback_data="kick"
54
  )
55
  ]
56
  ]
@@ -61,15 +61,15 @@ within_kb = InlineKeyboardMarkup(
61
  [
62
  InlineKeyboardButton(
63
  "5",
64
- callback_data="5"
65
  ),
66
  InlineKeyboardButton(
67
  "10",
68
- callback_data="10"
69
  ),
70
  InlineKeyboardButton(
71
  "15",
72
- callback_data="15"
73
  )
74
  ]
75
  ]
@@ -80,15 +80,15 @@ limit_kb = InlineKeyboardMarkup(
80
  [
81
  InlineKeyboardButton(
82
  "5",
83
- callback_data="l_5"
84
  ),
85
  InlineKeyboardButton(
86
  "10",
87
- callback_data="l_10"
88
  ),
89
  InlineKeyboardButton(
90
  "15",
91
- callback_data="l_15"
92
  )
93
  ]
94
  ]
@@ -98,15 +98,16 @@ limit_kb = InlineKeyboardMarkup(
98
  async def flood_action(c: Gojo, m: Message):
99
  bot = await c.get_chat_member(m.chat.id, Config.BOT_ID)
100
  status = bot.status
101
- if not status in [CMS.OWNER, CMS.ADMINISTRATOR] and not bot.privileges.can_restrict_members:
 
102
  return await m.reply_text("Give me permission to restict member first")
103
  if m.chat.type == CT.PRIVATE:
104
  await m.reply_text("Use this command in group")
105
  return
106
  c_id = m.chat.id
107
  is_flood = Flood.is_chat(c_id)
108
- saction = is_flood[2]
109
  if is_flood:
 
110
  await m.reply_text(
111
  f"Choose a action given bellow to do when flood happens.\n **CURRENT ACTION** is {saction}",
112
  reply_markup=action_kb
@@ -115,82 +116,123 @@ async def flood_action(c: Gojo, m: Message):
115
  await m.reply_text("Switch on the flood protection first.")
116
  return
117
 
118
- @Gojo.on_message(command(['setflood', 'flood']) & ~filters.bot & admin_filter)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  async def flood_set(c: Gojo, m: Message):
120
  bot = await c.get_chat_member(m.chat.id, Config.BOT_ID)
121
  status = bot.status
122
- if not status in [CMS.OWNER, CMS.ADMINISTRATOR] and not bot.privileges.can_restrict_members:
 
123
  return await m.reply_text("Give me permission to restict member first")
124
  if m.chat.type == CT.PRIVATE:
125
  return await m.reply_text("This command is ment to be used in groups.")
126
  split = m.text.split(None, 1)
127
  c_id = m.chat.id
128
  is_flood = Flood.is_chat(c_id)
129
- saction = is_flood[2]
130
- slimit = is_flood[0]
131
- swithin = is_flood[1]
132
  if len(split) == 1:
133
  c_id = m.chat.id
134
  if is_flood:
 
 
 
135
  return await m.reply_text(f"Flood is on for this chat\n**Action**:{saction}\n**Messages**:{slimit} within {swithin} sec")
136
  return await m.reply_text("Flood protection is off of this chat.")
137
 
138
- elif len(split) == 2:
 
 
 
 
139
  c_id = m.chat.id
140
  if split[1].lower() in on_key:
141
- if not is_flood:
142
- Flood.save_flood(m.chat.id, 5, 5, 'mute')
143
- await m.reply_text("Flood protection has been started for this group.")
144
- return
145
- return await m.reply_text(f"Flood is on for this chat\n**Action**:{saction}\n**Messages**:{slimit} within {swithin} sec")
146
  if split[1].lower() in off_key:
147
- Flood.rm_flood(m.chat.id, slimit, swithin, saction)
148
  await m.reply_text("Flood protection has been stopped for this chat")
149
  return
150
  await m.reply_text("**Usage:**\n `/setflood on/off`")
151
  return
152
 
153
- @Gojo.on_callback_query()
154
  async def callbacks(c: Gojo, q: CallbackQuery):
155
  data = q.data
156
- if data == "close":
157
  await q.answer("Closed")
158
  await q.message.delete()
159
  return
160
  c_id = q.message.chat.id
161
  is_flood = Flood.is_chat(c_id)
162
- saction = is_flood[2]
163
- slimit = is_flood[0]
164
- swithin = is_flood[1]
 
165
  user = q.from_user.id
166
  user_status = (await q.message.chat.get_member(q.from_user.id)).status
167
  if user in SUPPORT_STAFF or user_status in [CMS.OWNER, CMS.ADMINISTRATOR]:
168
- if data in ["mute", "ban", "kick"]:
169
- Flood.save_flood(c_id, slimit, swithin, data)
170
- await q.answer("Updated action", show_alert=True)
171
- await q.edit_message_caption(
172
- f"Set the limit of message after the flood protection will be activated\n **CURRENT LIMIT** {slimit} messages",
173
- reply_markup=limit_kb
174
- )
175
- return
176
- if data in ["l_5", "l_10", "l_15"]:
 
 
 
 
 
 
 
 
177
  change = int(data.split("_")[1])
178
- Flood.save_flood(c_id, change, swithin, saction)
179
- await q.answer("Updated limit", show_alert=True)
180
- await q.edit_message_caption(
181
- f"Set the time with the number of message recived treated as flood\n **CUURENT TIME** {swithin}",
182
- reply_markup=within_kb
183
- )
184
- return
185
- if data in ["5", "10", "15"]:
 
 
 
 
 
 
 
 
186
  change = int(data)
187
- Flood.save_flood(c_id, slimit, change, saction)
188
- await q.answer("Updated", show_alert=True)
189
- await q.edit_message_caption(
190
- "Flood protection setting has been updated",
191
- reply_markup=close_kb
192
- )
193
- return
 
 
 
 
 
 
 
194
  else:
195
  await q.answer(
196
  "You don't have enough permission to do this!\nStay in your limits!",
@@ -389,6 +431,34 @@ async def flood_watcher(c: Gojo, m: Message):
389
  dic[c_id][u_id][1].clear()
390
  dic[c_id][u_id][0].clear()
391
  return
 
 
 
 
 
 
 
392
  else:
393
  return
394
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  Flood = Floods()
23
 
24
+
25
 
26
  on_key = ["on", "start", "disable"]
27
  off_key = ["off", "end", "enable", "stop"]
 
31
  [
32
  InlineKeyboardButton(
33
  "Close ❌",
34
+ callback_data="fclose"
35
  )
36
  ]
37
  ]
 
42
  [
43
  InlineKeyboardButton(
44
  "Mute 🔇",
45
+ callback_data="f_mute"
46
  ),
47
  InlineKeyboardButton(
48
  "Ban 🚷",
49
+ callback_data="f_ban"
50
  ),
51
  InlineKeyboardButton(
52
+ "Kick 🦿",
53
+ callback_data="f_kick"
54
  )
55
  ]
56
  ]
 
61
  [
62
  InlineKeyboardButton(
63
  "5",
64
+ callback_data="f_f_5"
65
  ),
66
  InlineKeyboardButton(
67
  "10",
68
+ callback_data="f_f_10"
69
  ),
70
  InlineKeyboardButton(
71
  "15",
72
+ callback_data="f_f_15"
73
  )
74
  ]
75
  ]
 
80
  [
81
  InlineKeyboardButton(
82
  "5",
83
+ callback_data="f_5"
84
  ),
85
  InlineKeyboardButton(
86
  "10",
87
+ callback_data="f_10"
88
  ),
89
  InlineKeyboardButton(
90
  "15",
91
+ callback_data="f_15"
92
  )
93
  ]
94
  ]
 
98
  async def flood_action(c: Gojo, m: Message):
99
  bot = await c.get_chat_member(m.chat.id, Config.BOT_ID)
100
  status = bot.status
101
+ if not status in [CMS.OWNER, CMS.ADMINISTRATOR]:
102
+ if not bot.privileges.can_restrict_members:
103
  return await m.reply_text("Give me permission to restict member first")
104
  if m.chat.type == CT.PRIVATE:
105
  await m.reply_text("Use this command in group")
106
  return
107
  c_id = m.chat.id
108
  is_flood = Flood.is_chat(c_id)
 
109
  if is_flood:
110
+ saction = is_flood[2]
111
  await m.reply_text(
112
  f"Choose a action given bellow to do when flood happens.\n **CURRENT ACTION** is {saction}",
113
  reply_markup=action_kb
 
116
  await m.reply_text("Switch on the flood protection first.")
117
  return
118
 
119
+ @Gojo.on_message(command(['isflood', 'flood']) & ~filters.bot)
120
+ async def flood_on_off(c: Gojo, m: Message):
121
+ if m.chat.type == CT.PRIVATE:
122
+ return await m.reply_text("This command is ment to be used in groups.")
123
+ c_id = m.chat.id
124
+ is_flood = Flood.is_chat(c_id)
125
+ c_id = m.chat.id
126
+ if is_flood:
127
+ saction = is_flood[2]
128
+ slimit = is_flood[0]
129
+ swithin = is_flood[1]
130
+ return await m.reply_text(f"Flood is on for this chat\n**Action**: {saction}\n**Messages**: {slimit} within {swithin} sec")
131
+ return await m.reply_text("Flood protection is off for this chat.")
132
+
133
+ @Gojo.on_message(command(['setflood']) & ~filters.bot & admin_filter)
134
  async def flood_set(c: Gojo, m: Message):
135
  bot = await c.get_chat_member(m.chat.id, Config.BOT_ID)
136
  status = bot.status
137
+ if not status in [CMS.OWNER, CMS.ADMINISTRATOR]:
138
+ if not bot.privileges.can_restrict_members:
139
  return await m.reply_text("Give me permission to restict member first")
140
  if m.chat.type == CT.PRIVATE:
141
  return await m.reply_text("This command is ment to be used in groups.")
142
  split = m.text.split(None, 1)
143
  c_id = m.chat.id
144
  is_flood = Flood.is_chat(c_id)
 
 
 
145
  if len(split) == 1:
146
  c_id = m.chat.id
147
  if is_flood:
148
+ saction = is_flood[2]
149
+ slimit = is_flood[0]
150
+ swithin = is_flood[1]
151
  return await m.reply_text(f"Flood is on for this chat\n**Action**:{saction}\n**Messages**:{slimit} within {swithin} sec")
152
  return await m.reply_text("Flood protection is off of this chat.")
153
 
154
+ if len(split) == 2:
155
+ if is_flood:
156
+ saction = is_flood[2]
157
+ slimit = is_flood[0]
158
+ swithin = is_flood[1]
159
  c_id = m.chat.id
160
  if split[1].lower() in on_key:
161
+ Flood.save_flood(m.chat.id, 5, 5, 'mute')
162
+ await m.reply_text("Flood protection has been started for this group.")
163
+ return
 
 
164
  if split[1].lower() in off_key:
165
+ Flood.rm_flood(c_id, slimit, swithin, saction)
166
  await m.reply_text("Flood protection has been stopped for this chat")
167
  return
168
  await m.reply_text("**Usage:**\n `/setflood on/off`")
169
  return
170
 
171
+ @Gojo.on_callback_query(filters.regex("^f_"))
172
  async def callbacks(c: Gojo, q: CallbackQuery):
173
  data = q.data
174
+ if data == "fclose":
175
  await q.answer("Closed")
176
  await q.message.delete()
177
  return
178
  c_id = q.message.chat.id
179
  is_flood = Flood.is_chat(c_id)
180
+ if is_flood:
181
+ saction = is_flood[2]
182
+ slimit = is_flood[0]
183
+ swithin = is_flood[1]
184
  user = q.from_user.id
185
  user_status = (await q.message.chat.get_member(q.from_user.id)).status
186
  if user in SUPPORT_STAFF or user_status in [CMS.OWNER, CMS.ADMINISTRATOR]:
187
+ if data in ["f_mute", "f_ban", "f_kick"]:
188
+ change = data.split("_")[1]
189
+ if not change == saction:
190
+ Flood.save_flood(c_id, slimit, swithin, change)
191
+ await q.answer("Updated action", show_alert=True)
192
+ await q.edit_message_caption(
193
+ f"Set the limit of message after the flood protection will be activated\n **CURRENT LIMIT** {slimit} messages",
194
+ reply_markup=limit_kb
195
+ )
196
+ return
197
+ else:
198
+ await q.answer("Updated action", show_alert=True)
199
+ await q.edit_message_caption(
200
+ f"Set the limit of message after the flood protection will be activated\n **CURRENT LIMIT** {slimit} messages",
201
+ reply_markup=limit_kb
202
+ )
203
+ elif data in ["f_5", "f_10", "f_15"]:
204
  change = int(data.split("_")[1])
205
+ if not change == slimit:
206
+ Flood.save_flood(c_id, change, swithin, saction)
207
+ await q.answer("Updated limit", show_alert=True)
208
+ await q.edit_message_caption(
209
+ f"Set the time with the number of message recived treated as flood\n **CUURENT TIME** {swithin}",
210
+ reply_markup=within_kb
211
+ )
212
+ return
213
+ else:
214
+ await q.answer("Updated action", show_alert=True)
215
+ await q.edit_message_caption(
216
+ f"Set the limit of message after the flood protection will be activated\n **CURRENT LIMIT** {slimit} messages",
217
+ reply_markup=limit_kb
218
+ )
219
+ elif data in ["f_f_5", "f_f_10", "f_f_15"]:
220
+ data = data.split("_")[-1]
221
  change = int(data)
222
+ if not change == swithin:
223
+ Flood.save_flood(c_id, slimit, change, saction)
224
+ await q.answer("Updated", show_alert=True)
225
+ await q.edit_message_caption(
226
+ "Flood protection setting has been updated",
227
+ reply_markup=close_kb
228
+ )
229
+ return
230
+ else:
231
+ await q.answer("Updated action", show_alert=True)
232
+ await q.edit_message_caption(
233
+ f"Set the limit of message after the flood protection will be activated\n **CURRENT LIMIT** {slimit} messages",
234
+ reply_markup=limit_kb
235
+ )
236
  else:
237
  await q.answer(
238
  "You don't have enough permission to do this!\nStay in your limits!",
 
431
  dic[c_id][u_id][1].clear()
432
  dic[c_id][u_id][0].clear()
433
  return
434
+ elif y-x > within:
435
+ try:
436
+ dic[c_id][u_id][1].clear()
437
+ dic[c_id][u_id][0].clear()
438
+ return
439
+ except Exception:
440
+ pass
441
  else:
442
  return
443
 
444
+
445
+ __PLUGIN__ = "flood"
446
+ __alt_name__ = [
447
+ "anit-flood",
448
+ "flood",
449
+ "spam",
450
+ "anti-spam",
451
+ ]
452
+ __HELP__ = """
453
+ **Anti Flood**
454
+ **User Commands:**
455
+ • /flood: to check weather the group is protected from spam or not.
456
+
457
+ **Admin only:**
458
+ • /setflood `on/off`: To activate or deactivate the flood protection
459
+ • /floodaction: To customize the flood settings.
460
+
461
+ **Example:**
462
+ `/setflood on`
463
+ """
464
+
Powers/plugins/search.py CHANGED
@@ -237,7 +237,7 @@ __alt_name__ = [
237
  __HELP__ = """
238
  **Search**
239
 
240
- **Admin only:**
241
  • /google `<query>` : Search the google for the given query.
242
  • /anime `<query>` : Search myanimelist for the given query.
243
  • /stack `<query>` : Search stackoverflow for the given query.
 
237
  __HELP__ = """
238
  **Search**
239
 
240
+ **Available commands:**
241
  • /google `<query>` : Search the google for the given query.
242
  • /anime `<query>` : Search myanimelist for the given query.
243
  • /stack `<query>` : Search stackoverflow for the given query.
Powers/utils/extras.py CHANGED
@@ -663,30 +663,4 @@ StartPic = [
663
  "https://te.legra.ph/file/1751252a9f0483811e9b9.jpg",
664
  "https://te.legra.ph/file/380b862e0248225cc1a45.jpg",
665
  "https://te.legra.ph/file/f314f89640ce4b4118e9e.jpg",
666
- "https://te.legra.ph/file/37423e9680e3f79c9eb15.jpg",
667
- "https://te.legra.ph/file/4a9c4663d0120cff7cc82.jpg",
668
- "https://te.legra.ph/file/56d72d125005a16dba7b8.jpg",
669
- "https://te.legra.ph/file/c10f1b32adaf93c1a9fe1.jpg",
670
- "https://te.legra.ph/file/68c607517cca7d08e8910.jpg",
671
- "https://te.legra.ph/file/c86855e6d5a5668748ce1.jpg",
672
- "https://te.legra.ph/file/b480c0989f1e4a9ea63c7.jpg",
673
- "https://te.legra.ph/file/4cdf315e2925d8b4ef6ae.jpg",
674
- "https://te.legra.ph/file/fe9c620d294f4f47f4350.jpg",
675
- "https://te.legra.ph/file/6d4ae604c118cb49ab7ed.jpg",
676
- "https://te.legra.ph/file/a7a78ff8d710583f28e72.jpg",
677
- "https://te.legra.ph/file/a7a78ff8d710583f28e72.jpg",
678
- "https://te.legra.ph/file/c74c4f4be365971311510.jpg",
679
- "https://te.legra.ph/file/23e0a389fb5df7900c686.jpg",
680
- "https://te.legra.ph/file/fc0557000a350267adc0d.jpg",
681
- "https://te.legra.ph/file/cd381fd6f9960555664f6.jpg",
682
- "https://te.legra.ph/file/322466833973279848e60.jpg",
683
- "https://te.legra.ph/file/122cf568eef282ad3472a.jpg",
684
- "https://te.legra.ph/file/cd6aa9cbe621c7c3a12ea.jpg",
685
- "https://te.legra.ph/file/83c61271b95fdf421a9a0.jpg",
686
- "https://te.legra.ph/file/2f27c940f5e912c01aa63.jpg",
687
- "https://te.legra.ph/file/43780c4a5c3071af3de3c.jpg",
688
- "https://te.legra.ph/file/68d18ae5b2a4b67e793a4.jpg",
689
- "https://te.legra.ph/file/633bd27c1607fe98920b6.jpg",
690
- "https://te.legra.ph/file/52d92a67f0c6ce0a9f89f.jpg",
691
- "https://te.legra.ph/file/d91e7353b3803a8148bfc.jpg",
692
  ]
 
663
  "https://te.legra.ph/file/1751252a9f0483811e9b9.jpg",
664
  "https://te.legra.ph/file/380b862e0248225cc1a45.jpg",
665
  "https://te.legra.ph/file/f314f89640ce4b4118e9e.jpg",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
666
  ]
requirements.txt CHANGED
@@ -4,7 +4,7 @@ anyio==3.6.2; python_full_version >= "3.6.2" and python_version >= "3.6"
4
  asyncio==3.4.3
5
  beautifulsoup4==4.11.1; python_full_version >= "3.6"
6
  cachetools==5.2.0; python_version >= "3.7" and python_version < "4.0"
7
- certifi==2022.6.15; python_version >= "3.7" and python_version < "4"
8
  charset-normalizer==2.1.0; python_version >= "3.7" and python_version < "4" and python_full_version >= "3.6.0"
9
  dnspython==2.2.1; python_version >= "3.6" and python_version < "4.0"
10
  google==3.0.0
 
4
  asyncio==3.4.3
5
  beautifulsoup4==4.11.1; python_full_version >= "3.6"
6
  cachetools==5.2.0; python_version >= "3.7" and python_version < "4.0"
7
+ certifi==2022.12.7; python_version >= "3.7" and python_version < "4"
8
  charset-normalizer==2.1.0; python_version >= "3.7" and python_version < "4" and python_full_version >= "3.6.0"
9
  dnspython==2.2.1; python_version >= "3.6" and python_version < "4.0"
10
  google==3.0.0