lunarflu HF Staff commited on
Commit
975c25e
·
verified ·
1 Parent(s): a6e7992

test only log channels visible to @members

Browse files
Files changed (1) hide show
  1. app.py +25 -1
app.py CHANGED
@@ -38,7 +38,7 @@ logging.basicConfig(level=logging.DEBUG)
38
  message_cache = {}
39
 
40
 
41
-
42
 
43
 
44
 
@@ -55,6 +55,15 @@ number_of_messages = 0
55
  user_cooldowns = {}
56
 
57
 
 
 
 
 
 
 
 
 
 
58
  def extract_youtube_video_id(url):
59
  match = re.search(r"(?:youtu\.be/|youtube\.com/watch\?v=)([a-zA-Z0-9_-]{11})", url)
60
  return match.group(1) if match else None
@@ -74,6 +83,11 @@ async def on_message(message):
74
  try:
75
  global number_of_messages
76
  if message.author != bot.user:
 
 
 
 
 
77
  message_cache[message.id] = message
78
  lunarflu = bot.get_user(811235357663297546)
79
 
@@ -224,6 +238,10 @@ async def on_message_edit(before, after):
224
  try:
225
  if before.author == bot.user:
226
  return
 
 
 
 
227
 
228
  if before.content != after.content:
229
  embed = Embed(color=Color.orange())
@@ -262,6 +280,12 @@ async def on_raw_message_delete(payload):
262
  if message:
263
  if message.author == bot.user:
264
  return
 
 
 
 
 
 
265
 
266
  embed = Embed(color=Color.red())
267
  embed.set_author(name=f"{message.author} ID: {message.author.id}", icon_url=message.author.avatar.url if message.author.avatar else bot.user.avatar.url)
 
38
  message_cache = {}
39
 
40
 
41
+ MEMBER_ROLE_ID = 1346237573168894063
42
 
43
 
44
 
 
55
  user_cooldowns = {}
56
 
57
 
58
+ #test
59
+ def is_visible_to_member_role(channel, guild):
60
+ role = guild.get_role(MEMBER_ROLE_ID)
61
+ if not role:
62
+ return False
63
+ perms = channel.permissions_for(role)
64
+ return perms.view_channel
65
+
66
+
67
  def extract_youtube_video_id(url):
68
  match = re.search(r"(?:youtu\.be/|youtube\.com/watch\?v=)([a-zA-Z0-9_-]{11})", url)
69
  return match.group(1) if match else None
 
83
  try:
84
  global number_of_messages
85
  if message.author != bot.user:
86
+
87
+ if not is_visible_to_member_role(message.channel, message.guild):
88
+ return # skip logging if @member role can't view the channel
89
+
90
+
91
  message_cache[message.id] = message
92
  lunarflu = bot.get_user(811235357663297546)
93
 
 
238
  try:
239
  if before.author == bot.user:
240
  return
241
+
242
+
243
+ if not is_visible_to_member_role(before.channel, before.guild):
244
+ return
245
 
246
  if before.content != after.content:
247
  embed = Embed(color=Color.orange())
 
280
  if message:
281
  if message.author == bot.user:
282
  return
283
+
284
+ channel = bot.get_channel(payload.channel_id)
285
+ guild = bot.get_guild(payload.guild_id)
286
+ if channel and guild:
287
+ if not is_visible_to_member_role(channel, guild):
288
+ return
289
 
290
  embed = Embed(color=Color.red())
291
  embed.set_author(name=f"{message.author} ID: {message.author.id}", icon_url=message.author.avatar.url if message.author.avatar else bot.user.avatar.url)