Пример #1
0
    def test_module_instance(self):
        self.assertTrue(wordfilter.blacklisted('this string contains mustard.'))

        wordfilter.clear_list()
        self.assertFalse(wordfilter.blacklisted('this string contains mustard.'))

        wordfilter.add_words(['custom'])
        self.assertTrue(wordfilter.blacklisted('you can use a custom blacklist.'))

        wordfilter.remove_words(['custom'])
        self.assertFalse(wordfilter.blacklisted('custom'))
Пример #2
0
def wf_checker(tweet):
    try:
        if wordfilter.blacklisted(tweet.text):
            return False

    except AttributeError:
        try:
            if wordfilter.blacklisted(tweet['text']):
                return False

        except (KeyError, TypeError):
            pass

    return True
Пример #3
0
def wf_checker(tweet):
    try:
        if wordfilter.blacklisted(tweet.text):
            return False

    except AttributeError:
        try:
            if wordfilter.blacklisted(tweet['text']):
                return False

        except (KeyError, TypeError):
            pass

    return True
Пример #4
0
    async def on_message(self, message):
        if message.author.bot or message.content == "":
            return

        if wordfilter.blacklisted(message.content):
            await message.delete()
            cmd = self.bot.get_command('warn')
            ctx = await self.bot.get_context(message)
            await ctx.invoke(
                cmd,
                user=message.author,
                reason=
                f'Used a blacklisted word(s), message: `{message.content}`')

        channel = message.guild.get_channel(self.chatlog_channel)
        embed = discord.Embed(color=discord.Color.random())
        embed.timestamp = datetime.datetime.now()
        embed.add_field(name="Message Author",
                        value=message.author.mention,
                        inline=False)
        embed.add_field(name="Message Channel",
                        value=message.channel.mention,
                        inline=False)
        embed.add_field(name="Message:",
                        value=f"```{message.content}```",
                        inline=False)

        await channel.send(embed=embed)
        await self.log_message(message)
Пример #5
0
 def query_twitter(self, query):
     """Search Twitter for a phrase and return an object
     for each tweet that could be reformatted as an AMA.
     """
     if not self.twitter:
         return
     quoted = '"%s"' % query
     results = self.twitter.search(q=quoted)
     for tweet in results:
         text = tweet.text
         if text in self.already_seen:
             # Ignore this; we already have it as a potential.
             continue
         self.already_seen.add(text)
         if blacklisted(text):
             continue
         if 'AMA' in text or 'ask me anything' in text.lower():
             # Don't use an actual AMA or AMA joke.
             continue
         iama = IAMAExtractor.extract_iama(text, query)
         if not iama:
             # We couldn't actually turn this into an AMA lead-in.
             continue
         score, iama = iama
         yield dict(content=text, query=query, iama=iama, score=score)
Пример #6
0
def handle_message(message: twitch.chat.Message) -> None:

    try:
        with open(defs + message.sender + '.txt','r') as deffile:
            voiceid = deffile.read()
    except FileNotFoundError:
        random.seed(message.sender)
        voiceid = random.choice(voiceslist)
    random.seed(message.sender)
    color = random.choice(consolecolors) + "\u001b[1m"
    print(color +  message.sender + "\u001b[0m : "+ message.text)
    with open(defs + "nospeak" + '.txt','r') as speakfile:
        nospeak = speakfile.read()

    if wordfilter.blacklisted(message.text) == False:
        if message.text.startswith('Eli, '):
            try:
                fn = acapyla(message.text, voiceid)
            except:
                fn = acapyla("COMMAND ERROR IN PHONEME", voiceid)
            subprocess.Popen(['play', SOUNDS + fn + '.mp3'], shell=False, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
            subprocess.Popen([SH + "/sdischo.sh", message.sender+": "+message.text], shell=False, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
            subprocess.Popen(["notify-send", message.sender+": "+message.text], shell=False, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
        elif message.text.startswith('$voice'):
            rest = message.text.replace('$voice ','')
            if rest in voiceslist:
                with open(defs + message.sender + '.txt','w') as deffile:
                    deffile.write(rest)
                message.chat.send('Voice for ' + message.sender + ' changed to ' + rest + "!")
            else:
                message.chat.send('Invalid voice!')
        elif message.text.startswith('$nospeak'): # Please make this permission-based
            if message.sender == "eli_tv" or message.sender == "maddoxdragon":
                with open(defs + "nospeak" + '.txt','w') as speakfile:
                    speakfile.write("True")
                message.chat.send('TTS Disabled!')
        elif message.text.startswith('$speak'):
            if message.sender == "eli_tv" or message.sender == "maddoxdragon":
                with open(defs + "nospeak" + '.txt','w') as speakfile:
                    speakfile.write("False")
                message.chat.send('TTS Enabled!')
        elif message.text.startswith('$restart'):
            if message.sender == "eli_tv" or message.sender == "maddoxdragon":
                os.execl(sys.executable, sys.executable, *sys.argv)
        elif nospeak == "True":
            subprocess.Popen([SH + "/sdischo.sh", message.sender+": "+message.text], shell=False, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
        else:
            message.text = message.text.replace("IT","it")
            try:
                fn = acapyla(message.text, voiceid)
            except:
                fn = acapyla("COMMAND ERROR IN PHONEME", voiceid)
            if message.text.startswith('!!'):
                subprocess.Popen(['play', SOUNDS + fn + '.mp3', "tempo", "2"], shell=False, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
            else:
                subprocess.Popen(['play', SOUNDS + fn + '.mp3'], shell=False, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
            subprocess.Popen([SH + "/sdischo.sh", message.sender+": "+message.text], shell=False, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
    else:
        message.chat.send("I'm not going to say that. Stop it.")
Пример #7
0
def ok_to_tweet(m):
    # too long to tweet?
    if len(m) > 200:
        print("status is too long")
        return False
    # any bad words?
    elif wordfilter.blacklisted(m):
        print("found a bad word")
        return False
    else:
        return True
Пример #8
0
def isblacklisted(tweet):
    '''
    Checks if a given tweet contains a word blacklisted by WordFilter.

    Args:
        tweet (str/tweepy.Status/dict): A string, tweepy.Status object, or Status-like dict.

    Returns:
        bool
    '''
    try:
        return wordfilter.blacklisted(tweet.text)

    except AttributeError:
        try:
            return wordfilter.blacklisted(tweet['text'])

        except (KeyError, TypeError):
            return wordfilter.blacklisted(tweet)

    return False
Пример #9
0
def isblacklisted(tweet):
    '''
    Checks if a given tweet contains a word blacklisted by WordFilter.

    Args:
        tweet (str/tweepy.Status/dict): A string, tweepy.Status object, or Status-like dict.

    Returns:
        bool
    '''
    try:
        return wordfilter.blacklisted(tweet.text)

    except AttributeError:
        try:
            return wordfilter.blacklisted(tweet['text'])

        except (KeyError, TypeError):
            return wordfilter.blacklisted(tweet)

    return False
Пример #10
0
 def update_twitter(self):
     materials = set()
     for query in self.QUERIES:
         quoted = '"%s"' % query
         for tweet in self.twitter.search(q=quoted):
             text = tweet.text
             if blacklisted(text):
                 # If any part of the original tweet is blacklisted, don't
                 # take the risk of using part of it.
                 continue
             material = MaterialExtractor.extract_material(text, query)
             if material:
                 materials.add(material)
     return list(materials)
Пример #11
0
def create_team(*, user_id):
    if "name" not in flask.request.json:
        raise util.APIError(400, message="Please provide a team name.")

    # Validate team name
    name = flask.request.json["name"]
    if len(name) > TEAM_NAME_LENGTH or \
       profanity.contains_profanity(name) or \
       wordfilter.blacklisted(name) or \
       not TEAM_NAME_REGEX.match(name):
        raise util.APIError(
            400,
            message=
            "Invalid team name. Team name must begin with an upper or lower case ASCII letter and may only contain up to {} alphanumeric characters plus dashes and underscores."
            .format(TEAM_NAME_LENGTH))

    team_name = "Team " + name
    verification_code = secrets.token_hex(16)

    # Check if user is already on a team
    with model.engine.begin() as conn:
        if conn.execute(
                model.teams.select(
                    sqlalchemy.sql.func.lower(model.teams.c.name) ==
                    team_name.lower())).first():
            raise util.APIError(400, message="That team name is taken, sorry.")

        query = model.users.select((model.users.c.id == user_id)
                                   & (model.users.c.team_id != None))
        if conn.execute(query).first():
            raise util.APIError(400, message="You're already on a team.")

        try:
            team_id = conn.execute(model.teams.insert().values(
                name=team_name,
                verification_code=verification_code,
                leader_id=user_id,
            )).inserted_primary_key[0]
        except sqlalchemy.exc.IntegrityError:
            raise util.APIError(400, message="Duplicate team name.")

        conn.execute(model.users.update().values(
            team_id=team_id, ).where(model.users.c.id == user_id))

        return util.response_success({
            "team_id": team_id,
            "verification_code": verification_code,
        })
Пример #12
0
def is_valid_word(word):
    """

    Check if word is:
    - a 'bad word' (only words of oppresion,
    some profanity is ok) or if it is an http links
    - a link (https://)
    - a RT
    - an & (still finding out how to fix that)
    Return True if any of the above is true.

    >>> is_valid_p_o_s("Hello")
    Hello's part of speech:NN
    True
    >>> is_valid_p_o_s("And")
    And's part of speech:CC
    False
    >>> is_valid_word("bitch")
    False
    >>> is_valid_word("lovely")
    True
    >>> is_valid_word("http://mysite.com")
    False
    >>> is_valid_word("RT:")
    False

    """

    if wordfilter.blacklisted(word):
        return False

    if 'http' in word[:5]:
        return False

    if re.search(r"\bRT(\.|:|,|$)", word, re.IGNORECASE):
        return False

    if word == '&':
        return False

    return True
Пример #13
0
def is_valid_username(username):
    return len(username) <= USERNAME_LENGTH and \
        username and \
        not profanity.contains_profanity(username) and \
        not wordfilter.blacklisted(username) and \
        USERNAME_REGEX.match(username)
Пример #14
0
    # doesn't begin with a bracket (angle or square)
    'no_bracket': lambda prev, line: \
            not(any([line.startswith(ch) for ch in '[<'])),
    # isn't in title case
    'not_title_case': lambda prev, line: not(line.istitle()),
    # isn't title case when considering only longer words
    'not_mostly_title_case': lambda prev, line: \
        not(" ".join([w for w in line.split() if len(w) >= 4]).istitle()),
    # not more than 50% upper-case characters
    'not_mostly_upper': lambda prev, line: \
        (len([ch for ch in line if ch.isupper()]) / (len(line)+0.01)) < 0.5,
    # doesn't begin or end with a digit
    'not_number': lambda prev, line: \
            not(re.search("^\d", line)) and not(re.search("\d$", line)),
    # passes the wordfilter
    'wordfilter_ok': lambda prev, line: not(wordfilter.blacklisted(line))
}


def err(*args):
    print(*args, file=sys.stderr)


if __name__ == '__main__':

    # remove some terms from wordfilter because they were filtering large
    # numbers of inoffensive lines; added one because its presence in this
    # corpus is almost always questionable. (terms in rot13 as a kind of
    # content warning)
    wordfilter.remove_words([
        codecs.encode(item, "rot_13")
Пример #15
0
import offensive

with open ("/home/staeiou/bots/dystopedia/titles.txt", encoding="utf-8") as f:
    deltext = f.read()

deltext = deltext.replace(".", " ")
deltext = deltext.encode('ascii', 'ignore').decode('ascii')

deletion_model = markovify.NewlineText(deltext)

tweet = None
tweets = []
for i in range(250):
    title = deletion_model.make_short_sentence(90)
    if title is not None and not wordfilter.blacklisted(title) and offensive.tact(title):
        tweets.append(title)

tweets = sorted(tweets, key=len, reverse=True)
rand_num = random.randrange(0,25)

if tweets[rand_num] is not None:
    print(tweets[rand_num])

CONSUMER_KEY = twitter_login.CONSUMER_KEY
CONSUMER_SECRET = twitter_login.CONSUMER_SECRET
ACCESS_TOKEN = twitter_login.ACCESS_TOKEN
ACCESS_TOKEN_SECRET = twitter_login.ACCESS_TOKEN_SECRET

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)