Skip to content
Browse files

Merge pull request #2 from Wonderbread/master

Twitter plugin
  • Loading branch information...
2 parents 79e99c2 + 0c70a4f commit c34a34800517dc7b87a31919a5ea357316152450 Ashley Towns committed Jan 20, 2012
Showing with 27 additions and 2 deletions.
  1. +1 −2 Gemfile
  2. +1 −0 plugins/twitter-plugin/Gemfile
  3. +5 −0 plugins/twitter-plugin/twitter-plugin.yml
  4. +20 −0 plugins/twitter-plugin/twitter.rb
View
3 Gemfile
@@ -5,7 +5,6 @@ gem "thin", "~>1.3.1"
gem "daemons", "~>1.1.6"
gem "colorize", "~>0.5.8"
-# Handles the installing of the gems in the Gemfiles of plugins
Dir.glob(File.join(File.dirname(__FILE__), 'plugins', '**', "Gemfile")) do |gemfile|
self.send(:eval, File.open(gemfile, 'r').read)
-end
+end
View
1 plugins/twitter-plugin/Gemfile
@@ -0,0 +1 @@
+gem "twitter", "~> 2.0.2"
View
5 plugins/twitter-plugin/twitter-plugin.yml
@@ -0,0 +1,5 @@
+Name: Twitter
+Author: Rob Mcfadzean <root@sphericalcube.net>
+Version: 0.2
+Type: Channel
+Files: [ twitter.rb ]
View
20 plugins/twitter-plugin/twitter.rb
@@ -0,0 +1,20 @@
+# encoding: UTF-8
+require 'twitter'
+
+class TwitterPlugin < Mirai::Plugin
+ def on_register
+ add_channel_handler(/https?:\/\/twitter.com\/.*\/statuse?s?\/([0-9]{0,20})/, :tweet_handler, :trigger => :none)
+ end
+
+ def tweet_handler info, id
+ begin
+ t = Twitter.status id
+ screen_name, name, text = t.user.screen_name, t.user.name, t.text
+ action info[:chan], "@#{screen_name} (#{name}) => #{text}"
+ rescue Twitter::Error::Forbidden
+ msg info[:chan], "This tweet is private"
+ rescue Twitter::Error::NotFound
+ msg info[:chan], "No tweet with that ID"
+ end
+ end
+end

0 comments on commit c34a348

Please sign in to comment.
Something went wrong with that request. Please try again.