Created
September 20, 2016 15:34
-
-
Save albertywu/7eade01b76610dd8b26a57a4c16085d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sniffer = require('twitter-sniffer')({ # TODO: implement module | |
| consumer_key: '...', # TODO: add key | |
| consumer_secret: '...', # TODO: add key | |
| access_token: '...', # TODO: add key | |
| access_token_secret: '...' # TODO: add key | |
| }) | |
| SNIFF_PHRASE = "Live on #Periscope" | |
| module.exports = (robot) -> | |
| users = [] | |
| # initialize redis brain, so we can cache following users | |
| robot.brain.on 'loaded', -> robot.brain.data.periscope = users | |
| robot.hear /peribot follow +(\S+)/i, (msg) -> | |
| user = msg.match[1] | |
| users = users | |
| .filter (u) -> u isnt user | |
| .concat [user] | |
| sniffer.reset().set({ | |
| users: users, | |
| text: SNIFF_PHRASE, | |
| callback: (user, text) -> peribot_say "#{user}: #{text}", 'general' | |
| }) | |
| msg.send "Started following #{ user }" | |
| robot.hear /peribot unfollow +(\S+)/i, (msg) -> | |
| user = msg.match[1] | |
| if user is 'all' | |
| users = [] | |
| msg.send "I am not following anyone." | |
| else | |
| users = users | |
| .filter (u) -> u isnt user | |
| msg.send "Unfollowed #{ user }" | |
| sniffer.listen({ | |
| users: users, | |
| text: SNIFF_PHRASE, | |
| callback: (user, text) -> peribot_say "#{user}: #{text}", 'general' | |
| }) | |
| robot.hear /peribot list/i, (msg) -> | |
| if cache.length > 0 | |
| msg.send "I am following #{ cache.join(', ') }" | |
| else | |
| msg.send "I am not following anyone." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment