Bad Words Twitter Bot

PythonTwitter API

The specific words that people choose to use can provide insight into their background and character. Although reasonable people can vehemently disagree, a good indicator of mutual respect between two parties is that neither resorts to vulgarity. Inspired by other bots on platforms like Reddit and Discord that could provide information on the language that users have used and play a part in keeping online discussion civil, I set out to create a Twitter bot that when called upon by a Twitter user would provide information on vulgarities that a requested user had recently tweeted.

I wrote the bot in Python, following basic online video tutorials that detailed how to work with the Twitter API through the Python library tweepy. Although these tutorials showed me how to detect when a user had @ mentioned the bot and how to respond to tweets, the real challenge and substance of this bot came from accessing another user's tweets, parsing through them to find bad words, and reporting the frequency of these bad words within the 280-character limit of a Tweet.

After finding separate answers on how to access a given user's tweets, I got to work on detecting bad words. Although I found several GitHub repos that contained lists of bad words, many were too comprehensive, marking even words with possible negative connotations, like the names of political parties, as bad. I eventually settled on a list of 444 common words collected by Google. This list was comprehensive enough to cover most bad word, and even common variations like swapping a letter for a number. On the implementation side, I took advantage of Python's built in dictionary functionality to find matching bad words in a user's 100 most recent tweets and rank them by frequency.

The bot's Twitter handle is @BadWordCount. Go ahead and try it out on some of your favorite twitter users. The tweet shown above is from a movie starring Jason Bateman. The code that the bot is running is on my GitHub. The bot is currently not deployed. I hope to find a long term, affordable, and reliable deployment solution.