Пример #1
0
 def can_embed(self, d_message: discord.Message):
     can_embed = DiscordPermissionCheck.can_embed(d_message)
     if self.embed_only and not can_embed:
         raise InsightExc.DiscordError.DiscordPermissions("Insight is lacking the **embed links** and **send "
                                                          "messages** roles in this channel. You must enable "
                                                          "these roles to use this command.")
     return can_embed
Пример #2
0
 async def __call__(self, *args, **kwargs):
     if self.send_attempt_count >= 5:
         raise InsightExc.DiscordError.MessageMaxRetryExceed
     else:
         self.send_attempt_count += 1
         if self.text_only:
             if DiscordPermissionCheck.can_text(self.channel):
                 await self.channel.send(content=self.message_txt)
             else:
                 raise InsightExc.DiscordError.DiscordPermissions
         else:
             if DiscordPermissionCheck.can_embed(self.channel):
                 await self.channel.send(content=self.message_txt,
                                         embed=self.embed)
             else:
                 raise InsightExc.DiscordError.DiscordPermissions
Пример #3
0
 async def __call__(self, *args, **kwargs):
     if self.get_seconds_since_last_modify() >= 25:
         await self.refresh_visual()
     if self.send_attempt_count >= 5:
         raise InsightExc.DiscordError.MessageMaxRetryExceed
     else:
         self.send_attempt_count += 1
         if self.text_only:
             if DiscordPermissionCheck.can_text(self.channel):
                 async with (await LimitManager.cm(self.channel)):
                     await self.channel.send(content=self.message_txt)
             else:
                 raise InsightExc.DiscordError.DiscordPermissions
         else:
             if DiscordPermissionCheck.can_embed(self.channel):
                 async with (await LimitManager.cm(self.channel)):
                     await self.channel.send(content=self.message_txt,
                                             embed=self.embed)
             else:
                 raise InsightExc.DiscordError.DiscordPermissions
Пример #4
0
 def can_text(self, d_message: discord.Message):
     return DiscordPermissionCheck.can_text(d_message)
Пример #5
0
 async def post_all(self):
     while self.channel_manager.exists(self):
         try:
             mitem = await asyncio.wait_for(self.kmQueue.async_q.get(),
                                            timeout=3600)
         except asyncio.TimeoutError:
             continue
         except asyncio.CancelledError:
             break
         except Exception as ex:
             print(ex)
             traceback.print_exc()
             continue
         try:
             async with self.lock:
                 if self.cached_feed_table.feed_running and self.channel_manager.exists(
                         self):
                     st = InsightLogger.InsightLogger.time_start()
                     if isinstance(mitem, base_visual):
                         await mitem()
                         if mitem.send_attempt_count <= 1:
                             await self.channel_manager.add_delay(
                                 mitem.get_load_time())
                     else:
                         async with (await LimitManager.cm_hp(
                                 self.channel_discord_object)):
                             await self.channel_discord_object.send(
                                 str(mitem))
                     InsightLogger.InsightLogger.time_log(
                         self.logger, st, 'Send message/KM')
         except InsightExc.DiscordError.QueueDelayInvalidatesFilter:
             self.logger.info(
                 'Mail removed after failing filter recheck for being in the queue too long. '
                 '{}'.format(mitem.debug_info()))
             continue
         except InsightExc.DiscordError.DiscordPermissions:
             try:
                 self.log_mail_error.info(
                     "Permissions missing for mail. KM INFO: {}".format(
                         mitem.debug_info()))
                 await mitem.requeue(self.kmQueue)
                 if DiscordPermissionCheck.can_text(
                         self.channel_discord_object):
                     async with (await LimitManager.cm_hp(
                             self.channel_discord_object)):
                         await self.channel_discord_object.send(
                             "Insight attempted to post killmail ID: {} but there was an issue with permissions. "
                             "\n\nEnsure Insight has the embed links and send messages permissions for this channel.\n"
                             "See https://github.com/Nathan-LS/Insight#permissions\n\nRun the '!start' command to "
                             "resume the feed once permissions are correctly set."
                             .format(mitem.km_id))
             except:
                 print(traceback.print_exc())
             finally:
                 await self.remove()
         except discord.HTTPException as ex:
             try:
                 if isinstance(mitem, base_visual):
                     self.log_mail_error.info(
                         'Status: {} Code: {} Text: {}. KM Debug info: {}'.
                         format(ex.status, ex.code, ex.text,
                                mitem.debug_info()))
                 else:
                     self.logger.warning(
                         'Status: {} Code: {} Text: {}. MESSAGE TO SEND: {}'
                         .format(ex.status, ex.code, ex.text, mitem))
                 if ex.status == 404:  # channel deleted
                     await self.channel_manager.delete_feed(self.channel_id)
                 elif 500 <= ex.status < 600:
                     if isinstance(mitem, base_visual):
                         await mitem.requeue(self.kmQueue)
                 else:
                     pass
             except Exception as ex:
                 print(ex)
         except InsightExc.DiscordError.MessageMaxRetryExceed:
             self.log_mail_error.info(
                 'Max message retry limit exceeded when sending KM. KM INFO: {}'
                 .format(mitem.debug_info()))
             continue
         except OSError as ex:
             self.logger.warning(str(ex))
             if ex.errno == errno.ECONNRESET or ex.errno == errno.ENETRESET:
                 if isinstance(mitem, base_visual):
                     await mitem.requeue(self.kmQueue)
             else:
                 if isinstance(mitem, base_visual):
                     self.log_mail_error.error(
                         'Error {} - when sending KM. OSError. KM INFO: {}'.
                         format(ex, mitem.debug_info()))
         except Exception as ex:
             if isinstance(mitem, base_visual):
                 self.log_mail_error.error(
                     'Error {} - when sending KM. Other. KM INFO: {}'.
                     format(ex, mitem.debug_info()))
             self.logger.exception(ex)
         mitem = None  # remove reference
         await asyncio.sleep(.2)