Example #1
0
	def remove_ban(self, current_server, unban_str, author):
		requested_index = [ind for ind, ban in enumerate(current_server.banned_words) if is_confusable(unban_str, ban.banned_word)]
		if not len(requested_index):
			return "Sorry, I couldn't find a matching word to unban."
		unbanned_word = current_server.unban_word(requested_index[0])
		if unbanned_word:
			return "Ok {}, '{}' is no longer considered a forbidden word.".format(author.mention, unbanned_word)
		return "Sorry, I couldn't unban that word. You may have tried to unban your only banned word."
Example #2
0
    def post_one(self, session, authToken, serverid: str, banid: str,
                 banned_word: str) -> dict:
        try:
            serverid = int(serverid)
            banid = int(banid)
        except ValueError:
            raise InvalidTypeError

        if not authenticateBotOrServerAdmin(serverid, authToken):
            raise AuthenticationError
        if not isinstance(banned_word, str):
            raise InvalidTypeError
        server_to_modify = session.query(Server).filter_by(
            server_id=serverid).first()
        if not server_to_modify:
            raise NotFoundError

        if (len(server_to_modify.banned_words) >
                server_to_modify.get_plan().bannings_allowed):
            raise PlanError

        ban_to_modify = (session.query(Ban).filter_by(server_id=serverid,
                                                      rowid=banid).first())
        record_to_modify = session.query(BanRecord).filter_by(
            ban_id=banid).first()
        if not ban_to_modify or not record_to_modify:
            raise NotFoundError

        already_exists = any([
            is_confusable(banned_word, ban.banned_word)
            for ban in server_to_modify.banned_words
        ])
        if already_exists:
            raise DuplicateResourceError

        ban_to_modify.banned_word = banned_word
        ban_to_modify.infracted_at = datetime.now().strftime(
            "%Y-%m-%d %H:%M:%S")
        ban_to_modify.calledout_at = (
            datetime.now() - timedelta(weeks=52)).strftime("%Y-%m-%d %H:%M:%S")
        record_to_modify.reinitialize()

        return self.get_one(session, authToken, banid)
Example #3
0
    def post_collection(self, session, authToken, serverid: int,
                        banned_word: str) -> dict:
        try:
            serverid = int(serverid)
        except ValueError:
            raise InvalidTypeError

        if not authenticateBotOrServerAdmin(serverid, authToken):
            raise AuthenticationError
        if not isinstance(banned_word, str):
            raise InvalidTypeError

        server_to_modify = session.query(Server).filter_by(
            server_id=serverid).first()
        if not server_to_modify:
            raise NotFoundError

        if (len(server_to_modify.banned_words) >=
                server_to_modify.get_plan().bannings_allowed):
            raise PlanError

        already_exists = any([
            is_confusable(banned_word, ban.banned_word)
            for ban in server_to_modify.banned_words
        ])
        if already_exists:
            raise DuplicateResourceError

        new_ban = Ban(
            server_id=serverid,
            banned_word=banned_word,
            infracted_at=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
            calledout_at=(datetime.now() -
                          timedelta(weeks=52)).strftime("%Y-%m-%d %H:%M:%S"),
        )
        new_record = BanRecord(server_banned_word=new_ban)

        session.add(new_ban)
        session.add(new_record)
        return (session.query(Ban).filter_by(
            server_id=serverid, banned_word=banned_word).first().to_dict())
Example #4
0
 def check(self, name: str, ip_addr: str) -> bool:
     """Check if a given name is using a forbidden ip address"""
     if not self.settings.get("ipinfo_token") or self.settings.get(
             "ipinfo_token") == "":
         return True
     entrys = self.read()
     if not entrys:
         return True
     for entry in entrys:
         if not is_confusable(self.strip_null_chars(name), entry["name"]):
             continue
         data = self.ip_handler.getDetails(ip_addr)
         if not hasattr(data, "region"):
             return True
         region = data.region
         if region != entry["region"]:
             echo(
                 "[locked-names] region missmatch '" + \
                 str(region) + "' != '" + str(entry["region"]) + "'"
                 )
             return False
         return True
     return True
Example #5
0
 def test_is_confusable__unicode_mapping_only(self):
     self.assertTrue(is_confusable('rover', 'ฦฆแป๐•3โ„›'))
Example #6
0
 def test_is_confusable__empty_input(self):
     self.assertTrue(is_confusable('', ''))
     self.assertFalse(is_confusable('rover is my favourite dog', ''))
     self.assertFalse(is_confusable('', 'rover is my favourite dog'))
Example #7
0
 def test_is_confusable__None_input(self):
     self.assertTrue(is_confusable(None, None))
     self.assertFalse(is_confusable('rover is my favourite dog', None))
     self.assertFalse(is_confusable(None, 'rover is my favourite dog'))
Example #8
0
 def test_is_confusable__prefix_does_not_give_false_positive(self):
     self.assertFalse(is_confusable('ฦฆแป๐•3โ„›', 'rover is my favourite dog'))
     self.assertFalse(is_confusable('rover is my favourite dog', 'ฦฆแป๐•3โ„›'))
Example #9
0
 def test_is_confusable__not_remotely_similar_words(self):
     self.assertFalse(is_confusable('ฦฆแป๐•3โ„›', 'salmon'))
     self.assertFalse(is_confusable('salmon', 'ฦฆแป๐•3โ„›'))
Example #10
0
 def test_is_confusable__multi_character_mapping(self):
     self.assertTrue(is_confusable('ฦฆแป๐•3โ„›', 'ro\'ver'))
     self.assertTrue(is_confusable('ro\'ver', 'ฦฆแป๐•3โ„›'))