Giter Site home page Giter Site logo

argumatronic / haskell-twitter-bot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pranavvishnu/haskell-twitter-bot

0.0 2.0 0.0 140 KB

A Twitter bot built in Haskell that tries to send an emotionally appropriate response to mentions.

License: MIT License

Haskell 100.00%

haskell-twitter-bot's Introduction

Haskell Twitter Bot by Pranav Vishnu Ramabhadran

What it is:

A Twitter bot. You can tweet from it, read the timeline, look for mentions etc. and respond. The fun stuff has to do with the responses since I've cooked up an "emotional response engine" (it isn't real if it doesn't have a buzzword-filled name) that basically tried to respond with appropriate enthusiasm/disdain depending on what you tweet at it. So saying "OMG I really love Harry Potter" would get an equally enthusaistic response, while saying something like "I hate the hunger games" would get an equally acerbic response. At the moment, I've just typed out a few random inputs this understands that have to do with Harry Potter and the Hunger Games, but this is built for efficiency with a large number of inputs since I'm using Tries for lookup.

How to use it:

First, you need to go to Twitter's Dev console from the account you want to use as a bot, and get the Consumer Key, Consumer Secret for your account. Then you'll also need to get an Access Token and Secret for this specific project. add those into the Main file in the places marked out for it.

Fire up GHCI and run :load Main. You might need to install http-conduit and authenticate-oauth before this. You also will need to install split and bytestring-trie. Type in timeline [username] to see the most recent 5 tweets from a specific user. Type in tweet [string] to tweet out whatever string you provide from your Twitter account. Even better (and most importantly), type in runMain to look at the 5 most recent mentions (this is arbitrary and could just respond to all mentions instead, or any other number) and respond to them automatically using the bot's special "emotional response engine". Make sure you tweet something new at the bot (preferably regarding Harry Potter or The Hunger Games) before running this (to avoid Tweitter API violations)!

How it works:

  1. Build up Tries for topics.txt, response.txt and emotions.txt. These files are simply Key-Value Pairs separated by commas. These tries will store trimmed, lowercase versions of these pairs stripped of common punctuation like periods, commas, question marks and exclamation marks at either end of the string.
  2. Hit Twitter's API for a list of most recent mentions. Only ask for mentions after the tweet with ID as saved in the file latest.txt or if it's empty, ID 1, hence returning all mentions.
  3. For each tweet:
    • Create a list of all the words in the tweet and every pair of words that occur together.
    • Read through this list, looking for a match in our topics trie. If we find a match, then we can build up an appropiate response using the response trie, else we just return a standard response saying that we couldn't understand the tweet.
    • If we find a match, now look through the same list of words, but check for words that map to an emotion score, thus building up an emotion score.
    • Using the emotion score and the tweet response, tweet out the appropriate response using the tweet function.

haskell-twitter-bot's People

Contributors

pranavvishnu avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.