def __init__(self, botname, owner, client_id, token): self.host = "irc.chat.twitch.tv" self.port = 6667 self.username = botname.lower() self.client_id = client_id self.token = token self.channel = f"#{owner}" self.botname = botname self.prefix = "!" self.bot_owner = User(owner, MOD_LEVEL_OWNER) self.cmds = { "hello": self.hello, "friendcode": self.friendcode, "add": self.add, "github": self.github, "list": self.list_levels, "current": self.current_level, "currentlevel": self.current_level, "leave": self.leave, "clear": self.clear, "habits": self.habits, "timer": self.timer, "queue": self.list_levels, "help": self.help, } self.mod_cmds = { "nextlevel": self.next_level, "next": self.next_level, "mod": self.mod, "unmod": self.unmod, "remove": self.remove, "random": self.random, "finish": self.finish, "adduser": self.adduser, } url = f"https://api.twitch.tv/kraken/users?login={self.username}" headers = { "Client-ID": self.client_id, "Accept": "application/vnd.twitchtv.v5+json", } resp = get(url, headers=headers).json() self.channel_id = resp["users"][0]["_id"] self.cmdprocessor = Processor(self.bot_owner) super().__init__( [(self.host, self.port, f"oauth:{self.token}")], self.username, self.username, )
def __init__(self): self.test_owner = User("test_owner", MOD_LEVEL_OWNER) self.test_processor = Processor(self.test_owner) self.TEST_USER_A = "userA" self.TEST_USER_B = "userB" self.TEST_USER_C = "userC" self.LEVEL_INPUT_A = "aaa-aaa-aaa" self.LEVEL_EXPECTED_A = "AAA-AAA-AAA" self.LEVEL_INPUT_B = "bbb-bbb-bbb" self.LEVEL_EXPECTED_B = "BBB-BBB-BBB" self.LEVEL_INPUT_C = "ccc ccc ccc" self.LEVEL_EXPECTED_C = "CCC-CCC-CCC" self.LEVEL_INPUT_D = "ddd ddd ddd" self.LEVEL_EXPECTED_D = "DDD-DDD-DDD" self.LEVEL_INPUT_MULTIPLE_AB = "aaa aaa aaa bbb bbb bbb" self.LEVEL_INPUT_MULTIPLE_AB_EXPECTED = ["AAA-AAA-AAA", "BBB-BBB-BBB"] self.LEVEL_INPUT_MULTIPLE_BC = "bbb bbb bbb ccc ccc ccc" self.LEVEL_INPUT_MULTIPLE_BC_EXPECTED = ["BBB-BBB-BBB", "CCC-CCC-CCC"] self.LEVEL_INPUT_MULTIPLE_ABC = "aaa aaa aaa bbb bbb bbb ccc ccc ccc" self.LEVEL_INPUT_MULTIPLE_ABC_EXPECTED = [ "AAA-AAA-AAA", "BBB-BBB-BBB", "CCC-CCC-CCC", ] self.LEVEL_INPUT_MULTIPLE_BCD = "bbb bbb bbb ccc ccc ccc ddd ddd ddd" self.LEVEL_INPUT_MULTIPLE_BCD_EXPECTED = [ "BBB-BBB-BBB", "CCC-CCC-CCC", "DDD-DDD-DDD", ] self.LEVEL_INPUT_MULTIPLE_ABCD = ( "aaa aaa aaa bbb bbb bbb ccc ccc ccc ddd ddd ddd") self.LEVEL_INPUT_MULTIPLE_AA = "aaa aaa aaa aaa aaa aaa" self.LEVEL_INPUT_MULTIPLE_ABB = "aaa aaa aaa bbb bbb bbb bbb bbb bbb" self.LEVEL_INPUT_MULTIPLE_ABA = "aaa aaa aaa bbb bbb bbb aaa aaa aaa" self.LEVEL_INVALID_ONE = "abc-def-gh" self.LEVEL_INVALID_TWO = "aaa-aaa-aaa aaa aaa aai" self.LEVEL_INVALID_THREE_MIDDLE = "aaa-aaa-aaa bbb bbb bbi ccc ccc ccc" self.LEVEL_INVALID_THREE_MIDDLE_END = "aaa aaa aaa bbb bbb bbi ccc ccc cci" self.TEST_TIME = "1" self.TEST_TIME_ENGLISH = "1 minute"
def test_user_has_level_works(self): thelevel = Level("abc-def-ghd") theuser = User("userA") theuser.add_level(thelevel) does_not_have_level = Level("abc-def-ghh") self.assertEqual(theuser.has_level(thelevel), True) self.assertEqual(theuser.has_level(does_not_have_level), False)
def execute(self): if self.caller_user != self.processor.current_owner: return self.fail_mod_not_owner() if not self.user_to_mod: return self.fail_mod_none_specified() for user in self.processor.users: if user == self.user_to_mod: user.make_mod() return self.success_mod(user) modded_user = User(self.user_to_mod, MOD_LEVEL_MOD) self.processor.users.append(modded_user) return self.success_mod(modded_user)
def execute(self): levels = create_levels(self.levelcode) if not levels: return self.fail_add_user_level_invalid_code( self.invoker_name, self.levelcode ) for level in levels: for processed_user in self.processor.users: if processed_user.has_level(level): return self.fail_add_user_level_duplicate_code( self.invoker_name, level, processed_user ) levels = self.remove_duplicates(levels) foundUser = False for processed_user in self.processor.users: if processed_user == self.level_submitter: foundUser = True if self.levels_would_make_us_exceed_limit(levels, processed_user): return self.fail_add_user_level_level_limit(self.invoker_name) for level in levels: processed_user.add_level(level) return self.success_add_user_level(processed_user, levels) if not foundUser: foundUser = User(self.level_submitter) if self.levels_would_make_us_exceed_limit(levels, foundUser): return self.fail_add_user_level_level_limit(self.invoker_name) for level in levels: foundUser.add_level(level) self.processor.users.append(foundUser) return self.success_add_user_level(foundUser, levels)
def test_user_has_levels_with_levels(self): user = User("userA") user.add_level("123-123-123") self.assertEqual(user.has_levels(), True)
def test_user_has_levels_empty(self): user = User("userA") self.assertEqual(user.has_levels(), False)
def test_user_can_be_unmodded(self): theuser = User("userA", MOD_LEVEL_MOD) theuser.make_user() self.assertEqual(theuser.modlevel, MOD_LEVEL_USER)
def test_user_has_user_name(self): theuser = User("userA") self.assertEqual(theuser.username, "userA")
def test_user_can_be_mod_level_user(self): theuser = User("moderator", MOD_LEVEL_USER) self.assertEqual(theuser.mod_level(), MOD_LEVEL_USER)
def test_users_can_have_multiple_levels(self): levelOne = Level("abc-def-ghd") theuser = User("userA") theuser.add_level(levelOne) levelTwo = Level("aaa-bbb-ccc") theuser.add_level(levelTwo) self.assertEqual(str(theuser.next_level()), str(levelOne)) theuser.remove_level() self.assertEqual(str(theuser.next_level()), str(levelTwo)) theuser.remove_level() self.assertEqual(theuser.next_level(), None)
def test_user_can_remove_level(self): thelevel = Level("xxx-xxx-xxx") theuser = User("userA") theuser.add_level(thelevel) theuser.remove_level() self.assertEqual(theuser.next_level(), None)
def test_user_level_is_formatted(self): thelevel = Level("xxx-xxx-xxx") theuser = User("userA") theuser.add_level(thelevel) self.assertEqual(str(theuser.next_level()), "XXX-XXX-XXX")
def test_user_level_count_is_zero_by_default(self): theuser = User("userA") self.assertEqual(theuser.levelCount(), 0)
def test_user_mod_level_is_user_by_default(self): theuser = User("userA") self.assertEqual(theuser.modlevel, MOD_LEVEL_USER)
def setUp(self): self.test_owner = User("test_owner", MOD_LEVEL_OWNER) self.test_processor = Processor(self.test_owner)