Commit e0453204 authored by Andreas Nedbal's avatar Andreas Nedbal

Merge pull request #13 from nilsding/master

add support for tweeting
parents 832749b8 c86bb4ee
source "https://rubygems.org"
gem "Ruby-IRC"
gem "mumble-ruby"
\ No newline at end of file
gem "mumble-ruby"
gem 'twitter'
......@@ -8,23 +8,58 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.4.0)
buftok (0.2.0)
domain_name (0.5.20160310)
unf (>= 0.0.5, < 1.0.0)
equalizer (0.0.10)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
ffi (1.9.10)
hashie (3.4.2)
http (1.0.4)
addressable (~> 2.3)
http-cookie (~> 1.0)
http-form_data (~> 1.0.1)
http_parser.rb (~> 0.6.0)
http-cookie (1.0.2)
domain_name (~> 0.5)
http-form_data (1.0.1)
http_parser.rb (0.6.0)
i18n (0.7.0)
json (1.8.3)
memoizable (0.4.2)
thread_safe (~> 0.3, >= 0.3.1)
minitest (5.7.0)
multipart-post (2.0.0)
mumble-ruby (1.1.2)
activesupport
hashie
opus-ruby
ruby_protobuf
wavefile
naught (1.1.0)
opus-ruby (1.0.1)
ffi
ruby_protobuf (0.4.11)
simple_oauth (0.3.1)
thread_safe (0.3.5)
twitter (5.16.0)
addressable (~> 2.3)
buftok (~> 0.2.0)
equalizer (= 0.0.10)
faraday (~> 0.9.0)
http (~> 1.0)
http_parser.rb (~> 0.6.0)
json (~> 1.8)
memoizable (~> 0.4.0)
naught (~> 1.0)
simple_oauth (~> 0.3.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.2)
wavefile (0.6.0)
PLATFORMS
......@@ -33,3 +68,7 @@ PLATFORMS
DEPENDENCIES
Ruby-IRC
mumble-ruby
twitter
BUNDLED WITH
1.11.2
......@@ -23,6 +23,13 @@ mumble:
announce_joins: yes
twitter:
hashtag: 'myMumble'
consumer_key: ''
consumer_secret: ''
access_token: ''
access_token_secret: ''
help:
- command: "mumble"
description: "Send a message to the Mumble server (from IRC)"
......
......@@ -26,12 +26,23 @@ mumble = Mumble::Client.new(APP_CONFIG['mumble']['server'], APP_CONFIG['mumble']
conf.username = APP_CONFIG['mumble']['username']
end
# Optional: Twitter support (only if consumer key is given)
twitter_client = nil
unless APP_CONFIG['twitter']['consumer_key'].empty?
twitter_client = Twitter::REST::Client.new do |config|
config.consumer_key = APP_CONFIG['twitter']['consumer_key']
config.consumer_secret = APP_CONFIG['twitter']['consumer_secret']
config.access_token = APP_CONFIG['twitter']['access_token']
config.access_token_secret = APP_CONFIG['twitter']['access_token_secret']
end
end
irc = IRC.new(APP_CONFIG['irc']['nickname'],
APP_CONFIG['irc']['server'],
APP_CONFIG['irc']['port'],
APP_CONFIG['irc']['realname'])
def start(irc, mumble)
def start(irc, mumble, twitter_client)
#IRC
@irc_thread ||= Thread.new do
IRCEvent.add_callback('whoreply') do |event|
......@@ -175,6 +186,27 @@ def start(irc, mumble)
else
mumble.text_user(msg.actor, "Error: Invalid Channel '#{content}'")
end
when 'tweet'
if twitter_client.nil?
mumble.text_channel(mumble.current_channel, "Error: Twitter support is not enabled.")
next
end
tweet_text = content.strip
unless APP_CONFIG['twitter']['hashtag'].strip.empty?
tweet_text += " ##{APP_CONFIG['twitter']['hashtag'].strip}"
end
actual_length = tweet_text.gsub(%r(https?://\S+), 'x' * 23).length
if actual_length > 140
hashtag_length = APP_CONFIG['twitter']['hashtag'].strip.empty? ? 0 : APP_CONFIG['twitter']['hashtag'].strip.length + 2
mumble.text_channel(mumble.current_channel, "Tweet text too long, keep it under #{140 - hashtag_length} characters!"
next
end
begin
tweet = twitter_client.update tweet_text
mumble.text_channel(mumble.current_channel, "==> <a href=\"#{tweet.url}\">#{tweet.url}</a>"
rescue => e
mumble.text_channel(mumble.current_channel, "Error: Twitter returned an error -- <font face=\"Comic Sans MS\">#{e.message}</font>")
end
end
end
end # on_text_message
......@@ -230,4 +262,4 @@ def start(irc, mumble)
@mumble_thread.join
end
start(irc, mumble)
start(irc, mumble, twitter_client)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment