def test_impossible_throws_exception(): # not possible to fit this into one message of 30 length with pytest.raises(ValueError): split_into_chunks_with_prefix([{ "prefix": "TEST:", "parts": ["ABCDEFGHIJKLMNOPQRSTUVWXYZ"] }], limit=30)
def print_twitch_emotes(self, source, **rest): if self.settings["custom_sub_response"] != "": custom_message = self.settings["custom_sub_response"] self.bot.say( custom_message.format(streamer=StreamHelper.get_streamer(), source=source)) else: manager = self.bot.emote_manager.twitch_emote_manager messages = split_into_chunks_with_prefix( [ { "prefix": "Subscriber emotes:", "parts": [e.code for e in manager.tier_one_emotes] }, { "prefix": "T2:", "parts": [e.code for e in manager.tier_two_emotes] }, { "prefix": "T3:", "parts": [e.code for e in manager.tier_three_emotes] }, ], default= f"Looks like {StreamHelper.get_streamer()} has no subscriber emotes! :(", ) for message in messages: self.bot.say(message)
def test_basic(): expected = ["TEST: 1 2 3 4"] actual = split_into_chunks_with_prefix([{ "prefix": "TEST:", "parts": ["1", "2", "3", "4"] }]) assert actual == expected
def test_separator(): expected = ["TEST:KKona1KKona2KKona3KKona4"] actual = split_into_chunks_with_prefix([{ "prefix": "TEST:", "parts": ["1", "2", "3", "4"] }], separator="KKona") assert actual == expected
def test_default(): expected = ["KKona"] actual = split_into_chunks_with_prefix([{ "prefix": "TEST:", "parts": [] }], default="KKona") assert actual == expected
def print_emotes(self, manager): emotes = manager.channel_emotes messages = split_into_chunks_with_prefix( [{"prefix": "{} emotes:".format(manager.friendly_name), "parts": [e.code for e in emotes]}], default="No {} Emotes active in this chat :(".format(manager.friendly_name), ) for message in messages: self.bot.say(message)
def test_multiple_output_messages(): expected = ["TEST: ABC DEF GHI JKL MNO PQR", "TEST: STU VWX YZ"] actual = split_into_chunks_with_prefix([{ "prefix": "TEST:", "parts": ["ABC", "DEF", "GHI", "JKL", "MNO", "PQR", "STU", "VWX", "YZ"] }], limit=30) assert actual == expected
def print_emotes(self, source, manager): if self.settings[f"custom_{manager.friendly_name.lower()}_response"] != "": custom_message = self.settings[f"custom_{manager.friendly_name.lower()}_response"] self.bot.say(custom_message.format(streamer=StreamHelper.get_streamer_display(), source=source)) else: emotes = manager.channel_emotes messages = split_into_chunks_with_prefix( [{"prefix": f"{manager.friendly_name} emotes:", "parts": [e.code for e in emotes]}], default=f"No {manager.friendly_name} Emotes active in this chat :(", ) for message in messages: self.bot.say(message)
def print_twitch_emotes(self, **rest): manager = self.bot.emote_manager.twitch_emote_manager messages = split_into_chunks_with_prefix( [ {"prefix": "Subscriber emotes:", "parts": [e.code for e in manager.tier_one_emotes]}, {"prefix": "T2:", "parts": [e.code for e in manager.tier_two_emotes]}, {"prefix": "T3:", "parts": [e.code for e in manager.tier_three_emotes]}, ], default="Looks like {} has no subscriber emotes! :(".format(StreamHelper.get_streamer()), ) for message in messages: self.bot.say(message)
def test_chunk_boundary_at_message_boundary(): expected = ["TEST: ABC DEF GHI JKL MNO PQR", "XD: STU VWX YZ"] actual = split_into_chunks_with_prefix( [ { "prefix": "TEST:", "parts": ["ABC", "DEF", "GHI", "JKL", "MNO", "PQR"] }, { "prefix": "XD:", "parts": ["STU", "VWX", "YZ"] }, ], limit=30, ) assert actual == expected
def test_multiple_chunks_in_same_messages(): expected = ["TEST: ABC DEF GHI JKL MNO PQR XD: STU VWX YZ"] actual = split_into_chunks_with_prefix( [ { "prefix": "TEST:", "parts": ["ABC", "DEF", "GHI", "JKL", "MNO", "PQR"] }, { "prefix": "XD:", "parts": ["STU", "VWX", "YZ"] }, ], limit=500, ) assert actual == expected
def test_no_parts(): expected = [] actual = split_into_chunks_with_prefix([{"prefix": "TEST:", "parts": []}]) assert actual == expected
def cmd_module(bot, source, message, **options): module_manager = bot.module_manager if not message: return msg_args = message.split(" ") if len(msg_args) < 1: return sub_command = msg_args[0].lower() if sub_command == "list": messages = split_into_chunks_with_prefix( [{"prefix": "Available modules:", "parts": [module.ID for module in module_manager.all_modules]}], " ", default="No modules available.", ) for message in messages: bot.say(message) elif sub_command == "disable": if len(msg_args) < 2: return module_id = msg_args[1].lower() module = module_manager.get_module(module_id) if not module: bot.say(f"No module with the id {module_id} found") return if module.MODULE_TYPE > ModuleType.TYPE_NORMAL: bot.say(f"Unable to disable module {module_id}") return if not module_manager.disable_module(module_id): bot.say(f"Unable to disable module {module_id}, maybe it's not enabled?") return # Rebuild command cache bot.commands.rebuild() with DBManager.create_session_scope() as db_session: db_module = db_session.query(Module).filter_by(id=module_id).one() db_module.enabled = False AdminLogManager.post("Module toggled", source, "Disabled", module_id) bot.say(f"Disabled module {module_id}") elif sub_command == "enable": if len(msg_args) < 2: return module_id = msg_args[1].lower() module = module_manager.get_module(module_id) if not module: bot.say(f"No module with the id {module_id} found") return if module.MODULE_TYPE > ModuleType.TYPE_NORMAL: bot.say(f"Unable to enable module {module_id}") return if not module_manager.enable_module(module_id): bot.say(f"Unable to enable module {module_id}, maybe it's already enabled?") return # Rebuild command cache bot.commands.rebuild() with DBManager.create_session_scope() as db_session: db_module = db_session.query(Module).filter_by(id=module_id).one() db_module.enabled = True AdminLogManager.post("Module toggled", source, "Enabled", module_id) bot.say(f"Enabled module {module_id}")