├── .gitignore ├── bg.png ├── gosu.bundle ├── config.yml.example ├── README.textile └── metatweet.rb /.gitignore: -------------------------------------------------------------------------------- 1 | config.yml 2 | .DS_Store -------------------------------------------------------------------------------- /bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/al3x/metatweet/master/bg.png -------------------------------------------------------------------------------- /gosu.bundle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/al3x/metatweet/master/gosu.bundle -------------------------------------------------------------------------------- /config.yml.example: -------------------------------------------------------------------------------- 1 | jabber: 2 | jid: username@your.jabber.server 3 | password: yourpassword 4 | fullscreen: false -------------------------------------------------------------------------------- /README.textile: -------------------------------------------------------------------------------- 1 | h1. MetaTweet 2 | 3 | Twitter tracking Twitter on Twitter. 4 | 5 | h2. Requirements 6 | 7 | * Ruby 1.8.6 (might work on other versions) 8 | * xmpp4r-simple 9 | 10 | h2. Setup 11 | 12 | # Create a Twitter account. 13 | # Create a Jabber account. 14 | # Set up your Jabber account as a device for your Twitter account. 15 | # Send "track twitter" to the twitter@twiter.com Jabber bot. 16 | # Run metatweet.rb. 17 | # Soak up the zeitgeist. -------------------------------------------------------------------------------- /metatweet.rb: -------------------------------------------------------------------------------- 1 | %w( rubygems yaml xmpp4r-simple gosu htmlentities).each { |g| require g } 2 | include Gosu 3 | 4 | CONFIG = YAML.load_file 'config.yml' 5 | 6 | class Message 7 | #%w( body x y z alpha fontsize ).each { |at| attr_accessor at.to_sym } 8 | attr_accessor :body, :x, :y, :z, :alpha, :fontsize, :created_at 9 | 10 | def initialize(body, x=nil, y=nil) 11 | @body = HTMLEntities.new.decode body.split(':')[1] 12 | 13 | @x = x ? x : rand(100) 14 | @y = y ? y : rand(700) 15 | @z = 1 + rand(10) 16 | 17 | @alpha = 255 18 | @fontsize = 14 + rand(18) 19 | 20 | @created_at = Time.now 21 | end 22 | 23 | def age_in_seconds 24 | (Time.now - @created_at).floor 25 | end 26 | 27 | def degrade_alpha 28 | return @alpha if self.age_in_seconds < 45 29 | return @alpha if @alpha == 1 30 | @alpha = @alpha - 1 31 | end 32 | end 33 | 34 | class JabberStream 35 | def initialize 36 | @im = Jabber::Simple.new(CONFIG['jabber']['jid'], CONFIG['jabber']['password']) 37 | @im.status(:chat, 'tweet at me brah') 38 | @im.deliver('twitter@twitter.com', 'on') 39 | end 40 | 41 | def messages(&block) 42 | @im.received_messages { |msg| yield msg if msg.type == :chat } 43 | end 44 | end 45 | 46 | class TweetWindow < Gosu::Window 47 | def initialize 48 | super(1024, 768, CONFIG['fullscreen'], 20) 49 | self.caption = 'MetaTweet' 50 | 51 | @background_image = Gosu::Image.new(self, "bg.png", false) 52 | @jabber = JabberStream.new 53 | @messages = Array.new 54 | end 55 | 56 | def update 57 | @messages = Array.new if button_down?(Gosu::Button::MsLeft) 58 | 59 | @jabber.messages do |msg| 60 | @messages.shift if @messages.size > 10 61 | @messages << Message.new(msg.body) 62 | end 63 | end 64 | 65 | def draw 66 | @background_image.draw(0, 0, 0, 2, 2); 67 | 68 | @messages.each do |msg| 69 | t = Gosu::Image.from_text(self, msg.body, "Helvetica", msg.fontsize, 10, 800, :left) 70 | t.draw(msg.x, msg.y, msg.z, 1, 1, Gosu::Color.new(msg.degrade_alpha, 0, 83, 65)) 71 | end 72 | end 73 | end 74 | 75 | TweetWindow.new.show 76 | --------------------------------------------------------------------------------