|
24 | 24 | #Init |
25 | 25 | discord.VoiceClient.warn_nacl = False |
26 | 26 | load_dotenv() |
27 | | -BOT_VERSION = '1.7.1' |
| 27 | +BOT_VERSION = '1.7.2' |
28 | 28 | APP_FOLDER_NAME = 'AutoPublisher' |
29 | 29 | BOT_NAME = 'AutoPublisher' |
30 | 30 | if not os.path.exists(f'{APP_FOLDER_NAME}//Logs'): |
@@ -226,15 +226,20 @@ async def __wrong_selection(): |
226 | 226 | 'status - Set the status of the bot\n' |
227 | 227 | '```') |
228 | 228 |
|
| 229 | + channel = message.channel |
| 230 | + permissions = channel.permissions_for(channel.guild.me) |
| 231 | + |
229 | 232 | if message.author == bot.user: |
230 | 233 | return |
231 | 234 | if ( |
232 | 235 | message.channel.type == discord.ChannelType.news |
233 | 236 | and message.type not in NON_PUBLISHABLE_MESSAGE_TYPES |
| 237 | + and permissions.send_messages |
| 238 | + and permissions.manage_messages |
234 | 239 | and not message.flags.crossposted |
235 | 240 | and not message.flags.is_crossposted |
236 | 241 | ): |
237 | | - await Functions.auto_publish(message) |
| 242 | + await Functions.auto_publish(message, channel, permissions) |
238 | 243 | if message.guild is None and message.author.id == int(OWNERID): |
239 | 244 | args = message.content.split(' ') |
240 | 245 | program_logger.debug(args) |
@@ -343,50 +348,36 @@ async def __health_check(request): |
343 | 348 | except OSError as e: |
344 | 349 | program_logger.warning(f'Error while starting health server: {e}') |
345 | 350 |
|
346 | | - async def auto_publish(message: discord.Message, retries: int = 3): |
347 | | - channel = message.channel |
348 | | - permissions = channel.permissions_for(channel.guild.me) |
349 | | - |
350 | | - if permissions.add_reactions: |
| 351 | + async def auto_publish(message: discord.Message, channel: discord.TextChannel, permissions: discord.Permissions, retries: int = 3): |
| 352 | + if permissions.add_reactions and retries == 3: |
351 | 353 | await message.add_reaction("\U0001F4E2") # 📢 |
352 | 354 |
|
353 | | - if permissions.send_messages and permissions.manage_messages: |
354 | | - try: |
355 | | - await message.publish() |
356 | | - |
357 | | - except discord.HTTPException as e: |
358 | | - if e.code == 50068: |
359 | | - discord_logger.info(f"Message {message.id} in channel {channel.id} on guild {message.guild.id} is not an announcement message. (Type {message.type.value})") |
360 | | - elif e.code == 40033: |
361 | | - discord_logger.info(f"Message {message.id} in channel {channel.id} on guild {message.guild.id} is already published.") |
362 | | - elif e.status == 503 and e.code == 0: |
363 | | - if retries > 0: |
364 | | - discord_logger.info(f"Discord is currently unavailable. Retrying to publish message {message.id} in channel {channel.id} on guild {message.guild.id}. Retries left: {retries}") |
365 | | - await asyncio.sleep(5) |
366 | | - await Functions.auto_publish(message, retries=retries - 1) |
367 | | - return |
368 | | - else: |
369 | | - discord_logger.warning(f"Failed to publish message {message.id} in channel {channel.id} on guild {message.guild.id} after retries.") |
| 355 | + try: |
| 356 | + await message.publish() |
| 357 | + except discord.HTTPException as e: |
| 358 | + if e.code == 50068: |
| 359 | + discord_logger.info(f"Message {message.id} in channel {channel.id} on guild {message.guild.id} is not an announcement message. (Type {message.type.value})") |
| 360 | + elif e.code == 40033: |
| 361 | + discord_logger.info(f"Message {message.id} in channel {channel.id} on guild {message.guild.id} is already published.") |
| 362 | + elif e.status == 503 and e.code == 0: |
| 363 | + if retries > 0: |
| 364 | + discord_logger.info(f"Discord is currently unavailable. Retrying to publish message {message.id} in channel {channel.id} on guild {message.guild.id}. Retries left: {retries}") |
| 365 | + await asyncio.sleep(5) |
| 366 | + await Functions.auto_publish(message, channel, permissions, retries=retries - 1) |
| 367 | + return |
370 | 368 | else: |
371 | | - raise |
372 | | - |
373 | | - except discord.NotFound: |
374 | | - discord_logger.info(f"Message {message.id} in channel {channel.id} on guild {message.guild.id} not found.") |
375 | | - |
376 | | - except Exception as e: |
377 | | - if not message.flags.crossposted: |
378 | | - discord_logger.error(f"Error publishing message in {channel.id} on {message.guild.id}: {e}") |
379 | | - if permissions.add_reactions: |
380 | | - await message.add_reaction("\u26A0") # ⚠️ |
381 | | - |
382 | | - finally: |
383 | | - await message.remove_reaction("\U0001F4E2", bot.user) |
384 | | - |
385 | | - else: |
386 | | - discord_logger.info(f"No permission to publish in {channel.id} on guild {message.guild.id}.") |
| 369 | + discord_logger.warning(f"Failed to publish message {message.id} in channel {channel.id} on guild {message.guild.id} after retries.") |
| 370 | + else: |
| 371 | + raise |
| 372 | + except discord.NotFound: |
| 373 | + discord_logger.info(f"Message {message.id} in channel {channel.id} on guild {message.guild.id} not found.") |
| 374 | + except Exception as e: |
| 375 | + if not message.flags.crossposted: |
| 376 | + discord_logger.error(f"Error publishing message in {channel.id} on {message.guild.id}: {e}") |
| 377 | + if permissions.add_reactions: |
| 378 | + await message.add_reaction("\u26A0") # ⚠️ |
| 379 | + finally: |
387 | 380 | await message.remove_reaction("\U0001F4E2", bot.user) |
388 | | - if permissions.add_reactions: |
389 | | - await message.add_reaction("\u26D4") # ⛔ |
390 | 381 |
|
391 | 382 | async def create_support_invite(interaction): |
392 | 383 | try: |
|
0 commit comments