예제 #1
0
 def get_options():
     db: Session = self.cfeed.service.get_session()
     _options = dOpt.mapper_index_withAdditional(
         self.cfeed.discord_client, message_object)
     _options.set_main_header(
         "Remove an entity from being tracked in this feed:")
     try:
         for pilot in db.query(tb_Filter_characters).filter(
                 tb_Filter_characters.channel_id ==
                 self.cfeed.channel_id).all():
             _options.add_option(
                 dOpt.option_returns_object(
                     name=pilot.object_item.get_name(),
                     return_object=pilot))
         for corp in db.query(tb_Filter_corporations).filter(
                 tb_Filter_corporations.channel_id ==
                 self.cfeed.channel_id).all():
             _options.add_option(
                 dOpt.option_returns_object(
                     name=corp.object_item.get_name(),
                     return_object=corp))
         for ali in db.query(tb_Filter_alliances).filter(
                 tb_Filter_alliances.channel_id ==
                 self.cfeed.channel_id).all():
             _options.add_option(
                 dOpt.option_returns_object(
                     name=ali.object_item.get_name(),
                     return_object=ali))
     except Exception as ex:
         print(ex)
     finally:
         db.close()
         return _options
예제 #2
0
    async def InsightOptionRequired_tracktype(self, message_object:discord.Message):
        """Show losses/kills  - Set the feed to one of three modes for tracked entities: show losses only, show kills only, show both kills and losses"""
        def set_mode(option):
            db:Session = self.cfeed.service.get_session()
            try:
                __row: tb_enfeed = db.query(tb_enfeed).filter(tb_enfeed.channel_id == self.cfeed.channel_id).one()
                __row.show_mode = option
                db.merge(__row)
                db.commit()
            except Exception as ex:
                print(ex)
                raise InsightExc.Db.DatabaseError
            finally:
                db.close()

        __options = dOpt.mapper_index_withAdditional(self.cfeed.discord_client, message_object)
        __options.set_main_header("Select the KM viewing mode for this entity feed.")
        __options.add_option(dOpt.option_returns_object(
            name="Show losses only   - Only losses involving your tracked entities will be posted",
            return_object=enum_kmType.losses_only))
        __options.add_option(dOpt.option_returns_object(
            name="Show kills only   - Only kills where your tracked entities were attackers will be posted",
            return_object=enum_kmType.kills_only))
        __options.add_option(dOpt.option_returns_object(
            name="Show kills and losses   - Both kills and losses involving feed tracked entities will be posted",
            return_object=enum_kmType.show_both))
        __selected_option = await __options()
        await self.cfeed.discord_client.loop.run_in_executor(None, partial(set_mode, __selected_option))
        await self.reload(message_object)
예제 #3
0
 def test__current_option_index(self):
     self.assertEqual(0, self.options._current_option_index())
     self.options.add_header_row("Header")
     self.assertEqual(0, self.options._current_option_index())
     self.options.add_option(option_returns_object("Item 1", "item", 1))
     self.assertEqual(1, self.options._current_option_index())
     self.options.add_option(option_returns_object("Item 2", "item", 1))
     self.assertEqual(2, self.options._current_option_index())
예제 #4
0
 def header_make(row_list: List[tb_alliances], header_text):
     if len(row_list) > 0:
         __options.add_header_row(header_text)
         for i in row_list:
             __options.add_option(
                 dOpt.option_returns_object(name=i.get_name(),
                                            return_object=i))
예제 #5
0
파일: Base_Feed.py 프로젝트: evidex/Insight
    async def InsightOptionRequired_setAppearance(
            self, message_object: discord.Message):
        """Change visual appearance - Set the visual appearance of rich embeds."""
        def set_appearance(app_id):
            db: Session = self.cfeed.service.get_session()
            try:
                __row: tb_channels = db.query(tb_channels).filter(
                    tb_channels.channel_id == self.cfeed.channel_id).one()
                __row.appearance_id = app_id
                db.merge(__row)
                db.commit()
            except Exception as ex:
                print(ex)
                raise InsightExc.Db.DatabaseError
            finally:
                db.close()

        _options = dOpt.mapper_index_withAdditional(self.cfeed.discord_client,
                                                    message_object)
        _options.set_main_header(
            "Select a rich embed appearance. Appearances allow you to select a template for "
            "killmail presentation and differ in verbosity, size, and the amount of information "
            "provided. See https://github.com/Nathan-LS/Insight/wiki/Rich-Embed-Appearance for "
            "sample previews of each appearance. Note: appearances can be changed after feed "
            "creation by running the '!settings' command.")
        for ap in self.cfeed.linked_visual_base().appearance_options():
            _options.add_option(
                dOpt.option_returns_object(name=ap.get_desc(),
                                           return_object=ap.appearance_id()))
        a_id = await _options()
        await self.cfeed.discord_client.loop.run_in_executor(
            None, partial(set_appearance, a_id))
        await self.reload(message_object)
예제 #6
0
 def test_response_action(self):
     with self.subTest("Returns object"):
         self.options.add_option(option_returns_object("1", "", 5))
         self.assertEqual(5, self.loop.run_until_complete(self.options.response_action("0")))
     with self.subTest("Calls coro"):
         self.assertEqual(0, self.counter)
         self.options.add_option(option_calls_coroutine("1", "", self.set_counter()))
         self.loop.run_until_complete(self.options.response_action("1"))
         self.assertEqual(55, self.counter)
예제 #7
0
파일: Base_Feed.py 프로젝트: evidex/Insight
 async def InsightOption_setMention(self, message_object: discord.Message):
     """Set overall mention mode - Select the mention mode for any killmail posted to this feed."""
     options = dOpt.mapper_index(self.cfeed.discord_client, message_object)
     options.set_main_header(
         "Select the mention mode for this feed. Any killmail posted to this feed can optionally "
         "mention Discord channel users.")
     options.add_option(
         dOpt.option_returns_object("No mention",
                                    return_object=enum_mention.noMention))
     options.add_option(
         dOpt.option_returns_object("@ here",
                                    return_object=enum_mention.here))
     options.add_option(
         dOpt.option_returns_object("@ everyone",
                                    return_object=enum_mention.everyone))
     row = await self.get_cached_copy()
     row.mention = await options()
     await self.save_row(row)
     await self.reload(message_object)
예제 #8
0
 def test_add_option(self):
     for i in range(0, 401):
         if random.choice([True, False]):
             opt = option_returns_object("option", "desc", 1)
         else:
             opt = option_calls_coroutine("test coro", "test", None)
         self.options.add_option(opt)
         self.assertEqual(i+1, self.options._current_option_index())
         self.assertTrue(opt in self.options._option_container)
     with self.assertRaises(InsightExc.userInput.TooManyOptions):
         self.options.add_option(option_calls_coroutine("test coro", "test", None))
예제 #9
0
 def test_add_header_row(self):
     self.options.add_header_row("New header")
     self.assertEqual(1, len(self.options.e_header_container))
     self.assertEqual(0, self.options.header_index)
     self.options.add_header_row("New header 2")  # no body items so we overwrite tbe previous header
     self.assertEqual(1, len(self.options.e_header_container))
     self.assertEqual(0, self.options.header_index)
     with self.subTest("Adding body items"):
         self.options.add_option(option_returns_object("Item 1", "item", 1))
         self.options.add_header_row("Header 3")
         self.assertEqual(2, len(self.options.e_header_container))
         self.assertEqual(1, self.options.header_index)
예제 #10
0
        def make_options(search_str) -> dOpt.mapper_index:
            __options = dOpt.mapper_index_withAdditional(self.cfeed.discord_client, message_object)
            __options.set_main_header("Select the entity you wish to add.")
            db: Session = self.cfeed.service.get_session()

            def header_make(row_list:List[tb_alliances],header_text):
                if len(row_list) > 0:
                    __options.add_header_row(header_text)
                    for i in row_list:
                        __options.add_option(dOpt.option_returns_object(name=i.get_name(), return_object=i))
            try:
                header_make(db.query(tb_alliances).filter(tb_alliances.alliance_name.ilike("%{}%".format(search_str))).all(),"Alliances")
                header_make(db.query(tb_corporations).filter(tb_corporations.corporation_name.ilike("%{}%".format(search_str))).all(),"Corporations")
                header_make(db.query(tb_characters).filter(tb_characters.character_name.ilike("%{}%".format(search_str))).all(),"Pilots")
                __options.add_header_row("Additional Options")
                __options.add_option(dOpt.option_returns_object("Search again", return_object=None))
            except Exception as ex:
                print(ex)
                db.rollback()
            finally:
                db.close()
                return __options
예제 #11
0
        def make_options(search_str) -> dOpt.mapper_index:
            __options = dOpt.mapper_index_withAdditional(self.cfeed.discord_client, message_object)
            __options.set_main_header(
                "Select the entity you wish to add.\nNote: Additional entities can be added or removed after feed creation by running the ‘!settings’ command.")
            db: Session = self.cfeed.service.get_session()

            def header_make(row_list:List[tb_alliances],header_text):
                if len(row_list) > 0:
                    __options.add_header_row(header_text)
                    for i in row_list:
                        __options.add_option(dOpt.option_returns_object(name=i.get_name(), return_object=i))
            try:
                header_make(SearchHelper.search(db, tb_alliances, tb_alliances.alliance_name, search_str), "Alliances")
                header_make(SearchHelper.search(db, tb_corporations, tb_corporations.corporation_name, search_str), "Corporations")
                header_make(SearchHelper.search(db, tb_characters, tb_characters.character_name, search_str),"Pilots")
                __options.add_header_row("Additional Options")
                __options.add_option(dOpt.option_returns_object("Search again", return_object=None))
                return __options
            except Exception as ex:
                raise ex
            finally:
                db.close()
예제 #12
0
 def setUp(self):
     super().setUp()
     self.client = DiscordInsightClient.DiscordInsightClient()
     message = Message(TextChannel(1, 1), User(1, "TestUser"), "This is the start of a command message.")
     self.options = mapper_index(self.client, message, timeout_seconds=1)
     self.options.add_option(option_returns_object("1", "", 1))
예제 #13
0
 def test_get_option(self):
     opt = option_returns_object("1", "1", 1)
     self.options.add_option(opt)
     self.assertEqual(opt, self.options.get_option(0))
예제 #14
0
 def test_check_response(self):
     self.options.add_option(option_returns_object("Item", "", 5))
     for invalid_option in ["1", "2", "-1", "zero"]:
         with self.assertRaises(InsightExc.userInput.InvalidIndex):
             self.loop.run_until_complete(self.options.check_response(invalid_option))
     self.loop.run_until_complete(self.options.check_response("0"))
예제 #15
0
 def test_check_conditions(self):
     self.options.add_option(option_returns_object("test", "", 1))
     self.loop.run_until_complete(self.options.check_conditions())